Examples of HttpsURLConnection


Examples of javax.net.ssl.HttpsURLConnection

        }

        protected URLConnection openConnection(URL url) throws IOException {
            URLConnection con = url.openConnection();
            if ("HTTPS".equalsIgnoreCase(url.getProtocol())) {
                HttpsURLConnection scon = (HttpsURLConnection) con;
                try {
                    scon.setSSLSocketFactory(SSLUtil.getSSLSocketFactory(ks, password, alias));
                    scon.setHostnameVerifier(SSLUtil.getHostnameVerifier(SSLUtil.HOSTCERT_MIN_CHECK));
                } catch (GeneralException e) {
                    throw new IOException(e.getMessage());
                } catch (GeneralSecurityException e) {
                    throw new IOException(e.getMessage());
                }
View Full Code Here

Examples of javax.net.ssl.HttpsURLConnection

        log.trace(">getUrlConnection( URL url )");
        log.debug(" - url=" + url);
        URLConnection orgcon = url.openConnection();
        log.debug(orgcon.getClass());
        if (orgcon instanceof HttpsURLConnection) {
            HttpsURLConnection con = (HttpsURLConnection) orgcon;
            con.setHostnameVerifier(new SimpleVerifier());
            con.setSSLSocketFactory(getSSLFactory(trust));
        } else {
            log.debug("getUrlConnection(): Ingen HttpsUrlConnection!");
        }
        log.trace("<getUrlConnection() --> " + orgcon);
        return orgcon;
View Full Code Here

Examples of javax.net.ssl.HttpsURLConnection

     * @throws GeneralSecurityException
     */
    private URLConnection getUrlConnection(URL url) throws IOException, GeneralSecurityException {
        final URLConnection orgcon = url.openConnection();
        if (orgcon instanceof HttpsURLConnection) {
            HttpsURLConnection con = (HttpsURLConnection) orgcon;
            con.setHostnameVerifier(new SimpleVerifier());
            con.setSSLSocketFactory(getSSLFactory());
        }
        return orgcon;
    }
View Full Code Here

Examples of javax.net.ssl.HttpsURLConnection

    public HttpsTransport(TextWireFormat wireFormat, URI remoteUrl) throws MalformedURLException {
        super(wireFormat, remoteUrl);
    }

    protected synchronized HttpURLConnection createSendConnection() throws IOException {
        HttpsURLConnection conn = (HttpsURLConnection) getRemoteURL().openConnection();
        conn.setDoOutput(true);
        conn.setRequestMethod("POST");
        configureConnection(conn);
        conn.connect();
        return conn;
    }
View Full Code Here

Examples of javax.net.ssl.HttpsURLConnection

        conn.connect();
        return conn;
    }

    protected synchronized HttpURLConnection createReceiveConnection() throws IOException {
        HttpsURLConnection conn = (HttpsURLConnection) getRemoteURL().openConnection();
        conn.setDoOutput(false);
        conn.setDoInput(true);
        conn.setRequestMethod("GET");
        configureConnection(conn);
        conn.connect();
        return conn;
    }
View Full Code Here

Examples of javax.net.ssl.HttpsURLConnection

    // Get the size of a file from URL response header.
    public static Long getRemoteSize(String url) {
        Long remoteSize = (long) 0;
        HttpURLConnection httpConn = null;
        HttpsURLConnection httpsConn = null;
        try {
            URI uri = new URI(url);
            if (uri.getScheme().equalsIgnoreCase("http")) {
                httpConn = (HttpURLConnection) uri.toURL().openConnection();
                if (httpConn != null) {
                    String contentLength = httpConn.getHeaderField("content-length");
                    if (contentLength != null) {
                        remoteSize = Long.parseLong(contentLength);
                    }
                    httpConn.disconnect();
                }
            } else if (uri.getScheme().equalsIgnoreCase("https")) {
                httpsConn = (HttpsURLConnection) uri.toURL().openConnection();
                if (httpsConn != null) {
                    String contentLength = httpsConn.getHeaderField("content-length");
                    if (contentLength != null) {
                        remoteSize = Long.parseLong(contentLength);
                    }
                    httpsConn.disconnect();
                }
            }
        } catch (URISyntaxException e) {
            throw new IllegalArgumentException("Invalid URL " + url);
        } catch (IOException e) {
View Full Code Here

Examples of javax.net.ssl.HttpsURLConnection

        return;
    }

    public HttpsURLConnection openSecureConnection(URL url) throws Exception {
        // we assume the URL is https - if it is not, its an error so just let the cast throw exception
        HttpsURLConnection connection = (HttpsURLConnection) url.openConnection();

        TrustManager[] trustManagers;
        SSLContext sslContext = SSLContext.getInstance(getSecureSocketProtocol());

        if (getTruststoreFile() == null) {
            // we are configured to not care about authenticating the server, just encrypt but don't worry about certificates
            trustManagers = new TrustManager[] { NO_OP_TRUST_MANAGER };
            connection.setHostnameVerifier(NO_OP_HOSTNAME_VERIFIER);
        } else {
            // We need to configure our SSL connection with the agent's truststore so we can authenticate the server.
            // First, create a KeyStore, but load it with our truststore entries.
            KeyStore keyStore = KeyStore.getInstance(getTruststoreType());
            keyStore.load(new FileInputStream(getTruststoreFile()), getTruststorePassword().toCharArray());
            // now create a truststore manager instance and initialize it with our KeyStore we created with all our truststore entries
            TrustManagerFactory tmf = TrustManagerFactory.getInstance(getTruststoreAlgorithm());
            tmf.init(keyStore);
            trustManagers = tmf.getTrustManagers();
        }

        sslContext.init(null, trustManagers, null);
        connection.setSSLSocketFactory(sslContext.getSocketFactory());

        return connection;
    }
View Full Code Here

Examples of javax.net.ssl.HttpsURLConnection

            return true;
        }
    };

    public static void main(String[] args) throws Exception {
        HttpsURLConnection conn = new SecureConnector("TLS").openSecureConnection(new URL(args[0]));
        java.io.ByteArrayOutputStream out = new java.io.ByteArrayOutputStream();
        java.io.InputStream input = new java.io.BufferedInputStream(conn.getInputStream(), 32768);
        byte[] buffer = new byte[32768];
        for (int bytesRead = input.read(buffer); bytesRead != -1; bytesRead = input.read(buffer)) {
            out.write(buffer, 0, bytesRead);
        }
        out.flush();
View Full Code Here

Examples of javax.net.ssl.HttpsURLConnection

        int responseCode = -1;
        int outVal = -1;
        if (url != null) {
            try {
                if (url.getProtocol().equals("https")) {
                    HttpsURLConnection htuc = (HttpsURLConnection)url.openConnection();
                    responseCode = htuc.getResponseCode();
                    htuc.disconnect();
                } else if (url.getProtocol().equals("http")) {
                    HttpURLConnection htuc = (HttpURLConnection)url.openConnection();
                    responseCode = htuc.getResponseCode();
                    htuc.disconnect();
                } else {
                    outVal = 1; // invalid protocol
                }
            } catch (IOException ioe) {}
            if (responseCode == HttpURLConnection.HTTP_OK) {
View Full Code Here

Examples of javax.net.ssl.HttpsURLConnection

  @VisibleForTesting
  protected HttpURLConnection openConnection(URL url) throws IOException {
    HttpURLConnection conn = (HttpURLConnection) url.openConnection();
    if (sslShuffle) {
      HttpsURLConnection httpsConn = (HttpsURLConnection) conn;
      try {
        httpsConn.setSSLSocketFactory(sslFactory.createSSLSocketFactory());
      } catch (GeneralSecurityException ex) {
        throw new IOException(ex);
      }
      httpsConn.setHostnameVerifier(sslFactory.getHostnameVerifier());
    }
    return conn;
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.