felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fmesc...@apache.org
Subject svn commit: r1056579 - in /felix/trunk/http/jetty/src/main/java/org/apache/felix/http/jetty/internal: JettyConfig.java JettyService.java
Date Sat, 08 Jan 2011 00:59:44 GMT
Author: fmeschbe
Date: Sat Jan  8 00:59:44 2011
New Revision: 1056579

URL: http://svn.apache.org/viewvc?rev=1056579&view=rev
Log:
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

Modified:
    felix/trunk/http/jetty/src/main/java/org/apache/felix/http/jetty/internal/JettyConfig.java
    felix/trunk/http/jetty/src/main/java/org/apache/felix/http/jetty/internal/JettyService.java

Modified: felix/trunk/http/jetty/src/main/java/org/apache/felix/http/jetty/internal/JettyConfig.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/jetty/src/main/java/org/apache/felix/http/jetty/internal/JettyConfig.java?rev=1056579&r1=1056578&r2=1056579&view=diff
==============================================================================
--- felix/trunk/http/jetty/src/main/java/org/apache/felix/http/jetty/internal/JettyConfig.java
(original)
+++ felix/trunk/http/jetty/src/main/java/org/apache/felix/http/jetty/internal/JettyConfig.java
Sat Jan  8 00:59:44 2011
@@ -60,7 +60,13 @@ public final class JettyConfig
 
     /** 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 @@ public final class JettyConfig
     private String trustPassword;
     private boolean useHttp;
     private String clientcert;
+    private boolean useHttpNio;
+    private boolean useHttpsNio;
 
     public JettyConfig(BundleContext context)
     {
@@ -90,11 +98,21 @@ public final class JettyConfig
         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 @@ public final class JettyConfig
         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 @@ public final class JettyConfig
     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"));
         }

Modified: felix/trunk/http/jetty/src/main/java/org/apache/felix/http/jetty/internal/JettyService.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/jetty/src/main/java/org/apache/felix/http/jetty/internal/JettyService.java?rev=1056579&r1=1056578&r2=1056579&view=diff
==============================================================================
--- felix/trunk/http/jetty/src/main/java/org/apache/felix/http/jetty/internal/JettyService.java
(original)
+++ felix/trunk/http/jetty/src/main/java/org/apache/felix/http/jetty/internal/JettyService.java
Sat Jan  8 00:59:44 2011
@@ -23,11 +23,12 @@ import org.osgi.framework.Constants;
 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 @@ public final class JettyService
         this.dispatcher = dispatcher;
         this.controller = controller;
     }
-    
+
     public void start()
         throws Exception
     {
@@ -150,7 +151,9 @@ public final class JettyService
     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 @@ public final class JettyService
     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);
     }



Mime
View raw message