Java Code Examples for javax.net.ssl.HttpsURLConnection#getPeerPrincipal()

The following examples show how to use javax.net.ssl.HttpsURLConnection#getPeerPrincipal() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HttpsURLConnectionInfo.java    From cxf with Apache License 2.0 5 votes vote down vote up
/**
 * This constructor is used to create the info object
 * representing the this HttpsURLConnection. Connection parameter is
 * of supertype HttpURLConnection, which allows internal cast to
 * potentially divergent subtype (Https) implementations.
 */
public HttpsURLConnectionInfo(HttpURLConnection connection)
    throws IOException {
    super(connection.getURL(), connection.getRequestMethod());
    if (connection instanceof HttpsURLConnection) {
        HttpsURLConnection conn = (HttpsURLConnection) connection;
        enabledCipherSuite = conn.getCipherSuite();
        localCertificates = conn.getLocalCertificates();
        localPrincipal = conn.getLocalPrincipal();
        serverCertificates = conn.getServerCertificates();
        peerPrincipal = conn.getPeerPrincipal();
    } else {
        Exception ex = null;
        try {
            Method method = null;
            method = connection.getClass().getMethod("getCipherSuite", (Class[]) null);
            enabledCipherSuite = (String) method.invoke(connection, (Object[]) null);
            method = connection.getClass().getMethod("getLocalCertificates", (Class[]) null);
            localCertificates = (Certificate[]) method.invoke(connection, (Object[]) null);
            method = connection.getClass().getMethod("getServerCertificates", (Class[]) null);
            serverCertificates = (Certificate[]) method.invoke(connection, (Object[]) null);

            //TODO Obtain localPrincipal and peerPrincipal using the com.sun.net.ssl api
        } catch (Exception e) {
            ex = e;
        } finally {
            if (ex != null) {
                if (ex instanceof IOException) {
                    throw (IOException) ex;
                }
                IOException ioe = new IOException("Error constructing HttpsURLConnectionInfo "
                                                  + "for connection class "
                                                  + connection.getClass().getName());
                ioe.initCause(ex);
                throw ioe;

            }
        }
    }
}