@Override
 protected String getCallbackUrlForCancel(final HtmlPage authorizationPage) throws Exception {
   final HtmlForm form = authorizationPage.getForms().get(0);
   final HtmlSubmitInput submit = form.getInputByValue("Cancel");
   final HtmlPage callbackPage = submit.click();
   final String callbackUrl = callbackPage.getUrl().toString();
   logger.debug("callbackUrl : {}", callbackUrl);
   return callbackUrl;
 }
 private HtmlForm findForm(HtmlPage page, String action) {
   for (HtmlForm form : page.getForms()) {
     if (action.equals(form.getActionAttribute())) {
       return form;
     }
   }
   fail("no form found");
   return null;
 }
Esempio n. 3
0
 @Override
 protected String getCallbackUrl(final WebClient webClient, final HtmlPage authorizationPage)
     throws Exception {
   webClient.waitForBackgroundJavaScript(5000);
   HtmlForm form = authorizationPage.getForms().get(0);
   final HtmlTextInput login = form.getInputByName("login_email");
   login.setValueAttribute("*****@*****.**");
   final HtmlPasswordInput passwd = form.getInputByName("login_password");
   passwd.setValueAttribute("testpwdscribeup");
   HtmlButton submit = form.getButtonByName("");
   HtmlPage confirmPage = submit.click();
   confirmPage = (HtmlPage) confirmPage.refresh();
   webClient.waitForBackgroundJavaScript(5000);
   form = confirmPage.getForms().get(0);
   HtmlButton submit2 = form.getButtonByName("allow_access");
   final HtmlPage callbackPage = submit2.click();
   final String callbackUrl = callbackPage.getUrl().toString();
   logger.debug("callbackUrl : {}", callbackUrl);
   return callbackUrl;
 }
 @Override
 protected String getCallbackUrl(final WebClient webClient, final HtmlPage authorizationPage)
     throws Exception {
   final HtmlForm form = authorizationPage.getForms().get(0);
   final HtmlPasswordInput password = form.getInputByName("password");
   password.setValueAttribute("testpwdpac4j");
   final HtmlSubmitInput submit = form.getInputByValue("Sign In");
   final HtmlPage callbackPage = submit.click();
   /*form = confirmPage.getForms().get(0);
   HtmlButton continueButton = (HtmlButton) form.getElementById("continue-button");
   HtmlPage callbackPage = continueButton.click();*/
   final String callbackUrl = callbackPage.getUrl().toString();
   logger.debug("callbackUrl : {}", callbackUrl);
   return callbackUrl;
 }
  @Test
  public void testEndpoint()
      throws IOException, ServletException, DeploymentException, InterruptedException {
    UndertowWebSocketServer server = new UndertowWebSocketServer();
    server.start();

    WebClient webClient = new WebClient();
    HtmlPage page = webClient.getPage(BASE + "/index.html");
    HtmlForm dataForm = page.getForms().get(0);
    HtmlButtonInput sendMessageButton = dataForm.getInputByName("button");
    sendMessageButton.click();

    System.out.println(page.getElementById("div").getTextContent());

    server.stop();
  }
Esempio n. 6
0
  /**
   * Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
   *
   * @param request servlet request
   * @param response servlet response
   * @throws ServletException if a servlet-specific error occurs
   * @throws IOException if an I/O error occurs
   */
  protected void processRequest(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    response.setContentType("text/html;charset=UTF-8");
    PrintWriter out = response.getWriter();

    int no = 0;
    try {
      no = Integer.parseInt(request.getParameter("no"));

    } catch (NumberFormatException exception) {
      no = 0;
    }

    try {
      /* TODO output your page here. You may use following sample code. */
      out.println("<!DOCTYPE html>");
      out.println("<html>");
      out.println("<head>");
      out.println("<title>Servlet NewServlet</title>");
      out.println("</head>");
      out.println("<body>");

      final WebClient webClient = new WebClient();
      webClient.getCookieManager().clearCookies();
      webClient.getOptions().setUseInsecureSSL(true);
      webClient.setJavaScriptEnabled(false);
      final HtmlPage page = webClient.getPage("https://filestream.me/");
      // out.println(page.getTitleText());
      System.out.println("no of forms : " + page.getForms().size());
      HtmlForm form = page.getForms().get(1);
      final HtmlTextInput textField = form.getInputByName("login");
      textField.setAttribute("value", "*****@*****.**");

      final HtmlPasswordInput passField = form.getInputByName("password");
      passField.setAttribute("value", "ramkrishnan18");
      HtmlSubmitInput htmlSubmitInput = form.getInputByValue("login");
      HtmlPage page1 = htmlSubmitInput.click();

      HtmlTable htmlTable = page1.getHtmlElementById("fileCatTable");
      List<HtmlTableRow> listOfHtmlTableRow = htmlTable.getBodies().get(0).getRows();
      List<String> allLinks = new ArrayList<String>();
      for (HtmlTableRow htmlTableRow : listOfHtmlTableRow) {
        HtmlTableCell cell = htmlTableRow.getCells().get(htmlTableRow.getCells().size() - 1);
        for (DomElement domElement : cell.getChildElements()) {
          // out.println(domElement.getTagName());
          if (domElement.getTagName().equals("div")) {
            boolean flag = true;

            for (DomElement celldomElement : domElement.getChildElements()) {
              if (flag) {
                // out.println(celldomElement.getTagName());

                String title = celldomElement.getAttribute("title");
                if ("Download".equals(title) || "Downloads".equals(title)) {

                  String link = celldomElement.getAttribute("onclick");
                  String http =
                      link.substring(
                          link.indexOf('\'') + 1, link.indexOf('\'', link.indexOf('\'') + 1));

                  //  out.println(celldomElement.getAttribute("onclick") + "<br/>");
                  // out.println(http + "<br/>");
                  allLinks.add(http);
                  flag = false;
                }
              }
            }
          }
        }
      }

      //  InputStream is =anchorAttachment.click().getWebResponse().getContentAsStream();

      out.println("************ Start *************");

      //  HtmlAnchor anchorElement=HTMLAnchorElement.;
      //  anchorElement.set
      // anchorElement.setHref(allLinks.get(0));

      //  anchorElement.cl
      final String u = allLinks.get(no);
      Thread t =
          new Thread(
              new Runnable() {
                @Override
                public void run() {
                  try {
                    URL url = new URL(u);
                    System.out.println("Link : " + u);
                    HttpURLConnection con = (HttpURLConnection) url.openConnection();

                    // System.out.println("Response Code : " + con.getInputStream().available());
                    con.setRequestProperty("Accept-Encoding", "gzip,deflate");
                    con.setRequestProperty(
                        "User-Agent",
                        "Mozilla/5.0 (X11; Linux i686) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.71 Safari/537.36");

                    Map<String, List<String>> map = con.getHeaderFields();

                    for (String object : map.keySet()) {
                      System.out.println(object + " --> " + map.get(object));
                    }

                    System.out.println("Response Code : " + con.getResponseCode());
                    System.out.println("length :" + con.getContentLength());
                    System.out.println("Message " + con.getResponseMessage());

                    InputStream inputStream = con.getInputStream();
                    String path = System.getenv("OPENSHIFT_JBOSSAS_DIR");
                    FileOutputStream fileOutputStream = new FileOutputStream(path + "test.zip");
                    byte[] buffer = new byte[1024];
                    System.out.println(inputStream.available());
                    int bytesRead = 10;
                    while (true) {
                      //   System.out.print("--");
                      bytesRead = inputStream.read(buffer);
                      //   System.out.println(bytesRead);
                      if (bytesRead == -1) {
                        break;
                      }
                      fileOutputStream.write(buffer, 0, bytesRead);
                      // System.out.print(">");
                    }
                    fileOutputStream.close();

                    System.out.println("File Completed");
                  } catch (IOException ex) {
                    Logger.getLogger(MakeData.class.getName()).log(Level.SEVERE, null, ex);
                  }
                }
              });
      t.start();

      //            System.out.println(allLinks.get(0));
      //            System.out.println(webClient.getCookieManager().getCookies(new
      // URL(allLinks.get(0))).size());
      //            // System.out.println(httpPage.asText());
      //             HtmlPage httpPage = webClient.getPage(allLinks.get(0));
      //
      //           // final String pageAsXml = page1.asXml();
      //            // InputStream inputStream=httpPage.getWebResponse().getContentAsStream();
      //           //  inputStream.available();
      //              System.out.println("Code : "+httpPage.getWebResponse().getStatusMessage());
      //               System.out.println("Code : "+httpPage.getWebResponse().getContentType());
      //                System.out.println("netCode :
      // "+httpPage.getWebResponse().getContentCharset());
      //
      // out.println("<br/><br/>Code : "+httpPage.getWebResponse().getStatusCode());
      // out.println("<br/><br/>Code : "+httpPage.getWebResponse().getContentType());
      // out.println("<br/><br/>Code : "+httpPage.getWebResponse().getContentCharset());

      // final String pageAsText = page1.asText();

      // out.println(pageAsXml);
      webClient.closeAllWindows();
      out.println("<h1>Servlet NewServlet at " + request.getContextPath() + "</h1>");
      out.println("</body>");
      out.println("</html>");
    } finally {
      out.close();
    }
  }
 private void type(String id, String value) {
   page.getForms().get(0).<HtmlInput>getInputByName(id).setValueAttribute(value);
 }