Skip to content

Commit

Permalink
fixes TRINIDAD-6: Ability to set tomcat settings from config.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
calavera committed May 1, 2010
1 parent 23ad850 commit 683bc28
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 6 deletions.
17 changes: 17 additions & 0 deletions lib/trinidad/server.rb
Expand Up @@ -36,6 +36,7 @@ def load_tomcat_server
@tomcat.host.app_base = Dir.pwd
enable_naming

add_http_connector if http_configured?
add_ssl_connector if ssl_enabled?
add_ajp_connector if ajp_enabled?

Expand Down Expand Up @@ -66,11 +67,14 @@ def add_service_connector(options, protocol = nil)
connector.secure = opts.delete(:secure) || false
connector.port = opts.delete(:port).to_i

connector.protocol_handler_class_name = opts.delete(:protocol_handler) if opts[:protocol_handler]

opts.each do |key, value|
connector.setProperty(key.to_s, value.to_s)
end

@tomcat.getService().addConnector(connector)
connector
end

def add_ajp_connector
Expand All @@ -90,6 +94,15 @@ def add_ssl_connector
create_default_keystore(options) unless File.exist?(options[:keystore])
end

def add_http_connector
options = @config[:http]
options[:port] = @config[:port]
options[:protocol_handler] = 'org.apache.coyote.http11.Http11NioProtocol' if options[:nio]

connector = add_service_connector(options)
@tomcat.connector = connector
end

def ssl_enabled?
@config.has_key?(:ssl)
end
Expand All @@ -98,6 +111,10 @@ def ajp_enabled?
@config.has_key?(:ajp)
end

def http_configured?
@config.has_key?(:http)
end

def create_default_keystore(config)
keystore_file = java.io.File.new(config[:keystore])

Expand Down
42 changes: 36 additions & 6 deletions spec/trinidad/server_spec.rb
Expand Up @@ -17,38 +17,38 @@
JSystem.getProperty("catalina.useNaming").should == "true"
end

it "should have ssl disabled when config param is nil" do
it "disables ssl when config param is nil" do
server = Trinidad::Server.new
server.ssl_enabled?.should be_false
end

it "should have ajp disabled when config param is nil" do
it "disables ajp when config param is nil" do
server = Trinidad::Server.new
server.ajp_enabled?.should be_false
end

it "should have ssl enabled when config param is a number" do
it "enables ssl when config param is a number" do
server = Trinidad::Server.new({:ssl => {:port => 8443},
:web_app_dir => MOCK_WEB_APP_DIR})

server.ssl_enabled?.should be_true
end

it "should have ajp enabled when config param is a number" do
it "enables ajp when config param is a number" do
server = Trinidad::Server.new({:ajp => {:port => 8009}})

server.ajp_enabled?.should be_true
end

it "should have a connector with https scheme" do
it "includes a connector with https scheme when ssl is enabled" do
server = Trinidad::Server.new({:ssl => {:port => 8443},
:web_app_dir => MOCK_WEB_APP_DIR})

server.tomcat.service.findConnectors().should have(1).connectors
server.tomcat.service.findConnectors()[0].scheme.should == 'https'
end

it "should have an ajp connector enabled" do
it "includes a connector with protocol AJP when ajp is enabled" do
server = Trinidad::Server.new({:ajp => {:port => 8009}})

server.tomcat.service.findConnectors().should have(1).connectors
Expand Down Expand Up @@ -99,6 +99,36 @@
app.process_tlds.should be_false
end

it "uses the default HttpConnector when http is not configured" do
server = Trinidad::Server.new({:web_app_dir => MOCK_WEB_APP_DIR})
server.http_configured?.should be_false

server.tomcat.connector.protocol_handler_class_name.should == 'org.apache.coyote.http11.Http11Protocol'
end

it "uses the NioConnector when the http configuration sets nio to true" do
server = Trinidad::Server.new({
:web_app_dir => MOCK_WEB_APP_DIR,
:http => {:nio => true}
})
server.http_configured?.should be_true

server.tomcat.connector.protocol_handler_class_name.should == 'org.apache.coyote.http11.Http11NioProtocol'
end

it "configures NioConnector with http option values" do
server = Trinidad::Server.new({
:web_app_dir => MOCK_WEB_APP_DIR,
:http => {
:nio => true,
'maxKeepAliveRequests' => 4,
'socket.bufferPool' => 1000
}
})
server.tomcat.connector.get_property('maxKeepAliveRequests').should == 4
server.tomcat.connector.get_property('socket.bufferPool').should == '1000'
end

def default_context_should_be_loaded(children)
children.should have(1).web_apps
children[0].getDocBase().should == MOCK_WEB_APP_DIR
Expand Down

0 comments on commit 683bc28

Please sign in to comment.