< prev index next >

src/java.base/share/classes/javax/net/ssl/SSLServerSocketFactory.java

Print this page

        

*** 1,7 **** /* ! * Copyright (c) 1997, 2019, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this --- 1,7 ---- /* ! * Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this
*** 40,50 **** * @since 1.4 * @see SSLSocket * @see SSLServerSocket * @author David Brownell */ ! public abstract class SSLServerSocketFactory extends ServerSocketFactory { /** * Constructor is used only by subclasses. */ protected SSLServerSocketFactory() { /* NOTHING */ } --- 40,60 ---- * @since 1.4 * @see SSLSocket * @see SSLServerSocket * @author David Brownell */ ! public abstract class SSLServerSocketFactory extends ServerSocketFactory ! { ! private static SSLServerSocketFactory theFactory; ! ! private static boolean propertyChecked; ! ! private static void log(String msg) { ! if (SSLSocketFactory.DEBUG) { ! System.out.println(msg); ! } ! } /** * Constructor is used only by subclasses. */ protected SSLServerSocketFactory() { /* NOTHING */ }
*** 63,75 **** * call fails, an inoperative factory is returned. * * @return the default <code>ServerSocketFactory</code> * @see SSLContext#getDefault */ ! public static ServerSocketFactory getDefault() { ! if (DefaultFactoryHolder.defaultFactory != null) { ! return DefaultFactoryHolder.defaultFactory; } try { return SSLContext.getDefault().getServerSocketFactory(); } catch (NoSuchAlgorithmException | UnsupportedOperationException e) { --- 73,115 ---- * call fails, an inoperative factory is returned. * * @return the default <code>ServerSocketFactory</code> * @see SSLContext#getDefault */ ! public static synchronized ServerSocketFactory getDefault() { ! if (theFactory != null) { ! return theFactory; ! } ! ! if (propertyChecked == false) { ! propertyChecked = true; ! String clsName = SSLSocketFactory.getSecurityProperty ! ("ssl.ServerSocketFactory.provider"); ! if (clsName != null) { ! log("setting up default SSLServerSocketFactory"); ! try { ! Class<?> cls = null; ! try { ! cls = Class.forName(clsName); ! } catch (ClassNotFoundException e) { ! ClassLoader cl = ClassLoader.getSystemClassLoader(); ! if (cl != null) { ! cls = cl.loadClass(clsName); ! } ! } ! log("class " + clsName + " is loaded"); ! @SuppressWarnings("deprecation") ! SSLServerSocketFactory fac = (SSLServerSocketFactory)cls.newInstance(); ! log("instantiated an instance of class " + clsName); ! theFactory = fac; ! return fac; ! } catch (Exception e) { ! log("SSLServerSocketFactory instantiation failed: " + e); ! theFactory = new DefaultSSLServerSocketFactory(e); ! return theFactory; ! } ! } } try { return SSLContext.getDefault().getServerSocketFactory(); } catch (NoSuchAlgorithmException | UnsupportedOperationException e) {
*** 114,168 **** * * @return an array of cipher suite names * @see #getDefaultCipherSuites() */ public abstract String [] getSupportedCipherSuites(); - - // lazy initialization holder class idiom for static default factory - // - // See Effective Java Second Edition: Item 71. - private static final class DefaultFactoryHolder { - private static final SSLServerSocketFactory defaultFactory; - - static { - SSLServerSocketFactory mediator = null; - String clsName = SSLSocketFactory.getSecurityProperty( - "ssl.ServerSocketFactory.provider"); - if (clsName != null) { - log("setting up default SSLServerSocketFactory"); - try { - Class<?> cls = null; - try { - cls = Class.forName(clsName); - } catch (ClassNotFoundException e) { - ClassLoader cl = ClassLoader.getSystemClassLoader(); - if (cl != null) { - cls = cl.loadClass(clsName); - } - } - log("class " + clsName + " is loaded"); - - mediator = (SSLServerSocketFactory)cls - .getDeclaredConstructor().newInstance(); - log("instantiated an instance of class " + clsName); - } catch (Exception e) { - log("SSLServerSocketFactory instantiation failed: " + e); - mediator = new DefaultSSLServerSocketFactory(e); - } - } - - defaultFactory = mediator; - } - - private static void log(String msg) { - if (SSLSocketFactory.DEBUG) { - System.out.println(msg); - } - } - } } // // The default factory does NOTHING. // class DefaultSSLServerSocketFactory extends SSLServerSocketFactory { --- 154,166 ---- * * @return an array of cipher suite names * @see #getDefaultCipherSuites() */ public abstract String [] getSupportedCipherSuites(); } + // // The default factory does NOTHING. // class DefaultSSLServerSocketFactory extends SSLServerSocketFactory {
< prev index next >