Class: Trinidad::Extensions::ValveWebAppExtension
- Inherits:
-
WebAppExtension
- Object
- WebAppExtension
- Trinidad::Extensions::ValveWebAppExtension
- Defined in:
- lib/trinidad_valve_extension.rb
Instance Method Summary collapse
- #configure(tomcat, app_context) ⇒ Object
- #get_valve(valve_name) ⇒ Object
- #replace_properties(text) ⇒ Object
- #set_valve_properties(valve_instance, properties) ⇒ Object
Instance Method Details
#configure(tomcat, app_context) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/trinidad_valve_extension.rb', line 8 def configure(tomcat, app_context) @logger = app_context.logger @options[:valves] ||= Array.new if not @options[:valves].empty? @options[:valves].each do |valve_properties| valve_properties = valve_properties.clone class_name = valve_properties.delete 'className' if not class_name @logger.warn("Tomcat valve defined without a 'className' attribute. Skipping valve definition: '#{valve_properties.inspect}'") next end begin valve = get_valve(class_name) rescue NameError => e @logger.warn("Tomcat valve '#{class_name}' not found. Ensure valve exists in your classpath") next end set_valve_properties(valve, valve_properties) # Add the valve to the context using the suggested getPipeline() app_context.pipeline.add_valve(valve) end end end |
#get_valve(valve_name) ⇒ Object
38 39 40 41 |
# File 'lib/trinidad_valve_extension.rb', line 38 def get_valve(valve_name) valve_class = Java::JavaClass.for_name valve_name valve_instance = valve_class.constructor.new_instance.to_java end |
#replace_properties(text) ⇒ Object
59 60 61 62 |
# File 'lib/trinidad_valve_extension.rb', line 59 def replace_properties(text) java_import 'org.apache.tomcat.util.IntrospectionUtils' IntrospectionUtils.replace_properties(text, java.lang.System.getProperties(), nil) end |
#set_valve_properties(valve_instance, properties) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/trinidad_valve_extension.rb', line 43 def set_valve_properties(valve_instance, properties) properties.each do |option,value| begin if value.kind_of? String value = replace_properties(value) end valve_instance.send("#{option}=", value) rescue TypeError => e @logger.warn("Incorrect type passed for property '#{option}' on valve '#{valve_instance.java_class}'. Skipping property") rescue NoMethodError => e @logger.warn("No settable property '#{option}' found on valve '#{valve_instance.java_class}'") end end end |