Package java.net

Examples of java.net.HttpURLConnection


   
    conn = new URL(realUrlStr).openConnection();
   
    if (conn instanceof HttpURLConnection)
    {  // TODO: this is probably why JMF has explicit HTTP and FTP data sources - so we can check things explicitly.
      final HttpURLConnection huc = (HttpURLConnection) conn;
      if (user != null && !user.equals(""))
      {  huc.setRequestProperty("Authorization", "Basic " + StringUtils.byteArrayToBase64String((user + ":" + pass).getBytes()));
      }
      huc.connect();
     
      final int code = huc.getResponseCode();
      if (!(code >= 200 && code < 300))
      {  huc.disconnect();
        throw new IOException("HTTP response code: " + code);
     
     
      // TODO: what is the right place to apply ContentDescriptor.mimeTypeToPackageName?
      contentTypeStr = ContentDescriptor.mimeTypeToPackageName(stripTrailer(conn.getContentType()));
View Full Code Here


      return;
    if (conn != null)
    {
      if (conn instanceof HttpURLConnection)
      {
        final HttpURLConnection huc = (HttpURLConnection) conn;
        huc.disconnect();
      }
      // TODO: others
    }
    connected = false;
  }
View Full Code Here

      throw new RuntimeException(e);
    }
  }

  public static String getResponseText(URL constructedUrl, String encoding) {
    HttpURLConnection conn = null;
    try {
      conn = (HttpURLConnection) constructedUrl.openConnection();
      BufferedReader in = null;
      if (null == encoding) {
        in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
      } else {
        in = new BufferedReader(new InputStreamReader(conn.getInputStream(), encoding));
      }
      String line;
      final StringBuffer stringBuffer = new StringBuffer(255);

      synchronized (stringBuffer) {
        while ((line = in.readLine()) != null) {
          stringBuffer.append(line);
          stringBuffer.append("\n");
        }
        return stringBuffer.toString();
      }
    } catch (final Exception e) {
      e.printStackTrace();
      throw new RuntimeException(e);
    } finally {
      if (conn != null) {
        conn.disconnect();
      }
    }
  }
View Full Code Here

        return content;
    }
    private static String fetchContentOrNull(String urlToRead) {
        // slow but standard
        URL url;
        HttpURLConnection conn;
        BufferedReader rd;
        String line;
        StringBuilder result = new StringBuilder();
        try {
           url = new URL(urlToRead);
           conn = (HttpURLConnection) url.openConnection();
           conn.setRequestMethod("GET");
           rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
           while ((line = rd.readLine()) != null) {
              result.append(line);
           }
           rd.close();
        } catch (Exception e) {
View Full Code Here

    // URL to Tomcat
    URL url = new URL("http", host, 8080, "/") ;
    try {
      URLConnection conn = url.openConnection() ;
      if (conn instanceof HttpURLConnection) {
        HttpURLConnection http = (HttpURLConnection) conn ;
        int responseCode = http.getResponseCode();
       
        if (responseCode > 0 && responseCode < 400) {
          return true ;
        }
      }
View Full Code Here

                .getType("article"));
            entry.setField("citeseerurl", id);

            try {
                URL citeseerUrl = new URL(OAI_URL + id);
                HttpURLConnection citeseerConnection = (HttpURLConnection) citeseerUrl
                    .openConnection();
                InputStream inputStream = citeseerConnection.getInputStream();

                DefaultHandler handlerBase = new CiteSeerEntryFetcherHandler(entry);

                if (saxParser == null)
                    saxParser = SAXParserFactory.newInstance().newSAXParser();
View Full Code Here

   * @return The imnported BibtexEntry or null if none.
   */
  private BibtexDatabase importSpiresEntries(String key, OutputPrinter frame) {
    String url = constructUrl(key);
    try {
      HttpURLConnection conn = (HttpURLConnection) (new URL(url)).openConnection();
      conn.setRequestProperty("User-Agent", "Jabref");
      InputStream inputStream = conn.getInputStream();

      SPIRESBibtexFilterReader reader = new SPIRESBibtexFilterReader(
          new InputStreamReader(inputStream));

      ParserResult pr = BibtexParser.parse(reader);
View Full Code Here

            }
      System.out.println(url);
      try {
              URL trueURL = new URL(url);
              logger.info("Sending crush report...");
              HttpURLConnection conn = (HttpURLConnection) trueURL.openConnection();
              if(conn.getResponseCode()==200) {
                logger.info("Send crush report OK.");
              }else {
                logger.info("Send crush report Failed. status="+conn.getResponseCode()+" "+conn.getResponseMessage());
              }
            } catch (MalformedURLException e) {
              logger.info("send crush report Failed",e);
            } catch (IOException e) {
              logger.info("send crush report Failed",e);
View Full Code Here

   * @throws IOException
   */
  public static HttpURLConnection openConnection(String url, String method, String contentType, String ssic) throws IOException
  {
    URL realURL = new URL(url);
    HttpURLConnection conn = (HttpURLConnection) realURL.openConnection();
    //conn.setRequestProperty("User-Agent", "IIC2.0/PC "+FetionClient.PROTOCOL_VERSION);
    conn.setRequestProperty("User-Agent", "IIC2.0/PC 4.0.0000");
    conn.setRequestProperty("Cookie", "ssic="+ssic);
    conn.setRequestProperty("Host", realURL.getHost());
    conn.setRequestProperty("Accept", "*/*");
    conn.setRequestProperty("Cache-Control", "no-cache");
    if(contentType!=nullconn.setRequestProperty("Content-Type", contentType);
    conn.setRequestMethod(method);
    return conn;
  }
View Full Code Here

   * @return
   * @throws IOException
   */
  public static byte[] doFetchData(String url, String method, String contentType, String ssic, InputStream in) throws IOException
  {
    HttpURLConnection conn = openConnection(url, method, contentType, ssic);
    if(in!=nullsendData(conn, in);
    if(conn.getResponseCode()==HttpURLConnection.HTTP_OK){
      return fetchData(conn);
    }else{
      throw new IOException("Http response is not OK. code="+conn.getResponseCode());
    }
  }
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.