protected InputStream getInputStreamFromConnection()

in src/main/java/com/vmware/vim25/ws/WSClient.java [201:238]


    protected InputStream getInputStreamFromConnection(HttpURLConnection postCon) throws RemoteException{
        InputStream is;

        try {
            is = postCon.getInputStream();
            if (log.isTraceEnabled()) {
                log.trace("Successfully fetched InputStream.");
            }
        }
        catch (IOException ioe) {
            log.debug("Caught an IOException. Reading ErrorStream for results.", ioe);
            InputStream errorStream = postCon.getErrorStream();

            // check if there is an error stream available
            if (errorStream != null) {
                // return the error stream as the input stream so it can be parsed
                is = errorStream;
            } else {
                // if there is no error stream available, wrap the IOException to give meaningful error
                throw new RemoteException(MessageFormat.format("An error occurred getting a response from the connection at url {0}", baseUrl), ioe);
            }
        }

        if (thumbprint == null && postCon instanceof HttpsURLConnection) {
            try {
                Certificate[] certs = ((HttpsURLConnection)postCon).getServerCertificates();
                for (int i = 0; thumbprint == null && i < certs.length; i++) {
                    if (certs[i] instanceof X509Certificate) {
                        setServerThumbprint(computeX509CertificateThumbprint((X509Certificate) certs[i]));
                    }
                }
            }
            catch (SSLPeerUnverifiedException e) {
                log.debug("SSLPeerUnverifiedException caught.", e);
            }
        }
        return is;
    }