Examples of HttpsURLConnection


Examples of javax.net.ssl.HttpsURLConnection

   * @param map Key-value map.
   * @return the response input stream.
   */
  private InputStream doRequest(String url, String requestMethod, Map<String, String> map) {
    try {
      HttpsURLConnection conn = (HttpsURLConnection) new URL(url)
          .openConnection();
      conn.setRequestProperty("Accept-Encoding", "gzip, deflate");
            conn.setDoOutput(requestMethod.equals(METHOD_POST) || requestMethod.equals(METHOD_PUT));
            conn.setRequestMethod(requestMethod);

            if(map != null && !map.isEmpty()) {
                StringBuilder sb = new StringBuilder();
                for (String key : map.keySet()) {
                    sb.append(sb.length() > 0 ? "&" : "")
                        .append(key)
                        .append("=")
                        .append(URLEncoder.encode(map.get(key), "UTF-8"));
                }
                conn.getOutputStream().write(sb.toString().getBytes());
                conn.getOutputStream().close();
            }

      if (conn.getResponseCode() > 399) {
        return null;
      } else {
        return getWrappedInputStream(
                    conn.getInputStream(), GZIP_ENCODING.equalsIgnoreCase(conn.getContentEncoding())
                );
      }
    } catch (IOException e) {
      throw new TrelloException(e.getMessage());
    }
View Full Code Here

Examples of javax.net.ssl.HttpsURLConnection

   * Verify hostname verifier is set and accepts all
   */
  @Test
  public void verifierAccepts() {
    HttpRequest request = get("https://localhost");
    HttpsURLConnection connection = (HttpsURLConnection) request
        .getConnection();
    request.trustAllHosts();
    assertNotNull(connection.getHostnameVerifier());
    assertTrue(connection.getHostnameVerifier().verify(null, null));
  }
View Full Code Here

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

Examples of javax.net.ssl.HttpsURLConnection

        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

Examples of javax.net.ssl.HttpsURLConnection

    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

Examples of javax.net.ssl.HttpsURLConnection

            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

Examples of javax.net.ssl.HttpsURLConnection

     */
    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

Examples of javax.net.ssl.HttpsURLConnection

   *                      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

Examples of javax.net.ssl.HttpsURLConnection

   * @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

Examples of javax.net.ssl.HttpsURLConnection

            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
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.