use of org.apache.http.HttpRequest in project incubator-skywalking by apache.
the class HttpHostInterceptor method beforeMethod.
@Override
public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, MethodInterceptResult result) throws Throwable {
HttpHost producer = (HttpHost) allArguments[0];
String uri = producer.toURI();
AbstractSpan span = ContextManager.createLocalSpan("httpasyncclient/" + method.getName());
span.setComponent(ComponentsDefine.HTTP_ASYNC_CLIENT).setLayer(SpanLayer.HTTP);
Tags.HTTP.METHOD.set(span, ((HttpRequest) allArguments[1]).getRequestLine().getMethod());
Tags.URL.set(span, uri);
}
use of org.apache.http.HttpRequest in project connect-sdk-java by Ingenico-ePayments.
the class DefaultConnectionIdempotenceTest method setResponse.
private Answer<Void> setResponse(final String body, final int statusCode, final Map<String, String> responseHeaders, final Map<String, String> requestHeaders) {
return new Answer<Void>() {
@Override
public Void answer(InvocationOnMock invocation) throws Throwable {
HttpRequest request = invocation.getArgumentAt(0, HttpRequest.class);
HttpResponse response = invocation.getArgumentAt(1, HttpResponse.class);
if (requestHeaders != null) {
for (Header header : request.getAllHeaders()) {
requestHeaders.put(header.getName(), header.getValue());
}
}
response.setStatusCode(statusCode);
response.setHeader("Content-Type", "application/json");
for (Map.Entry<String, String> entry : responseHeaders.entrySet()) {
response.setHeader(entry.getKey(), entry.getValue());
}
response.setEntity(new StringEntity(body, ContentType.APPLICATION_JSON));
return null;
}
};
}
use of org.apache.http.HttpRequest in project connect-sdk-java by Ingenico-ePayments.
the class DefaultConnection method createHttpClient.
private CloseableHttpClient createHttpClient(ProxyConfiguration proxyConfiguration) {
HttpClientBuilder builder = HttpClients.custom().setConnectionManager(connectionManager);
HttpRoutePlanner routePlanner;
CredentialsProvider credentialsProvider;
if (proxyConfiguration != null) {
HttpHost proxy = new HttpHost(proxyConfiguration.getHost(), proxyConfiguration.getPort(), proxyConfiguration.getScheme());
routePlanner = new DefaultProxyRoutePlanner(proxy, DefaultSchemePortResolver.INSTANCE);
credentialsProvider = new BasicCredentialsProvider();
if (proxyConfiguration.getUsername() != null) {
AuthScope authscope = new AuthScope(proxyConfiguration.getHost(), proxyConfiguration.getPort());
final Credentials credentials = new UsernamePasswordCredentials(proxyConfiguration.getUsername(), proxyConfiguration.getPassword());
credentialsProvider.setCredentials(authscope, credentials);
// enable preemptive authentication
HttpRequestInterceptor proxyAuthenticationInterceptor = new HttpRequestInterceptor() {
@Override
public void process(HttpRequest request, HttpContext context) throws HttpException, IOException {
Header header = request.getFirstHeader(AUTH.PROXY_AUTH_RESP);
if (header == null) {
header = new BasicScheme((Charset) null).authenticate(credentials, request, context);
if (!AUTH.PROXY_AUTH_RESP.equals(header.getName())) {
header = new BasicHeader(AUTH.PROXY_AUTH_RESP, header.getValue());
}
request.setHeader(header);
}
}
};
builder = builder.addInterceptorLast(proxyAuthenticationInterceptor);
}
} else {
// add support for system properties
routePlanner = new SystemDefaultRoutePlanner(DefaultSchemePortResolver.INSTANCE, ProxySelector.getDefault());
credentialsProvider = new SystemDefaultCredentialsProvider();
}
// add logging - last for requests, first for responses
LoggingInterceptor loggingInterceptor = new LoggingInterceptor();
builder = builder.addInterceptorLast((HttpRequestInterceptor) loggingInterceptor);
builder = builder.addInterceptorFirst((HttpResponseInterceptor) loggingInterceptor);
return builder.setRoutePlanner(routePlanner).setDefaultCredentialsProvider(credentialsProvider).build();
}
use of org.apache.http.HttpRequest in project spring-cloud-netflix by spring-cloud.
the class GZIPCompression method httpClientDoesNotDecompressEncodedData.
@Test
public void httpClientDoesNotDecompressEncodedData() throws Exception {
setupContext();
InputStreamEntity inputStreamEntity = new InputStreamEntity(new ByteArrayInputStream(new byte[] { 1 }));
HttpRequest httpRequest = getFilter().buildHttpRequest("GET", "/app/compressed/get/1", inputStreamEntity, new LinkedMultiValueMap<String, String>(), new LinkedMultiValueMap<String, String>(), new MockHttpServletRequest());
CloseableHttpResponse response = getFilter().newClient().execute(new HttpHost("localhost", this.port), httpRequest);
assertEquals(200, response.getStatusLine().getStatusCode());
byte[] responseBytes = copyToByteArray(response.getEntity().getContent());
assertTrue(Arrays.equals(GZIPCompression.compress("Get 1"), responseBytes));
}
use of org.apache.http.HttpRequest in project spring-cloud-netflix by spring-cloud.
the class GZIPCompression method putRequestBuiltWithBody.
@Test
public void putRequestBuiltWithBody() throws Exception {
setupContext();
InputStreamEntity inputStreamEntity = new InputStreamEntity(new ByteArrayInputStream(new byte[] { 1 }));
HttpRequest httpRequest = getFilter().buildHttpRequest("PUT", "uri", inputStreamEntity, new LinkedMultiValueMap<String, String>(), new LinkedMultiValueMap<String, String>(), new MockHttpServletRequest());
assertTrue(httpRequest instanceof HttpEntityEnclosingRequest);
HttpEntityEnclosingRequest httpEntityEnclosingRequest = (HttpEntityEnclosingRequest) httpRequest;
assertTrue(httpEntityEnclosingRequest.getEntity() != null);
}
Aggregations