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

      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

Examples of javax.net.ssl.HttpsURLConnection

   * @param sampleRate The sample rate for your audio file.
   */
  private void openHttpsPostConnection(final String urlStr, final byte[] data, final int sampleRate) {
    new Thread () {
      public void run() {
        HttpsURLConnection httpConn = null;
        ByteBuffer buff = ByteBuffer.wrap(data);
        byte[] destdata = new byte[2048];
        int resCode = -1;
        OutputStream out = null;
        try {
          URL url = new URL(urlStr);
          URLConnection urlConn = url.openConnection();
          if (!(urlConn instanceof HttpsURLConnection)) {
            throw new IOException ("URL must be HTTPS");
          }
          httpConn = (HttpsURLConnection)urlConn;
          httpConn.setAllowUserInteraction(false);
          httpConn.setInstanceFollowRedirects(true);
          httpConn.setRequestMethod("POST");
          httpConn.setDoOutput(true);
          httpConn.setChunkedStreamingMode(0); //TransferType: chunked
          httpConn.setRequestProperty("Content-Type", "audio/x-flac; rate=" + sampleRate);
          // this opens a connection, then sends POST & headers.
          out = httpConn.getOutputStream();
          //beyond 15 sec duration just simply writing the file
          // does not seem to work. So buffer it and delay to simulate
          // bufferd microphone delivering stream of speech
          // re: net.http.ChunkedOutputStream.java
          while(buff.remaining() >= destdata.length){
            buff.get(destdata);
            out.write(destdata);
          };
          byte[] lastr = new byte[buff.remaining()];
          buff.get(lastr, 0, lastr.length);
          out.write(lastr);
          out.close();
          resCode = httpConn.getResponseCode();
          if(resCode >= HttpURLConnection.HTTP_UNAUTHORIZED){//Stops here if Google doesn't like us/
            throw new HTTPException(HttpURLConnection.HTTP_UNAUTHORIZED);//Throws
          }
          String line;//Each line that is read back from Google.
          BufferedReader br =  new BufferedReader(new InputStreamReader(httpConn.getInputStream()));
          while ((line = br.readLine( )) != null) {
            if(line.length()>19 && resCode > 100 && resCode < HttpURLConnection.HTTP_UNAUTHORIZED){
              GoogleResponse gr = new GoogleResponse();
              parseResponse(line, gr);
              fireResponseEvent(gr);
            }
          }
        } catch (MalformedURLException e) {
          e.printStackTrace();
        } catch (IOException e) {
          e.printStackTrace();
        }
        finally {httpConn.disconnect();}
      }
    }.start();
  }
View Full Code Here

Examples of javax.net.ssl.HttpsURLConnection

      URL url = new URL(urlStr);
      URLConnection urlConn = url.openConnection();
      if (!(urlConn instanceof HttpsURLConnection)) {
        throw new IOException ("URL is not an Https URL");
      }
      HttpsURLConnection httpConn = (HttpsURLConnection)urlConn;
      httpConn.setAllowUserInteraction(false);
      // TIMEOUT is required
      httpConn.setInstanceFollowRedirects(true);
      httpConn.setRequestMethod("GET");

      httpConn.connect();
      resCode = httpConn.getResponseCode();
      if (resCode == HttpsURLConnection.HTTP_OK) {
        return new Scanner(httpConn.getInputStream());
      }
      else{
        System.out.println("Error: " + resCode);
      }
    } catch (MalformedURLException e) {
View Full Code Here

Examples of javax.net.ssl.HttpsURLConnection

      url = new URL(murl);
      URLConnection urlConn = url.openConnection();
      if (!(urlConn instanceof HttpsURLConnection)) {
        throw new IOException ("URL is not an Https URL");
      }
      HttpsURLConnection httpConn = (HttpsURLConnection)urlConn;
      httpConn.setAllowUserInteraction(false);
      httpConn.setInstanceFollowRedirects(true);
      httpConn.setRequestMethod("POST");
      httpConn.setDoOutput(true);
      httpConn.setChunkedStreamingMode(0);
      httpConn.setRequestProperty("Transfer-Encoding", "chunked");
      httpConn.setRequestProperty("Content-Type", "audio/x-flac; rate=" + (int)maf.getSampleRate());
      // also worked with ("Content-Type", "audio/amr; rate=8000");
      httpConn.connect();

      // this opens a connection, then sends POST & headers.
      OutputStream out = httpConn.getOutputStream();
      //Note : if the audio is more than 15 seconds
      // dont write it to UrlConnInputStream all in one block as this sample does.
      // Rather, segment the byteArray and on intermittently, sleeping thread
      // supply bytes to the urlConn Stream at a rate that approaches
      // the bitrate ( =30K per sec. in this instance ).
      System.out.println("Starting to write data to output...");
      AudioInputStream ais = new AudioInputStream(mtl);
      ChunkedOutputStream os = new ChunkedOutputStream(out);
      AudioSystem.write(ais, FLACFileWriter.FLAC, os);
      out.write(FINAL_CHUNK);
      System.out.println("IO WRITE DONE");
      out.close();
      // do you need the trailer?
      // NOW you can look at the status.
      int resCode = httpConn.getResponseCode();
      if (resCode / 100 != 2) {
        System.out.println("ERROR");
      }
    }catch(Exception ex){
      ex.printStackTrace();
View Full Code Here

Examples of javax.net.ssl.HttpsURLConnection

      URL url = new URL(urlStr);
      URLConnection urlConn = url.openConnection();
      if (!(urlConn instanceof HttpsURLConnection)) {
        throw new IOException ("URL is not an Https URL");
      }
      HttpsURLConnection httpConn = (HttpsURLConnection)urlConn;
      httpConn.setAllowUserInteraction(false);
      httpConn.setInstanceFollowRedirects(true);
      httpConn.setRequestMethod("POST");
      httpConn.setDoOutput(true);
      httpConn.setChunkedStreamingMode(0);
      httpConn.setRequestProperty("Transfer-Encoding", "chunked");
      httpConn.setRequestProperty("Content-Type", "audio/x-flac; rate=" + sampleRate);
      // also worked with ("Content-Type", "audio/amr; rate=8000");
      httpConn.connect();
      try {
        // this opens a connection, then sends POST & headers.
        out = httpConn.getOutputStream();
        //Note : if the audio is more than 15 seconds
        // dont write it to UrlConnInputStream all in one block as this sample does.
        // Rather, segment the byteArray and on intermittently, sleeping thread
        // supply bytes to the urlConn Stream at a rate that approaches
        // the bitrate ( =30K per sec. in this instance ).
        System.out.println("Starting to write");
        for(byte[] dataArray: mextrad){
          out.write(dataArray); // one big block supplied instantly to the underlying chunker wont work for duration > 15 s.
          try {
            Thread.sleep(1000);//Delays the Audio so Google thinks its a mic.
          } catch (InterruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
          }
        }
        out.write(FINAL_CHUNK);
        System.out.println("IO WRITE DONE");
        // do you need the trailer?
        // NOW you can look at the status.
        resCode = httpConn.getResponseCode();
        if (resCode / 100 != 2)  {
          System.out.println("ERROR");
        }
      } catch (IOException e) {

      }
      if (resCode == HttpsURLConnection.HTTP_OK) {
        return new Scanner(httpConn.getInputStream());
      }
      else{
        System.out.println("HELP: " + resCode);
      }
    } catch (MalformedURLException e) {
View Full Code Here

Examples of javax.net.ssl.HttpsURLConnection

   {
      HttpURLConnection conn = super.createURLConnection(url, metadata);

      if (conn instanceof HttpsURLConnection)
      {
         HttpsURLConnection sconn = (HttpsURLConnection) conn;

         SocketFactory socketFactory = getSocketFactory();
         if (socketFactory != null && socketFactory instanceof SSLSocketFactory)
         {
            SSLSocketFactory sslSocketFactory = getHandshakeCompatibleFactory((SSLSocketFactory) socketFactory, metadata);
            sconn.setSSLSocketFactory(sslSocketFactory);
         }

         setHostnameVerifier(sconn, metadata);
      }
View Full Code Here

Examples of javax.net.ssl.HttpsURLConnection

     * @return true if posting succeeds; otherwise, false.
     */
    private static boolean postRegistrationData(URL url,
                                                RegistrationData registration) {
        try {
            HttpsURLConnection con = (HttpsURLConnection) url.openConnection();
            con.setDoInput(true);
            con.setDoOutput(true);
            con.setUseCaches(false);
            con.setAllowUserInteraction(false);

            // default 10 seconds timeout
            String timeout = System.getProperty(SVCTAG_CONNECTION_TIMEOUT, "10");
            con.setConnectTimeout(Util.getIntValue(timeout) * 1000);

            if (Util.isVerbose()) {
                System.out.println("Connecting to post registration data at " + url);
            }

            con.setRequestMethod("POST");
            con.setRequestProperty("Content-Type", "text/xml;charset=\"utf-8\"");
            con.connect();
           
            OutputStream out = con.getOutputStream();
            registration.storeToXML(out);
            out.flush();
            out.close();

            int returnCode = con.getResponseCode();
            if (Util.isVerbose()) {
                System.out.println("POST return status = " + returnCode);
                printReturnData(con, returnCode);
            }
            return (returnCode == HttpURLConnection.HTTP_OK);
View Full Code Here

Examples of javax.net.ssl.HttpsURLConnection

        url = new URL(getBaseURL(true) + address);
       
        requestInput = JaxWSTest.class.getResourceAsStream("/request1.xml");
        assertNotNull("SOAP request not specified", requestInput);
       
        HttpsURLConnection conn2 = (HttpsURLConnection) url.openConnection();
        if (basicAuth) {
            conn2.setRequestProperty("Authorization", TestUtils.getAuthorizationValue());
        }
        conn2.setHostnameVerifier(new TestUtils.TestHostnameVerifier());
        try {
            checkResponse(requestInput, conn2);
        } finally {
            TestUtils.unset("javax.net.ssl.trustStore", oldTrustStore);
            TestUtils.unset("javax.net.ssl.trustStorePassword", oldTrustStorePassword);
           
            conn2.disconnect();
        }
    }
View Full Code Here

Examples of javax.net.ssl.HttpsURLConnection

        System.setProperty("javax.net.ssl.trustStore", keyStore.getAbsolutePath());
        System.setProperty("javax.net.ssl.trustStorePassword", "secret");
       
        url = new URL(getBaseURL(true) + "https?wsdl");
               
        HttpsURLConnection conn2 = (HttpsURLConnection) url.openConnection();
        conn2.setHostnameVerifier(new TestUtils.TestHostnameVerifier());
        try {
            checkWSDL(conn2);
        } finally {
            TestUtils.unset("javax.net.ssl.trustStore", oldTrustStore);
            TestUtils.unset("javax.net.ssl.trustStorePassword", oldTrustStorePassword);
           
            conn2.disconnect();
        }
    }
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.