use of org.apache.http.impl.client.CloseableHttpClient in project c4sg-services by Code4SocialGood.
the class SlackUtils method createHttpClient.
public static CloseableHttpClient createHttpClient(int timeout) {
RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(timeout).setConnectTimeout(timeout).build();
PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager();
CloseableHttpClient httpClient = HttpClientBuilder.create().setConnectionManager(connectionManager).setDefaultRequestConfig(requestConfig).build();
return httpClient;
}
use of org.apache.http.impl.client.CloseableHttpClient in project wildfly by wildfly.
the class WebSecurityCERTTestCase method makeCall.
protected void makeCall(String alias, int expectedStatusCode) throws Exception {
try (CloseableHttpClient httpclient = getHttpsClient(alias)) {
HttpGet httpget = new HttpGet("https://" + mgmtClient.getMgmtAddress() + ":8380/web-secure-client-cert/secured/");
HttpResponse response = httpclient.execute(httpget);
StatusLine statusLine = response.getStatusLine();
assertEquals(expectedStatusCode, statusLine.getStatusCode());
}
}
use of org.apache.http.impl.client.CloseableHttpClient in project wildfly by wildfly.
the class WebSecurityExternalAuthTestCase method makeCall.
protected void makeCall(String user, int expectedStatusCode) throws Exception {
try (CloseableHttpClient httpClient = HttpClients.createDefault()) {
HttpGet httpget = new HttpGet(url.toExternalForm() + "secured/");
httpget.addHeader("User", user);
HttpResponse response = httpClient.execute(httpget);
HttpEntity entity = response.getEntity();
StatusLine statusLine = response.getStatusLine();
assertEquals(expectedStatusCode, statusLine.getStatusCode());
EntityUtils.consume(entity);
}
}
use of org.apache.http.impl.client.CloseableHttpClient in project wildfly by wildfly.
the class TransportGuaranteeTestCase method checkGetURL.
/**
* Check response on given url
*
* @param url
* @param responseSubstring - if null we are checking response code only
* @return
* @throws Exception
*/
private boolean checkGetURL(String url, String responseSubstring, String user, String pass) throws Exception {
log.trace("Checking URL=" + url);
CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
credentialsProvider.setCredentials(new AuthScope(AuthScope.ANY), new UsernamePasswordCredentials(user, pass));
CloseableHttpClient httpClient;
if (url.startsWith("https")) {
httpClient = TestHttpClientUtils.getHttpsClient(credentialsProvider);
} else {
httpClient = HttpClientBuilder.create().setDefaultCredentialsProvider(credentialsProvider).build();
}
HttpGet get = new HttpGet(url);
HttpResponse hr;
try {
try {
hr = httpClient.execute(get);
} catch (Exception e) {
if (// in case substring is defined, rethrow exception so, we can easier analyze the cause
responseSubstring == null) // in case substring is defined, rethrow exception so, we can easier analyze the cause
{
return false;
} else {
throw new Exception(e);
}
}
int statusCode = hr.getStatusLine().getStatusCode();
if (statusCode != 200) {
log.trace("statusCode not expected. statusCode=" + statusCode + ", URL=" + url);
return false;
}
if (responseSubstring == null) {
// this indicates that negative test had problems
log.trace("statusCode==200 on URL=" + url);
return true;
}
String response = EntityUtils.toString(hr.getEntity());
if (response.indexOf(responseSubstring) != -1) {
return true;
} else {
log.trace("Response doesn't contain expected substring (" + responseSubstring + ")");
return false;
}
} finally {
if (httpClient != null) {
httpClient.close();
}
}
}
use of org.apache.http.impl.client.CloseableHttpClient in project wildfly by wildfly.
the class SessionPersistenceTestCase method testLifeCycle.
@Test
public void testLifeCycle() throws Exception {
try (CloseableHttpClient client = HttpClients.createDefault()) {
HttpGet get = new HttpGet("http://" + TestSuiteEnvironment.getServerAddress() + ":8080/sessionPersistence/SessionPersistenceServlet");
deployer.deploy("web");
String result = runGet(get, client);
assertEquals("0", result);
result = runGet(get, client);
assertEquals("1", result);
result = runGet(get, client);
assertEquals("2", result);
deployer.undeploy("web");
deployer.deploy("web");
result = runGet(get, client);
assertEquals("3", result);
result = runGet(get, client);
assertEquals("4", result);
}
}
Aggregations