lib/trinidad/web_app.rb in trinidad-0.8.3 vs lib/trinidad/web_app.rb in trinidad-0.9.0
- old
+ new
@@ -12,22 +12,18 @@
@app = app
@class_loader = org.jruby.util.JRubyClassLoader.new(JRuby.runtime.jruby_class_loader)
end
- def add_rack_filter
- unless rack_filter_configured?
- filter_def = Trinidad::Tomcat::FilterDef.new
- filter_def.setFilterName('RackFilter')
- filter_def.setFilterClass('org.jruby.rack.RackFilter')
+ def configure_rack(servlet_class = 'org.jruby.rack.RackServlet', servlet_name = 'RackServlet')
+ unless rack_configured?
+ wrapper = @context.createWrapper()
+ wrapper.setServletClass(servlet_class)
+ wrapper.setName(servlet_name)
- filter_map = Trinidad::Tomcat::FilterMap.new
- filter_map.setFilterName('RackFilter')
- filter_map.addURLPattern('/*')
-
- @context.addFilterDef(filter_def)
- @context.addFilterMap(filter_map)
+ @context.addChild(wrapper)
+ @context.addServletMapping('/*', servlet_name)
end
end
def add_context_loader
add_application_libs(@class_loader)
@@ -44,15 +40,10 @@
add_parameter_unless_exist('jruby.max.runtimes', jruby_max_runtimes.to_s)
add_parameter_unless_exist('jruby.initial.runtimes', jruby_min_runtimes.to_s)
add_parameter_unless_exist('public.root', File.join('/', public_root))
end
- def add_web_dir_resources
- doc_base = File.join(@app[:web_app_dir], public_root)
- @context.setDocBase(doc_base) if File.exist?(doc_base)
- end
-
def add_rack_context_listener
unless rack_listener_configured?
@context.addApplicationListener(context_listener)
end
end
@@ -70,22 +61,20 @@
class_loader.addURL(java.io.File.new(resources_dir).to_url)
end
def load_default_web_xml
file = File.expand_path(File.join(@app[:web_app_dir], default_web_xml))
+ file = File.expand_path("../#{provided_web_xml}", __FILE__) unless File.exist?(file)
- if File.exist?(file)
- @context.setDefaultWebXml(file)
- @context.setDefaultContextXml(file)
+ @context.setDefaultWebXml(file)
- context_config = Trinidad::Tomcat::ContextConfig.new
- context_config.setDefaultWebXml(file)
+ context_config = Trinidad::Tomcat::ContextConfig.new
+ context_config.setDefaultWebXml(file)
- @context.addLifecycleListener(context_config)
- end
+ @context.addLifecycleListener(context_config)
end
- def rack_filter_configured?
+ def rack_configured?
return false if @context.getDefaultWebXml().nil?
web_xml = IO.read(@context.getDefaultWebXml()).gsub(/\s+/, '')
return web_xml.include?('<servlet-class>org.jruby.rack.RackServlet') ||