Package org.apache.http.impl.client

Examples of org.apache.http.impl.client.DefaultHttpClient.addRequestInterceptor()


    }

    protected HttpClient createHttpClient() {
        DefaultHttpClient client = new DefaultHttpClient(createClientConnectionManager());
        if (useCompression) {
            client.addRequestInterceptor( new HttpRequestInterceptor() {
                @Override
                public void process(HttpRequest request, HttpContext context) {
                    // We expect to received a compression response that we un-gzip
                    request.addHeader("Accept-Encoding", "gzip");
                }
View Full Code Here


                new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT, AuthScope.ANY_REALM, AuthPolicy.BASIC),
                new UsernamePasswordCredentials(key, "")
        );

        // Add a request interceptor so we don't have to set the credentials on every request.
        client.addRequestInterceptor(new AuthenticationInterceptor(), 0);

        return new Clever(client);
    }
}
View Full Code Here

          new AuthScope(apiURL.getHost(), apiURL.getPort(),
              AuthScope.ANY_REALM),
              new UsernamePasswordCredentials(mUser, mPassword));
      BasicHttpContext localcontext = new BasicHttpContext();
      localcontext.setAttribute("preemptive-auth", new BasicScheme());
      httpClient.addRequestInterceptor(new PreemptiveAuth(), 0);
      HttpPost request = new HttpPost(url);
      ObjectMapper mapper = new ObjectMapper();
      StringEntity params = new StringEntity(mapper.writeValueAsString(new Body(body)));
      request.addHeader("Content-Type", "application/json");
      request.setEntity(params);
View Full Code Here

              jdbcURI + ". " + e.getMessage();
          throw new SQLException(msg, " 08S01", e);
        }
      }
    }
    httpClient.addRequestInterceptor(requestInterceptor);
    return httpClient;
  }

  /**
   * Create transport per the connection options
View Full Code Here

        // Suppose we already know the expected nonce value
        digestAuth.overrideParamter("nonce", "whatever");       
        localcontext.setAttribute("preemptive-auth", digestAuth);
       
        // Add as the first request interceptor
        httpclient.addRequestInterceptor(new PreemptiveAuth(), 0);
        // Add as the last response interceptor
        httpclient.addResponseInterceptor(new PersistentDigest());
       
        HttpHost targetHost = new HttpHost("localhost", 80, "http");
View Full Code Here

        // execution context
        BasicScheme basicAuth = new BasicScheme();
        localcontext.setAttribute("preemptive-auth", basicAuth);
       
        // Add as the first request interceptor
        httpclient.addRequestInterceptor(new PreemptiveAuth(), 0);
       
        HttpHost targetHost = new HttpHost("localhost", 80, "http");

        HttpGet httpget = new HttpGet("/");
View Full Code Here

public class ClientGZipContentCompression {

    public final static void main(String[] args) throws Exception {
        DefaultHttpClient httpclient = new DefaultHttpClient();

        httpclient.addRequestInterceptor(new HttpRequestInterceptor() {
          
            public void process(
                    final HttpRequest request,
                    final HttpContext context) throws HttpException, IOException {
                if (!request.containsHeader("Accept-Encoding")) {
View Full Code Here

                // JVM will be used

                final DefaultHttpClient client = new SystemDefaultHttpClient();
                // Support compressed data
                // http://hc.apache.org/httpcomponents-client-ga/tutorial/html/httpagent.html#d5e1238
                client.addRequestInterceptor(new RequestAcceptEncoding());
                client.addResponseInterceptor(new ResponseContentEncoding());
                final CacheConfig cacheConfig = new CacheConfig();
                cacheConfig.setMaxObjectSize(1024 * 128); // 128 kB
                cacheConfig.setMaxCacheEntries(1000);
                // and allow caching
View Full Code Here

    // try resending the request once
    client.setHttpRequestRetryHandler(new DefaultHttpRequestRetryHandler(1, true));

    // Add hooks for gzip/deflate
    client.addRequestInterceptor(new HttpRequestInterceptor() {
      public void process(
          final org.apache.http.HttpRequest request,
          final HttpContext context) throws HttpException, IOException {
        if (!request.containsHeader("Accept-Encoding")) {
          request.addHeader("Accept-Encoding", "gzip, deflate");
View Full Code Here

                    // will be used

                    final DefaultHttpClient client = new SystemDefaultHttpClient();
                    // Support compressed data
                    // http://hc.apache.org/httpcomponents-client-ga/tutorial/html/httpagent.html#d5e1238
                    client.addRequestInterceptor(new RequestAcceptEncoding());
                    client.addResponseInterceptor(new ResponseContentEncoding());
                    final CacheConfig cacheConfig = new CacheConfig();
                    cacheConfig.setMaxObjectSize(1024 * 128); // 128 kB
                    cacheConfig.setMaxCacheEntries(1000);
                    // and allow caching
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.