1package com.xtremelabs.robolectric.shadows; 2 3import com.xtremelabs.robolectric.Robolectric; 4import com.xtremelabs.robolectric.internal.Implementation; 5import com.xtremelabs.robolectric.internal.Implements; 6import com.xtremelabs.robolectric.internal.RealObject; 7import org.apache.http.HttpHost; 8import org.apache.http.HttpRequest; 9import org.apache.http.HttpResponse; 10import org.apache.http.client.ClientProtocolException; 11import org.apache.http.client.HttpClient; 12import org.apache.http.client.ResponseHandler; 13import org.apache.http.client.methods.HttpUriRequest; 14import org.apache.http.conn.ClientConnectionManager; 15import org.apache.http.impl.client.DefaultHttpClient; 16import org.apache.http.params.HttpParams; 17import org.apache.http.protocol.HttpContext; 18 19import android.content.Context; 20import android.net.http.AndroidHttpClient; 21 22import java.io.IOException; 23 24@Implements(AndroidHttpClient.class) 25public class ShadowAndroidHttpClient { 26 @RealObject private AndroidHttpClient client; 27 28 private HttpClient httpClient = new DefaultHttpClient(); 29 30 @Implementation 31 public static AndroidHttpClient newInstance(String userAgent) { 32 return Robolectric.newInstanceOf(AndroidHttpClient.class); 33 } 34 35 @Implementation 36 public static AndroidHttpClient newInstance(String userAgent, Context context) { 37 return Robolectric.newInstanceOf(AndroidHttpClient.class); 38 } 39 40 @Implementation 41 public HttpParams getParams() { 42 return httpClient.getParams(); 43 } 44 45 @Implementation 46 public ClientConnectionManager getConnectionManager() { 47 return httpClient.getConnectionManager(); 48 } 49 50 @Implementation 51 public HttpResponse execute(HttpUriRequest httpUriRequest) throws IOException, ClientProtocolException { 52 return httpClient.execute(httpUriRequest); 53 } 54 55 @Implementation 56 public HttpResponse execute(HttpUriRequest httpUriRequest, HttpContext httpContext) throws IOException, ClientProtocolException { 57 return httpClient.execute(httpUriRequest, httpContext); 58 } 59 60 @Implementation 61 public HttpResponse execute(HttpHost httpHost, HttpRequest httpRequest) throws IOException, ClientProtocolException { 62 return httpClient.execute(httpHost, httpRequest); 63 } 64 65 @Implementation 66 public HttpResponse execute(HttpHost httpHost, HttpRequest httpRequest, HttpContext httpContext) throws IOException, ClientProtocolException { 67 return httpClient.execute(httpHost, httpRequest, httpContext); 68 } 69 70 @Implementation 71 public <T> T execute(HttpUriRequest httpUriRequest, ResponseHandler<? extends T> responseHandler) throws IOException, ClientProtocolException { 72 return httpClient.execute(httpUriRequest, responseHandler); 73 } 74 75 @Implementation 76 public <T> T execute(HttpUriRequest httpUriRequest, ResponseHandler<? extends T> responseHandler, HttpContext httpContext) throws IOException, ClientProtocolException { 77 return httpClient.execute(httpUriRequest, responseHandler, httpContext); 78 } 79 80 @Implementation 81 public <T> T execute(HttpHost httpHost, HttpRequest httpRequest, ResponseHandler<? extends T> responseHandler) throws IOException, ClientProtocolException { 82 return httpClient.execute(httpHost, httpRequest, responseHandler); 83 } 84 85 @Implementation 86 public <T> T execute(HttpHost httpHost, HttpRequest httpRequest, ResponseHandler<? extends T> responseHandler, HttpContext httpContext) throws IOException, ClientProtocolException { 87 return httpClient.execute(httpHost, httpRequest, responseHandler, httpContext); 88 } 89} 90