jdk/src/share/classes/sun/net/www/protocol/https/AbstractDelegateHttpsURLConnection.java
author chegar
Fri, 16 Sep 2011 12:09:04 -0700
changeset 10596 39b3a979e600
parent 5506 202f599c92aa
child 16499 88276d2da9c0
permissions -rw-r--r--
7090158: Networking Libraries don't build with javac -Werror Summary: Minor changes to networking java files to remove warnings Reviewed-by: chegar, weijun, hawtin Contributed-by: kurchi.subhra.hazra@oracle.com, sasha_bu@hotmail.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
10596
39b3a979e600 7090158: Networking Libraries don't build with javac -Werror
chegar
parents: 5506
diff changeset
     2
 * Copyright (c) 2001, 2011, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package sun.net.www.protocol.https;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.net.URL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.net.Proxy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.net.SecureCacheResponse;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.security.Principal;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.util.List;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import javax.net.ssl.SSLPeerUnverifiedException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import sun.net.www.http.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import sun.net.www.protocol.http.HttpURLConnection;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * HTTPS URL connection support.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * We need this delegate because HttpsURLConnection is a subclass of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * java.net.HttpURLConnection. We will avoid copying over the code from
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * sun.net.www.protocol.http.HttpURLConnection by having this class
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
public abstract class AbstractDelegateHttpsURLConnection extends
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
        HttpURLConnection {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    protected AbstractDelegateHttpsURLConnection(URL url,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
            sun.net.www.protocol.http.Handler handler) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
        this(url, null, handler);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    protected AbstractDelegateHttpsURLConnection(URL url, Proxy p,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
            sun.net.www.protocol.http.Handler handler) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
        super(url, p, handler);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    protected abstract javax.net.ssl.SSLSocketFactory getSSLSocketFactory();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    protected abstract javax.net.ssl.HostnameVerifier getHostnameVerifier();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
     * No user application is able to call these routines, as no one
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
     * should ever get access to an instance of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
     * DelegateHttpsURLConnection (sun.* or com.*)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
     * Create a new HttpClient object, bypassing the cache of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
     * HTTP client objects/connections.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
     * Note: this method is changed from protected to public because
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
     * the com.sun.ssl.internal.www.protocol.https handler reuses this
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
     * class for its actual implemantation
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
     * @param url the URL being accessed
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    public void setNewClient (URL url)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        setNewClient (url, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     * Obtain a HttpClient object. Use the cached copy if specified.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     * Note: this method is changed from protected to public because
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     * the com.sun.ssl.internal.www.protocol.https handler reuses this
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     * class for its actual implemantation
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     * @param url       the URL being accessed
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     * @param useCache  whether the cached connection should be used
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     *        if present
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    public void setNewClient (URL url, boolean useCache)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        http = HttpsClient.New (getSSLSocketFactory(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
                                url,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
                                getHostnameVerifier(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
                                useCache);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        ((HttpsClient)http).afterConnect();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     * Create a new HttpClient object, set up so that it uses
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     * per-instance proxying to the given HTTP proxy.  This
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     * bypasses the cache of HTTP client objects/connections.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     * Note: this method is changed from protected to public because
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     * the com.sun.ssl.internal.www.protocol.https handler reuses this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     * class for its actual implemantation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     * @param url       the URL being accessed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     * @param proxyHost the proxy host to use
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     * @param proxyPort the proxy port to use
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    public void setProxiedClient (URL url, String proxyHost, int proxyPort)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
            throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        setProxiedClient(url, proxyHost, proxyPort, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     * Obtain a HttpClient object, set up so that it uses per-instance
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     * proxying to the given HTTP proxy. Use the cached copy of HTTP
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     * client objects/connections if specified.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     * Note: this method is changed from protected to public because
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     * the com.sun.ssl.internal.www.protocol.https handler reuses this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     * class for its actual implemantation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     * @param url       the URL being accessed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     * @param proxyHost the proxy host to use
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     * @param proxyPort the proxy port to use
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     * @param useCache  whether the cached connection should be used
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     *        if present
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    public void setProxiedClient (URL url, String proxyHost, int proxyPort,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
            boolean useCache) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        proxiedConnect(url, proxyHost, proxyPort, useCache);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        if (!http.isCachedConnection()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
            doTunneling();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        ((HttpsClient)http).afterConnect();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    protected void proxiedConnect(URL url, String proxyHost, int proxyPort,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
            boolean useCache) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        if (connected)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        http = HttpsClient.New (getSSLSocketFactory(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
                                url,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
                                getHostnameVerifier(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
                                proxyHost, proxyPort, useCache);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        connected = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     * Used by subclass to access "connected" variable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    public boolean isConnected() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        return connected;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     * Used by subclass to access "connected" variable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    public void setConnected(boolean conn) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        connected = conn;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     * Implements the HTTP protocol handler's "connect" method,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     * establishing an SSL connection to the server as necessary.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    public void connect() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        if (connected)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        plainConnect();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        if (cachedResponse != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
            // using cached response
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        if (!http.isCachedConnection() && http.needsTunneling()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
            doTunneling();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        ((HttpsClient)http).afterConnect();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
    // will try to use cached HttpsClient
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    protected HttpClient getNewHttpClient(URL url, Proxy p, int connectTimeout)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        return HttpsClient.New(getSSLSocketFactory(), url,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
                               getHostnameVerifier(), p, true, connectTimeout);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
    // will open new connection
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
    protected HttpClient getNewHttpClient(URL url, Proxy p, int connectTimeout,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
                                          boolean useCache)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        return HttpsClient.New(getSSLSocketFactory(), url,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
                               getHostnameVerifier(), p,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
                               useCache, connectTimeout);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     * Returns the cipher suite in use on this connection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
    public String getCipherSuite () {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
        if (cachedResponse != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
            return ((SecureCacheResponse)cachedResponse).getCipherSuite();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        if (http == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
            throw new IllegalStateException("connection not yet open");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
           return ((HttpsClient)http).getCipherSuite ();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     * Returns the certificate chain the client sent to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     * server, or null if the client did not authenticate.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
    public java.security.cert.Certificate[] getLocalCertificates() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        if (cachedResponse != null) {
10596
39b3a979e600 7090158: Networking Libraries don't build with javac -Werror
chegar
parents: 5506
diff changeset
   224
            List<java.security.cert.Certificate> l = ((SecureCacheResponse)cachedResponse).getLocalCertificateChain();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
            if (l == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
            } else {
10596
39b3a979e600 7090158: Networking Libraries don't build with javac -Werror
chegar
parents: 5506
diff changeset
   228
                return l.toArray(new java.security.cert.Certificate[0]);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        if (http == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
            throw new IllegalStateException("connection not yet open");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
            return (((HttpsClient)http).getLocalCertificates ());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     * Returns the server's certificate chain, or throws
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     * SSLPeerUnverified Exception if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     * the server did not authenticate.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
    public java.security.cert.Certificate[] getServerCertificates()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
            throws SSLPeerUnverifiedException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        if (cachedResponse != null) {
10596
39b3a979e600 7090158: Networking Libraries don't build with javac -Werror
chegar
parents: 5506
diff changeset
   246
            List<java.security.cert.Certificate> l = ((SecureCacheResponse)cachedResponse).getServerCertificateChain();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
            if (l == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
            } else {
10596
39b3a979e600 7090158: Networking Libraries don't build with javac -Werror
chegar
parents: 5506
diff changeset
   250
                return l.toArray(new java.security.cert.Certificate[0]);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
        if (http == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
            throw new IllegalStateException("connection not yet open");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
            return (((HttpsClient)http).getServerCertificates ());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
     * Returns the server's X.509 certificate chain, or null if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
     * the server did not authenticate.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
    public javax.security.cert.X509Certificate[] getServerCertificateChain()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
            throws SSLPeerUnverifiedException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
        if (cachedResponse != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
            throw new UnsupportedOperationException("this method is not supported when using cache");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
        if (http == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
            throw new IllegalStateException("connection not yet open");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
            return ((HttpsClient)http).getServerCertificateChain ();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
     * Returns the server's principal, or throws SSLPeerUnverifiedException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
     * if the server did not authenticate.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
    Principal getPeerPrincipal()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
            throws SSLPeerUnverifiedException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
        if (cachedResponse != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
            return ((SecureCacheResponse)cachedResponse).getPeerPrincipal();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
        if (http == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
            throw new IllegalStateException("connection not yet open");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
            return (((HttpsClient)http).getPeerPrincipal());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
     * Returns the principal the client sent to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
     * server, or null if the client did not authenticate.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
    Principal getLocalPrincipal()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
        if (cachedResponse != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
            return ((SecureCacheResponse)cachedResponse).getLocalPrincipal();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
        if (http == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
            throw new IllegalStateException("connection not yet open");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
            return (((HttpsClient)http).getLocalPrincipal());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
}