Package com.gargoylesoftware.htmlunit

Examples of com.gargoylesoftware.htmlunit.WebRequestSettings


    public void test02OpenScep() throws Exception {
        log.debug(">test02OpenScep()");
        // send message to server and see what happens
        final WebClient webClient = new WebClient();
        WebConnection con = webClient.getWebConnection();
        WebRequestSettings settings = new WebRequestSettings(new URL(httpReqPath + '/' + resourceScep), SubmitMethod.GET);
        ArrayList<NameValuePair> l = new ArrayList<NameValuePair>();
        l.add(new NameValuePair("operation", "PKIOperation"));
        l.add(new NameValuePair("message", new String(Base64.encode(openscep))));
        settings.setRequestParameters(l);
        WebResponse resp = con.getResponse(settings);
        // TODO: since our request most certainly uses the wrong CA cert to
        // encrypt the
        // request, it will fail. If we get something back, we came a little bit
        // at least :)
View Full Code Here


    return new RequestFileAttachment( temp, false, ( AbstractHttpRequest<?> )request );
  }

  private byte[] downloadResource( HtmlPage page, HtmlElement htmlElement, URL url ) throws IOException
  {
    WebRequestSettings wrs = null;

    wrs = new WebRequestSettings( url );
    wrs.setAdditionalHeader( "Referer", page.getWebResponse().getRequestSettings().getUrl().toString() );
    client.addRequestHeader( "Accept", acceptTypes.get( htmlElement.getTagName().toLowerCase() ) );
    return client.getPage( wrs ).getWebResponse().getContentAsBytes();

  }
View Full Code Here

  private String postSigned(final List<KeyValuePair> parameters)
  throws IOException {
    WebClient client = createWebClient();

    log.debug("Posting shopping cart to " + postURL);
    WebRequestSettings request = new WebRequestSettings(new URL(postURL),
        SubmitMethod.POST);  
    request.setRequestParameters(parameters);   
    log.debug(parameters.toString());
    try {
      Page page = client.getPage(request);     
      String path = page.getWebResponse().getUrl().getFile();
      return path;
View Full Code Here

      final String body)
  throws IOException {
    WebClient client = createWebClient();

    log.debug("Posting shopping cart to " + postURL);
    WebRequestSettings request = new WebRequestSettings(new URL(postURL),
        SubmitMethod.POST);

    request.setRequestBody(body);
    Map headers = new HashMap<String, String>();
    for (KeyValuePair current : parameters) {
      headers.put(current.getKey(), current.getValue());
    }
    request.setAdditionalHeaders(headers);
    try {
      Page page = client.getPage(request);     
      CheckoutRedirect response = (CheckoutRedirect) CartUtils.unmarshal(
          page.getWebResponse().getContentAsString()).getValue();
      URL url = new URL(URLDecoder.decode(response.getRedirectUrl(), "UTF-8"));
View Full Code Here

              final WebWindow window = page.getEnclosingWindow();
              if (window == null) {
                  return;
              }
              final WebClient client = window.getWebClient();
              client.getPage(window, new WebRequestSettings(url));
        }
        else
        {
          LOG.info("no refresh performed to " + url + " (delay: " + iTimeBeforeRefresh + ") according to configuration");
        }
View Full Code Here

    protected Page findTarget() throws IOException, SAXException {
        if ("POST".equals(getMethod())) {
            return findTargetByPost();
        }
        fCompleteUrl = getContext().getConfig().getUrlForPage(getUrl());
        final WebRequestSettings settings = new WebRequestSettings(new URL(fCompleteUrl));
        settings.setHttpMethod(HttpMethod.valueOf(getMethod().toUpperCase()));
        return getResponse(settings);
    }
View Full Code Here

        return getResponse(settings);
    }

    private Page findTargetByPost() throws IOException, SAXException {
        String url = getContext().getConfig().getUrlForPage(getUrl());
        WebRequestSettings settings = new WebRequestSettings(new URL(url), HttpMethod.POST);
       
        // get default encoding
        final String charset = System.getProperty("file.encoding");
       
        final Map headers = new HashMap();
        if (!StringUtils.isEmpty(fSoapAction)) {
            headers.put("Content-type", "text/xml; charset=" + charset);
            headers.put("SOAPAction", fSoapAction);
        }
        else {
            // TODO: is this the correct Content-type for non-SOAP posts?
            headers.put("Content-type", "application/x-www-form-urlencoded");
        }
        settings.setAdditionalHeaders(headers);
        final String content;
        if (getContent() != null) {
            content = getContent();
        }
        else {
            content = FileUtil.readFileToString(getContentFile(), this);
        }
        settings.setRequestBody(content);
        settings.setCharset(charset);
        return getResponse(settings);
    }
View Full Code Here

    protected Page findTargetWithResults(AppletPluginResults apr, Context context) throws IOException, SAXException {
        if (fTarget != null) {
            final Map allFrames = apr.getFrames();
            if (allFrames.containsKey(fTarget)) {
                final URL url = (URL) allFrames.get(fTarget);
                return getResponse(new WebRequestSettings(url));
            }
            else {
                for (final Iterator frames = allFrames.entrySet().iterator(); frames.hasNext();) {
                  final Map.Entry frame = (Map.Entry) frames.next();
                    LOG.error(frame.getKey() + " -> " + ((URL) frame.getValue()).toExternalForm());
View Full Code Here

    }

    @Test
    public void testPostRequest() throws Exception {
        WebClient wc = startWebClient();
        WebRequestSettings request =
            new WebRequestSettings(new URL(url("/cards/CreateCard.action")), HttpMethod.POST);
        HtmlPage page = wc.getPage(request);
        testTitle(page, "Log in");
        HtmlPage pageAfterLogin = login(page);
        testTitle(pageAfterLogin, "Cards");
    }
View Full Code Here

    }

    @Test
    public void testAjaxRequest() throws Exception {
        WebClient wc = startWebClient();
        WebRequestSettings request =
            new WebRequestSettings(new URL(url("/cards/CreateCard.action")), HttpMethod.GET);
        request.setAdditionalHeader("X-Requested-With", "XMLHttpRequest");
        wc.setThrowExceptionOnFailingStatusCode(false);
        HtmlPage page = wc.getPage(request);
        assertEquals(403, page.getWebResponse().getStatusCode());
    }
View Full Code Here

TOP

Related Classes of com.gargoylesoftware.htmlunit.WebRequestSettings

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.