Skip to content

Commit 11bbab9

Browse files
committed
Merge remote-tracking branch 'upstream/master'
2 parents 4a4e59f + 2035e97 commit 11bbab9

File tree

4 files changed

+41
-13
lines changed

4 files changed

+41
-13
lines changed

src/main/java/com/ning/http/client/providers/apache/ApacheResponseFuture.java

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
import com.ning.http.client.Request;
1717
import com.ning.http.client.listenable.AbstractListenableFuture;
1818
import org.apache.commons.httpclient.HttpMethodBase;
19+
import org.slf4j.Logger;
20+
import org.slf4j.LoggerFactory;
1921

2022
import java.util.concurrent.Callable;
2123
import java.util.concurrent.CancellationException;
@@ -30,6 +32,8 @@
3032

3133
public class ApacheResponseFuture<V> extends AbstractListenableFuture<V> {
3234

35+
private final static Logger logger = LoggerFactory.getLogger(ApacheResponseFuture.class);
36+
3337
private Future<V> innerFuture;
3438
private final AsyncHandler<V> asyncHandler;
3539
private final int responseTimeoutInMs;
@@ -63,11 +67,12 @@ public void done(Callable callable) {
6367
if (reaperFuture != null) {
6468
reaperFuture.cancel(true);
6569
}
66-
super.done();
70+
super.done();
6771
}
6872

6973
/**
7074
* TODO.
75+
*
7176
* @param v The new content
7277
*/
7378
public void content(V v) {
@@ -113,14 +118,22 @@ public void abort(Throwable t) {
113118

114119
exception.set(t);
115120
if (!timedOut.get() && !cancelled.get()) {
116-
asyncHandler.onThrowable(t);
117-
}
121+
try {
122+
asyncHandler.onThrowable(t);
123+
} catch (Throwable t2) {
124+
logger.debug("asyncHandler.onThrowable", t2);
125+
}
126+
}
118127
}
119128

120129
public boolean cancel(boolean mayInterruptIfRunning) {
121130
if (!cancelled.get() && innerFuture != null) {
122131
method.abort();
123-
asyncHandler.onThrowable(new CancellationException());
132+
try {
133+
asyncHandler.onThrowable(new CancellationException());
134+
} catch (Throwable t) {
135+
logger.debug("asyncHandler.onThrowable", t);
136+
}
124137
cancelled.set(true);
125138
if (reaperFuture != null) {
126139
reaperFuture.cancel(true);
@@ -160,7 +173,7 @@ public V get(long timeout, TimeUnit unit) throws InterruptedException, Execution
160173
}
161174
} catch (TimeoutException t) {
162175
if (!contentProcessed.get() && timeout != -1 && ((System.currentTimeMillis() - touch.get()) <= responseTimeoutInMs)) {
163-
return get(timeout,unit);
176+
return get(timeout, unit);
164177
}
165178
timedOut.set(true);
166179
throw new TimeoutException(String.format("No response received after %s", responseTimeoutInMs));
@@ -178,7 +191,7 @@ public V get(long timeout, TimeUnit unit) throws InterruptedException, Execution
178191
*
179192
* @return <code>true</code> if response has expired and should be terminated.
180193
*/
181-
public boolean hasExpired(){
194+
public boolean hasExpired() {
182195
return responseTimeoutInMs != -1 && ((System.currentTimeMillis() - touch.get()) >= responseTimeoutInMs);
183196
}
184197

@@ -195,7 +208,7 @@ public Request getRequest() {
195208
* {@inheritDoc}
196209
*/
197210
/* @Override */
198-
public boolean getAndSetWriteHeaders(boolean writeHeaders) {
211+
public boolean getAndSetWriteHeaders(boolean writeHeaders) {
199212
boolean b = this.writeHeaders;
200213
this.writeHeaders = writeHeaders;
201214
return b;

src/main/java/com/ning/http/client/providers/jdk/JDKFuture.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@
1313
package com.ning.http.client.providers.jdk;
1414

1515
import com.ning.http.client.AsyncHandler;
16-
import com.ning.http.client.ListenableFuture;
1716
import com.ning.http.client.listenable.AbstractListenableFuture;
17+
import org.slf4j.Logger;
18+
import org.slf4j.LoggerFactory;
1819

1920
import java.net.HttpURLConnection;
2021
import java.util.concurrent.Callable;
@@ -30,6 +31,8 @@
3031

3132
public class JDKFuture<V> extends AbstractListenableFuture<V> {
3233

34+
private final static Logger logger = LoggerFactory.getLogger(JDKFuture.class);
35+
3336
protected Future<V> innerFuture;
3437
protected final AsyncHandler<V> asyncHandler;
3538
protected final int responseTimeoutInMs;
@@ -76,7 +79,11 @@ public void content(V v) {
7679
public boolean cancel(boolean mayInterruptIfRunning) {
7780
if (!cancelled.get() && innerFuture != null) {
7881
urlConnection.disconnect();
79-
asyncHandler.onThrowable(new CancellationException());
82+
try {
83+
asyncHandler.onThrowable(new CancellationException());
84+
} catch (Throwable te) {
85+
logger.debug("asyncHandler.onThrowable", te);
86+
}
8087
cancelled.set(true);
8188
return innerFuture.cancel(mayInterruptIfRunning);
8289
} else {

src/main/java/com/ning/http/client/providers/netty/NettyAsyncHttpProvider.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@
6868
import org.jboss.netty.channel.MessageEvent;
6969
import org.jboss.netty.channel.SimpleChannelUpstreamHandler;
7070
import org.jboss.netty.channel.group.ChannelGroup;
71-
import org.jboss.netty.channel.group.DefaultChannelGroup;
7271
import org.jboss.netty.channel.socket.ClientSocketChannelFactory;
7372
import org.jboss.netty.channel.socket.nio.NioClientSocketChannelFactory;
7473
import org.jboss.netty.channel.socket.oio.OioClientSocketChannelFactory;
@@ -93,7 +92,6 @@
9392
import org.slf4j.LoggerFactory;
9493

9594
import javax.net.ssl.SSLEngine;
96-
import javax.net.ssl.SSLException;
9795
import java.io.File;
9896
import java.io.FileInputStream;
9997
import java.io.IOException;
@@ -122,8 +120,8 @@
122120
import java.util.concurrent.atomic.AtomicBoolean;
123121
import java.util.concurrent.atomic.AtomicInteger;
124122

125-
import static org.jboss.netty.channel.Channels.pipeline;
126123
import static com.ning.http.util.AsyncHttpProviderUtils.DEFAULT_CHARSET;
124+
import static org.jboss.netty.channel.Channels.pipeline;
127125

128126
public class NettyAsyncHttpProvider extends SimpleChannelUpstreamHandler implements AsyncHttpProvider<HttpResponse> {
129127
private final static String HTTP_HANDLER = "httpHandler";
@@ -785,7 +783,11 @@ private <T> ListenableFuture<T> doConnect(final Request request, final AsyncHand
785783
if (!connectionsPool.canCacheConnection() ||
786784
(config.getMaxTotalConnections() > -1 && (maxConnections.get() + 1) > config.getMaxTotalConnections())) {
787785
IOException ex = new IOException(String.format("Too many connections %s", config.getMaxTotalConnections()));
788-
asyncHandler.onThrowable(ex);
786+
try {
787+
asyncHandler.onThrowable(ex);
788+
} catch (Throwable t) {
789+
log.warn("asyncHandler.onThrowable",t);
790+
}
789791
throw ex;
790792
}
791793

src/main/java/com/ning/http/client/providers/netty/NettyResponseFuture.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,8 @@ public V get(long l, TimeUnit tu) throws InterruptedException, TimeoutException,
199199
TimeoutException te = new TimeoutException(String.format("No response received after %s", l));
200200
try {
201201
asyncHandler.onThrowable(te);
202+
} catch (Throwable t) {
203+
logger.debug("asyncHandler.onThrowable", t);
202204
} finally {
203205
throw te;
204206
}
@@ -228,6 +230,8 @@ V getContent() throws ExecutionException {
228230
} catch (Throwable ex) {
229231
try {
230232
asyncHandler.onThrowable(ex);
233+
} catch (Throwable t) {
234+
logger.debug("asyncHandler.onThrowable", t);
231235
} finally {
232236
throw new RuntimeException(ex);
233237
}
@@ -270,6 +274,8 @@ public final void abort(final Throwable t) {
270274
exEx.compareAndSet(null, new ExecutionException(t));
271275
try {
272276
asyncHandler.onThrowable(t);
277+
} catch (Throwable te) {
278+
logger.debug("asyncHandler.onThrowable", te);
273279
} finally {
274280
isCancelled.set(true);
275281
latch.countDown();

0 commit comments

Comments
 (0)