Search in sources :

Example 21 with WebRequest

use of com.gargoylesoftware.htmlunit.WebRequest in project archiva by apache.

the class AbstractRepositoryServletProxiedMetadataTestCase method requestMetadataOK.

protected String requestMetadataOK(String path) throws Exception {
    // process the response code later, not via an exception.
    // HttpUnitOptions.setExceptionsThrownOnErrorStatus( false );
    WebRequest request = new GetMethodWebRequest("http://machine.com/repository/internal/" + path);
    WebResponse response = getServletUnitClient().getResponse(request);
    assertResponseOK(response);
    return response.getContentAsString();
}
Also used : WebResponse(com.gargoylesoftware.htmlunit.WebResponse) WebRequest(com.gargoylesoftware.htmlunit.WebRequest)

Example 22 with WebRequest

use of com.gargoylesoftware.htmlunit.WebRequest in project workflow-job-plugin by jenkinsci.

the class PipelineTriggersJobPropertyTest method triggerPresentDuringStart.

@Issue("JENKINS-42446")
@Test
public void triggerPresentDuringStart() throws Exception {
    WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "triggerPresent");
    assertNull(getTriggerFromList(QueryingMockTrigger.class, p.getTriggersJobProperty().getTriggers()));
    JenkinsRule.WebClient wc = r.createWebClient();
    String newConfig = org.apache.commons.io.IOUtils.toString(PipelineTriggersJobPropertyTest.class.getResourceAsStream("/org/jenkinsci/plugins/workflow/job/properties/PipelineTriggersJobPropertyTest/triggerPresentDuringStart.json"), "UTF-8");
    WebRequest request = new WebRequest(new URL(p.getAbsoluteUrl() + "configSubmit"), HttpMethod.POST);
    wc.addCrumb(request);
    List<NameValuePair> params = new ArrayList<>();
    params.addAll(request.getRequestParameters());
    params.add(new NameValuePair("json", newConfig));
    request.setRequestParameters(params);
    wc.getPage(request);
    QueryingMockTrigger t = getTriggerFromList(QueryingMockTrigger.class, p.getTriggersJobProperty().getTriggers());
    assertNotNull(t);
    assertTrue(t.isStarted);
    assertTrue(t.foundSelf);
}
Also used : NameValuePair(com.gargoylesoftware.htmlunit.util.NameValuePair) WebRequest(com.gargoylesoftware.htmlunit.WebRequest) ArrayList(java.util.ArrayList) JenkinsRule(org.jvnet.hudson.test.JenkinsRule) WorkflowJob(org.jenkinsci.plugins.workflow.job.WorkflowJob) URL(java.net.URL) Issue(org.jvnet.hudson.test.Issue) Test(org.junit.Test)

Example 23 with WebRequest

use of com.gargoylesoftware.htmlunit.WebRequest in project javaee7-samples by javaee-samples.

the class MyResourceTest method testPut.

@Test
public void testPut() throws IOException, SAXException {
    webClient.setCredentialsProvider(correctCreds);
    try {
        WebRequest postRequest = new WebRequest(toUrlUnsafe(base + "webresources/myresource"), PUT);
        postRequest.setRequestBody("name=myname");
        webClient.getPage(postRequest);
    } catch (FailingHttpStatusCodeException e) {
        assertEquals(403, e.getStatusCode());
        return;
    }
    // All methods are excluded except for GET
    fail("PUT is not authorized and can still be called");
}
Also used : WebRequest(com.gargoylesoftware.htmlunit.WebRequest) FailingHttpStatusCodeException(com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException) Test(org.junit.Test)

Example 24 with WebRequest

use of com.gargoylesoftware.htmlunit.WebRequest in project javaee7-samples by javaee-samples.

the class SecureServletTest method tearDown.

@After
public void tearDown() throws IOException {
    // Remove Bouncy Castle as provider
    TextPage pageb = webClient.getPage(new WebRequest(new URL(base + "BouncyServlet"), HttpMethod.DELETE));
    log.log(INFO, "Bouncy Castle provider removed: {0}", pageb.getContent());
    webClient.getCookieManager().clearCookies();
    // Internally throws:
    // 
    // TransportContext.java:313|Fatal (INTERNAL_ERROR): closing inbound before receiving peer's close_notify (
    // "throwable" : {
    // javax.net.ssl.SSLException: closing inbound before receiving peer's close_notify
    // at java.base/sun.security.ssl.Alert.createSSLException(Alert.java:133)
    // at java.base/sun.security.ssl.Alert.createSSLException(Alert.java:117)
    // at java.base/sun.security.ssl.TransportContext.fatal(TransportContext.java:308)
    // at java.base/sun.security.ssl.TransportContext.fatal(TransportContext.java:264)
    // at java.base/sun.security.ssl.TransportContext.fatal(TransportContext.java:255)
    // at java.base/sun.security.ssl.SSLSocketImpl.shutdownInput(SSLSocketImpl.java:645)
    // at java.base/sun.security.ssl.SSLSocketImpl.shutdownInput(SSLSocketImpl.java:624)
    // at org.apache.http.impl.BHttpConnectionBase.close(BHttpConnectionBase.java:325)
    // at org.apache.http.impl.conn.LoggingManagedHttpClientConnection.close(LoggingManagedHttpClientConnection.java:81)
    // at org.apache.http.impl.conn.CPoolEntry.closeConnection(CPoolEntry.java:70)
    // at org.apache.http.impl.conn.CPoolEntry.close(CPoolEntry.java:96)
    // at org.apache.http.pool.AbstractConnPool.shutdown(AbstractConnPool.java:148)
    // at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.shutdown(PoolingHttpClientConnectionManager.java:411)
    // at com.gargoylesoftware.htmlunit.HttpWebConnection.close(HttpWebConnection.java:1011)
    // 
    // Visible when -Dssl.debug is used
    // 
    // Should be fixed in JDK11.03, but isn't?
    // See https://stackoverflow.com/questions/52016415/jdk-11-ssl-error-on-valid-certificate-working-in-previous-versions
    webClient.close();
    System.out.println("\n*********** TEST END ***************************\n");
}
Also used : WebRequest(com.gargoylesoftware.htmlunit.WebRequest) TextPage(com.gargoylesoftware.htmlunit.TextPage) URL(java.net.URL) After(org.junit.After)

Example 25 with WebRequest

use of com.gargoylesoftware.htmlunit.WebRequest in project javaee7-samples by javaee-samples.

the class SecureServletTest method testPutMethod.

@Test
public void testPutMethod() throws Exception {
    webClient.setCredentialsProvider(correctCreds);
    WebRequest request = new WebRequest(new URL(base + "SecureServlet"), PUT);
    System.out.println("\n\n**** After request");
    try {
        TextPage p = webClient.getPage(request);
        System.out.println(p.getContent());
    } catch (FailingHttpStatusCodeException e) {
        assertNotNull(e);
        assertEquals(403, e.getStatusCode());
        return;
    }
    fail("PUT method could be called even with deny-unocvered-http-methods");
}
Also used : WebRequest(com.gargoylesoftware.htmlunit.WebRequest) FailingHttpStatusCodeException(com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException) TextPage(com.gargoylesoftware.htmlunit.TextPage) URL(java.net.URL) Test(org.junit.Test)

Aggregations

WebRequest (com.gargoylesoftware.htmlunit.WebRequest)84 Test (org.junit.Test)65 WebResponse (com.gargoylesoftware.htmlunit.WebResponse)49 URL (java.net.URL)31 Path (java.nio.file.Path)31 FailingHttpStatusCodeException (com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException)12 TextPage (com.gargoylesoftware.htmlunit.TextPage)12 InputStream (java.io.InputStream)7 MkColMethodWebRequest (org.apache.archiva.webdav.httpunit.MkColMethodWebRequest)7 JenkinsRule (org.jvnet.hudson.test.JenkinsRule)7 WebClient (com.gargoylesoftware.htmlunit.WebClient)5 HtmlPage (com.gargoylesoftware.htmlunit.html.HtmlPage)5 IOException (java.io.IOException)5 FreeStyleProject (hudson.model.FreeStyleProject)4 Page (com.gargoylesoftware.htmlunit.Page)3 NameValuePair (com.gargoylesoftware.htmlunit.util.NameValuePair)3 HashMap (java.util.HashMap)3 Issue (org.jvnet.hudson.test.Issue)3 SeleniumOperationException (com.axway.ats.uiengine.exceptions.SeleniumOperationException)2 IncorrectnessListener (com.gargoylesoftware.htmlunit.IncorrectnessListener)2