Code example for BasicHttpProcessor

Methods: BasicHttpProcessor.addInterceptor, addInterceptor, addRequestInterceptor

0
    this.delegate = new DefaultHttpClient(ccm, params) {
      @Override 
      protected BasicHttpProcessor createHttpProcessor() {
        // Add interceptor to prevent making requests from main thread. 
        BasicHttpProcessor processor = super.createHttpProcessor();
        processor.addRequestInterceptor(sThreadCheckInterceptor);
        return processor;
      } 
 
      @Override 
      protected HttpContext createHttpContext() {
        // Same as DefaultHttpClient.createHttpContext() minus the 
        // cookie store. 
        HttpContext context = new BasicHttpContext();
        context.setAttribute(ClientContext.AUTHSCHEME_REGISTRY, getAuthSchemes());
        context.setAttribute(ClientContext.COOKIESPEC_REGISTRY, getCookieSpecs());
        context.setAttribute(ClientContext.CREDS_PROVIDER, getCredentialsProvider());
         
		CookieSyncManager syncr = CookieSyncManager.createInstance(mActivity);
		syncr.startSync();
		CookieManager cookieManager = CookieManager.getInstance();
		cookieManager.setAcceptCookie(true);
		String cookie = cookieManager.getCookie(mUrl);
		if( cookie != null)
		{ 
			Log.d("HttpClient", "Cookie=" + cookie);
	        CookieStore store = new BasicCookieStore();
	        String[] parts = cookie.split(";");
	        for(int i = 0; i < parts.length;i++)
	        { 
	        	String[] pieces = parts[i].split("=");
	        	if( pieces.length == 2 )
	        	{ 
	        		//Log.d("HttpClient", "Adding cookie: "+ pieces[0] + "|" + pieces[1]); 
			        Cookie c = new BasicClientCookie(pieces[0], pieces[1]);
			        store.addCookie(c);
	        	} 
	        } 
 
	        context.setAttribute(ClientContext.COOKIE_STORE, store);
	        if( parts.length == 0)
	        	Log.e("HttpClient", "Bad cookie value=" + cookie);
	         
		} 
      	syncr.stopSync();
         
        return context;
      } 
    }; 
  } 
 
  /** 
   * Release resources associated with this client.  You must call this, 
   * or significant resources (sockets and memory) may be leaked. 
   */ 
  public void close() { 
    getConnectionManager().shutdown();
  } 
 
  public HttpParams getParams() {
    return delegate.getParams();
  } 
 
  public ClientConnectionManager getConnectionManager() {
    return delegate.getConnectionManager();
  } 
 
  public HttpResponse execute(HttpUriRequest request) throws IOException {
    return delegate.execute(request);
  } 
 
  public HttpResponse execute(HttpUriRequest request, HttpContext context) throws IOException {
    return delegate.execute(request, context);
  } 
 
  public HttpResponse execute(HttpHost target, HttpRequest request) throws IOException {
    return delegate.execute(target, request);
  } 
 
  public HttpResponse execute(HttpHost target, HttpRequest request,
                              HttpContext context) throws IOException {
    return delegate.execute(target, request, context);
  } 
 
  public <T> T execute(HttpUriRequest request, ResponseHandler<? extends T> responseHandler) throws IOException {
    return delegate.execute(request, responseHandler);
  } 
 
  public <T> T execute(HttpUriRequest request, ResponseHandler<? extends T> responseHandler, HttpContext context)
      throws IOException { 
    return delegate.execute(request, responseHandler, context);
  } 
 
  public <T> T execute(HttpHost target, HttpRequest request, ResponseHandler<? extends T> responseHandler)
      throws IOException { 
    return delegate.execute(target, request, responseHandler);
  } 
 
  public <T> T execute(HttpHost target, HttpRequest request,
                       ResponseHandler<? extends T> responseHandler,
                       HttpContext context)
      throws IOException { 
    return delegate.execute(target, request, responseHandler, context);
  } 
 
}