Repository: cxf Updated Branches: refs/heads/3.1.x-fixes 5329502b9 -> 1f61dfba7
[CXF-7112]AsyncHTTPConduit ignore the ReceiveTimeout when use Async JAXWS api (cherry picked from commit 2f980ec89c98aa2c04abd3c536087de2b9e2d998) Project: http://git-wip-us.apache.org/repos/asf/cxf/repo Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/1f61dfba Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/1f61dfba Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/1f61dfba Branch: refs/heads/3.1.x-fixes Commit: 1f61dfba75809a0b58dd0e6126acb0df9548945f Parents: 5329502 Author: Freeman Fang <[email protected]> Authored: Fri Oct 28 11:39:21 2016 +0800 Committer: Freeman Fang <[email protected]> Committed: Fri Oct 28 11:40:11 2016 +0800 ---------------------------------------------------------------------- .../http/asyncclient/AsyncHTTPConduit.java | 30 ++++++++++++++++++++ .../http/asyncclient/AsyncHTTPConduitTest.java | 15 ++++++++++ 2 files changed, 45 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cxf/blob/1f61dfba/rt/transports/http-hc/src/main/java/org/apache/cxf/transport/http/asyncclient/AsyncHTTPConduit.java ---------------------------------------------------------------------- diff --git a/rt/transports/http-hc/src/main/java/org/apache/cxf/transport/http/asyncclient/AsyncHTTPConduit.java b/rt/transports/http-hc/src/main/java/org/apache/cxf/transport/http/asyncclient/AsyncHTTPConduit.java index 85d08cc..dba9673 100644 --- a/rt/transports/http-hc/src/main/java/org/apache/cxf/transport/http/asyncclient/AsyncHTTPConduit.java +++ b/rt/transports/http-hc/src/main/java/org/apache/cxf/transport/http/asyncclient/AsyncHTTPConduit.java @@ -52,11 +52,13 @@ import org.apache.cxf.Bus; import org.apache.cxf.common.util.StringUtils; import org.apache.cxf.configuration.jsse.SSLUtils; import org.apache.cxf.configuration.jsse.TLSClientParameters; +import org.apache.cxf.endpoint.ClientCallback; import org.apache.cxf.helpers.HttpHeaderHelper; import org.apache.cxf.helpers.IOUtils; import org.apache.cxf.io.CacheAndWriteOutputStream; import org.apache.cxf.io.CachedOutputStream; import org.apache.cxf.io.CopyingOutputStream; +import org.apache.cxf.message.Exchange; import org.apache.cxf.message.Message; import org.apache.cxf.message.MessageUtils; import org.apache.cxf.service.model.EndpointInfo; @@ -640,6 +642,7 @@ public class AsyncHTTPConduit extends URLConnectionHTTPConduit { protected void handleResponseAsync() throws IOException { isAsync = true; + new CheckReceiveTimeoutForAsync().start(); } protected void closeInputStream() throws IOException { @@ -856,6 +859,33 @@ public class AsyncHTTPConduit extends URLConnectionHTTPConduit { } } + class CheckReceiveTimeoutForAsync extends Thread { + public void run() { + long startTime = System.currentTimeMillis(); + while (httpResponse == null && exception == null + && (System.currentTimeMillis() - startTime) < csPolicy.getReceiveTimeout()) { + try { + Thread.sleep(1000); + } catch (InterruptedException e) { + throw new RuntimeException(e); + } + } + if (httpResponse == null) { + outbuf.shutdown(); + inbuf.shutdown(); + if (exception != null) { + throw new RuntimeException(exception); + } + + Exchange exchange = outMessage.getExchange(); + ClientCallback cc = exchange.get(ClientCallback.class); + if (cc != null) { + cc.handleException(null, new SocketTimeoutException()); + } + } + } + } + } http://git-wip-us.apache.org/repos/asf/cxf/blob/1f61dfba/rt/transports/http-hc/src/test/java/org/apache/cxf/transport/http/asyncclient/AsyncHTTPConduitTest.java ---------------------------------------------------------------------- diff --git a/rt/transports/http-hc/src/test/java/org/apache/cxf/transport/http/asyncclient/AsyncHTTPConduitTest.java b/rt/transports/http-hc/src/test/java/org/apache/cxf/transport/http/asyncclient/AsyncHTTPConduitTest.java index d4a25f6..fb0f78c 100644 --- a/rt/transports/http-hc/src/test/java/org/apache/cxf/transport/http/asyncclient/AsyncHTTPConduitTest.java +++ b/rt/transports/http-hc/src/test/java/org/apache/cxf/transport/http/asyncclient/AsyncHTTPConduitTest.java @@ -132,6 +132,21 @@ public class AsyncHTTPConduitTest extends AbstractBusClientServerTestBase { //expected!!! } } + + @Test + public void testTimeoutAsync() throws Exception { + updateAddressPort(g, PORT); + HTTPConduit c = (HTTPConduit)ClientProxy.getClient(g).getConduit(); + c.getClient().setReceiveTimeout(3000); + try { + assertEquals("Hello " + request, g.greetMeLater(-5000)); + Response<GreetMeLaterResponse> future = g.greetMeLaterAsync(-5000L); + future.get(); + fail(); + } catch (Exception ex) { + //expected!!! + } + } @Test public void testConnectIssue() throws Exception { updateAddressPort(g, PORT_INV);
