List of usage examples for org.apache.http.impl.client ClientParamsStack getRequestParams
public final HttpParams getRequestParams()
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 www.j a v a 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:org.apache.http.impl.client.ClientParamsStack.java
/** * Creates a copy of a parameter stack./*from www . ja v a2 s .c o m*/ * The new stack will have the exact same entries as the argument stack. * There is no copying of parameters. * * @param stack the stack to copy */ public ClientParamsStack(ClientParamsStack stack) { this(stack.getApplicationParams(), stack.getClientParams(), stack.getRequestParams(), stack.getOverrideParams()); }
From source file:org.apache.http.impl.client.ClientParamsStack.java
/** * Creates a modified copy of a parameter stack. * The new stack will contain the explicitly passed elements. * For elements where the explicit argument is <code>null</code>, * the corresponding element from the argument stack is used. * There is no copying of parameters./*from w w w . jav a 2s. c o m*/ * * @param stack the stack to modify * @param aparams application parameters, or <code>null</code> * @param cparams client parameters, or <code>null</code> * @param rparams request parameters, or <code>null</code> * @param oparams override parameters, or <code>null</code> */ public ClientParamsStack(ClientParamsStack stack, HttpParams aparams, HttpParams cparams, HttpParams rparams, HttpParams oparams) { this((aparams != null) ? aparams : stack.getApplicationParams(), (cparams != null) ? cparams : stack.getClientParams(), (rparams != null) ? rparams : stack.getRequestParams(), (oparams != null) ? oparams : stack.getOverrideParams()); }