Package com.gargoylesoftware.htmlunit

Examples of com.gargoylesoftware.htmlunit.WebConnection


    public void testEjbcaHealthHttp() throws Exception {
        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);
        assertEquals("ALLOK", contentAsString);
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 httpReqPath = "http://127.0.0.1:" + httpPort + "/ejbca";
        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 resourceName5 = "enrol/browser.jsp";
        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

      // This test assumes we have a default AdminCA1 installed with CAId=-1688117755
        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();
        iter = list.iterator();
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

     */
    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 :)
        // We should get a NOT_FOUND error back.
View Full Code Here

     * @param urlStr
     */
    public static void defineAsCurrentResponse(final Context context, final byte[] responseBytes,
                                               final String contentType, final String urlStr) {
        final WebClient webClient = context.getWebClient();
        final WebConnection originalConnection = webClient.getWebConnection();
        try {
            final MockWebConnection mockConnection = new MockWebConnection();
            webClient.setWebConnection(mockConnection);
            mockConnection.setDefaultResponse(responseBytes, 200, "ok", contentType);
           
View Full Code Here

TOP

Related Classes of com.gargoylesoftware.htmlunit.WebConnection

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.