Skip to content

Commit 1a10694

Browse files
committed
Fixed javadocs for createConnectionManager, and asserted error when custom implemenation would return null
1 parent 6cc866f commit 1a10694

File tree

1 file changed

+21
-9
lines changed

1 file changed

+21
-9
lines changed

library/src/main/java/com/loopj/android/http/AsyncHttpClient.java

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
import org.apache.http.client.methods.HttpUriRequest;
5050
import org.apache.http.client.params.ClientPNames;
5151
import org.apache.http.client.protocol.ClientContext;
52+
import org.apache.http.conn.ClientConnectionManager;
5253
import org.apache.http.conn.params.ConnManagerParams;
5354
import org.apache.http.conn.params.ConnPerRouteBean;
5455
import org.apache.http.conn.params.ConnRoutePNames;
@@ -237,7 +238,8 @@ public AsyncHttpClient(SchemeRegistry schemeRegistry) {
237238

238239
HttpProtocolParams.setVersion(httpParams, HttpVersion.HTTP_1_1);
239240

240-
ThreadSafeClientConnManager cm = new ThreadSafeClientConnManager(httpParams, schemeRegistry);
241+
ClientConnectionManager cm = createConnectionManager(schemeRegistry, httpParams);
242+
Utils.asserts(cm != null, "Custom implementation of #createConnectionManager(SchemeRegistry, BasicHttpParams) returned null");
241243

242244
threadPool = getDefaultThreadPool();
243245
requestMap = Collections.synchronizedMap(new WeakHashMap<Context, List<RequestHandle>>());
@@ -382,6 +384,17 @@ protected ExecutorService getDefaultThreadPool() {
382384
return Executors.newCachedThreadPool();
383385
}
384386

387+
/**
388+
* Provided so it is easier for developers to provide custom ThreadSafeClientConnManager implementation
389+
*
390+
* @param schemeRegistry SchemeRegistry, usually provided by {@link #getDefaultSchemeRegistry(boolean, int, int)}
391+
* @param httpParams BasicHttpParams
392+
* @return ClientConnectionManager instance
393+
*/
394+
protected ClientConnectionManager createConnectionManager(SchemeRegistry schemeRegistry, BasicHttpParams httpParams) {
395+
return new ThreadSafeClientConnManager(httpParams, schemeRegistry);
396+
}
397+
385398
/**
386399
* Simple interface method, to enable or disable redirects. If you set manually RedirectHandler
387400
* on underlying HttpClient, effects of this method will be canceled. <p>&nbsp;</p> Default
@@ -1065,7 +1078,7 @@ public RequestHandle put(Context context, String url, Header[] headers, HttpEnti
10651078
if (headers != null) request.setHeaders(headers);
10661079
return sendRequest(httpClient, httpContext, request, contentType, responseHandler, context);
10671080
}
1068-
1081+
10691082
/**
10701083
* Perform a HTTP PATCH request, without any parameters.
10711084
*
@@ -1101,20 +1114,19 @@ public RequestHandle patch(String url, RequestParams params, ResponseHandlerInte
11011114
public RequestHandle patch(Context context, String url, RequestParams params, ResponseHandlerInterface responseHandler) {
11021115
return patch(context, url, paramsToEntity(params, responseHandler), null, responseHandler);
11031116
}
1104-
1117+
11051118
/**
11061119
* Perform a HTTP PATCH request and track the Android Context which initiated the request.
11071120
*
11081121
* @param context the Android Context which initiated the request.
11091122
* @param url the URL to send the request to.
1110-
* @param params additional PUT parameters or files to send with the request.
11111123
* @param responseHandler the response handler instance that should handle the response.
11121124
* @return RequestHandle of future request process
11131125
*/
11141126
public RequestHandle patch(Context context, String url, HttpEntity entity, String contentType, ResponseHandlerInterface responseHandler) {
11151127
return sendRequest(httpClient, httpContext, addEntityToRequestBase(new HttpPatch(URI.create(url).normalize()), entity), contentType, responseHandler, context);
11161128
}
1117-
1129+
11181130
/**
11191131
* Perform a HTTP PATCH request and track the Android Context which initiated the request. And set
11201132
* one-time headers for the request
@@ -1131,11 +1143,11 @@ public RequestHandle patch(Context context, String url, HttpEntity entity, Strin
11311143
* @return RequestHandle of future request process
11321144
*/
11331145
public RequestHandle patch(Context context, String url, Header[] headers, HttpEntity entity, String contentType, ResponseHandlerInterface responseHandler) {
1134-
HttpEntityEnclosingRequestBase request = addEntityToRequestBase(new HttpPatch(URI.create(url).normalize()), entity);
1135-
if (headers != null) request.setHeaders(headers);
1136-
return sendRequest(httpClient, httpContext, request, contentType, responseHandler, context);
1146+
HttpEntityEnclosingRequestBase request = addEntityToRequestBase(new HttpPatch(URI.create(url).normalize()), entity);
1147+
if (headers != null) request.setHeaders(headers);
1148+
return sendRequest(httpClient, httpContext, request, contentType, responseHandler, context);
11371149
}
1138-
1150+
11391151
// [-] HTTP PUT
11401152
// [+] HTTP DELETE
11411153

0 commit comments

Comments
 (0)