|
1 | 1 | /*
|
2 |
| - * Copyright (c) 2012 Sonatype, Inc. All rights reserved. |
| 2 | + * Copyright (c) 2012-2013 Sonatype, Inc. All rights reserved. |
3 | 3 | *
|
4 | 4 | * This program is licensed to you under the Apache License Version 2.0,
|
5 | 5 | * and you may not use this file except in compliance with the Apache License Version 2.0.
|
|
18 | 18 | import com.ning.http.client.AsyncHttpProvider;
|
19 | 19 | import com.ning.http.client.Body;
|
20 | 20 | import com.ning.http.client.BodyGenerator;
|
| 21 | +import com.ning.http.client.ConnectionPoolKeyStrategy; |
21 | 22 | import com.ning.http.client.ConnectionsPool;
|
22 | 23 | import com.ning.http.client.Cookie;
|
23 | 24 | import com.ning.http.client.FluentCaseInsensitiveStringsMap;
|
@@ -214,9 +215,7 @@ public void completed(final Connection c) {
|
214 | 215 | try {
|
215 | 216 | execute(c, request, handler, future);
|
216 | 217 | } catch (Exception e) {
|
217 |
| - if (e instanceof RuntimeException) { |
218 |
| - failed(e); |
219 |
| - } else if (e instanceof IOException) { |
| 218 | + if (e instanceof RuntimeException || e instanceof IOException) { |
220 | 219 | failed(e);
|
221 | 220 | }
|
222 | 221 | if (LOGGER.isWarnEnabled()) {
|
@@ -1452,7 +1451,7 @@ private static HttpTransactionContext cleanup(final FilterChainContext ctx,
|
1452 | 1451 | if (!context.provider.connectionManager.canReturnConnection(c)) {
|
1453 | 1452 | context.abort(new IOException("Maximum pooled connections exceeded"));
|
1454 | 1453 | } else {
|
1455 |
| - if (!context.provider.connectionManager.returnConnection(context.requestUrl, c)) { |
| 1454 | + if (!context.provider.connectionManager.returnConnection(context.request, c)) { |
1456 | 1455 | ctx.getConnection().close();
|
1457 | 1456 | }
|
1458 | 1457 | }
|
@@ -2412,7 +2411,7 @@ void doAsyncTrackedConnection(final Request request,
|
2412 | 2411 | final CompletionHandler<Connection> connectHandler)
|
2413 | 2412 | throws IOException, ExecutionException, InterruptedException {
|
2414 | 2413 | final String url = request.getUrl();
|
2415 |
| - Connection c = pool.poll(AsyncHttpProviderUtils.getBaseUrl(url)); |
| 2414 | + Connection c = pool.poll(getPoolKey(request)); |
2416 | 2415 | if (c == null) {
|
2417 | 2416 | if (!connectionMonitor.acquire()) {
|
2418 | 2417 | throw new IOException("Max connections exceeded");
|
@@ -2497,9 +2496,9 @@ private ProxyServer getProxyServer(Request request) {
|
2497 | 2496 |
|
2498 | 2497 | }
|
2499 | 2498 |
|
2500 |
| - boolean returnConnection(final String url, final Connection c) { |
| 2499 | + boolean returnConnection(final Request request, final Connection c) { |
2501 | 2500 | final boolean result = (DO_NOT_CACHE.get(c) == null
|
2502 |
| - && pool.offer(AsyncHttpProviderUtils.getBaseUrl(url), c)); |
| 2501 | + && pool.offer(getPoolKey(request), c)); |
2503 | 2502 | if (result) {
|
2504 | 2503 | if (provider.resolver != null) {
|
2505 | 2504 | provider.resolver.setTimeoutMillis(c, IdleTimeoutFilter.FOREVER);
|
@@ -2560,6 +2559,11 @@ public void updated(Connection result) {
|
2560 | 2559 | };
|
2561 | 2560 | }
|
2562 | 2561 |
|
| 2562 | + private static String getPoolKey(final Request request) { |
| 2563 | + final ConnectionPoolKeyStrategy keyStrategy = request.getConnectionPoolKeyStrategy(); |
| 2564 | + return keyStrategy.getKey(AsyncHttpProviderUtils.createUri(AsyncHttpProviderUtils.getBaseUrl(request.getUrl()))); |
| 2565 | + } |
| 2566 | + |
2563 | 2567 | // ------------------------------------------------------ Nested Classes
|
2564 | 2568 |
|
2565 | 2569 | private static class ConnectionMonitor implements Connection.CloseListener {
|
|
0 commit comments