|
Java example source code file (HttpsURLConnectionImpl.java)
The HttpsURLConnectionImpl.java Java example source code/* * Copyright (c) 2001, 2013, 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 * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ /* * NOTE: This class lives in the package sun.net.www.protocol.https. * There is a copy in com.sun.net.ssl.internal.www.protocol.https for JSSE * 1.0.2 compatibility. It is 100% identical except the package and extends * lines. Any changes should be made to be class in sun.net.* and then copied * to com.sun.net.*. */ // For both copies of the file, uncomment one line and comment the other package sun.net.www.protocol.https; // package com.sun.net.ssl.internal.www.protocol.https; import java.net.URL; import java.net.Proxy; import java.net.ProtocolException; import java.io.*; import javax.net.ssl.*; import java.security.Permission; import java.security.Principal; import java.util.Map; import java.util.List; import sun.net.www.http.HttpClient; /** * A class to represent an HTTP connection to a remote object. * * Ideally, this class should subclass and inherit the http handler * implementation, but it can't do so because that class have the * wrong Java Type. Thus it uses the delegate (aka, the * Adapter/Wrapper design pattern) to reuse code from the http * handler. * * Since it would use a delegate to access * sun.net.www.protocol.http.HttpURLConnection functionalities, it * needs to implement all public methods in it's super class and all * the way to Object. * */ // For both copies of the file, uncomment one line and comment the // other. The differences between the two copies are introduced for // plugin, and it is marked as such. public class HttpsURLConnectionImpl extends javax.net.ssl.HttpsURLConnection { // public class HttpsURLConnectionOldImpl // extends com.sun.net.ssl.HttpsURLConnection { // NOTE: made protected for plugin so that subclass can set it. protected DelegateHttpsURLConnection delegate; // For both copies of the file, uncomment one line and comment the other HttpsURLConnectionImpl(URL u, Handler handler) throws IOException { // HttpsURLConnectionOldImpl(URL u, Handler handler) throws IOException { this(u, null, handler); } // For both copies of the file, uncomment one line and comment the other HttpsURLConnectionImpl(URL u, Proxy p, Handler handler) throws IOException { // HttpsURLConnectionOldImpl(URL u, Proxy p, Handler handler) throws IOException { super(u); delegate = new DelegateHttpsURLConnection(url, p, handler, this); } // NOTE: introduced for plugin // subclass needs to overwrite this to set delegate to // the appropriate delegatee protected HttpsURLConnectionImpl(URL u) throws IOException { super(u); } /** * Create a new HttpClient object, bypassing the cache of * HTTP client objects/connections. * * @param url the URL being accessed */ protected void setNewClient(URL url) throws IOException { delegate.setNewClient(url, false); } /** * Obtain a HttpClient object. Use the cached copy if specified. * * @param url the URL being accessed * @param useCache whether the cached connection should be used * if present */ protected void setNewClient(URL url, boolean useCache) throws IOException { delegate.setNewClient(url, useCache); } /** * Create a new HttpClient object, set up so that it uses * per-instance proxying to the given HTTP proxy. This * bypasses the cache of HTTP client objects/connections. * * @param url the URL being accessed * @param proxyHost the proxy host to use * @param proxyPort the proxy port to use */ protected void setProxiedClient(URL url, String proxyHost, int proxyPort) throws IOException { delegate.setProxiedClient(url, proxyHost, proxyPort); } /** * Obtain a HttpClient object, set up so that it uses per-instance * proxying to the given HTTP proxy. Use the cached copy of HTTP * client objects/connections if specified. * * @param url the URL being accessed * @param proxyHost the proxy host to use * @param proxyPort the proxy port to use * @param useCache whether the cached connection should be used * if present */ protected void setProxiedClient(URL url, String proxyHost, int proxyPort, boolean useCache) throws IOException { delegate.setProxiedClient(url, proxyHost, proxyPort, useCache); } /** * Implements the HTTP protocol handler's "connect" method, * establishing an SSL connection to the server as necessary. */ public void connect() throws IOException { delegate.connect(); } /** * Used by subclass to access "connected" variable. Since we are * delegating the actual implementation to "delegate", we need to * delegate the access of "connected" as well. */ protected boolean isConnected() { return delegate.isConnected(); } /** * Used by subclass to access "connected" variable. Since we are * delegating the actual implementation to "delegate", we need to * delegate the access of "connected" as well. */ protected void setConnected(boolean conn) { delegate.setConnected(conn); } /** * Returns the cipher suite in use on this connection. */ public String getCipherSuite() { return delegate.getCipherSuite(); } /** * Returns the certificate chain the client sent to the * server, or null if the client did not authenticate. */ public java.security.cert.Certificate [] getLocalCertificates() { return delegate.getLocalCertificates(); } /** * Returns the server's certificate chain, or throws * SSLPeerUnverified Exception if * the server did not authenticate. */ public java.security.cert.Certificate [] getServerCertificates() throws SSLPeerUnverifiedException { return delegate.getServerCertificates(); } /** * Returns the server's X.509 certificate chain, or null if * the server did not authenticate. * * NOTE: This method is not necessary for the version of this class * implementing javax.net.ssl.HttpsURLConnection, but provided for * compatibility with the com.sun.net.ssl.HttpsURLConnection version. */ public javax.security.cert.X509Certificate[] getServerCertificateChain() { try { return delegate.getServerCertificateChain(); } catch (SSLPeerUnverifiedException e) { // this method does not throw an exception as declared in // com.sun.net.ssl.HttpsURLConnection. // Return null for compatibility. return null; } } /** * Returns the principal with which the server authenticated itself, * or throw a SSLPeerUnverifiedException if the server did not authenticate. */ public Principal getPeerPrincipal() throws SSLPeerUnverifiedException { return delegate.getPeerPrincipal(); } /** * Returns the principal the client sent to the * server, or null if the client did not authenticate. */ public Principal getLocalPrincipal() { return delegate.getLocalPrincipal(); } /* * Allowable input/output sequences: * [interpreted as POST/PUT] * - get output, [write output,] get input, [read input] * - get output, [write output] * [interpreted as GET] * - get input, [read input] * Disallowed: * - get input, [read input,] get output, [write output] */ public synchronized OutputStream getOutputStream() throws IOException { return delegate.getOutputStream(); } public synchronized InputStream getInputStream() throws IOException { return delegate.getInputStream(); } public InputStream getErrorStream() { return delegate.getErrorStream(); } /** * Disconnect from the server. */ public void disconnect() { delegate.disconnect(); } public boolean usingProxy() { return delegate.usingProxy(); } /** * Returns an unmodifiable Map of the header fields. * The Map keys are Strings that represent the * response-header field names. Each Map value is an * unmodifiable List of Strings that represents * the corresponding field values. * * @return a Map of header fields * @since 1.4 */ public Map<String,List Other Java examples (source code examples)Here is a short list of links related to this Java HttpsURLConnectionImpl.java source code file: |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.