Ejemplo n.º 1
0
 public String getExstention() {
   CloseableHttpClient httpClient = HttpClientBuilder.create().build();
   CloseableHttpResponse response = null;
   try {
     HttpGet httpGet = new HttpGet("http://thepiratebay.org");
     httpGet.addHeader(
         "User-Agent",
         "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.90 Safari/537.36");
     response = httpClient.execute(httpGet);
     Header[] cookieJar = response.getHeaders("set-cookie");
     if (response.getStatusLine().getStatusCode() == 200 && cookieJar.length > 0) {
       for (int i = 0; i < cookieJar.length; i++) {
         String[] cookies = response.getHeaders("set-cookie")[i].getValue().split(";");
         for (int c = 0; c < cookies.length; c++) {
           if (cookies[c].contains("domain=")) {
             return cookies[c].substring(cookies[c].indexOf('=') + 2);
           }
         }
       }
     } else {
       SendMailTLS sendMail = new SendMailTLS();
       sendMail.sendEmail("FAILD TO OBTAIN WEB EXTENTION!", response.toString());
       return "FAIL";
     }
     response.close();
   } catch (Exception e) {
     Utilities.sendExceptionEmail(e.getMessage());
     return e.getMessage();
   }
   return "";
 }
Ejemplo n.º 2
0
  /**
   * Queries the CoNE service and transforms the result into a DOM node.
   *
   * @param model The type of object (e.g. "persons")
   * @param name The person's name.
   * @return A DOM node containing the results.
   */
  public static List<String> queryConePerson(String name) {
    if (ConfigUtil.VERBOSE) {
      System.out.println("-------------------\nStarted Querying CoNE\n-------------------");
    }
    List<String> possibleDublicates = new ArrayList<String>();

    try {
      String queryUrl =
          ConfigUtil.CONE_URL
              + ConfigUtil.PERSON_MODEL
              + "/query?format=jquery&dc:title="
              + URLEncoder.encode("\"" + name + "\"", "UTF-8")
              + "&n=0";
      CloseableHttpClient httpClient = HttpClients.createDefault();
      HttpGet httpGet = new HttpGet(queryUrl);
      CloseableHttpResponse httpResponse = httpClient.execute(httpGet);
      if (ConfigUtil.VERBOSE) {
        System.out.println("\n--------------------\nCoNE query: " + queryUrl + " returned ");
        System.out.println("--------------------\nHeader\n--------------------");
        System.out.println(httpResponse.toString());
        System.out.println("--------------------\nContent\n--------------------");
      }
      BufferedReader in =
          new BufferedReader(new InputStreamReader(httpResponse.getEntity().getContent(), "UTF-8"));
      String line = null;
      while ((line = in.readLine()) != null) {
        possibleDublicates.add(line);
        if (ConfigUtil.VERBOSE) {
          System.out.println(line);
        }
      }
      if (httpResponse.getStatusLine().getStatusCode() == 200) {
        queryUrl =
            ConfigUtil.CONE_URL
                + ConfigUtil.PERSON_MODEL
                + "/query?format=jquery&dcterms:alternative="
                + URLEncoder.encode("\"" + name + "\"", "UTF-8")
                + "&n=0";
        httpGet = new HttpGet(queryUrl);
        httpResponse = httpClient.execute(httpGet);
        if (ConfigUtil.VERBOSE) {
          System.out.println("\n--------------------\nCoNE query: " + queryUrl + " returned ");
          System.out.println("--------------------\nHeader\n--------------------");
          System.out.println(httpResponse.toString());
          System.out.println("--------------------\nContent\n--------------------");
        }
        in =
            new BufferedReader(
                new InputStreamReader(httpResponse.getEntity().getContent(), "UTF-8"));
        while ((line = in.readLine()) != null) {
          possibleDublicates.add(line);
          if (ConfigUtil.VERBOSE) {
            System.out.println(line);
          }
        }
      } else {
        System.out.println(
            "Error querying CoNE for "
                + name
                + " (Status: "
                + httpResponse.getStatusLine().getStatusCode()
                + ")\n"
                + httpResponse.toString());
      }
    } catch (Exception e) {
      System.out.println(
          "Error querying CoNE service [" + ConeUtils.class.getEnclosingMethod() + "]");
      e.printStackTrace();
    }
    return possibleDublicates;
  }
Ejemplo n.º 3
0
  /**
   * gets a Map of all CoNE persons (each person only once)
   *
   * @return Map <String CoNE-ID, String [String Person-CompleteName, String Person-Organization]
   */
  public static Map<String, String[]> getAllCone() {
    Map<String, String[]> persons = new HashMap<String, String[]>();
    String queryUrl = ConfigUtil.CONE_URL + ConfigUtil.PERSON_MODEL + "/all?format=jquery";
    //    	String queryUrl = ConfigUtil.CONE_URL + ConfigUtil.PERSON_MODEL +
    // "/query?format=jquery&q=a*&n=200"; // for testing issues
    CloseableHttpClient httpClient = HttpClients.createDefault();
    HttpGet httpGet = new HttpGet(queryUrl);

    try {
      CloseableHttpResponse httpResponse = httpClient.execute(httpGet);
      if (ConfigUtil.VERBOSE) {
        System.out.println("\n--------------------\nCoNE query: " + queryUrl + " returned ");
        System.out.println("--------------------\nHeader\n--------------------");
        System.out.println(httpResponse.toString());
        System.out.println("--------------------\nContent\n--------------------");
      }
      BufferedReader in =
          new BufferedReader(new InputStreamReader(httpResponse.getEntity().getContent(), "UTF-8"));
      String line = null;
      String[] splitedQuery = new String[2];

      while ((line = in.readLine()) != null) {
        splitedQuery = line.split("\\|");
        if (!persons.containsKey(splitedQuery[1])) {
          String[] nameAndOrganization = new String[2];
          if (splitedQuery[0].indexOf("(") >= 0) {
            nameAndOrganization[0] =
                splitedQuery[0].substring(0, (splitedQuery[0].indexOf("(") - 1)).trim();
            nameAndOrganization[1] =
                splitedQuery[0]
                    .substring((splitedQuery[0].indexOf("(") + 1), splitedQuery[0].lastIndexOf(")"))
                    .trim();
            persons.put(splitedQuery[1].trim(), nameAndOrganization);
            if (ConfigUtil.VERBOSE) {
              System.out.println(
                  "Added ["
                      + splitedQuery[1].trim()
                      + " | {"
                      + nameAndOrganization[0]
                      + ","
                      + nameAndOrganization[1]
                      + "}] to persons");
            }
          } else {
            nameAndOrganization[0] = splitedQuery[0].trim();
            nameAndOrganization[1] = "";
            persons.put(splitedQuery[1].trim(), nameAndOrganization);
            if (ConfigUtil.VERBOSE) {
              System.out.println(
                  "Added ["
                      + splitedQuery[1].trim()
                      + " | {"
                      + nameAndOrganization[0]
                      + ","
                      + nameAndOrganization[1]
                      + "}] to persons");
            }
          }

        } else if (ConfigUtil.VERBOSE) {
          System.out.println("[" + splitedQuery[1] + "] already contained in persons");
        }
      }
    } catch (ClientProtocolException e) {
      System.out.println(
          "Error querying CoNE service [" + ConeUtils.class.getEnclosingMethod() + "]");
      e.printStackTrace();
    } catch (IOException e) {
      System.out.println(
          "Error querying CoNE service [" + ConeUtils.class.getEnclosingMethod() + "]");
      e.printStackTrace();
    }
    return persons;
  }
  public String logInCookie(String userName, String password, String wikiURL) {
    String client_id = HeliosConfig.getClientId();
    String client_secret = HeliosConfig.getClientSecret();
    String heliosBaseUrl = HeliosConfig.getUrl(HeliosConfig.HeliosController.TOKEN);

    CloseableHttpClient httpClient = HttpClients.createDefault();

    HttpPost httpPost = new HttpPost(heliosBaseUrl);
    List<NameValuePair> nvps = new ArrayList<NameValuePair>();

    nvps.add(new BasicNameValuePair("grant_type", HeliosConfig.GrantType.PASSWORD.getGrantType()));
    nvps.add(new BasicNameValuePair("client_id", client_id));
    nvps.add(new BasicNameValuePair("client_secret", client_secret));
    nvps.add(new BasicNameValuePair("username", userName));
    nvps.add(new BasicNameValuePair("password", password));

    CloseableHttpResponse response = null;
    httpPost.setEntity(new UrlEncodedFormEntity(nvps, StandardCharsets.UTF_8));
    try {
      response = httpClient.execute(httpPost);

      HttpEntity entity = response.getEntity();
      JSONObject responseValue = new JSONObject(EntityUtils.toString(entity));

      EntityUtils.consume(entity);

      PageObjectLogging.log("LOGIN HEADERS: ", response.toString(), true);
      PageObjectLogging.log("LOGIN RESPONSE: ", responseValue.toString(), true);

      String token = responseValue.getString("access_token");

      String domian = Configuration.getEnvType().equals("dev") ? ".wikia-dev.com" : ".wikia.com";

      driver.manage().addCookie(new Cookie("access_token", token, domian, null, null));

      if (driver.getCurrentUrl().contains("Logout")) {
        driver.get(wikiURL);
      } else {
        driver.navigate().refresh();
      }

      verifyUserLoggedIn(userName);
      PageObjectLogging.log(
          "loginCookie", "user was logged in by by helios using acces token: " + token, true);
      return token;
    } catch (TimeoutException e) {
      PageObjectLogging.log("loginCookie", "page timeout after login by cookie", false);
    } catch (UnsupportedEncodingException | ClientProtocolException e) {
      PageObjectLogging.log("logInCookie", "UnsupportedEncodingException", false);
      throw new WebDriverException();
    } catch (JSONException e) {
      PageObjectLogging.log("logInCookie", "Problem with parsing JSON response", false);
      throw new WebDriverException();
    } catch (IOException e) {
      PageObjectLogging.log("logInCookie", "IO Exception", false);
    } finally {
      try {
        response.close();
      } catch (IOException | NullPointerException e) {
        PageObjectLogging.log("logInCookie", "IO Exception", false);
      }
    }
    return "";
  }