Author: remm
Date: Fri Dec 11 16:58:31 2015
New Revision: 1719473

URL: http://svn.apache.org/viewvc?rev=1719473&view=rev
Log:
Add an extra flag to the APR listener to allow using NIO + OpenSSL in a cleaner 
way. At the moment, the default behavior is unchanged.

Modified:
    tomcat/trunk/java/org/apache/catalina/connector/Connector.java
    tomcat/trunk/java/org/apache/catalina/core/AprLifecycleListener.java
    tomcat/trunk/webapps/docs/changelog.xml

Modified: tomcat/trunk/java/org/apache/catalina/connector/Connector.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/connector/Connector.java?rev=1719473&r1=1719472&r2=1719473&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/connector/Connector.java (original)
+++ tomcat/trunk/java/org/apache/catalina/connector/Connector.java Fri Dec 11 
16:58:31 2015
@@ -33,10 +33,12 @@ import org.apache.catalina.util.Lifecycl
 import org.apache.coyote.Adapter;
 import org.apache.coyote.ProtocolHandler;
 import org.apache.coyote.UpgradeProtocol;
+import org.apache.coyote.http11.AbstractHttp11JsseProtocol;
 import org.apache.juli.logging.Log;
 import org.apache.juli.logging.LogFactory;
 import org.apache.tomcat.util.IntrospectionUtils;
 import org.apache.tomcat.util.net.SSLHostConfig;
+import org.apache.tomcat.util.net.openssl.OpenSSLImplementation;
 import org.apache.tomcat.util.res.StringManager;
 
 
@@ -540,12 +542,12 @@ public class Connector extends Lifecycle
     public String getProtocol() {
 
         if (("org.apache.coyote.http11.Http11NioProtocol".equals
-            (getProtocolHandlerClassName()) && 
!AprLifecycleListener.isAprAvailable())
+            (getProtocolHandlerClassName()) && 
(!AprLifecycleListener.isAprAvailable() || 
!AprLifecycleListener.isAprPreferred()))
             || "org.apache.coyote.http11.Http11AprProtocol".equals
             (getProtocolHandlerClassName())) {
             return "HTTP/1.1";
         } else if (("org.apache.coyote.ajp.AjpNioProtocol".equals
-                   (getProtocolHandlerClassName()) && 
!AprLifecycleListener.isAprAvailable())
+                   (getProtocolHandlerClassName()) && 
(!AprLifecycleListener.isAprAvailable() || 
!AprLifecycleListener.isAprPreferred()))
                    || "org.apache.coyote.ajp.AjpAprProtocol".equals
                    (getProtocolHandlerClassName())) {
             return "AJP/1.3";
@@ -562,7 +564,7 @@ public class Connector extends Lifecycle
      */
     public void setProtocol(String protocol) {
 
-        if (AprLifecycleListener.isAprAvailable()) {
+        if (AprLifecycleListener.isAprAvailable() && 
AprLifecycleListener.isAprPreferred()) {
             if ("HTTP/1.1".equals(protocol)) {
                 setProtocolHandlerClassName
                     ("org.apache.coyote.http11.Http11AprProtocol");
@@ -973,6 +975,14 @@ public class Connector extends Lifecycle
                     sm.getString("coyoteConnector.protocolHandlerNoApr",
                             getProtocolHandlerClassName()));
         }
+        if (AprLifecycleListener.isAprAvailable() && 
!AprLifecycleListener.isAprPreferred()
+                && protocolHandler instanceof AbstractHttp11JsseProtocol) {
+            AbstractHttp11JsseProtocol<?> jsseProtocolHandler = 
(AbstractHttp11JsseProtocol<?>) protocolHandler;
+            if (jsseProtocolHandler.getSslImplementationName() == null) {
+                // OpenSSL is compatible with the JSSE configuration, so use 
it if APR is available
+                
jsseProtocolHandler.setSslImplementationName(OpenSSLImplementation.IMPLEMENTATION_NAME);
+            }
+        }
 
         try {
             protocolHandler.init();

Modified: tomcat/trunk/java/org/apache/catalina/core/AprLifecycleListener.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/core/AprLifecycleListener.java?rev=1719473&r1=1719472&r2=1719473&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/core/AprLifecycleListener.java 
(original)
+++ tomcat/trunk/java/org/apache/catalina/core/AprLifecycleListener.java Fri 
Dec 11 16:58:31 2015
@@ -40,7 +40,6 @@ import org.apache.tomcat.util.res.String
  * Implementation of <code>LifecycleListener</code> that will init and
  * and destroy APR.
  *
- * @author Remy Maucherat
  * @since 4.1
  */
 public class AprLifecycleListener
@@ -79,6 +78,7 @@ public class AprLifecycleListener
     protected static boolean sslInitialized = false;
     protected static boolean aprInitialized = false;
     protected static boolean aprAvailable = false;
+    protected static boolean aprPreferred = true;
     protected static boolean fipsModeActive = false;
 
     /**
@@ -394,4 +394,15 @@ public class AprLifecycleListener
     public boolean isFIPSModeActive() {
         return fipsModeActive;
     }
+
+    public void setAprPreferred(boolean aprPreferred) {
+        if (aprPreferred != AprLifecycleListener.aprPreferred) {
+            AprLifecycleListener.aprPreferred = aprPreferred;
+        }
+    }
+
+    public static boolean isAprPreferred() {
+        return aprPreferred;
+    }
+
 }

Modified: tomcat/trunk/webapps/docs/changelog.xml
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/webapps/docs/changelog.xml?rev=1719473&r1=1719472&r2=1719473&view=diff
==============================================================================
--- tomcat/trunk/webapps/docs/changelog.xml (original)
+++ tomcat/trunk/webapps/docs/changelog.xml Fri Dec 11 16:58:31 2015
@@ -126,6 +126,12 @@
         <code>StandardWrapper</code> when unloading a Servlet so that a new
         instance may be correctly initialized. (markt)
       </fix>
+      <update>
+        Add a new flag <code>aprPreferred</code> to the Apr listener. if set to
+        <code>false</code>, when using the connector defaults, it will use
+        NIO + OpenSSL if tomcat-native is available, rather than the APR
+        connector. (remm)
+      </update>
     </changelog>
   </subsection>
   <subsection name="Coyote">



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org

Reply via email to