use of org.apache.http.protocol.HttpContext in project spring-framework by spring-projects.
the class HttpComponentsAsyncClientHttpRequestFactory method createAsyncRequest.
@Override
public AsyncClientHttpRequest createAsyncRequest(URI uri, HttpMethod httpMethod) throws IOException {
HttpAsyncClient asyncClient = getHttpAsyncClient();
startAsyncClient();
HttpUriRequest httpRequest = createHttpUriRequest(httpMethod, uri);
postProcessHttpRequest(httpRequest);
HttpContext context = createHttpContext(httpMethod, uri);
if (context == null) {
context = HttpClientContext.create();
}
// Request configuration not set in the context
if (context.getAttribute(HttpClientContext.REQUEST_CONFIG) == null) {
// Use request configuration given by the user, when available
RequestConfig config = null;
if (httpRequest instanceof Configurable) {
config = ((Configurable) httpRequest).getConfig();
}
if (config == null) {
config = createRequestConfig(asyncClient);
}
if (config != null) {
context.setAttribute(HttpClientContext.REQUEST_CONFIG, config);
}
}
return new HttpComponentsAsyncClientHttpRequest(asyncClient, httpRequest, context);
}
use of org.apache.http.protocol.HttpContext in project spring-security-oauth by spring-projects.
the class ServerRunning method createRestTemplate.
public RestOperations createRestTemplate() {
RestTemplate client = new RestTemplate();
client.setRequestFactory(new HttpComponentsClientHttpRequestFactory() {
@Override
protected HttpContext createHttpContext(HttpMethod httpMethod, URI uri) {
HttpClientContext context = HttpClientContext.create();
Builder builder = RequestConfig.custom().setCookieSpec(CookieSpecs.IGNORE_COOKIES).setAuthenticationEnabled(false).setRedirectsEnabled(false);
context.setRequestConfig(builder.build());
return context;
}
});
client.setErrorHandler(new DefaultResponseErrorHandler() {
@Override
public boolean hasError(ClientHttpResponse response) throws IOException {
return false;
}
});
return client;
}
use of org.apache.http.protocol.HttpContext in project XobotOS by xamarin.
the class AbstractHttpClient method execute.
// non-javadoc, see interface HttpClient
public final HttpResponse execute(HttpHost target, HttpRequest request, HttpContext context) throws IOException, ClientProtocolException {
if (request == null) {
throw new IllegalArgumentException("Request must not be null.");
}
// a null target may be acceptable, this depends on the route planner
// a null context is acceptable, default context created below
HttpContext execContext = null;
RequestDirector director = null;
// all shared objects that are potentially threading unsafe.
synchronized (this) {
HttpContext defaultContext = createHttpContext();
if (context == null) {
execContext = defaultContext;
} else {
execContext = new DefaultedHttpContext(context, defaultContext);
}
// Create a director for this request
director = createClientRequestDirector(getRequestExecutor(), getConnectionManager(), getConnectionReuseStrategy(), getConnectionKeepAliveStrategy(), getRoutePlanner(), getHttpProcessor().copy(), getHttpRequestRetryHandler(), getRedirectHandler(), getTargetAuthenticationHandler(), getProxyAuthenticationHandler(), getUserTokenHandler(), determineParams(request));
}
try {
return director.execute(target, request, execContext);
} catch (HttpException httpException) {
throw new ClientProtocolException(httpException);
}
}
use of org.apache.http.protocol.HttpContext in project camel by apache.
the class HttpProducerTwoHeadersWithSameKeyTest method setUp.
@Before
@Override
public void setUp() throws Exception {
localServer = ServerBootstrap.bootstrap().setHttpProcessor(getBasicHttpProcessor()).setConnectionReuseStrategy(getConnectionReuseStrategy()).setResponseFactory(getHttpResponseFactory()).setExpectationVerifier(getHttpExpectationVerifier()).setSslContext(getSSLContext()).registerHandler("/myapp", new HttpRequestHandler() {
@Override
public void handle(HttpRequest request, HttpResponse response, HttpContext context) throws HttpException, IOException {
Header[] from = request.getHeaders("from");
assertEquals("me", from[0].getValue());
Header[] to = request.getHeaders("to");
assertEquals("[foo, bar]", to[0].getValue());
response.setHeader("bar", "yes");
response.addHeader("foo", "123");
response.addHeader("foo", "456");
response.setEntity(new StringEntity("OK", "ASCII"));
response.setStatusCode(HttpStatus.SC_OK);
}
}).registerHandler("/myapp", new HttpRequestHandler() {
@Override
public void handle(HttpRequest request, HttpResponse response, HttpContext context) throws HttpException, IOException {
Header[] from = request.getHeaders("from");
assertEquals("me", from[0].getValue());
Header[] to = request.getHeaders("to");
assertEquals("[foo, bar]", to[0].getValue());
response.setHeader("bar", "yes");
response.addHeader("foo", "123");
response.addHeader("foo", "456");
response.setEntity(new StringEntity("OK", "ASCII"));
response.setStatusCode(HttpStatus.SC_OK);
}
}).create();
localServer.start();
super.setUp();
}
use of org.apache.http.protocol.HttpContext in project camel by apache.
the class HttpProducerTwoParametersWithSameKeyTest method setUp.
@Before
@Override
public void setUp() throws Exception {
localServer = ServerBootstrap.bootstrap().setHttpProcessor(getBasicHttpProcessor()).setConnectionReuseStrategy(getConnectionReuseStrategy()).setResponseFactory(getHttpResponseFactory()).setExpectationVerifier(getHttpExpectationVerifier()).setSslContext(getSSLContext()).registerHandler("/myapp", new HttpRequestHandler() {
@Override
public void handle(HttpRequest request, HttpResponse response, HttpContext context) throws HttpException, IOException {
String uri = request.getRequestLine().getUri();
assertEquals("/myapp?from=me&to=foo&to=bar", uri);
response.setHeader("bar", "yes");
response.addHeader("foo", "123");
response.addHeader("foo", "456");
response.setEntity(new StringEntity("OK", "ASCII"));
response.setStatusCode(HttpStatus.SC_OK);
}
}).create();
localServer.start();
super.setUp();
}
Aggregations