Package java.net

Examples of java.net.URLConnection


        } else {
            builder.setEntityResolver(entityResolver);
        }

        // Parse document
        URLConnection urlConnection = null;
        try {
            urlConnection = url.openConnection();
        } catch (IOException e) {
            throw new DocumentParserException("Cannot open a connection on URL '" + url + "'", e);
        }
        urlConnection.setDefaultUseCaches(false);
        Reader reader = null;
        try {
            reader = new InputStreamReader(urlConnection.getInputStream());
        } catch (IOException e) {
            throw new DocumentParserException("Cannot build an input stream reader on URL '" + url + "'", e);
        }

        InputSource inputSource = new InputSource(reader);
View Full Code Here


        if (configPath == null || configPath.trim().equals("")) {
            throw new NullConfigPathException("Config is null or empty.");
        }
        switch (configType) {
            case URL:
                URLConnection urlConn = new URL(configPath).openConnection();
                urlConn.setDoInput(true);
                urlConn.setUseCaches(false);

                in = new DataInputStream(urlConn.getInputStream());
                br = new BufferedReader(new InputStreamReader(in));
                break;
            case FILE:
                br = new BufferedReader(new FileReader(configPath));
                break;
View Full Code Here

*/
class JDKManifestFinder extends AbstractManifestFinder
{
   protected Manifest findManifest(URL url) throws Exception
   {
      URLConnection conn = url.openConnection();
      if (conn instanceof JarURLConnection)
      {
         JarURLConnection jarConn = (JarURLConnection)conn;
         return jarConn.getManifest();
      }
View Full Code Here

  /* check if there is a Tomcat connection to the server */
  private static boolean isServerStarted(String host) throws MalformedURLException {
    // 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) {
View Full Code Here

   * @param url the url to connect to
   * @return returns the input stream for the connection
   * @throws java.io.IOException cannot get result
   */
  private InputStream connect(String url) throws IOException {
    URLConnection conn = new URL(URL_BASE + url).openConnection();
    conn.setConnectTimeout(CONNECT_TIMEOUT);
    conn.setReadTimeout(READ_TIMEOUT);
    conn.setRequestProperty("User-Agent", USER_AGENT);
    return conn.getInputStream();
  }
View Full Code Here

   * @param url the url to connect to
   * @return returns the input stream for the connection
   * @throws IOException cannot get result
   */
  private InputStream connect(String url) throws IOException {
    URLConnection conn = new URL(URL_BASE + url).openConnection();
    conn.setConnectTimeout(CONNECT_TIMEOUT);
    conn.setReadTimeout(READ_TIMEOUT);
    conn.setRequestProperty("User-Agent", USER_AGENT);
    return conn.getInputStream();
  }
View Full Code Here

  public BinaryResource bytes(URI anUri, AbstractContent someContent) throws IOException {
    return doPOSTOrPUT(anUri, someContent, new BinaryResource());
  }

  protected <T extends AbstractResource> T doGET(URI anUri, T resource) throws IOException {
    URLConnection con = openConnection(anUri, resource);
    return fillResourceFromURL(con, resource);
  }
View Full Code Here

    return fillResourceFromURL(con, resource);
  }

  protected <T extends AbstractResource> T doPOSTOrPUT(URI anUri, AbstractContent requestContent, T resource)
      throws IOException {
    URLConnection con = openConnection(anUri,resource);
    requestContent.addContent(con);
    return fillResourceFromURL(con, resource);
  }
View Full Code Here

    return fillResourceFromURL(con, resource);
  }
 
  protected <T extends AbstractResource> URLConnection openConnection(URI anUri, T resource)
      throws IOException, MalformedURLException {
    URLConnection con = anUri.toURL().openConnection();
    addStandardHeaders(con, resource);
    return con;
  }
View Full Code Here

   */
  private FeedIF retrieveFeed(String uri) throws FeedManagerException {
    try {
      URL urlToRetrieve = new URL(uri);

      URLConnection conn = null;
      try {
        conn = urlToRetrieve.openConnection();

        if (conn instanceof HttpURLConnection) {

          HttpURLConnection httpConn = (HttpURLConnection) conn;

          httpConn.setInstanceFollowRedirects(true); // not needed, default ?

          //   Hack for User-Agent : problem for
          // http://www.diveintomark.org/xml/rss.xml
          HttpHeaderUtils.setUserAgent(httpConn, "Informa Java API");

          logger.debug("retr feed at url " + uri + ": ETag"
              + HttpHeaderUtils.getETagValue(httpConn) + " if-modified :"
              + HttpHeaderUtils.getLastModified(httpConn));

          // get initial values for cond. GET in updateChannel
          this.httpHeaders.setETag(HttpHeaderUtils.getETagValue(httpConn));
          this.httpHeaders.setIfModifiedSince(HttpHeaderUtils
              .getLastModified(httpConn));
        }
      } catch (java.lang.ClassCastException e) {
        conn = null;
        logger.warn("problem cast to HttpURLConnection " + uri, e);
        throw new FeedManagerException(e);
      } catch (NullPointerException e) {
        logger.error("problem NPE " + uri + " conn=" + conn, e);
        conn = null;
        throw new FeedManagerException(e);
      }

      ChannelIF channel = null;
      /*
       * if ( conn == null ) { channel = FeedParser.parse(getChannelBuilder(),
       * uri); } else {
       */
      channel = FeedParser.parse(getChannelBuilder(), conn.getInputStream());
      //}

      this.timeToExpire = getTimeToExpire(channel);
      this.feed = new Feed(channel);

View Full Code Here

TOP

Related Classes of java.net.URLConnection

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.