Package com.gargoylesoftware.htmlunit

Examples of com.gargoylesoftware.htmlunit.WebRequestSettings


     * Evaluates the literal Jelly script passed as a parameter as HTML and returns the page.
     */
    protected HtmlPage evaluateAsHtml(String jellyScript) throws Exception {
        HudsonTestCase.WebClient wc = new WebClient();
       
        WebRequestSettings req = new WebRequestSettings(wc.createCrumbedUrl("eval"), POST);
        req.setRequestBody("<j:jelly xmlns:j='jelly:core' xmlns:st='jelly:stapler' xmlns:l='/lib/layout' xmlns:f='/lib/form'>"+jellyScript+"</j:jelly>");
        Page page = wc.getPage(req);
        return (HtmlPage) page;
    }
View Full Code Here


            this.wc = wc;
            this.run = r;
        }

        String next() throws IOException {
            WebRequestSettings req = new WebRequestSettings(new URL(getURL() + run.getUrl() + "/logText/progressiveHtml"+(start!=null?"?start="+start:"")));
            Map headers = new HashMap();
            if (consoleAnnotator!=null)
                headers.put("X-ConsoleAnnotator",consoleAnnotator);
            req.setAdditionalHeaders(headers);

            p = wc.getPage(req);
            consoleAnnotator = p.getWebResponse().getResponseHeaderValue("X-ConsoleAnnotator");
            start = p.getWebResponse().getResponseHeaderValue("X-Text-Size");
            return p.getWebResponse().getContentAsString();
View Full Code Here

        HtmlPage page = wc.goTo("computer/(master)/");
        for (HtmlAnchor a : page.getAnchors())
            assertFalse(a.getHrefAttribute(),a.getHrefAttribute().endsWith("delete"));

        // try to delete it by hitting the final URL directly
        WebRequestSettings req = new WebRequestSettings(new URL(wc.getContextPath()+"computer/(master)/doDelete"), HttpMethod.POST);
        try {
            wc.getPage(req);
            fail("Error code expected");
        } catch (FailingHttpStatusCodeException e) {
            assertEquals(SC_FORBIDDEN,e.getStatusCode());
View Full Code Here

        log.trace(">testEjbcaHealthHttp()");
        // Make a quick test first that it works at all before starting all threads
        final WebClient webClient = new WebClient();
    webClient.setTimeout(31*1000);
        WebConnection con = webClient.getWebConnection();
        WebRequestSettings settings = new WebRequestSettings(new URL(httpReqPath));
        WebResponse resp = con.getResponse(settings);
        final int statusCode = resp.getStatusCode();
        final String contentAsString = resp.getContentAsString();
        log.debug("Response: statusCode=" + statusCode + " contentAsString=" + contentAsString);
        assertEquals("Response code", 200, statusCode);
View Full Code Here

    public void test01Access() throws Exception {
        // Hit with GET does work since EJBCA 3.8.2
        final WebClient webClient = new WebClient();
        WebConnection con = webClient.getWebConnection();
        WebRequestSettings settings = new WebRequestSettings(new URL(httpReqPath + '/' + resourceOcsp));
        WebResponse resp = con.getResponse(settings);
        assertEquals("Response code", 200, resp.getStatusCode());
    }
View Full Code Here

    /** Do a HTTP GET. */
    private int getUrl(String url) throws IOException {
        final WebClient webClient = new WebClient();
        WebConnection con = webClient.getWebConnection();
        WebRequestSettings settings = new WebRequestSettings(new URL(url));
        settings.setSubmitMethod(SubmitMethod.GET);
        WebResponse resp = con.getResponse(settings);
        return resp.getStatusCode();
    }
View Full Code Here

        String resourceName = "publicweb/webdist/certdist";
        String resourceName1 = "publicweb/webdist/certdist?cmd=cacert&issuer=CN%3dAdminCA1%2cO%3dEJBCA+Sample%2cC%3dSE&level=0";

        final WebClient webClient = new WebClient();
        WebConnection con = webClient.getWebConnection();
        WebRequestSettings settings = new WebRequestSettings(new URL(httpReqPath + '/' + resourceName));
        WebResponse resp = con.getResponse(settings);
        assertEquals("Response code", 400, resp.getStatusCode());

        settings = new WebRequestSettings(new URL(httpReqPath + '/' + resourceName1));
        resp = con.getResponse(settings);
        assertEquals("Response code", 200, resp.getStatusCode());

    }
View Full Code Here

        String resourceName6 = "enrol/server.jsp";
        String resourceName7 = "enrol/keystore.jsp";

        final WebClient webClient = new WebClient();
        WebConnection con = webClient.getWebConnection();
        WebRequestSettings settings = new WebRequestSettings(new URL(httpReqPath + '/' + resourceName));
        WebResponse resp = con.getResponse(settings);
        assertEquals("Response code", 200, resp.getStatusCode());

        settings = new WebRequestSettings(new URL(httpReqPath + '/' + resourceName1));
        resp = con.getResponse(settings);
        assertEquals("Response code", 200, resp.getStatusCode());

        settings = new WebRequestSettings(new URL(httpReqPath + '/' + resourceName2));
        resp = con.getResponse(settings);
        assertEquals("Response code", 200, resp.getStatusCode());

        settings = new WebRequestSettings(new URL(httpReqPath + '/' + resourceName3));
        resp = con.getResponse(settings);
        assertEquals("Response code", 200, resp.getStatusCode());

        settings = new WebRequestSettings(new URL(httpReqPath + '/' + resourceName4));
        resp = con.getResponse(settings);
        assertEquals("Response code", 200, resp.getStatusCode());

        settings = new WebRequestSettings(new URL(httpReqPath + '/' + resourceName5));
        resp = con.getResponse(settings);
        assertEquals("Response code", 200, resp.getStatusCode());

        settings = new WebRequestSettings(new URL(httpReqPath + '/' + resourceName6));
        resp = con.getResponse(settings);
        assertEquals("Response code", 200, resp.getStatusCode());

        settings = new WebRequestSettings(new URL(httpReqPath + '/' + resourceName7));
        resp = con.getResponse(settings);
        assertEquals("Response code", 200, resp.getStatusCode());

    }
View Full Code Here

        String httpReqPathPem = "http://localhost:" + httpPort + "/ejbca/publicweb/webdist/certdist?cmd=cachain&caid=-1688117755&format=pem";
        String httpReqPathJks = "http://localhost:" + httpPort + "/ejbca/publicweb/webdist/certdist?cmd=cachain&caid=-1688117755&format=jks";

        final WebClient webClient = new WebClient();
        WebConnection con = webClient.getWebConnection();
        WebRequestSettings settings = new WebRequestSettings(new URL(httpReqPathPem));
        WebResponse resp = con.getResponse(settings);
        assertEquals("Response code", 200, resp.getStatusCode());
        String ctype = resp.getContentType();
        assertTrue(StringUtils.startsWith(ctype, "application/octet-stream"));
        List<NameValuePair> list = resp.getResponseHeaders();
        Iterator<NameValuePair> iter = list.iterator();
        boolean found = false;
        while (iter.hasNext()) {
          NameValuePair pair = iter.next();
          log.debug(pair.getName() + ": " + pair.getValue());
          if (StringUtils.equalsIgnoreCase("Content-disposition", pair.getName())) {
            assertEquals("attachment; filename=\"chain.pem\"", pair.getValue());
            found = true;
          }
        }
        assertTrue("Unable find AdminCA1 in certificate chain or parsing the response wrong.", found);

        settings = new WebRequestSettings(new URL(httpReqPathJks));
        resp = con.getResponse(settings);
        assertEquals("Response code", 200, resp.getStatusCode());
        ctype = resp.getContentType();
        assertTrue(StringUtils.startsWith(ctype, "application/octet-stream"));
        list = resp.getResponseHeaders();
View Full Code Here

    public void test01Access() throws Exception {
        // Hit scep, gives a 400: Bad Request
        final WebClient webClient = new WebClient();
        WebConnection con = webClient.getWebConnection();
        WebRequestSettings settings = new WebRequestSettings(new URL(httpReqPath + '/' + resourceScep));
        WebResponse resp = con.getResponse(settings);
        assertEquals("Response code", 400, resp.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.