List of usage examples for org.apache.http.impl.client RequestWrapper RequestWrapper
public RequestWrapper(final HttpRequest request) throws ProtocolException
From source file:com.clarionmedia.infinitum.http.rest.impl.CachingEnabledRestfulClient.java
@Override public RestResponse executePost(String uri, HttpEntity httpEntity) { HttpPost httpPost = new HttpPost(uri); httpPost.addHeader("content-type", httpEntity.getContentType().getValue()); httpPost.setEntity(httpEntity);/*from w ww . ja v a2 s . c o m*/ try { RequestWrapper request = new RequestWrapper(httpPost); return executeRequest(new HashableHttpRequest(request)); } catch (ProtocolException e) { throw new InfinitumRuntimeException("Unable to execute request", e); } }
From source file:com.clarionmedia.infinitum.http.rest.impl.CachingEnabledRestfulClient.java
@Override public RestResponse executePost(String uri, HttpEntity httpEntity, Map<String, String> headers) { HttpPost httpPost = new HttpPost(uri); for (Entry<String, String> header : headers.entrySet()) { httpPost.addHeader(header.getKey(), header.getValue()); }/*from w w w . jav a2 s .c om*/ httpPost.setEntity(httpEntity); try { RequestWrapper request = new RequestWrapper(httpPost); return executeRequest(new HashableHttpRequest(request)); } catch (ProtocolException e) { throw new InfinitumRuntimeException("Unable to execute request", e); } }
From source file:com.netscape.certsrv.client.PKIConnection.java
public PKIConnection(ClientConfig config) { this.config = config; // Register https scheme. Scheme scheme = new Scheme("https", 443, new JSSProtocolSocketFactory()); httpClient.getConnectionManager().getSchemeRegistry().register(scheme); // Don't retry operations. httpClient.setHttpRequestRetryHandler(new DefaultHttpRequestRetryHandler(0, false)); if (config.getUsername() != null && config.getPassword() != null) { List<String> authPref = new ArrayList<String>(); authPref.add(AuthPolicy.BASIC);/*from ww w. j ava 2 s . c o m*/ httpClient.getParams().setParameter(AuthPNames.PROXY_AUTH_PREF, authPref); httpClient.getCredentialsProvider().setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(config.getUsername(), config.getPassword())); } httpClient.addRequestInterceptor(new HttpRequestInterceptor() { @Override public void process(HttpRequest request, HttpContext context) throws HttpException, IOException { requestCounter++; if (verbose) { System.out.println("HTTP request: " + request.getRequestLine()); for (Header header : request.getAllHeaders()) { System.out.println(" " + header.getName() + ": " + header.getValue()); } } if (output != null) { File file = new File(output, "http-request-" + requestCounter); storeRequest(file, request); } // Set the request parameter to follow redirections. HttpParams params = request.getParams(); if (params instanceof ClientParamsStack) { ClientParamsStack paramsStack = (ClientParamsStack) request.getParams(); params = paramsStack.getRequestParams(); } HttpClientParams.setRedirecting(params, true); } }); httpClient.addResponseInterceptor(new HttpResponseInterceptor() { @Override public void process(HttpResponse response, HttpContext context) throws HttpException, IOException { responseCounter++; if (verbose) { System.out.println("HTTP response: " + response.getStatusLine()); for (Header header : response.getAllHeaders()) { System.out.println(" " + header.getName() + ": " + header.getValue()); } } if (output != null) { File file = new File(output, "http-response-" + responseCounter); storeResponse(file, response); } } }); httpClient.setRedirectStrategy(new DefaultRedirectStrategy() { @Override public HttpUriRequest getRedirect(HttpRequest request, HttpResponse response, HttpContext context) throws ProtocolException { HttpUriRequest uriRequest = super.getRedirect(request, response, context); URI uri = uriRequest.getURI(); if (verbose) System.out.println("HTTP redirect: " + uri); // Redirect the original request to the new URI. RequestWrapper wrapper; if (request instanceof HttpEntityEnclosingRequest) { wrapper = new EntityEnclosingRequestWrapper((HttpEntityEnclosingRequest) request); } else { wrapper = new RequestWrapper(request); } wrapper.setURI(uri); return wrapper; } @Override public boolean isRedirected(HttpRequest request, HttpResponse response, HttpContext context) throws ProtocolException { // The default redirection policy does not redirect POST or PUT. // This overrides the policy to follow redirections for all HTTP methods. return response.getStatusLine().getStatusCode() == 302; } }); engine = new ApacheHttpClient4Engine(httpClient); resteasyClient = new ResteasyClientBuilder().httpEngine(engine).build(); resteasyClient.register(PKIRESTProvider.class); }
From source file:com.clarionmedia.infinitum.http.rest.impl.CachingEnabledRestfulClient.java
@Override public RestResponse executePost(String uri, InputStream messageBody, int messageBodyLength, String contentType) {/*from ww w . ja va 2 s. co m*/ HttpPost httpPost = new HttpPost(uri); httpPost.addHeader("content-type", contentType); httpPost.setEntity(new InputStreamEntity(messageBody, messageBodyLength)); try { RequestWrapper request = new RequestWrapper(httpPost); return executeRequest(new HashableHttpRequest(request)); } catch (ProtocolException e) { throw new InfinitumRuntimeException("Unable to execute request", e); } }
From source file:com.apigee.sdk.apm.http.impl.client.cache.RequestProtocolCompliance.java
private HttpRequest upgradeRequestTo(HttpRequest request, ProtocolVersion version) throws ProtocolException { RequestWrapper newRequest = new RequestWrapper(request); newRequest.setProtocolVersion(version); return newRequest; }
From source file:com.apigee.sdk.apm.http.impl.client.cache.RequestProtocolCompliance.java
private HttpRequest downgradeRequestTo(HttpRequest request, ProtocolVersion version) throws ProtocolException { RequestWrapper newRequest = new RequestWrapper(request); newRequest.setProtocolVersion(version); return newRequest; }
From source file:com.clarionmedia.infinitum.http.rest.impl.CachingEnabledRestfulClient.java
@Override public RestResponse executePost(String uri, InputStream messageBody, int messageBodyLength, String contentType, Map<String, String> headers) { HttpPost httpPost = new HttpPost(uri); for (Entry<String, String> header : headers.entrySet()) { httpPost.addHeader(header.getKey(), header.getValue()); }//from w w w. j ava 2 s . co m httpPost.addHeader("content-type", contentType); httpPost.setEntity(new InputStreamEntity(messageBody, messageBodyLength)); try { RequestWrapper request = new RequestWrapper(httpPost); return executeRequest(new HashableHttpRequest(request)); } catch (ProtocolException e) { throw new InfinitumRuntimeException("Unable to execute request", e); } }
From source file:com.clarionmedia.infinitum.http.rest.impl.CachingEnabledRestfulClient.java
@Override public RestResponse executeDelete(String uri) { try {// w ww. j a va2 s. co m RequestWrapper request = new RequestWrapper(new HttpDelete(uri)); return executeRequest(new HashableHttpRequest(request)); } catch (ProtocolException e) { throw new InfinitumRuntimeException("Unable to execute request", e); } }
From source file:com.clarionmedia.infinitum.http.rest.impl.CachingEnabledRestfulClient.java
@Override public RestResponse executeDelete(String uri, Map<String, String> headers) { HttpDelete httpDelete = new HttpDelete(uri); for (Entry<String, String> header : headers.entrySet()) { httpDelete.addHeader(header.getKey(), header.getValue()); }// w w w. java 2s .co m try { RequestWrapper request = new RequestWrapper(httpDelete); return executeRequest(new HashableHttpRequest(request)); } catch (ProtocolException e) { throw new InfinitumRuntimeException("Unable to execute request", e); } }
From source file:com.clarionmedia.infinitum.http.rest.impl.CachingEnabledRestfulClient.java
@Override public RestResponse executePut(String uri, String messageBody, String contentType) { HttpPut httpPut = new HttpPut(uri); httpPut.addHeader("content-type", contentType); try {// w ww. j av a2s . c o m httpPut.setEntity(new StringEntity(messageBody, "UTF-8")); } catch (UnsupportedEncodingException e) { mLogger.error("Unable to send PUT request (could not encode message body)", e); return null; } try { RequestWrapper request = new RequestWrapper(httpPut); return executeRequest(new HashableHttpRequest(request)); } catch (ProtocolException e) { throw new InfinitumRuntimeException("Unable to execute request", e); } }