Package javax.net.ssl

Examples of javax.net.ssl.HttpsURLConnection


      throws IOException {
    try {
      query = updateQuery(query);
      final URL url = new URI("https", null, nnAddr.getHostName(),
          nnAddr.getPort(), path, query, null).toURL();
      HttpsURLConnection conn = (HttpsURLConnection)url.openConnection();
      // bypass hostname verification
      conn.setHostnameVerifier(new DummyHostnameVerifier());
      return (HttpURLConnection)conn;
    } catch (URISyntaxException e) {
      throw (IOException)new IOException().initCause(e);
    }
  }
View Full Code Here


        HttpURLConnection conn = (HttpURLConnection) url.openConnection();

        if (this.isIgnoreSslCertificateHostname()) {
            if (conn instanceof HttpsURLConnection) {
                HttpsURLConnection secure = (HttpsURLConnection) conn;
                secure.setHostnameVerifier(new HostnameVerifier() {

                    @Override
                    public boolean verify(String hostname, SSLSession session) {
                        boolean result = true;
                        log("SSL verification ignored for current session and hostname: "
View Full Code Here

    tempNode.putByteArray("xxx", url.getUserInfo().getBytes());
    String authInfo = tempNode.get("xxx", null);
    tempNode.removeNode();
    //
    sslContext.init(null, new TrustManager[] { new TrustEveryone() }, null);
    HttpsURLConnection urlConnection = (HttpsURLConnection) url.openConnection();
//    HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
    urlConnection.setRequestProperty("User-Agent", "jhg/0.1.0");
    urlConnection.setRequestProperty("Accept", "application/mercurial-0.1");
    urlConnection.setRequestProperty("Authorization", "Basic " + authInfo);
    urlConnection.setSSLSocketFactory(sslContext.getSocketFactory());
//    byte[] body = "pairs=f5aed108754e817d2ca374d1a4f6daf1218dcc91-9429c7bd1920fab164a9d2b621d38d57bcb49ae0".getBytes();
//    urlConnection.setRequestMethod("POST");
//    urlConnection.setRequestProperty("Content-Length", String.valueOf(body.length));
//    urlConnection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
//    urlConnection.setDoOutput(true);
//    urlConnection.setDoInput(true);
    urlConnection.connect();
//    OutputStream os = urlConnection.getOutputStream();
//    os.write(body);
//    os.flush();
//    os.close();
    System.out.println("Query:" + url.getQuery());
    System.out.println("Response headers:");
    final Map<String, List<String>> headerFields = urlConnection.getHeaderFields();
    for (String s : headerFields.keySet()) {
      System.out.printf("%s: %s\n", s, urlConnection.getHeaderField(s));
    }
    System.out.printf("Content type is %s and its length is %d\n", urlConnection.getContentType(), urlConnection.getContentLength());
    InputStream is = urlConnection.getInputStream();
    //
//    dump(is, -1); // simple dump, any cmd
    writeBundle(is, false, "HG10GZ"); // cmd=changegroup
    //writeBundle(is, true, "" or "HG10UN");
    //
    urlConnection.disconnect();
    //
  }
View Full Code Here

            verifier = CertificateHostnameVerifier.DEFAULT;
        }
       
        if (connection instanceof HttpsURLConnection) {
            // handle the expected case (javax.net.ssl)
            HttpsURLConnection conn = (HttpsURLConnection) connection;
            conn.setHostnameVerifier(verifier);
            conn.setSSLSocketFactory(socketFactory);
        } else {
            // handle the deprecated sun case and other possible hidden API's
            // that are similar to the Sun cases
            try {
                Method method = connection.getClass().getMethod("getHostnameVerifier");
View Full Code Here

     */
    HttpsURLConnectionInfo(HttpURLConnection connection)
        throws IOException {
        super(connection);
        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);
View Full Code Here

   *                      credentials are incorrect
   */
  public void login() throws IOException {
    String postContent = "accountType=HOSTED&Email=" + urlEncode(adminEmail) +
        "&Passwd=" + urlEncode(adminPassword);
    HttpsURLConnection connection = (HttpsURLConnection)
        new URL(AUTH_URL).openConnection();
    connection.setRequestMethod("POST");
    connection.setRequestProperty("Content-Length",
        Integer.toString(postContent.getBytes().length));
    connection.setRequestProperty("Content-Type",
        "application/x-www-form-urlencoded");
    connection.setDoInput(true);
    connection.setDoOutput(true);
    connection.setInstanceFollowRedirects(true);
    DataOutputStream out = new DataOutputStream(connection.getOutputStream());
    out.writeBytes(postContent);
    out.flush();
    out.close();
    BufferedReader reader = new BufferedReader(new InputStreamReader(
        connection.getInputStream()));
    String line = reader.readLine();
    while (line != null) {
      if (line.startsWith("SID=")) {
        reader.close();
        token = line.substring("SID=".length());
View Full Code Here

   * @param  request      report request containing request attributes
   * @throws IOException  if an HTTPS connection error occurs
   */
  private InputStream getReportData(ReportRequest request) throws IOException {
    String postContent = request.toXmlString();
    HttpsURLConnection connection = (HttpsURLConnection)
        new URL(REPORTING_URL).openConnection();
    connection.setRequestMethod("POST");
    connection.setRequestProperty("Content-Length",
        Integer.toString(postContent.getBytes().length));
    connection.setDoInput(true);
    connection.setDoOutput(true);
    connection.setInstanceFollowRedirects(true);
    DataOutputStream out = new DataOutputStream(connection.getOutputStream());
    out.writeBytes(postContent);
    out.flush();
    out.close();
    return connection.getInputStream();
  }
View Full Code Here

            throw new IOException("Illegal Protocol "
                    + url.getProtocol()
                    + " for HTTPS URLConnection Factory.");
        }
       
        HttpsURLConnection connection =
            (HttpsURLConnection) (proxy != null
                                   ? url.openConnection(proxy)
                                   : url.openConnection());
                                  
        if (tlsClientParameters != null) {
View Full Code Here

        }

        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

      throws IOException {
    final TrustManager[] trustAllCerts = new TrustManager[] { new DummyX509TrustManager() };
    try {
      SSLContext ctx = SSLContext.getInstance("SSL");
      ctx.init(null, trustAllCerts, null);
      final HttpsURLConnection sslConn = (HttpsURLConnection) conn;
      sslConn.setSSLSocketFactory(ctx.getSocketFactory());
    } catch (KeyManagementException e) {
      throw new IOException(e.getMessage());
    } catch (NoSuchAlgorithmException e) {
      throw new IOException(e.getMessage());
    }
View Full Code Here

TOP

Related Classes of javax.net.ssl.HttpsURLConnection

Copyright © 2018 www.massapicom. 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.