Package net.sf.jpluck.http

Examples of net.sf.jpluck.http.HttpResponse


    byte[] data = null;
    if (html.startsWith("http://")) {
      System.out.println("Downloading " + html);
      HttpClient httpClient = new HttpClient();
      HttpResponse response = httpClient.doGet(html);
      data = response.getContent();     
    } else {
      File file = new File(html);
      System.out.println("Reading " + file.getAbsolutePath());
      data = new byte[(int)file.length()];
      FileInputStream in = new FileInputStream(file);
View Full Code Here


        public void run() {
            try {
                HttpClient client = new HttpClient();
                String filename = convertToFilename(name);
                HttpResponse response = client.doGet(rootPath + "/" + filename);
                if (response.getStatusCode() == 200) {
                    byte[] data = response.getContent();
                    if (!JPluckX.getInstance().isWebStart()) {
                        FileOutputStream out = new FileOutputStream(new File(dir, filename));
                        out.write(data);
                        out.close();
                    }
View Full Code Here

  private boolean download() {
    try {
      setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
      byte[] data = null;
      try {
        HttpResponse response = DownloadDialog.download(url, this, "Download", "Downloading RSS feed",
                                "Downloading feed and extracting information...");
        if (response.getStatusCode() != 200) {
          JOptionPane.showMessageDialog(this,
                          "Feed could not be downloaded.\n" + response.getStatusCode() +
                          ": " + response.getStatusMessage(), "Error Downloading Feed",
                          JOptionPane.ERROR_MESSAGE);
          return false;
        }
        data = response.getContent();
      } catch (Exception e) {
        Throwable t;
        if (e.getCause() != null) {
          t = e.getCause();
        } else {
View Full Code Here

      logger.finer("Added to retrieval queue: " + uri);
    }
  }

  HttpResponse retrieveFromCache(String uri) {
    HttpResponse response = null;
    if (jxlDocument.isUseHTTPCache() && httpCache != null) {
      synchronized (httpCache) {
        if (!running) {
          return null;
        }
View Full Code Here

                         ClientConfiguration.getDefault().getAcceptCharset());
    httpClient.setReferrer(referrer);
    try {
      spider.fireRetrievalStarted(uri);

      HttpResponse cached = spider.retrieveFromCache(uri);
      long ifModifiedSince = 0;
      if (cached != null) {
        ifModifiedSince = cached.getDate();
      } else {
        if (Spider.isOffline()) {
          logger.warning("Could not retrieve " + uri + " from HTTP cache.");
          return;
        }
      }

      HttpResponse response;
      if (Spider.isOffline()) {
        response = cached;
        logger.info(response.getStatusCode() + " " + response.getStatusMessage() + ": " + uri);
      } else {
        response = httpClient.doGet(uri, ifModifiedSince, spider.cookieStore);
        logger.info(response.getStatusCode() + " " + response.getStatusMessage() + ": " + uri);
        if (response.getStatusCode() == 304) {
          response = cached;
        }
      }
      if (!spider.isRunning()) {
        return;
      }
      if (response.getStatusCode() == 200) {
        if (response != cached && !Spider.isOffline() && spider.jxlDocument.isUseHTTPCache()) {
          spider.storeInCache(uri, response);
        }

        String redirectionURI = null;
        if (response.isRedirected()) {
          redirectionURI = response.getRedirectionURL();
          logger.fine(uri + ": redirected to " + redirectionURI);
          if (spider.jxlDocument.getUri().equals(uri)) {
            // Correct the starting URI
            logger.fine("Resetting starting URI to " + redirectionURI);
            spider.jxlDocument.setStartingURI(URI.create(redirectionURI));
          }
        }

        ContentType contentType = new ContentType(response.getContentType());

        if (!spider.jxlDocument.isAutoDetectInputEncoding()) {
          contentType = contentType.derive(spider.jxlDocument.getInputEncoding());
        }

        Resource resource = new Resource(uri, redirectionURI, contentType, response.getContent(), level,
                         embedded);
        if (spider.jxlDocument.isAutoDetectInputEncoding()) {
          resource.scanForContentType();
        }
        spider.parse(resource);
View Full Code Here

    public void run() {
        HttpClient httpClient = new HttpClient();
        try {
            httpClient.addHttpListener(this);
            HttpResponse response = httpClient.doGet(url);
            if (isVisible()) {
                this.response = response;
            }
        } catch (Exception e) {
            exception = e;
View Full Code Here

TOP

Related Classes of net.sf.jpluck.http.HttpResponse

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.