use of org.apache.http.client.methods.HttpUriRequest in project jersey by jersey.
the class ApacheConnector method apply.
@Override
public ClientResponse apply(final ClientRequest clientRequest) throws ProcessingException {
final HttpUriRequest request = getUriHttpRequest(clientRequest);
final Map<String, String> clientHeadersSnapshot = writeOutBoundHeaders(clientRequest.getHeaders(), request);
try {
final CloseableHttpResponse response;
final HttpClientContext context = HttpClientContext.create();
if (preemptiveBasicAuth) {
final AuthCache authCache = new BasicAuthCache();
final BasicScheme basicScheme = new BasicScheme();
authCache.put(getHost(request), basicScheme);
context.setAuthCache(authCache);
}
response = client.execute(getHost(request), request, context);
HeaderUtils.checkHeaderChanges(clientHeadersSnapshot, clientRequest.getHeaders(), this.getClass().getName());
final Response.StatusType status = response.getStatusLine().getReasonPhrase() == null ? Statuses.from(response.getStatusLine().getStatusCode()) : Statuses.from(response.getStatusLine().getStatusCode(), response.getStatusLine().getReasonPhrase());
final ClientResponse responseContext = new ClientResponse(status, clientRequest);
final List<URI> redirectLocations = context.getRedirectLocations();
if (redirectLocations != null && !redirectLocations.isEmpty()) {
responseContext.setResolvedRequestUri(redirectLocations.get(redirectLocations.size() - 1));
}
final Header[] respHeaders = response.getAllHeaders();
final MultivaluedMap<String, String> headers = responseContext.getHeaders();
for (final Header header : respHeaders) {
final String headerName = header.getName();
List<String> list = headers.get(headerName);
if (list == null) {
list = new ArrayList<>();
}
list.add(header.getValue());
headers.put(headerName, list);
}
final HttpEntity entity = response.getEntity();
if (entity != null) {
if (headers.get(HttpHeaders.CONTENT_LENGTH) == null) {
headers.add(HttpHeaders.CONTENT_LENGTH, String.valueOf(entity.getContentLength()));
}
final Header contentEncoding = entity.getContentEncoding();
if (headers.get(HttpHeaders.CONTENT_ENCODING) == null && contentEncoding != null) {
headers.add(HttpHeaders.CONTENT_ENCODING, contentEncoding.getValue());
}
}
try {
responseContext.setEntityStream(new HttpClientResponseInputStream(getInputStream(response)));
} catch (final IOException e) {
LOGGER.log(Level.SEVERE, null, e);
}
return responseContext;
} catch (final Exception e) {
throw new ProcessingException(e);
}
}
use of org.apache.http.client.methods.HttpUriRequest in project FastDev4Android by jiangqqlmj.
the class HttpClientStackTest method createPutRequest.
@Test
public void createPutRequest() throws Exception {
TestRequest.Put request = new TestRequest.Put();
assertEquals(request.getMethod(), Method.PUT);
HttpUriRequest httpRequest = HttpClientStack.createHttpRequest(request, null);
assertTrue(httpRequest instanceof HttpPut);
}
use of org.apache.http.client.methods.HttpUriRequest in project FastDev4Android by jiangqqlmj.
the class HttpClientStackTest method createDeleteRequest.
@Test
public void createDeleteRequest() throws Exception {
TestRequest.Delete request = new TestRequest.Delete();
assertEquals(request.getMethod(), Method.DELETE);
HttpUriRequest httpRequest = HttpClientStack.createHttpRequest(request, null);
assertTrue(httpRequest instanceof HttpDelete);
}
use of org.apache.http.client.methods.HttpUriRequest in project FastDev4Android by jiangqqlmj.
the class HttpClientStackTest method createPostRequestWithBody.
@Test
public void createPostRequestWithBody() throws Exception {
TestRequest.PostWithBody request = new TestRequest.PostWithBody();
assertEquals(request.getMethod(), Method.POST);
HttpUriRequest httpRequest = HttpClientStack.createHttpRequest(request, null);
assertTrue(httpRequest instanceof HttpPost);
}
use of org.apache.http.client.methods.HttpUriRequest in project FastDev4Android by jiangqqlmj.
the class HttpClientStackTest method createPatchRequestWithBody.
@Test
public void createPatchRequestWithBody() throws Exception {
TestRequest.PatchWithBody request = new TestRequest.PatchWithBody();
assertEquals(request.getMethod(), Method.PATCH);
HttpUriRequest httpRequest = HttpClientStack.createHttpRequest(request, null);
assertTrue(httpRequest instanceof HttpPatch);
}
Aggregations