use of org.apache.http.protocol.HttpContext in project tmdm-studio-se by Talend.
the class HttpClientUtil method uploadImageFile.
public static String uploadImageFile(String URL, String localFilename, String filename, String imageCatalog, String username, String password, HashMap<String, String> picturePathMap) throws XtentisException {
HttpUriRequest request = createUploadRequest(URL, username, localFilename, filename, imageCatalog, picturePathMap);
DefaultHttpClient client = wrapAuthClient(URL, username, password);
HttpContext preemptiveContext = getPreemptiveContext(URL);
authenticate(username, password, request, preemptiveContext);
// $NON-NLS-1$//$NON-NLS-2$
String errMessage = Messages.Util_25 + "%s" + Messages.Util_26 + "%s";
String content = getTextContent(client, request, preemptiveContext, errMessage);
if (null == content) {
// $NON-NLS-1$
throw new XtentisException("no response content");
}
if (content.contains("upload")) {
// $NON-NLS-1$
// $NON-NLS-1$//$NON-NLS-2$
String returnValue = content.substring(content.indexOf("upload"), content.indexOf("}") - 1);
if (picturePathMap != null) {
File file = new File(localFilename);
String fileName1 = file.getName();
picturePathMap.put(fileName1, returnValue);
}
return returnValue;
} else {
// $NON-NLS-1$
return "";
}
}
use of org.apache.http.protocol.HttpContext in project iaf by ibissource.
the class HttpResponseMock method answer.
@Override
public HttpResponse answer(InvocationOnMock invocation) throws Throwable {
HttpHost host = (HttpHost) invocation.getArguments()[0];
HttpRequestBase request = (HttpRequestBase) invocation.getArguments()[1];
HttpContext context = (HttpContext) invocation.getArguments()[2];
InputStream response = null;
if (request instanceof HttpGet)
response = doGet(host, (HttpGet) request, context);
else if (request instanceof HttpPost)
response = doPost(host, (HttpPost) request, context);
else if (request instanceof HttpPut)
response = doPut(host, (HttpPut) request, context);
else if (request instanceof HttpPatch)
response = doPatch(host, (HttpPatch) request, context);
else if (request instanceof HttpDelete)
response = doDelete(host, (HttpDelete) request, context);
else
throw new Exception("mock method not implemented");
return buildResponse(response);
}
use of org.apache.http.protocol.HttpContext in project keycloak by keycloak.
the class CookieTest method testCookieValue.
private void testCookieValue(String cookieName) throws Exception {
final String accountClientId = realmsResouce().realm("test").clients().findByClientId("account").get(0).getId();
final String clientSecret = realmsResouce().realm("test").clients().get(accountClientId).getSecret().getValue();
AuthorizationEndpointResponse codeResponse = oauth.clientId("account").redirectUri(accountPage.buildUri().toString()).doLogin("test-user@localhost", "password");
OAuthClient.AccessTokenResponse accTokenResp = oauth.doAccessTokenRequest(codeResponse.getCode(), clientSecret);
String accessToken = accTokenResp.getAccessToken();
accountPage.navigateTo();
accountPage.assertCurrent();
try (CloseableHttpClient hc = OAuthClient.newCloseableHttpClient()) {
BasicCookieStore cookieStore = new BasicCookieStore();
BasicClientCookie cookie = new BasicClientCookie(cookieName, accessToken);
cookie.setDomain("localhost");
cookie.setPath("/");
cookieStore.addCookie(cookie);
HttpContext localContext = new BasicHttpContext();
localContext.setAttribute(HttpClientContext.COOKIE_STORE, cookieStore);
HttpGet get = new HttpGet(oauth.clientId("account").redirectUri(accountPage.buildUri().toString()).getLoginFormUrl());
try (CloseableHttpResponse resp = hc.execute(get, localContext)) {
final String pageContent = EntityUtils.toString(resp.getEntity());
// Ensure that we did not get to the account page ...
assertThat(pageContent, not(containsString("First name")));
assertThat(pageContent, not(containsString("Last name")));
// ... but were redirected to login page
assertThat(pageContent, containsString("Sign In"));
assertThat(pageContent, containsString("Forgot Password?"));
}
}
}
use of org.apache.http.protocol.HttpContext in project keycloak by keycloak.
the class CookieTest method testCookieValueLoggedOut.
@Test
public void testCookieValueLoggedOut() throws Exception {
final String accountClientId = realmsResouce().realm("test").clients().findByClientId("account").get(0).getId();
final String clientSecret = realmsResouce().realm("test").clients().get(accountClientId).getSecret().getValue();
AuthorizationEndpointResponse codeResponse = oauth.clientId("account").redirectUri(accountPage.buildUri().toString()).doLogin("test-user@localhost", "password");
OAuthClient.AccessTokenResponse accTokenResp = oauth.doAccessTokenRequest(codeResponse.getCode(), clientSecret);
String accessToken = accTokenResp.getAccessToken();
accountPage.navigateTo();
accountPage.assertCurrent();
accountPage.logOut();
try (CloseableHttpClient hc = OAuthClient.newCloseableHttpClient()) {
BasicCookieStore cookieStore = new BasicCookieStore();
BasicClientCookie cookie = new BasicClientCookie(KEYCLOAK_IDENTITY_COOKIE, accessToken);
cookie.setDomain("localhost");
cookie.setPath("/");
cookieStore.addCookie(cookie);
HttpContext localContext = new BasicHttpContext();
localContext.setAttribute(HttpClientContext.COOKIE_STORE, cookieStore);
HttpGet get = new HttpGet(oauth.clientId("account").redirectUri(accountPage.buildUri().toString()).getLoginFormUrl());
try (CloseableHttpResponse resp = hc.execute(get, localContext)) {
final String pageContent = EntityUtils.toString(resp.getEntity());
// Ensure that we did not get to the account page ...
assertThat(pageContent, not(containsString("First name")));
assertThat(pageContent, not(containsString("Last name")));
// ... but were redirected to login page
assertThat(pageContent, containsString("Sign In"));
assertThat(pageContent, containsString("Forgot Password?"));
}
}
}
use of org.apache.http.protocol.HttpContext in project coprhd-controller by CoprHD.
the class WinRMTarget method sendMessage.
public String sendMessage(String request) throws WinRMException {
try {
HttpPost post = new HttpPost(getUrl().toExternalForm());
post.setEntity(new StringEntity(request, SOAP));
HttpHost targetHost = new HttpHost(getHost(), getPort(), getProtocol());
CloseableHttpClient client = getClient();
HttpContext context = getContext();
HttpResponse response = client.execute(targetHost, post, context);
String text = EntityUtils.toString(response.getEntity());
if (response.getStatusLine().getStatusCode() != 200) {
handleError(response, text);
}
return text;
} catch (WinRMException e) {
throw e;
} catch (Exception e) {
throw new WinRMException(e);
}
}
Aggregations