Package placeholder.website

Examples of placeholder.website.WebsiteResult


  @Override
  protected boolean __fill() throws WebsiteResultQueueFlushException {
    HashMap<String, String> postFields = new HashMap<String, String>();
    try {
      WebsiteResult result;
      while ((result = this.queue.removeFirst()) != null) {
        // http status
        postFields.put("websites[" + result.getWebsite() + "][httpStatus]", new Integer(result.getHTTPStatus()).toString());

        // check time
        postFields.put("websites[" + result.getWebsite() + "][checkTime]", new Integer(result.getCheckTime()).toString());
       
        // websites
        String[] websites = result.getWebsites();
        for (int i = 0; i < websites.length; i++) {
          postFields.put("websites[" + result.getWebsite() + "][websites][" + i + "]", websites[i]);
        }
       
        // services
        String[] services = result.getServices();
        for (int i = 0; i < services.length; i++) {
          postFields.put("websites[" + result.getWebsite() + "][services][" + i + "]", services[i]);
        }
      }
    } catch (NoSuchElementException e) {
      // do nothing
    }
View Full Code Here


        // start request
        int responseCode = 0;
        String redirectLocation = null;
        String responseContent = null;
        WebsiteResult result;
        try {
          this.out.titledPrint("\tStarting request...");
         
          String website2 = "http://" + website;
          do {
            HttpRequest request = new HttpRequest(website2);
            request.send();
            responseCode = request.getConnection().getResponseCode();
            redirectLocation = request.getConnection().getHeaderField("Location");
            responseContent = request.getResponseBody();
           
            // follow redirect?
            try {
              URL url = new URL(redirectLocation);
              if (website.equals(url.getHost())) {
                website2 = redirectLocation;
              }
              else {
                website2 = null;
              }
            } catch (MalformedURLException e) {
              website2 = null;
            }
          } while (website2 != null);
          this.out.println("finished!");
        } catch(Exception e) {
          responseCode = -1;
          responseContent = "";
        } finally {
          result = new WebsiteResult(website, responseCode);
          this.resultQueue.add(result);
        }
       
        if (responseCode == 200) {
          // look for other websites adresses
          this.out.titledPrint("\tLooking for other websites...");
          Matcher matcher = pattern.matcher(responseContent);
          while (matcher.find() && matcher.group(1).indexOf(".") != -1) {           
            try {
              String host = new URL(matcher.group(1)).getHost();
             
              // ignore ip addresses
              if (host.matches("\\d{1,3}(\\.\\d{1,3}){3}")) {
                continue;
              }
             
              // ignore sub domains
              String[] parts = host.split("\\.", 5);
              String topLevel = parts[parts.length - 1];
              int maxParts = (topLevel.matches("at|be|biz|ca|cc|ch|com|cz|de|dk|fr|edu|es|eu|in|int|it|info|li|mobi|name|net|nl|org|ru|se|tv|us|ws") ? 3 : 4);

              if (parts.length > maxParts || parts.length == maxParts && !parts[0].equals("www")) {
                // remove lowed namespace
                StringBuilder builder = new StringBuilder();
                for (int i = parts.length - maxParts + 1; i < parts.length; i++) {
                  if (builder.length() > 0) builder.append(".");
                  builder.append(parts[i]);
                }
                host = builder.toString();
              }
             
              result.addWebsite(host);
            } catch (MalformedURLException e) {
              // ignore bad urls
              continue;
            }
          }
          this.out.println(result.getWebsites().length + " found.");
 
          // look for services
          this.out.titledPrint("\tLooking for services...");
          for (String service: CheckServices.check(responseContent)) {
            result.addService(service);
          }
          this.out.println(result.getServices().length + " found.");
        }
        else if (redirectLocation != null) {
          try {
            URL url = new URL(redirectLocation);
            result.addWebsite(url.getHost());
            this.out.titledPrintln("\tFound redirect to website: " + url.getHost());
          } catch (MalformedURLException e) {
            // ignore bad urls
            continue;
          }
View Full Code Here

TOP

Related Classes of placeholder.website.WebsiteResult

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.