Search in sources :

Example 1 with WebResponse

use of com.gargoylesoftware.htmlunit.WebResponse in project camel by apache.

the class LinkedInOAuthRequestFilter method getAccessToken.

private OAuthToken getAccessToken(String refreshToken) throws IOException {
    final String tokenUrl = String.format(ACCESS_TOKEN_URL, refreshToken, oAuthParams.getRedirectUri(), oAuthParams.getClientId(), oAuthParams.getClientSecret());
    final WebRequest webRequest = new WebRequest(new URL(tokenUrl), HttpMethod.POST);
    final WebResponse webResponse = webClient.loadWebResponse(webRequest);
    if (webResponse.getStatusCode() != HttpStatus.SC_OK) {
        throw new IOException(String.format("Error getting access token: [%s: %s]", webResponse.getStatusCode(), webResponse.getStatusMessage()));
    }
    final long currentTime = System.currentTimeMillis();
    final ObjectMapper mapper = new ObjectMapper();
    final Map map = mapper.readValue(webResponse.getContentAsStream(), Map.class);
    final String accessToken = map.get("access_token").toString();
    final Integer expiresIn = Integer.valueOf(map.get("expires_in").toString());
    return new OAuthToken(refreshToken, accessToken, currentTime + TimeUnit.MILLISECONDS.convert(expiresIn, TimeUnit.SECONDS));
}
Also used : WebResponse(com.gargoylesoftware.htmlunit.WebResponse) WebRequest(com.gargoylesoftware.htmlunit.WebRequest) IOException(java.io.IOException) HashMap(java.util.HashMap) Map(java.util.Map) URL(java.net.URL) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 2 with WebResponse

use of com.gargoylesoftware.htmlunit.WebResponse in project blueocean-plugin by jenkinsci.

the class GitSampleRepoRule method notifyCommit.

public void notifyCommit(JenkinsRule r) throws Exception {
    synchronousPolling(r);
    WebResponse webResponse = r.createWebClient().goTo("git/notifyCommit?url=" + bareUrl(), "text/plain").getWebResponse();
    System.out.println(webResponse.getContentAsString());
    for (NameValuePair pair : webResponse.getResponseHeaders()) {
        if (pair.getName().equals("Triggered")) {
            System.out.println("Triggered: " + pair.getValue());
        }
    }
    r.waitUntilNoActivity();
}
Also used : NameValuePair(com.gargoylesoftware.htmlunit.util.NameValuePair) WebResponse(com.gargoylesoftware.htmlunit.WebResponse)

Example 3 with WebResponse

use of com.gargoylesoftware.htmlunit.WebResponse in project blueocean-plugin by jenkinsci.

the class GitSampleRepoRule method notifyCommit.

public void notifyCommit(JenkinsRule r) throws Exception {
    synchronousPolling(r);
    WebResponse webResponse = r.createWebClient().goTo("git/notifyCommit?url=" + bareUrl(), "text/plain").getWebResponse();
    System.out.println(webResponse.getContentAsString());
    for (NameValuePair pair : webResponse.getResponseHeaders()) {
        if (pair.getName().equals("Triggered")) {
            System.out.println("Triggered: " + pair.getValue());
        }
    }
    r.waitUntilNoActivity();
}
Also used : NameValuePair(com.gargoylesoftware.htmlunit.util.NameValuePair) WebResponse(com.gargoylesoftware.htmlunit.WebResponse)

Example 4 with WebResponse

use of com.gargoylesoftware.htmlunit.WebResponse in project spring-framework by spring-projects.

the class MockWebResponseBuilder method build.

public WebResponse build() throws IOException {
    WebResponseData webResponseData = webResponseData();
    long endTime = System.currentTimeMillis();
    return new WebResponse(webResponseData, webRequest, endTime - startTime);
}
Also used : WebResponse(com.gargoylesoftware.htmlunit.WebResponse) WebResponseData(com.gargoylesoftware.htmlunit.WebResponseData)

Example 5 with WebResponse

use of com.gargoylesoftware.htmlunit.WebResponse in project spring-framework by spring-projects.

the class DelegatingWebConnectionTests method getResponseSecondMatches.

@Test
public void getResponseSecondMatches() throws Exception {
    when(matcher2.matches(request)).thenReturn(true);
    when(connection2.getResponse(request)).thenReturn(expectedResponse);
    WebResponse response = webConnection.getResponse(request);
    assertThat(response, sameInstance(expectedResponse));
    verify(matcher1).matches(request);
    verify(matcher2).matches(request);
    verifyNoMoreInteractions(connection1, defaultConnection);
    verify(connection2).getResponse(request);
}
Also used : WebResponse(com.gargoylesoftware.htmlunit.WebResponse) Test(org.junit.Test)

Aggregations

WebResponse (com.gargoylesoftware.htmlunit.WebResponse)22 Test (org.junit.Test)14 NameValuePair (com.gargoylesoftware.htmlunit.util.NameValuePair)5 WebRequest (com.gargoylesoftware.htmlunit.WebRequest)4 URL (java.net.URL)4 WebClient (com.gargoylesoftware.htmlunit.WebClient)3 WebResponseData (com.gargoylesoftware.htmlunit.WebResponseData)3 StringWebResponse (com.gargoylesoftware.htmlunit.StringWebResponse)2 Cookie (javax.servlet.http.Cookie)2 JvmAttributeGaugeSet (com.codahale.metrics.JvmAttributeGaugeSet)1 MetricRegistry (com.codahale.metrics.MetricRegistry)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 HttpWebConnection (com.gargoylesoftware.htmlunit.HttpWebConnection)1 NicelyResynchronizingAjaxController (com.gargoylesoftware.htmlunit.NicelyResynchronizingAjaxController)1 WebConnection (com.gargoylesoftware.htmlunit.WebConnection)1 HtmlPage (com.gargoylesoftware.htmlunit.html.HtmlPage)1 IOException (java.io.IOException)1 PrintWriter (java.io.PrintWriter)1 StringWriter (java.io.StringWriter)1 HashMap (java.util.HashMap)1