/**
  * Perform a HTTP GET request and track the Android Context which initiated the request with
  * customized headers
  *
  * @param url the URL to send the request to.
  * @param headers set headers only for this request
  * @param params additional GET parameters to send with the request.
  * @param responseHandler the response handler instance that should handle the response.
  */
 public void get(
     Context context,
     String url,
     Header[] headers,
     RequestParams params,
     AsyncHttpResponseHandler responseHandler) {
   HttpUriRequest request = new HttpGet(getUrlWithQueryString(url, params));
   if (headers != null) request.setHeaders(headers);
   sendRequest(cachingHttpClient, httpContext, request, null, responseHandler, context);
 }
  // Private stuff
  protected void sendRequest(
      SurespotCachingHttpClient client,
      HttpContext httpContext,
      HttpUriRequest uriRequest,
      String contentType,
      AsyncHttpResponseHandler responseHandler,
      Context context) {
    if (contentType != null) {
      uriRequest.addHeader("Content-Type", contentType);
    }

    Future<?> request =
        threadPool.submit(new AsyncHttpRequest(client, httpContext, uriRequest, responseHandler));

    if (context != null) {
      // Add request to request map
      List<WeakReference<Future<?>>> requestList = requestMap.get(context);
      if (requestList == null) {
        requestList = new LinkedList<WeakReference<Future<?>>>();
        requestMap.put(context, requestList);
      }

      requestList.add(new WeakReference<Future<?>>(request));

      // TODO: Remove dead weakrefs from requestLists?
    }
  }
Beispiel #3
0
 protected SilkHttpResponse performRequest(final HttpUriRequest request) throws SilkHttpException {
   if (mHeaders.size() > 0) {
     for (SilkHttpHeader header : mHeaders) request.setHeader(header.getName(), header.getValue());
   }
   HttpResponse response;
   try {
     response = mClient.execute(request);
   } catch (Exception e) {
     reset();
     throw new SilkHttpException(e);
   }
   int status = response.getStatusLine().getStatusCode();
   if (status != 200) {
     reset();
     throw new SilkHttpException(response);
   }
   reset();
   return new SilkHttpResponse(response);
 }