lib/trinidad/server.rb in trinidad-0.7.2 vs lib/trinidad/server.rb in trinidad-0.8.0

- old
+ new

@@ -1,10 +1,12 @@ module Trinidad + JSystem = java.lang.System + JContext = javax.naming.Context + class Server + attr_reader :tomcat, :config - attr_reader :tomcat - def default_options { :environment => 'development', :context_path => '/', :libs_dir => 'lib', @@ -21,21 +23,24 @@ load_tomcat_server create_web_apps end def load_config(config) - @config = default_options.deep_merge(config) + @config = default_options.deep_merge(config).symbolize! add_default_web_app!(@config) end def load_tomcat_server @tomcat = Trinidad::Tomcat::Tomcat.new @tomcat.setPort(@config[:port].to_i) @tomcat.setBaseDir(Dir.pwd) + enable_naming add_ssl_connector if ssl_enabled? add_ajp_connector if ajp_enabled? + + Trinidad::Extensions.configure_server_extensions(@config[:extensions], @tomcat) end def create_web_apps @config[:web_apps].each do |name, app| app[:context_path] ||= (name.to_s == 'default' ? '/' : "/#{name.to_s}") @@ -45,10 +50,11 @@ web_app = WebApp.create(tomcat_app, @config, app) web_app.load_default_web_xml web_app.add_rack_filter + web_app.configure_extensions(@tomcat) web_app.add_context_loader web_app.add_init_params web_app.add_web_dir_resources web_app.add_rack_context_listener @@ -62,11 +68,11 @@ connector.scheme = opts.delete(:scheme) if opts[:scheme] connector.secure = opts.delete(:secure) || false connector.port = opts.delete(:port).to_i - options.each do |key, value| + opts.each do |key, value| connector.setProperty(key.to_s, value.to_s) end @tomcat.getService().addConnector(connector) end @@ -95,11 +101,11 @@ def ajp_enabled? @config.has_key?(:ajp) end def create_default_keystore(config) - keystore_file = java.io.File.new(config[:ssl][:keystore]) + keystore_file = java.io.File.new(config[:keystore]) if (!keystore_file.parent_file.exists() && !keystore_file.parent_file.mkdir()) raise "Unable to create keystore folder: " + keystore_file.parent_file.canonical_path end @@ -108,13 +114,13 @@ "-alias", "localhost", "-dname", "CN=localhost, OU=Trinidad, O=Trinidad, C=ES", "-keyalg", "RSA", "-validity", "365", "-storepass", "key", - "-keystore", config[:ssl][:keystore], - "-storepass", config[:ssl][:keystorePass], - "-keypass", config[:ssl][:keystorePass]] + "-keystore", config[:keystore], + "-storepass", config[:keystorePass], + "-keypass", config[:keystorePass]] Trinidad::Tomcat::KeyTool.main(keytool_args.to_java(:string)) end def start @@ -134,7 +140,23 @@ config[:web_apps] = { :default => default_app } end end + def enable_naming + @tomcat.getServer().addLifecycleListener(Trinidad::Tomcat::NamingContextListener.new) + + JSystem.setProperty("catalina.useNaming", "true") + + value = "org.apache.naming" + old_value = JSystem.getProperty(JContext.URL_PKG_PREFIXES) || value + + value = value + ":" + old_value unless old_value.include?(value) + JSystem.setProperty(JContext.URL_PKG_PREFIXES, value) + + value = JSystem.getProperty(JContext.INITIAL_CONTEXT_FACTORY) + unless value + JSystem.setProperty(JContext.INITIAL_CONTEXT_FACTORY, "org.apache.naming.java.javaURLContextFactory") + end + end end end