diff options
author | Jan Stamer <jan.stamer@freenet.de> | 2014-02-15 22:30:31 +0100 |
---|---|---|
committer | Jan Stamer <jan.stamer@freenet.de> | 2014-02-15 22:30:31 +0100 |
commit | 22cd25e7b80e2f7f6acd5388ca9580afbf603c2b (patch) | |
tree | d18a21fb3b34d617dd956fe72a8545180118d98f | |
parent | 0d0d98cfe42511d55991bc378ed9700d9f62d1c4 (diff) | |
download | sonarqube-22cd25e7b80e2f7f6acd5388ca9580afbf603c2b.tar.gz sonarqube-22cd25e7b80e2f7f6acd5388ca9580afbf603c2b.zip |
SONAR-4742 Add support of AJP 1.3 protocol
3 files changed, 38 insertions, 4 deletions
diff --git a/sonar-application/src/main/assembly/conf/sonar.properties b/sonar-application/src/main/assembly/conf/sonar.properties index b97e9e3da21..372ad04c7d5 100644 --- a/sonar-application/src/main/assembly/conf/sonar.properties +++ b/sonar-application/src/main/assembly/conf/sonar.properties @@ -140,6 +140,10 @@ sonar.jdbc.timeBetweenEvictionRunsMillis=30000 # Access logs are enabled by default. #sonar.web.accessLogs.enable=true +# TCP port for incoming AJP connections. Disabled when value is -1. +# sonar.ajp.port=9009 + + #-------------------------------------------------------------------------------------------------- # UPDATE CENTER diff --git a/sonar-application/src/main/java/org/sonar/application/Connectors.java b/sonar-application/src/main/java/org/sonar/application/Connectors.java index 2fdb9c8ebe7..65b3d8291a4 100644 --- a/sonar-application/src/main/java/org/sonar/application/Connectors.java +++ b/sonar-application/src/main/java/org/sonar/application/Connectors.java @@ -30,6 +30,7 @@ class Connectors { private static final int DISABLED_PORT = -1; static final String HTTP_PROTOCOL = "HTTP/1.1"; + static final String AJP_PROTOCOL = "AJP/1.3"; static void configure(Tomcat tomcat, Props props) { configureShutdown(tomcat, props); @@ -38,7 +39,7 @@ class Connectors { private static void configureConnectors(Tomcat tomcat, Props props) { List<Connector> connectors = new ArrayList<Connector>(); - connectors.addAll(Arrays.asList(newHttpConnector(props), newHttpsConnector(props))); + connectors.addAll(Arrays.asList(newHttpConnector(props), newAjpConnector(props), newHttpsConnector(props))); connectors.removeAll(Collections.singleton(null)); verify(connectors); @@ -57,7 +58,7 @@ class Connectors { for (Connector connector : connectors) { int port = connector.getPort(); if (ports.contains(port)) { - throw new IllegalStateException(String.format("HTTP and HTTPS must not use the same port %d", port)); + throw new IllegalStateException(String.format("HTTP, AJP and HTTPS must not use the same port %d", port)); } ports.add(port); } @@ -87,6 +88,18 @@ class Connectors { } @Nullable + private static Connector newAjpConnector(Props props) { + Connector connector = null; + int port = props.intOf("sonar.ajp.port", DISABLED_PORT); + if (port > DISABLED_PORT) { + connector = newConnector(props, AJP_PROTOCOL, "http"); + connector.setPort(port); + info("AJP connector is enabled on port " + port); + } + return connector; + } + + @Nullable private static Connector newHttpsConnector(Props props) { Connector connector = null; int port = props.intOf("sonar.web.https.port", DISABLED_PORT); diff --git a/sonar-application/src/test/java/org/sonar/application/ConnectorsTest.java b/sonar-application/src/test/java/org/sonar/application/ConnectorsTest.java index 4d8e9b4773c..6478937967c 100644 --- a/sonar-application/src/test/java/org/sonar/application/ConnectorsTest.java +++ b/sonar-application/src/test/java/org/sonar/application/ConnectorsTest.java @@ -133,6 +133,7 @@ public class ConnectorsTest { public void all_connectors_are_enabled() { Properties p = new Properties(); p.setProperty("sonar.web.port", "9000"); + p.setProperty("sonar.ajp.port", "9009"); p.setProperty("sonar.web.https.port", "9443"); Props props = new Props(p); @@ -146,6 +147,13 @@ public class ConnectorsTest { } })); verify(tomcat.getService()).addConnector(argThat(new ArgumentMatcher<Connector>() { + @Override + public boolean matches(Object o) { + Connector c = (Connector) o; + return c.getScheme().equals("http") && c.getPort() == 9009 && c.getProtocol().equals(Connectors.AJP_PROTOCOL); + } + })); + verify(tomcat.getService()).addConnector(argThat(new ArgumentMatcher<Connector>() { @Override public boolean matches(Object o) { Connector c = (Connector) o; @@ -155,16 +163,17 @@ public class ConnectorsTest { } @Test - public void http_and_https_ports_should_be_different() throws Exception { + public void http_and_ajp_and_https_ports_should_be_different() throws Exception { Properties p = new Properties(); p.setProperty("sonar.web.port", "9000"); + p.setProperty("sonar.ajp.port", "9000"); p.setProperty("sonar.web.https.port", "9000"); try { Connectors.configure(tomcat, new Props(p)); fail(); } catch (IllegalStateException e) { - assertThat(e).hasMessage("HTTP and HTTPS must not use the same port 9000"); + assertThat(e).hasMessage("HTTP, AJP and HTTPS must not use the same port 9000"); } } @@ -172,6 +181,7 @@ public class ConnectorsTest { public void bind_to_all_addresses_by_default() throws Exception { Properties p = new Properties(); p.setProperty("sonar.web.port", "9000"); + p.setProperty("sonar.ajp.port", "9009"); p.setProperty("sonar.web.https.port", "9443"); Connectors.configure(tomcat, new Props(p)); @@ -184,6 +194,13 @@ public class ConnectorsTest { } })); verify(tomcat.getService()).addConnector(argThat(new ArgumentMatcher<Connector>() { + @Override + public boolean matches(Object o) { + Connector c = (Connector) o; + return c.getScheme().equals("http") && c.getPort() == 9009 && ((InetAddress)c.getProperty("address")).getHostAddress().equals("0.0.0.0"); + } + })); + verify(tomcat.getService()).addConnector(argThat(new ArgumentMatcher<Connector>() { @Override public boolean matches(Object o) { Connector c = (Connector) o; |