Author: remm
Date: Fri Jul 17 14:22:19 2015
New Revision: 1691569

URL: http://svn.apache.org/r1691569
Log:
The new API to set ALPN seems compatible, so use it to remove boilerplate code 
in the APR connector (reading the result is not compatible apparently).

Modified:
    tomcat/trunk/java/org/apache/tomcat/util/net/AprEndpoint.java

Modified: tomcat/trunk/java/org/apache/tomcat/util/net/AprEndpoint.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/net/AprEndpoint.java?rev=1691569&r1=1691568&r2=1691569&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/util/net/AprEndpoint.java (original)
+++ tomcat/trunk/java/org/apache/tomcat/util/net/AprEndpoint.java Fri Jul 17 
14:22:19 2015
@@ -24,7 +24,6 @@ import java.nio.channels.CompletionHandl
 import java.nio.charset.StandardCharsets;
 import java.util.ArrayList;
 import java.util.HashMap;
-import java.util.List;
 import java.util.Map;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.Executor;
@@ -78,11 +77,6 @@ public class AprEndpoint extends Abstrac
 
     private static final Log log = LogFactory.getLog(AprEndpoint.class);
 
-    // http/1.1 with preceding length
-    private static final byte[] ALPN_DEFAULT =
-            new byte[] { 0x08, 0x68, 0x74, 0x74, 0x70, 0x2f, 0x31, 0x2e, 0x31 
};
-
-
     // ----------------------------------------------------------------- Fields
 
     /**
@@ -547,10 +541,11 @@ public class AprEndpoint extends Abstrac
                 }
 
                 if (negotiableProtocols.size() > 0) {
-                    byte[] protocols = buildAlpnConfig(negotiableProtocols);
-                    if (SSLContext.setALPN(ctx, protocols, protocols.length) 
!= 0) {
-                        log.warn(sm.getString("endpoint.alpn.fail", 
negotiableProtocols));
-                    }
+                    ArrayList<String> protocols = new ArrayList<>();
+                    protocols.addAll(negotiableProtocols);
+                    protocols.add("http/1.1");
+                    String[] protocolsArray = protocols.toArray(new String[0]);
+                    SSLContext.setAlpnProtos(ctx, protocolsArray, 
SSL.SSL_SELECTOR_FAILURE_NO_ADVERTISE);
                 }
                 sslHostConfig.setOpenSslContext(Long.valueOf(ctx));
             }
@@ -574,39 +569,6 @@ public class AprEndpoint extends Abstrac
     }
 
 
-    private byte[] buildAlpnConfig(List<String> protocols) {
-        /*
-         * The expected format is zero or more of the following:
-         * - Single byte for size
-         * - Sequence of size bytes for the identifier
-         */
-        byte[][] protocolsBytes = new byte[protocols.size()][];
-        int i = 0;
-        int size = 0;
-        for (String protocol : protocols) {
-            protocolsBytes[i] = protocol.getBytes(StandardCharsets.UTF_8);
-            size += protocolsBytes[i].length;
-            // And one byte to store the size
-            size++;
-            i++;
-        }
-
-        size += ALPN_DEFAULT.length;
-
-        byte[] result = new byte[size];
-        int pos = 0;
-        for (byte[] protocolBytes : protocolsBytes) {
-            result[pos++] = (byte) (0xff & protocolBytes.length);
-            System.arraycopy(protocolBytes, 0, result, pos, 
protocolBytes.length);
-            pos += protocolBytes.length;
-        }
-
-        System.arraycopy(ALPN_DEFAULT, 0, result, pos, ALPN_DEFAULT.length);
-
-        return result;
-    }
-
-
     /**
      * Start the APR endpoint, creating acceptor, poller and sendfile threads.
      */



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

Reply via email to