Author: markt Date: Wed Jan 18 11:20:56 2017 New Revision: 1779312 URL: http://svn.apache.org/viewvc?rev=1779312&view=rev Log: First pass add adding support for SSLParameters.setApplicationProtocols() to JreCompat
Added: tomcat/trunk/java/org/apache/tomcat/util/compat/LocalStrings.properties Modified: tomcat/trunk/java/org/apache/tomcat/util/compat/Jre9Compat.java tomcat/trunk/java/org/apache/tomcat/util/compat/JreCompat.java Modified: tomcat/trunk/java/org/apache/tomcat/util/compat/Jre9Compat.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/compat/Jre9Compat.java?rev=1779312&r1=1779311&r2=1779312&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/tomcat/util/compat/Jre9Compat.java (original) +++ tomcat/trunk/java/org/apache/tomcat/util/compat/Jre9Compat.java Wed Jan 18 11:20:56 2017 @@ -16,21 +16,30 @@ */ package org.apache.tomcat.util.compat; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; + +import javax.net.ssl.SSLParameters; + class Jre9Compat extends JreCompat { private static final Class<?> inaccessibleObjectExceptionClazz; - + private static final Method setApplicationProtocolsMethod; static { Class<?> c1 = null; + Method m2 = null; + try { c1 = Class.forName("java.lang.reflect.InaccessibleObjectException"); - } catch (SecurityException e) { + SSLParameters.class.getMethod("setApplicationProtocolsMethod", String[].class); + } catch (SecurityException | NoSuchMethodException e) { // Should never happen } catch (ClassNotFoundException e) { // Must be Java 8 } inaccessibleObjectExceptionClazz = c1; + setApplicationProtocolsMethod = m2; } @@ -47,4 +56,14 @@ class Jre9Compat extends JreCompat { return inaccessibleObjectExceptionClazz.isAssignableFrom(t.getClass()); } + + + @Override + public void setApplicationProtocols(SSLParameters sslParameters, String[] protocols) { + try { + setApplicationProtocolsMethod.invoke(sslParameters, (Object) protocols); + } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { + throw new UnsupportedOperationException(e); + } + } } Modified: tomcat/trunk/java/org/apache/tomcat/util/compat/JreCompat.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/compat/JreCompat.java?rev=1779312&r1=1779311&r2=1779312&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/tomcat/util/compat/JreCompat.java (original) +++ tomcat/trunk/java/org/apache/tomcat/util/compat/JreCompat.java Wed Jan 18 11:20:56 2017 @@ -16,6 +16,10 @@ */ package org.apache.tomcat.util.compat; +import javax.net.ssl.SSLParameters; + +import org.apache.tomcat.util.res.StringManager; + /** * This is the base implementation class for JRE compatibility and provides an * implementation based on Java 8. Sub-classes may extend this class and provide @@ -25,7 +29,7 @@ public class JreCompat { private static final JreCompat instance; private static final boolean jre9Available; - + private static final StringManager sm = StringManager.getManager(JreCompat.class); static { // This is Tomcat 9 with a minimum Java version of Java 8. @@ -69,4 +73,16 @@ public class JreCompat { // Exception does not exist prior to Java 9 return false; } + + + /** + * Set the application protocols the server will accept for ALPN + * + * @param sslParameters The SSL parameters for a connection + * @param protocols The application protocols to be allowed for that + * connection + */ + public void setApplicationProtocols(SSLParameters sslParameters, String[] protocols) { + throw new UnsupportedOperationException(sm.getString("jreCompat.noApplicationProtocols")); + } } Added: tomcat/trunk/java/org/apache/tomcat/util/compat/LocalStrings.properties URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/compat/LocalStrings.properties?rev=1779312&view=auto ============================================================================== --- tomcat/trunk/java/org/apache/tomcat/util/compat/LocalStrings.properties (added) +++ tomcat/trunk/java/org/apache/tomcat/util/compat/LocalStrings.properties Wed Jan 18 11:20:56 2017 @@ -0,0 +1,16 @@ +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +jreCompat.noApplicationProtocols=Java Runtime does not support SSLParameters.setApplicationProtocols(). You must use Java 9 to use this feature. \ No newline at end of file --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org