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));
}
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();
}
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();
}
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);
}
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);
}
Aggregations