nolman-jetty-rails 0.9.6-jruby
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/History.txt +49 -0
- data/Licenses.txt +37 -0
- data/Manifest.txt +51 -0
- data/PostInstall.txt +2 -0
- data/README.rdoc +130 -0
- data/Rakefile +27 -0
- data/TODO.txt +11 -0
- data/bin/jetty_merb +41 -0
- data/bin/jetty_rails +41 -0
- data/jetty-libs/core-3.1.1.jar +0 -0
- data/jetty-libs/jetty-6.1.14.jar +0 -0
- data/jetty-libs/jetty-plus-6.1.14.jar +0 -0
- data/jetty-libs/jetty-util-6.1.14.jar +0 -0
- data/jetty-libs/jsp-2.1.jar +0 -0
- data/jetty-libs/jsp-api-2.1.jar +0 -0
- data/jetty-libs/servlet-api-2.5-6.1.14.jar +0 -0
- data/lib/jetty_rails.rb +26 -0
- data/lib/jetty_rails/adapters/abstract_adapter.rb +25 -0
- data/lib/jetty_rails/adapters/merb_adapter.rb +34 -0
- data/lib/jetty_rails/adapters/rails_adapter.rb +22 -0
- data/lib/jetty_rails/adapters/rails_jms_adapter.rb +104 -0
- data/lib/jetty_rails/config/command_line_reader.rb +75 -0
- data/lib/jetty_rails/config/rdoc_fix.rb +28 -0
- data/lib/jetty_rails/handler/delegate_on_errors_handler.rb +29 -0
- data/lib/jetty_rails/handler/public_directory_handler.rb +24 -0
- data/lib/jetty_rails/handler/web_app_handler.rb +85 -0
- data/lib/jetty_rails/jars.rb +36 -0
- data/lib/jetty_rails/runner.rb +46 -0
- data/lib/jetty_rails/server.rb +79 -0
- data/lib/jetty_rails/warbler_reader.rb +13 -0
- data/lib/jruby-rack-0.9.7-SNAPSHOT.jar +0 -0
- data/script/console +10 -0
- data/script/destroy +14 -0
- data/script/generate +14 -0
- data/script/txt2html +71 -0
- data/spec/config.yml +28 -0
- data/spec/jetty_merb_spec.rb +195 -0
- data/spec/jetty_rails/config_file_spec.rb +68 -0
- data/spec/jetty_rails/handler/delegate_on_errors_handler_spec.rb +29 -0
- data/spec/jetty_rails/runner_spec.rb +162 -0
- data/spec/jetty_rails_sample_1.yml +13 -0
- data/spec/jetty_rails_sample_2.yml +28 -0
- data/spec/jetty_rails_spec.rb +195 -0
- data/spec/spec.opts +2 -0
- data/spec/spec_helper.rb +12 -0
- data/tasks/jruby.rake +7 -0
- data/tasks/rspec.rake +49 -0
- data/website/index.txt +194 -0
- data/website/javascripts/rounded_corners_lite.inc.js +285 -0
- data/website/stylesheets/screen.css +159 -0
- data/website/template.html.erb +56 -0
- metadata +174 -0
@@ -0,0 +1,34 @@
|
|
1
|
+
module JettyRails
|
2
|
+
module Adapters
|
3
|
+
|
4
|
+
class MerbAdapter < AbstractAdapter
|
5
|
+
|
6
|
+
def init_params
|
7
|
+
# please refer to goldspike and jruby-rack documentation
|
8
|
+
@merb_params ||= {
|
9
|
+
'merb.root' => '/',
|
10
|
+
'merb.environment' => config[:environment]
|
11
|
+
}.merge(base_init_params)
|
12
|
+
end
|
13
|
+
|
14
|
+
def event_listeners
|
15
|
+
[ Rack::MerbServletContextListener.new, SignalHandler.new ]
|
16
|
+
end
|
17
|
+
|
18
|
+
class SignalHandler
|
19
|
+
include Java::JavaxServlet::ServletContextListener
|
20
|
+
|
21
|
+
def contextInitialized(cfg)
|
22
|
+
trap("INT") do
|
23
|
+
puts "\nbye!"
|
24
|
+
java.lang.System.exit(0)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def contextDestroyed(cfg)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module JettyRails
|
2
|
+
module Adapters
|
3
|
+
|
4
|
+
class RailsAdapter < AbstractAdapter
|
5
|
+
|
6
|
+
def init_params
|
7
|
+
# please refer to goldspike and jruby-rack documentation
|
8
|
+
# in: PoolingRackApplicationFactory
|
9
|
+
@rails_params ||= {
|
10
|
+
'rails.root' => '/',
|
11
|
+
'rails.env' => config[:environment]
|
12
|
+
}.merge(base_init_params)
|
13
|
+
end
|
14
|
+
|
15
|
+
def event_listeners
|
16
|
+
[ Rack::RailsServletContextListener.new ]
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,104 @@
|
|
1
|
+
module JettyRails
|
2
|
+
module Adapters
|
3
|
+
|
4
|
+
# This adapter extends the standard Rails adapter with
|
5
|
+
# an additional listener for JMS queues
|
6
|
+
class RailsJmsAdapter < RailsAdapter
|
7
|
+
|
8
|
+
# Defaults to expecting OpenMQ jars in lib_dir/jms_dir at startup
|
9
|
+
@@defaults = {
|
10
|
+
:jms_dir => "jms",
|
11
|
+
:queue_name => "rails_queue",
|
12
|
+
:mq_host => "localhost",
|
13
|
+
:mq_port => 7676
|
14
|
+
}
|
15
|
+
|
16
|
+
def initialize(config)
|
17
|
+
super @@defaults.merge(config)
|
18
|
+
require_jms_jars()
|
19
|
+
end
|
20
|
+
|
21
|
+
def event_listeners
|
22
|
+
super << Rack::JMS::QueueContextListener.new(queue_manager_factory())
|
23
|
+
end
|
24
|
+
|
25
|
+
def queue_manager_factory
|
26
|
+
factory = jndiless_default_queue_manager_factory_class()
|
27
|
+
factory.queue_name = config[:queue_name]
|
28
|
+
factory.mq_host = config[:mq_host]
|
29
|
+
factory.mq_port = config[:mq_port]
|
30
|
+
factory.new
|
31
|
+
end
|
32
|
+
|
33
|
+
protected
|
34
|
+
|
35
|
+
def jms_jars_path
|
36
|
+
File.join(config[:base], config[:lib_dir], config[:jms_dir])
|
37
|
+
end
|
38
|
+
|
39
|
+
def require_jms_jars
|
40
|
+
Dir["#{self.jms_jars_path}/*.jar"].each {|jar| require jar }
|
41
|
+
end
|
42
|
+
|
43
|
+
# JRuby Rack's DefaultQueueManager uses JNDI for discovery
|
44
|
+
# JNDI is overkill for embedded servers like Jetty Rails
|
45
|
+
#
|
46
|
+
# This method returns a custom Rack::JMS::QueueManagerFactory
|
47
|
+
# which produces a JNDI-less Rack::JMS::DefaultQueueManager
|
48
|
+
def jndiless_default_queue_manager_factory_class
|
49
|
+
factory_class = Class.new
|
50
|
+
factory_class.send :cattr_accessor, :queue_name, :mq_host, :mq_port
|
51
|
+
|
52
|
+
# Implement Rack::JMS::QueueManagerFactory Interface
|
53
|
+
factory_class.send :include, Rack::JMS::QueueManagerFactory
|
54
|
+
factory_class.module_eval(<<-EOS)
|
55
|
+
|
56
|
+
def newQueueManager
|
57
|
+
manager_class = Class.new Rack::JMS::DefaultQueueManager
|
58
|
+
|
59
|
+
manager_class.send :field_accessor, :context,
|
60
|
+
:connectionFactory
|
61
|
+
|
62
|
+
manager_class.send :attr_accessor, :queue_name, :mq_host, :mq_port
|
63
|
+
|
64
|
+
# Overrides JNDI parts of DefaultQueueManager
|
65
|
+
manager_class.module_eval do
|
66
|
+
|
67
|
+
# Overrides in order to initialize connection factory w/o JNDI
|
68
|
+
def init(context)
|
69
|
+
self.context = context
|
70
|
+
unless self.connectionFactory
|
71
|
+
import "com.sun.messaging.ConnectionFactory"
|
72
|
+
factory = com.sun.messaging.ConnectionFactory.new
|
73
|
+
config = com.sun.messaging.ConnectionConfiguration
|
74
|
+
factory.setProperty(config.imqAddressList, "mq://" + self.mq_host + ":" + self.mq_port.to_s)
|
75
|
+
self.connectionFactory = factory
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
# Overrides in order to perform lookup of queue w/o JNDI
|
80
|
+
def lookup(name)
|
81
|
+
if name == self.queue_name
|
82
|
+
@jndiless_queue ||= com.sun.messaging.Queue.new(self.queue_name)
|
83
|
+
else
|
84
|
+
super(name)
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
end
|
89
|
+
|
90
|
+
returning manager_class.new do |m|
|
91
|
+
m.queue_name = self.class.queue_name
|
92
|
+
m.mq_host = self.class.mq_host
|
93
|
+
m.mq_port = self.class.mq_port
|
94
|
+
end
|
95
|
+
end
|
96
|
+
EOS
|
97
|
+
|
98
|
+
factory_class
|
99
|
+
end
|
100
|
+
|
101
|
+
end
|
102
|
+
|
103
|
+
end
|
104
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
require 'getoptlong'
|
2
|
+
require 'jetty_rails/config/rdoc_fix'
|
3
|
+
|
4
|
+
|
5
|
+
class CommandLineReader
|
6
|
+
|
7
|
+
def default_config()
|
8
|
+
@@config ||= {
|
9
|
+
:rails => {
|
10
|
+
:base => Dir.pwd,
|
11
|
+
:port => 3000,
|
12
|
+
:config_file => "#{File.join(Dir.pwd, 'config', 'jetty_rails.yml')}",
|
13
|
+
:adapter => :rails,
|
14
|
+
:environment => "development"
|
15
|
+
},
|
16
|
+
:merb => {
|
17
|
+
:base => Dir.pwd,
|
18
|
+
:port => 4000,
|
19
|
+
:config_file => "#{File.join(Dir.pwd, 'config', 'jetty_merb.yml')}",
|
20
|
+
:adapter => :merb
|
21
|
+
}
|
22
|
+
}
|
23
|
+
end
|
24
|
+
|
25
|
+
def read(default_adapter = :rails)
|
26
|
+
config = default_config[default_adapter]
|
27
|
+
|
28
|
+
opts = GetoptLong.new(
|
29
|
+
[ '--version', '-v', GetoptLong::NO_ARGUMENT ],
|
30
|
+
[ '--help', '-h', GetoptLong::NO_ARGUMENT ],
|
31
|
+
[ '--context-path', '-u', GetoptLong::REQUIRED_ARGUMENT ],
|
32
|
+
[ '--port', '-p', GetoptLong::REQUIRED_ARGUMENT ],
|
33
|
+
[ '--environment', '-e', GetoptLong::REQUIRED_ARGUMENT ],
|
34
|
+
[ '--lib', '--jars', GetoptLong::REQUIRED_ARGUMENT ],
|
35
|
+
[ '--classes', GetoptLong::REQUIRED_ARGUMENT ],
|
36
|
+
[ '--config', '-c', GetoptLong::OPTIONAL_ARGUMENT ]
|
37
|
+
)
|
38
|
+
|
39
|
+
opts.each do |opt, arg|
|
40
|
+
case opt
|
41
|
+
when '--version'
|
42
|
+
require 'jetty_rails/version'
|
43
|
+
puts "JettyRails version #{JettyRails::VERSION::STRING} - http://jetty-rails.rubyforge.org"
|
44
|
+
exit(0)
|
45
|
+
when '--help'
|
46
|
+
RDoc::usage
|
47
|
+
when '--context-path'
|
48
|
+
config[:context_path] = arg
|
49
|
+
when '--port'
|
50
|
+
config[:port] = arg.to_i
|
51
|
+
when '--environment'
|
52
|
+
config[:environment] = arg
|
53
|
+
when '--classes'
|
54
|
+
config[:classes_dir] = arg
|
55
|
+
when '--lib'
|
56
|
+
config[:lib_dir] = arg
|
57
|
+
when '--config'
|
58
|
+
config[:config_file] = arg if !arg.nil? && arg != ""
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
config[:base] = ARGV.shift unless ARGV.empty?
|
63
|
+
|
64
|
+
if File.exists?(config[:config_file])
|
65
|
+
config_file = YAML.load_file(config[:config_file])
|
66
|
+
config.merge!(config_file[config[:environment]] || config_file) # check for env scope
|
67
|
+
puts "Loaded #{config[:config_file]}"
|
68
|
+
end
|
69
|
+
|
70
|
+
config
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
74
|
+
|
75
|
+
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'rdoc/usage'
|
2
|
+
|
3
|
+
# fix to work with rubygems (use current file instead of main)
|
4
|
+
def RDoc.usage_no_exit(*args)
|
5
|
+
comment = File.open(File.join(File.dirname(__FILE__), %w(.. .. .. bin), File.basename($0))) do |file|
|
6
|
+
find_comment(file)
|
7
|
+
end
|
8
|
+
|
9
|
+
comment = comment.gsub(/^\s*#/, '')
|
10
|
+
|
11
|
+
markup = SM::SimpleMarkup.new
|
12
|
+
flow_convertor = SM::ToFlow.new
|
13
|
+
|
14
|
+
flow = markup.convert(comment, flow_convertor)
|
15
|
+
|
16
|
+
format = "plain"
|
17
|
+
|
18
|
+
unless args.empty?
|
19
|
+
flow = extract_sections(flow, args)
|
20
|
+
end
|
21
|
+
|
22
|
+
options = RI::Options.instance
|
23
|
+
if args = ENV["RI"]
|
24
|
+
options.parse(args.split)
|
25
|
+
end
|
26
|
+
formatter = options.formatter.new(options, "")
|
27
|
+
formatter.display_flow(flow)
|
28
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module JettyRails
|
2
|
+
module Handler
|
3
|
+
|
4
|
+
class DelegateOnErrorsResponse
|
5
|
+
include Java::JavaxServletHttp::HttpServletResponse
|
6
|
+
|
7
|
+
def initialize(original, request)
|
8
|
+
@original = original
|
9
|
+
@request = request
|
10
|
+
end
|
11
|
+
|
12
|
+
def sendError(status_code)
|
13
|
+
@request.handled = false
|
14
|
+
end
|
15
|
+
|
16
|
+
def method_missing(method, *args, &blk)
|
17
|
+
@original.send(method, *args, &blk)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
class DelegateOnErrorsHandler < Jetty::Handler::HandlerWrapper
|
22
|
+
def handle(target, request, response, dispatch)
|
23
|
+
decorated_response = DelegateOnErrorsResponse.new(response, request)
|
24
|
+
self.handler.handle(target, request, decorated_response, dispatch)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
|
2
|
+
module JettyRails
|
3
|
+
module Handler
|
4
|
+
class PublicDirectoryHandler < JettyRails::Handler::DelegateOnErrorsHandler
|
5
|
+
|
6
|
+
def initialize(config)
|
7
|
+
super()
|
8
|
+
@config = config
|
9
|
+
@resources = Jetty::Handler::ResourceHandler.new
|
10
|
+
@resources.resource_base = @config[:base] + '/public'
|
11
|
+
context_capable = add_context_capability_to @resources
|
12
|
+
self.handler = context_capable
|
13
|
+
end
|
14
|
+
|
15
|
+
def add_context_capability_to(handler)
|
16
|
+
return handler if @config[:context_path].root?
|
17
|
+
context_handler = Jetty::Handler::ContextHandler.new(@config[:context_path])
|
18
|
+
context_handler.handler = handler
|
19
|
+
context_handler
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,85 @@
|
|
1
|
+
module JettyRails
|
2
|
+
module Handler
|
3
|
+
class WebAppHandler < Jetty::Handler::WebAppContext
|
4
|
+
attr_reader :config, :adapter
|
5
|
+
|
6
|
+
def initialize(config)
|
7
|
+
super("/", config[:context_path])
|
8
|
+
@config = config
|
9
|
+
|
10
|
+
self.class_loader = each_context_has_its_own_classloader
|
11
|
+
self.resource_base = "#{config[:base]}/public"
|
12
|
+
self.descriptor = config[:web_xml]
|
13
|
+
|
14
|
+
add_classes_dir_to_classpath(config)
|
15
|
+
add_lib_dir_jars_to_classpath(config)
|
16
|
+
|
17
|
+
@adapter = adapter_for(config[:adapter])
|
18
|
+
self.init_params = @adapter.init_params
|
19
|
+
|
20
|
+
unless File.exist?(self.descriptor)
|
21
|
+
@adapter.event_listeners.each do |listener|
|
22
|
+
add_event_listener(listener)
|
23
|
+
end
|
24
|
+
|
25
|
+
add_filter(rack_filter, "/*", Jetty::Context::DEFAULT)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.add_adapter(adapter_key, adapter)
|
30
|
+
adapters[adapter_key] = adapter
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.adapters
|
34
|
+
@adapters ||= {
|
35
|
+
:rails => JettyRails::Adapters::RailsAdapter,
|
36
|
+
:rails_jms => JettyRails::Adapters::RailsJmsAdapter,
|
37
|
+
:merb => JettyRails::Adapters::MerbAdapter
|
38
|
+
}
|
39
|
+
end
|
40
|
+
|
41
|
+
def adapters
|
42
|
+
self.class.adapters
|
43
|
+
end
|
44
|
+
|
45
|
+
alias :get_from_public_otherwise :getResource
|
46
|
+
|
47
|
+
def getResource(resource)
|
48
|
+
return fix_for_base_url if resource == '/'
|
49
|
+
get_from_public_otherwise resource
|
50
|
+
end
|
51
|
+
|
52
|
+
protected
|
53
|
+
def rack_filter
|
54
|
+
Jetty::FilterHolder.new(Rack::RackFilter.new)
|
55
|
+
end
|
56
|
+
|
57
|
+
def adapter_for(kind)
|
58
|
+
adapters[kind.to_sym].new(@config)
|
59
|
+
end
|
60
|
+
|
61
|
+
private
|
62
|
+
def fix_for_base_url
|
63
|
+
Jetty::FileResource.new(java.io.File.new(config[:base]).to_url)
|
64
|
+
end
|
65
|
+
|
66
|
+
def add_lib_dir_jars_to_classpath(config)
|
67
|
+
lib_dir = "#{config[:base]}/#{config[:lib_dir]}/**/*.jar"
|
68
|
+
Dir[lib_dir].each do |jar|
|
69
|
+
url = java.io.File.new(jar).to_url
|
70
|
+
self.class_loader.add_url(url)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
def add_classes_dir_to_classpath(config)
|
75
|
+
classes_dir = "#{config[:base]}/#{config[:classes_dir]}"
|
76
|
+
url = java.io.File.new(classes_dir).to_url
|
77
|
+
self.class_loader.add_url(url)
|
78
|
+
end
|
79
|
+
|
80
|
+
def each_context_has_its_own_classloader()
|
81
|
+
org.jruby.util.JRubyClassLoader.new(JRuby.runtime.jruby_class_loader)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module JettyRails
|
2
|
+
|
3
|
+
require "servlet-api-2.5-6.1.14"
|
4
|
+
require "jetty-6.1.14"
|
5
|
+
require "jetty-util-6.1.14"
|
6
|
+
require "jetty-plus-6.1.14"
|
7
|
+
require "core-3.1.1"
|
8
|
+
require "jsp-api-2.1"
|
9
|
+
require "jsp-2.1"
|
10
|
+
|
11
|
+
module Jetty
|
12
|
+
include_package "org.mortbay.jetty"
|
13
|
+
include_package "org.mortbay.jetty.servlet"
|
14
|
+
include_package "org.mortbay.jetty.nio"
|
15
|
+
include_package "org.mortbay.resource"
|
16
|
+
module Handler
|
17
|
+
include_package "org.mortbay.jetty.handler"
|
18
|
+
include_package "org.mortbay.jetty.webapp"
|
19
|
+
end
|
20
|
+
module Thread
|
21
|
+
include_package "org.mortbay.thread"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
require "jruby-rack-0.9.7-SNAPSHOT"
|
26
|
+
module Rack
|
27
|
+
include_package "org.jruby.rack"
|
28
|
+
include_package "org.jruby.rack.rails"
|
29
|
+
include_package "org.jruby.rack.merb"
|
30
|
+
|
31
|
+
module JMS
|
32
|
+
include_package "org.jruby.rack.jms"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|