FELIX-2398 Add configuration properties to set whether NIO is to be used for HTTP(S):
org.apache.felix.http.nio - (boolean) whether to use NIO for HTTP or not, default is true
org.apache.felix.https.nio - (boolean) whether to use NIO for HTTPS or not, default is to use
the value of the org.apache.felix.http.nio property
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1056579 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/http/jetty/src/main/java/org/apache/felix/http/jetty/internal/JettyConfig.java b/http/jetty/src/main/java/org/apache/felix/http/jetty/internal/JettyConfig.java
index 194af16..487e64b 100644
--- a/http/jetty/src/main/java/org/apache/felix/http/jetty/internal/JettyConfig.java
+++ b/http/jetty/src/main/java/org/apache/felix/http/jetty/internal/JettyConfig.java
@@ -60,7 +60,13 @@
/** Felix specific property to control whether to want or require HTTPS client certificates. Valid values are "none", "wants", "needs". Default is "none". */
private static final String FELIX_HTTPS_CLIENT_CERT = "org.apache.felix.https.clientcertificate";
-
+
+ /** Felix specific property to control whether Jetty uses NIO or not for HTTP. Valid values are "true", "false". Default is true */
+ public static final String FELIX_HTTP_NIO = "org.apache.felix.http.nio";
+
+ /** Felix specific property to control whether Jetty uses NIO or not for HTTPS. Valid values are "true", "false". Default is the value of org.apache.felix.http.nio */
+ public static final String FELIX_HTTPS_NIO = "org.apache.felix.https.nio";
+
private final BundleContext context;
private boolean debug;
private int httpPort;
@@ -73,6 +79,8 @@
private String trustPassword;
private boolean useHttp;
private String clientcert;
+ private boolean useHttpNio;
+ private boolean useHttpsNio;
public JettyConfig(BundleContext context)
{
@@ -90,11 +98,21 @@
return this.useHttp;
}
+ public boolean isUseHttpNio()
+ {
+ return this.useHttpNio;
+ }
+
public boolean isUseHttps()
{
return this.useHttps;
}
+ public boolean isUseHttpsNio()
+ {
+ return this.useHttpsNio;
+ }
+
public int getHttpPort()
{
return this.httpPort;
@@ -157,6 +175,8 @@
this.truststore = getProperty(props, FELIX_TRUSTSTORE, null);
this.trustPassword = getProperty(props, FELIX_TRUSTSTORE_PASSWORD, null);
this.clientcert = getProperty(props, FELIX_HTTPS_CLIENT_CERT, "none");
+ this.useHttpNio = getBooleanProperty(props, FELIX_HTTP_NIO, true);
+ this.useHttpsNio = getBooleanProperty(props, FELIX_HTTPS_NIO, this.useHttpNio);
}
private String getProperty(Dictionary props, String name, String defValue)
@@ -172,6 +192,9 @@
private boolean getBooleanProperty(Dictionary props, String name, boolean defValue)
{
String value = getProperty(props, name, null);
+ if (value == null) {
+ value = this.context.getProperty(name);
+ }
if (value != null) {
return (value.equalsIgnoreCase("true") || value.equalsIgnoreCase("yes"));
}
diff --git a/http/jetty/src/main/java/org/apache/felix/http/jetty/internal/JettyService.java b/http/jetty/src/main/java/org/apache/felix/http/jetty/internal/JettyService.java
index d7fcee0..1637bab 100644
--- a/http/jetty/src/main/java/org/apache/felix/http/jetty/internal/JettyService.java
+++ b/http/jetty/src/main/java/org/apache/felix/http/jetty/internal/JettyService.java
@@ -23,11 +23,12 @@
import org.osgi.framework.ServiceRegistration;
import org.mortbay.jetty.security.HashUserRealm;
import org.mortbay.jetty.security.SslSelectChannelConnector;
+import org.mortbay.jetty.security.SslSocketConnector;
import org.mortbay.jetty.Server;
import org.mortbay.jetty.Connector;
+import org.mortbay.jetty.bio.SocketConnector;
import org.mortbay.jetty.nio.SelectChannelConnector;
import org.mortbay.jetty.servlet.*;
-import org.mortbay.log.Log;
import org.apache.felix.http.base.internal.DispatcherServlet;
import org.apache.felix.http.base.internal.HttpServiceController;
import org.apache.felix.http.base.internal.logger.SystemLogger;
@@ -58,7 +59,7 @@
this.dispatcher = dispatcher;
this.controller = controller;
}
-
+
public void start()
throws Exception
{
@@ -150,7 +151,9 @@
private void initializeHttp()
throws Exception
{
- Connector connector = new SelectChannelConnector();
+ Connector connector = this.config.isUseHttpNio()
+ ? new SelectChannelConnector()
+ : new SocketConnector();
connector.setPort(this.config.getHttpPort());
connector.setMaxIdleTime(60000);
this.server.addConnector(connector);
@@ -159,37 +162,97 @@
private void initializeHttps()
throws Exception
{
- SslSelectChannelConnector connector = new SslSelectChannelConnector();
+ // this massive code duplication is caused by the SslSelectChannelConnector
+ // and the SslSocketConnector not have a common API to setup security
+ // stuff
+ Connector connector;
+ if (this.config.isUseHttpsNio())
+ {
+ SslSelectChannelConnector sslConnector = new SslSelectChannelConnector();
+
+ if (this.config.getKeystore() != null)
+ {
+ sslConnector.setKeystore(this.config.getKeystore());
+ }
+
+ if (this.config.getPassword() != null)
+ {
+ System.setProperty(SslSelectChannelConnector.PASSWORD_PROPERTY, this.config.getPassword());
+ sslConnector.setPassword(this.config.getPassword());
+ }
+
+ if (this.config.getKeyPassword() != null)
+ {
+ System.setProperty(SslSelectChannelConnector.KEYPASSWORD_PROPERTY, this.config.getKeyPassword());
+ sslConnector.setKeyPassword(this.config.getKeyPassword());
+ }
+
+ if (this.config.getTruststore() != null)
+ {
+ sslConnector.setTruststore(this.config.getTruststore());
+ }
+
+ if (this.config.getTrustPassword() != null)
+ {
+ sslConnector.setTrustPassword(this.config.getTrustPassword());
+ }
+
+ if ("wants".equals(this.config.getClientcert()))
+ {
+ sslConnector.setWantClientAuth(true);
+ }
+ else if ("needs".equals(this.config.getClientcert()))
+ {
+ sslConnector.setNeedClientAuth(true);
+ }
+
+ connector = sslConnector;
+ }
+ else
+ {
+ SslSocketConnector sslConnector = new SslSocketConnector();
+
+ if (this.config.getKeystore() != null)
+ {
+ sslConnector.setKeystore(this.config.getKeystore());
+ }
+
+ if (this.config.getPassword() != null)
+ {
+ System.setProperty(SslSelectChannelConnector.PASSWORD_PROPERTY, this.config.getPassword());
+ sslConnector.setPassword(this.config.getPassword());
+ }
+
+ if (this.config.getKeyPassword() != null)
+ {
+ System.setProperty(SslSelectChannelConnector.KEYPASSWORD_PROPERTY, this.config.getKeyPassword());
+ sslConnector.setKeyPassword(this.config.getKeyPassword());
+ }
+
+ if (this.config.getTruststore() != null)
+ {
+ sslConnector.setTruststore(this.config.getTruststore());
+ }
+
+ if (this.config.getTrustPassword() != null)
+ {
+ sslConnector.setTrustPassword(this.config.getTrustPassword());
+ }
+
+ if ("wants".equals(this.config.getClientcert()))
+ {
+ sslConnector.setWantClientAuth(true);
+ }
+ else if ("needs".equals(this.config.getClientcert()))
+ {
+ sslConnector.setNeedClientAuth(true);
+ }
+
+ connector = sslConnector;
+ }
+
connector.setPort(this.config.getHttpsPort());
connector.setMaxIdleTime(60000);
-
- if (this.config.getKeystore() != null) {
- connector.setKeystore(this.config.getKeystore());
- }
-
- if (this.config.getPassword() != null) {
- System.setProperty(SslSelectChannelConnector.PASSWORD_PROPERTY, this.config.getPassword());
- connector.setPassword(this.config.getPassword());
- }
-
- if (this.config.getKeyPassword() != null) {
- System.setProperty(SslSelectChannelConnector.KEYPASSWORD_PROPERTY, this.config.getKeyPassword());
- connector.setKeyPassword(this.config.getKeyPassword());
- }
-
- if (this.config.getTruststore() != null) {
- connector.setTruststore(this.config.getTruststore());
- }
-
- if (this.config.getTrustPassword() != null) {
- connector.setTrustPassword(this.config.getTrustPassword());
- }
-
- if ("wants".equals(this.config.getClientcert())) {
- connector.setWantClientAuth(true);
- } else if ("needs".equals(this.config.getClientcert())) {
- connector.setNeedClientAuth(true);
- }
this.server.addConnector(connector);
}