lib/tomcat-rails/server.rb in calavera-tomcat-rails-0.1.1 vs lib/tomcat-rails/server.rb in calavera-tomcat-rails-0.1.2
- old
+ new
@@ -2,73 +2,39 @@
class Server
@@defaults = {
:environment => 'development',
:context_path => '/',
- :lib_dir => 'lib',
+ :libs_dir => 'lib',
:classes_dir => 'classes',
:port => 3000,
:jruby_min_runtimes => 1,
:jruby_max_runtimes => 5
}
def initialize(config = {})
- @config = config.merge!(@@defaults)
+ @config = @@defaults.merge!(config)
+ @config[:web_app_dir] = Dir.pwd
@tomcat = TomcatRails::Tomcat::Tomcat.new
- @tomcat.setPort(@config[:port])
+ @tomcat.setPort(@config[:port].to_i)
- web_app = @tomcat.addWebapp(@config[:context_path], Dir.pwd)
+ create_web_app
+ end
+
+ def create_web_app
+ web_app = WebApp.new(@tomcat.addWebapp(@config[:context_path].to_s, @config[:web_app_dir]), @config)
- add_rack_filter(web_app, @config[:context_path])
- add_context_loader(web_app)
- add_init_params(web_app)
- add_web_dir_resources(web_app)
+ web_app.add_rack_filter
+ web_app.add_context_loader
+ web_app.add_init_params
+ web_app.add_web_dir_resources
- web_app.addApplicationListener('org.jruby.rack.rails.RailsServletContextListener')
+ web_app.add_rack_context_listener
end
def start
@tomcat.start
@tomcat.getServer().await
- end
-
- private
- def add_rack_filter(web_app, context_path)
- filter_def = TomcatRails::Tomcat::FilterDef.new
- filter_def.setFilterName('RackFilter')
- filter_def.setFilterClass('org.jruby.rack.RackFilter')
-
- pattern = context_path[-1..-1] != '/' ? context_path : context_path[0..-2]
- filter_map = TomcatRails::Tomcat::FilterMap.new
- filter_map.setFilterName('RackFilter')
- filter_map.addURLPattern("#{pattern}/*")
-
- web_app.addFilterDef(filter_def)
- web_app.addFilterMap(filter_map)
- end
-
- def add_context_loader(web_app)
- class_loader = org.jruby.util.JRubyClassLoader.new(JRuby.runtime.jruby_class_loader)
- loader = TomcatRails::Tomcat::WebappLoader.new(class_loader)
-
- loader.container = web_app
- web_app.loader = loader
- end
-
- def add_init_params(web_app)
- [:jruby_min_runtimes, :jruby_max_runtimes].each do |param|
- web_app.addParameter(param.to_s.gsub(/_/, '.'), @config[param].to_s)
- end
-
- web_app.addParameter('jruby.initial.runtimes', @config[:jruby_min_runtimes].to_s)
- web_app.addParameter('rails.env', @config[:environment].to_s)
- web_app.addParameter('rails.root', '/')
- web_app.addParameter('public.root', '/public')
-
- end
-
- def add_web_dir_resources(web_app)
- web_app.setDocBase(File.join(Dir.pwd, "public/"))
end
end
end
\ No newline at end of file