Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/net/ssl/FixingJavadocs/ComURLNulls.java
38853 views
/*1* Copyright (c) 2001, 2015, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @bug 4387882 445103826* @summary Need to revisit the javadocs for JSSE, especially the27* promoted classes, and HttpsURLConnection.getCipherSuite throws28* NullPointerException29* @run main/othervm ComURLNulls30*31* SunJSSE does not support dynamic system properties, no way to re-use32* system properties in samevm/agentvm mode.33* @author Brad Wetmore34*/3536import java.net.*;37import java.io.*;38import javax.net.ssl.*;39import com.sun.net.ssl.HttpsURLConnection;40import com.sun.net.ssl.HostnameVerifier;4142/*43* Tests that the com null argument changes made it in ok.44*/4546public class ComURLNulls {4748private static class ComSunHTTPSHandlerFactory implements URLStreamHandlerFactory {49private static String SUPPORTED_PROTOCOL = "https";5051public URLStreamHandler createURLStreamHandler(String protocol) {52if (!protocol.equalsIgnoreCase(SUPPORTED_PROTOCOL))53return null;5455return new com.sun.net.ssl.internal.www.protocol.https.Handler();56}57}5859public static void main(String[] args) throws Exception {60HostnameVerifier reservedHV =61HttpsURLConnection.getDefaultHostnameVerifier();62try {63URL.setURLStreamHandlerFactory(new ComSunHTTPSHandlerFactory());6465/**66* This test does not establish any connection to the specified67* URL, hence a dummy URL is used.68*/69URL foobar = new URL("https://example.com/");7071HttpsURLConnection urlc =72(HttpsURLConnection) foobar.openConnection();7374try {75urlc.getCipherSuite();76} catch (IllegalStateException e) {77System.out.print("Caught proper exception: ");78System.out.println(e.getMessage());79}8081try {82urlc.getServerCertificateChain();83} catch (IllegalStateException e) {84System.out.print("Caught proper exception: ");85System.out.println(e.getMessage());86}8788try {89urlc.setDefaultHostnameVerifier(null);90} catch (IllegalArgumentException e) {91System.out.print("Caught proper exception: ");92System.out.println(e.getMessage());93}9495try {96urlc.setHostnameVerifier(null);97} catch (IllegalArgumentException e) {98System.out.print("Caught proper exception: ");99System.out.println(e.getMessage());100}101102try {103urlc.setDefaultSSLSocketFactory(null);104} catch (IllegalArgumentException e) {105System.out.print("Caught proper exception: ");106System.out.println(e.getMessage());107}108109try {110urlc.setSSLSocketFactory(null);111} catch (IllegalArgumentException e) {112System.out.print("Caught proper exception");113System.out.println(e.getMessage());114}115System.out.println("TESTS PASSED");116} finally {117HttpsURLConnection.setDefaultHostnameVerifier(reservedHV);118}119}120}121122123