Package java.net

Examples of java.net.HttpURLConnection


          citeseerURLString.append(OAI_URL);
          citeseerURLString.append(OAI_ACTION);
          citeseerURLString.append("&" + OAI_METADATAPREFIX);
                citeseerURLString.append("&" + "identifier=").append(identifier);
                    URL citeseerUrl = new URL( citeseerURLString.toString());
                    HttpURLConnection citeseerConnection = (HttpURLConnection)citeseerUrl.openConnection();                 
          InputStream inputStream  = citeseerConnection.getInputStream();
          DefaultHandler handlerBase = new CiteSeerUndoHandler(citeseerNC, be, panel, newValue, overwriteAll, overwriteNone);

          saxParser.parse(inputStream, handlerBase);
        } else {
                    int row = panel.mainTable.findEntry(be);
View Full Code Here


     * @throws IOException for connection error
     */
    private URL resolveRedirects(URL url, int redirectCount) throws IOException {
        URLConnection uc = url.openConnection();
        if (uc instanceof HttpURLConnection) {
            HttpURLConnection huc = (HttpURLConnection)uc;
            huc.setInstanceFollowRedirects(false);
            huc.connect();
            int responseCode = huc.getResponseCode();
            String location = huc.getHeaderField("location");
            huc.disconnect();
            if ((responseCode == HttpURLConnection.HTTP_MOVED_TEMP) && (redirectCount < 5)) {
                //System.out.println(responseCode);
                //System.out.println(location);
                try {
                    URL newUrl = new URL(location);
View Full Code Here

    }

    public static String loadPage(URL url) throws IOException {
        Reader in = null;
        URLConnection uc;
        HttpURLConnection huc = null;
        try {
            uc = url.openConnection();
            if (uc instanceof HttpURLConnection) {
                huc = (HttpURLConnection)uc;
                huc.setInstanceFollowRedirects(false);
                huc.connect();

                in = new InputStreamReader(huc.getInputStream());
                StringBuilder sb = new StringBuilder();
                int c;
                while ((c = in.read()) != -1)
                    sb.append((char)c);
                return sb.toString();
            }
            else
                return null; // TODO: are other types of connection (https?) relevant?
        } finally {
            try {
                if (in != null) in.close();
                if (huc != null) huc.disconnect();
            } catch (IOException ex) { ex.printStackTrace(); }
        }

    }
View Full Code Here

  private String internalReadURL(String urlString) throws Exception {
    log.debug("Creating URL from string: " + urlString);
    URL url = new URL(urlString);
    log.debug("Created URL object from string, protocol="
        + url.getProtocol());
    HttpURLConnection conn = (HttpURLConnection) url.openConnection();
    /*
     * Override the host verifier so we can use a test server cert with a
     * hostname that may not match the https url hostname.
     */
    System.setProperty("org.jboss.security.ignoreHttpsHost", "true");
    Util.configureHttpsHostVerifier(conn);

    // if SSL is used we must point to the test truststore.
    if (conn instanceof HttpsURLConnection) {
      // Setup the test keystore (truststore).
      URL keyStoreURL = Thread.currentThread().getContextClassLoader()
          .getResource("META-INF/tst.keystore");
      InputStream stream = keyStoreURL.openStream();
      KeyStore keyStore = KeyStore.getInstance("JKS");
      keyStore.load(stream, "unit-tests".toCharArray());
      // Setup the test TrustManagerFactory.
      TrustManagerFactory trustMgr = TrustManagerFactory
          .getInstance(TrustManagerFactory.getDefaultAlgorithm());
      trustMgr.init(keyStore);
      // Setup the test SSLSocketFactory.
      SSLContext sslCtx = SSLContext.getInstance("TLS");
      sslCtx.init(null, trustMgr.getTrustManagers(), null);
      ((HttpsURLConnection) conn).setSSLSocketFactory(sslCtx.getSocketFactory());     
    }
   
    // Connect to the remote HTTP server.
    log.debug("Connecting to URL: " + url);
    byte[] buffer = new byte[1024];
    int length = conn.getContentLength();
    log.debug("ContentLength: " + length);
    InputStream is = conn.getInputStream();
    StringBuffer reply = new StringBuffer();
    while ((length = is.read(buffer)) > 0)
      reply.append(new String(buffer, 0, length));
    log.debug("Done, closing streams");
    is.close();
View Full Code Here

      // Initialize the proxy Util class to integrate JAAS authentication
      Util.init();
      if( log.isTraceEnabled() )
         log.trace("Retrieving content from : "+providerURL);

      HttpURLConnection conn = (HttpURLConnection) providerURL.openConnection();
      Util.configureHttpsHostVerifier(conn);
      Util.configureSSLSocketFactory(conn);
      int length = conn.getContentLength();
      String type = conn.getContentType();
      if( log.isTraceEnabled() )
         log.trace("ContentLength: "+length+"\nContentType: "+type);

      InputStream is = conn.getInputStream();
      ObjectInputStream ois = new ObjectInputStream(is);
      MarshalledValue mv = (MarshalledValue) ois.readObject();
      ois.close();

      Object obj = mv.get();
View Full Code Here

        key = fixKey(key);
       
        String url = constructUrl(key);
        try {
            URL oai2Url = new URL(url);
            HttpURLConnection oai2Connection = (HttpURLConnection) oai2Url.openConnection();
            oai2Connection.setRequestProperty("User-Agent", "Jabref");
            InputStream inputStream = oai2Connection.getInputStream();
   
            /* create an empty BibtexEntry and set the oai2identifier field */
            BibtexEntry be = new BibtexEntry(Util.createNeutralId(), BibtexEntryType.ARTICLE);
            be.setField(OAI2_IDENTIFIER_FIELD, key);
            DefaultHandler handlerBase = new OAI2Handler(be);
View Full Code Here

      String turl = this.url+"?";
      turl += "t="+s;
      turl += "&i="+ Integer.toString(i);
     
      URL realURL = new URL(turl);
      HttpURLConnection connection = (HttpURLConnection) realURL.openConnection();
      connection.setRequestMethod("POST");
      connection.setRequestProperty("User-Agent", "IIC2.0/PC 3.5.2540");
      connection.setRequestProperty("Pragma", this.pragma);
      connection.setRequestProperty("Content-Type", "application/oct-stream");
      connection.setRequestProperty("Accept", "*/*");
      connection.setRequestProperty("Cookie", "ssic="+this.ssic);
      connection.setDoOutput(true);
      OutputStream out = connection.getOutputStream();
      out.write(writer.toByteArray(), 0, writer.size());
      out.flush();
     
      if(connection.getResponseCode()==200) {
          int contentLength = connection.getContentLength();
          if(contentLength>4) {
              InputStream in = connection.getInputStream();
              writer.clear();
              while(contentLength>4){
                writer.writeByte(in.read());
                contentLength--;
              }
              this.bytesRecived(writer.toByteArray(), 0, writer.size());
          }
      }else {
        throw new IOException("Invalid response stateCode="+connection.getResponseCode());
      }
    }
View Full Code Here

        city = msg.substring(msg.indexOf("#")+1);
      }
     
      String url ="http://webservice.webxml.com.cn/WebServices/WeatherWS.asmx/getWeather?theCityCode={city}&theUserID=";
      url = url.replace("{city}", URLEncoder.encode(city, "UTF8"));
      HttpURLConnection conn = (HttpURLConnection) new URL(url).openConnection();
      if(conn.getResponseCode()==200) {
        SAXBuilder builder = new SAXBuilder();
          Document doc = builder.build(conn.getInputStream());
          List strings = doc.getRootElement().getChildren();
          String[] sugguestions = getText(strings.get(6)).split("\n");
         
          /*
          四川 成都
View Full Code Here

   public ClientResponse execute(ClientRequest request) throws Exception
   {
      String uri = request.getUri();
      String httpMethod = request.getHttpMethod();

      HttpURLConnection connection = (HttpURLConnection) new URL(uri)
              .openConnection();
      connection.setRequestMethod(httpMethod);
      setupRequest(request, connection);
      return execute(request, connection);
   }
View Full Code Here

    return sb.toString();
  }
 
  private String sendSoapRequest(String request) throws IOException {
    //Set up the request
    HttpURLConnection httpConn = (HttpURLConnection) new URL(SOAP_URL).openConnection();
    httpConn.setRequestProperty("Content-Length", String.valueOf(request.length()));
    httpConn.setRequestProperty("Content-Type", "text/xml; charset=utf-8");
    httpConn.setRequestProperty("SOAPAction", SOAP_ACTION);
    httpConn.setRequestMethod("POST");
    httpConn.setDoOutput(true);
    httpConn.setDoInput(true);

    //Send our xml request
    PrintWriter out = new PrintWriter(httpConn.getOutputStream());
    out.println(request);
    out.close();

    //Receive the answer
    BufferedReader in = new BufferedReader(new InputStreamReader(httpConn
        .getInputStream()));
    String inputLine;
    StringBuffer sb = new StringBuffer();
    while ((inputLine = in.readLine()) != null) {
      sb.append(inputLine);
View Full Code Here

TOP

Related Classes of java.net.HttpURLConnection

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.