use of com.gargoylesoftware.htmlunit.WebRequest 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.WebRequest in project workflow-cps-plugin by jenkinsci.
the class SnippetizerTester method assertGenerateSnippet.
/**
* Tests a form submitting part of snippetizer.
*
* @param json
* The form submission value from the configuration page to be tested.
* @param responseText
* Expected snippet to be generated
* @param referer
* needed because of {@link StaplerReferer}
*/
public void assertGenerateSnippet(@Nonnull String json, @Nonnull String responseText, @CheckForNull String referer) throws Exception {
JenkinsRule.WebClient wc = r.createWebClient();
WebRequest wrs = new WebRequest(new URL(r.getURL(), Snippetizer.GENERATE_URL), HttpMethod.POST);
if (referer != null) {
wrs.setAdditionalHeader("Referer", referer);
}
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new NameValuePair("json", json));
// WebClient.addCrumb *replaces* rather than *adds*:
params.add(new NameValuePair(r.jenkins.getCrumbIssuer().getDescriptor().getCrumbRequestField(), r.jenkins.getCrumbIssuer().getCrumb(null)));
wrs.setRequestParameters(params);
WebResponse response = wc.getPage(wrs).getWebResponse();
assertEquals("text/plain", response.getContentType());
assertEquals(responseText, response.getContentAsString().trim());
}
use of com.gargoylesoftware.htmlunit.WebRequest in project archiva by apache.
the class RepositoryServletRepositoryGroupTest method testGetFromLastManagedRepositoryReturnOk.
/*
* Test Case 3.c
*/
@Test
public void testGetFromLastManagedRepositoryReturnOk() throws Exception {
String resourceName = "dummy/dummy-last-resource/1.0/dummy-last-resource-1.0.txt";
Path dummyReleasesResourceFile = repoRootLast.resolve(resourceName);
Files.createDirectories(dummyReleasesResourceFile.getParent());
org.apache.archiva.common.utils.FileUtils.writeStringToFile(dummyReleasesResourceFile, Charset.defaultCharset(), "last");
WebRequest request = new GetMethodWebRequest("http://machine.com/repository/" + REPO_GROUP_WITH_VALID_REPOS + "/" + resourceName);
WebResponse response = getServletUnitClient().getResponse(request);
assertResponseOK(response);
assertThat(response.getContentAsString()).isEqualTo("last");
}
use of com.gargoylesoftware.htmlunit.WebRequest in project archiva by apache.
the class RepositoryServletRepositoryGroupTest method testBrowseWithTwoArtifactsWithSameGroupIdInRepos.
// MRM-901
@Test
public void testBrowseWithTwoArtifactsWithSameGroupIdInRepos() throws Exception {
String resourceName = "dummy/dummy-artifact/1.0/dummy-artifact-1.0.txt";
Path dummyInternalResourceFile = repoRootFirst.resolve(resourceName);
Files.createDirectories(dummyInternalResourceFile.getParent());
org.apache.archiva.common.utils.FileUtils.writeStringToFile(dummyInternalResourceFile, Charset.defaultCharset(), "first");
resourceName = "dummy/dummy-artifact/2.0/dummy-artifact-2.0.txt";
Path dummyReleasesResourceFile = repoRootLast.resolve(resourceName);
Files.createDirectories(dummyReleasesResourceFile.getParent());
org.apache.archiva.common.utils.FileUtils.writeStringToFile(dummyReleasesResourceFile, Charset.defaultCharset(), "last");
WebRequest request = new GetMethodWebRequest("http://machine.com/repository/" + REPO_GROUP_WITH_VALID_REPOS + "/dummy/dummy-artifact/");
WebResponse response = getServletUnitClient().getResource(request);
assertResponseOK(response);
assertThat(response.getContentAsString()).contains("Collection").contains("dummy/dummy-artifact").contains("1.0").contains("2.0");
}
use of com.gargoylesoftware.htmlunit.WebRequest in project archiva by apache.
the class RepositoryServletTest method testGetRepositoryInvalidPathPassthroughPresent.
@Test
public void testGetRepositoryInvalidPathPassthroughPresent() throws Exception {
String path = REQUEST_PATH + ".index/filecontent/segments.gen";
populateRepo(repoRootInternal, ".index/filecontent/segments.gen", "index file");
WebRequest request = new GetMethodWebRequest(path);
WebResponse response = getServletUnitClient().getResponse(request);
assertResponseOK(response);
assertEquals("index file", response.getContentAsString());
}
Aggregations