@@ -278,57 +278,47 @@ protected <T> ListenableFuture<T> execute(final Connection c,
278
278
279
279
protected void initializeTransport (AsyncHttpClientConfig clientConfig ) {
280
280
281
- GrizzlyAsyncHttpProviderConfig providerConfig =
282
- (GrizzlyAsyncHttpProviderConfig ) clientConfig .getAsyncHttpProviderConfig ();
283
- if (providerConfig != null ) {
284
- final TransportCustomizer customizer = (TransportCustomizer )
285
- providerConfig .getProperty (TRANSPORT_CUSTOMIZER );
286
- if (customizer != null ) {
287
- customizer .customize (clientTransport );
288
- } else {
289
- clientTransport .setIOStrategy (SameThreadIOStrategy .getInstance ());
290
- }
291
- } else {
292
- clientTransport .setIOStrategy (SameThreadIOStrategy .getInstance ());
293
- }
281
+
294
282
295
283
final FilterChainBuilder fcb = FilterChainBuilder .stateless ();
296
284
fcb .add (new AsyncHttpClientTransportFilter ());
297
285
298
286
final int timeout = clientConfig .getRequestTimeoutInMs ();
299
- int delay = 500 ;
300
- if (timeout < delay ) {
301
- delay = timeout - 10 ;
302
- }
303
- timeoutExecutor = IdleTimeoutFilter .createDefaultIdleDelayedExecutor (delay , TimeUnit .MILLISECONDS );
304
- timeoutExecutor .start ();
305
- final IdleTimeoutFilter .TimeoutResolver timeoutResolver =
306
- new IdleTimeoutFilter .TimeoutResolver () {
307
- @ Override
308
- public long getTimeout (FilterChainContext ctx ) {
309
- final HttpTransactionContext context =
310
- GrizzlyAsyncHttpProvider .this .getHttpTransactionContext (ctx .getConnection ());
311
- if (context != null ) {
312
- final PerRequestConfig config = context .request .getPerRequestConfig ();
313
- if (config != null ) {
314
- final long timeout = config .getRequestTimeoutInMs ();
315
- if (timeout > 0 ) {
316
- return timeout ;
287
+ if (timeout > 0 ) {
288
+ int delay = 500 ;
289
+ if (timeout < delay ) {
290
+ delay = timeout - 10 ;
291
+ }
292
+ timeoutExecutor = IdleTimeoutFilter .createDefaultIdleDelayedExecutor (delay , TimeUnit .MILLISECONDS );
293
+ timeoutExecutor .start ();
294
+ final IdleTimeoutFilter .TimeoutResolver timeoutResolver =
295
+ new IdleTimeoutFilter .TimeoutResolver () {
296
+ @ Override
297
+ public long getTimeout (FilterChainContext ctx ) {
298
+ final HttpTransactionContext context =
299
+ GrizzlyAsyncHttpProvider .this .getHttpTransactionContext (ctx .getConnection ());
300
+ if (context != null ) {
301
+ final PerRequestConfig config = context .request .getPerRequestConfig ();
302
+ if (config != null ) {
303
+ final long timeout = config .getRequestTimeoutInMs ();
304
+ if (timeout > 0 ) {
305
+ return timeout ;
306
+ }
317
307
}
318
308
}
309
+ return timeout ;
319
310
}
320
- return timeout ;
321
- }
322
- };
323
- final IdleTimeoutFilter timeoutFilter = new IdleTimeoutFilter (timeoutExecutor ,
324
- timeoutResolver ,
325
- new IdleTimeoutFilter .TimeoutHandler () {
326
- public void onTimeout (Connection connection ) {
327
- timeout (connection );
328
- }
329
- });
330
- fcb .add (timeoutFilter );
331
- resolver = timeoutFilter .getResolver ();
311
+ };
312
+ final IdleTimeoutFilter timeoutFilter = new IdleTimeoutFilter (timeoutExecutor ,
313
+ timeoutResolver ,
314
+ new IdleTimeoutFilter .TimeoutHandler () {
315
+ public void onTimeout (Connection connection ) {
316
+ timeout (connection );
317
+ }
318
+ });
319
+ fcb .add (timeoutFilter );
320
+ resolver = timeoutFilter .getResolver ();
321
+ }
332
322
333
323
SSLContext context = clientConfig .getSSLContext ();
334
324
boolean defaultSecState = (context != null );
@@ -364,6 +354,21 @@ public void onTimeout(Connection connection) {
364
354
}
365
355
fcb .add (eventFilter );
366
356
fcb .add (clientFilter );
357
+
358
+ GrizzlyAsyncHttpProviderConfig providerConfig =
359
+ (GrizzlyAsyncHttpProviderConfig ) clientConfig .getAsyncHttpProviderConfig ();
360
+ if (providerConfig != null ) {
361
+ final TransportCustomizer customizer = (TransportCustomizer )
362
+ providerConfig .getProperty (TRANSPORT_CUSTOMIZER );
363
+ if (customizer != null ) {
364
+ customizer .customize (clientTransport , fcb );
365
+ } else {
366
+ clientTransport .setIOStrategy (SameThreadIOStrategy .getInstance ());
367
+ }
368
+ } else {
369
+ clientTransport .setIOStrategy (SameThreadIOStrategy .getInstance ());
370
+ }
371
+
367
372
clientTransport .setProcessor (fcb .build ());
368
373
369
374
}
@@ -379,12 +384,16 @@ void touchConnection(final Connection c, final Request request) {
379
384
final long timeout = config .getRequestTimeoutInMs ();
380
385
if (timeout > 0 ) {
381
386
final long newTimeout = System .currentTimeMillis () + timeout ;
382
- resolver .setTimeoutMillis (c , newTimeout );
387
+ if (resolver != null ) {
388
+ resolver .setTimeoutMillis (c , newTimeout );
389
+ }
383
390
}
384
391
} else {
385
392
final long timeout = clientConfig .getRequestTimeoutInMs ();
386
393
if (timeout > 0 ) {
387
- resolver .setTimeoutMillis (c , System .currentTimeMillis () + timeout );
394
+ if (resolver != null ) {
395
+ resolver .setTimeoutMillis (c , System .currentTimeMillis () + timeout );
396
+ }
388
397
}
389
398
}
390
399
@@ -1061,6 +1070,7 @@ protected void onInitialLineParsed(HttpHeader httpHeader,
1061
1070
protected void onHttpError (final HttpHeader httpHeader ,
1062
1071
final FilterChainContext ctx ,
1063
1072
final Throwable t ) throws IOException {
1073
+ t .printStackTrace ();
1064
1074
httpHeader .setSkipRemainder (true );
1065
1075
final HttpTransactionContext context =
1066
1076
provider .getHttpTransactionContext (ctx .getConnection ());
@@ -2119,7 +2129,9 @@ boolean returnConnection(final String url, final Connection c) {
2119
2129
final boolean result = (DO_NOT_CACHE .get (c ) == null
2120
2130
&& pool .offer (AsyncHttpProviderUtils .getBaseUrl (url ), c ));
2121
2131
if (result ) {
2122
- provider .resolver .setTimeoutMillis (c , IdleTimeoutFilter .FOREVER );
2132
+ if (provider .resolver != null ) {
2133
+ provider .resolver .setTimeoutMillis (c , IdleTimeoutFilter .FOREVER );
2134
+ }
2123
2135
}
2124
2136
return result ;
2125
2137
0 commit comments