HTTP provider timeout
maciej.krysiuk May 11, 2010 10:31 AMHi all,
I have a scenario where I want to implement a timeout for my HTTP client in FUSE. So simply, I want that after a configurable period of time, my HTTP client does not wait for HTTP response anymore and throws an exception that can be handled by preceding components in an invocation chain.
I have implemented it in a following simple way:
<http:provider service="middleware:payments-output" endpoint="out"
locationURI="${payments.output.uri}"
clientSoTimeout="${payments.output.httptimeout}" />
To test this implementation, I have set payments.output.httptimeout=5000 (5 seconds) and started up a mock HTTP server that waits 60 seconds before sending a response.
When I execute the test, the following happens:
1. HTTP provider sends a request
2. After 5 seconds HTTP provider still waits for the response.
3. After 60 seconds in total, server sends back the response.
4. Now HTTP provider sends back HTTP response as Out message, but also throws an exception:
ERROR - HttpComponent - Error processing exchange InOut[ ...
java.lang.Exception: HTTP request has timed out for exchange: ID:192.168.0.224-12887925a3d-17:4
at org.apache.servicemix.http.endpoints.HttpConsumerEndpoint.process(HttpConsumerEndpoint.java:267)
at org.apache.servicemix.common.AsyncBaseLifeCycle.doProcess(AsyncBaseLifeCycle.java:627)
at org.apache.servicemix.common.AsyncBaseLifeCycle.processExchange(AsyncBaseLifeCycle.java:598)
at org.apache.servicemix.common.AsyncBaseLifeCycle.onMessageExchange(AsyncBaseLifeCycle.java:535)
at org.apache.servicemix.common.SyncLifeCycleWrapper.onMessageExchange(SyncLifeCycleWrapper.java:60)
at org.apache.servicemix.jbi.messaging.DeliveryChannelImpl.processInBound(DeliveryChannelImpl.java:623)
at org.apache.servicemix.jbi.nmr.flow.AbstractFlow.doRouting(AbstractFlow.java:172)
at org.apache.servicemix.jbi.nmr.flow.seda.SedaFlow.doRouting(SedaFlow.java:168)
at org.apache.servicemix.jbi.nmr.flow.seda.SedaQueue$1.run(SedaQueue.java:134)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:619)
ERROR - HttpComponent - Error setting exchange status to ERROR
java.lang.IllegalStateException: component is not owner when trying to set error: java.lang.Exception: HTTP request has timed out for exchange: ID:192
.168.0.224-12887925a3d-17:4
at org.apache.servicemix.jbi.messaging.MessageExchangeImpl.setError(MessageExchangeImpl.java:264)
at org.apache.servicemix.common.AsyncBaseLifeCycle.onMessageExchange(AsyncBaseLifeCycle.java:550)
at org.apache.servicemix.common.SyncLifeCycleWrapper.onMessageExchange(SyncLifeCycleWrapper.java:60)
at org.apache.servicemix.jbi.messaging.DeliveryChannelImpl.processInBound(DeliveryChannelImpl.java:623)
at org.apache.servicemix.jbi.nmr.flow.AbstractFlow.doRouting(AbstractFlow.java:172)
at org.apache.servicemix.jbi.nmr.flow.seda.SedaFlow.doRouting(SedaFlow.java:168)
at org.apache.servicemix.jbi.nmr.flow.seda.SedaQueue$1.run(SedaQueue.java:134)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:619)
Caused by: java.lang.Exception: HTTP request has timed out for exchange: ID:192.168.0.224-12887925a3d-17:4
at org.apache.servicemix.http.endpoints.HttpConsumerEndpoint.process(HttpConsumerEndpoint.java:267)
at org.apache.servicemix.common.AsyncBaseLifeCycle.doProcess(AsyncBaseLifeCycle.java:627)
at org.apache.servicemix.common.AsyncBaseLifeCycle.processExchange(AsyncBaseLifeCycle.java:598)
at org.apache.servicemix.common.AsyncBaseLifeCycle.onMessageExchange(AsyncBaseLifeCycle.java:535)
... 8 more
So, according two me 2 weird things are happening:
1. HTTP provider does not throw exception after 5 seconds.
2. HTTP provider does throw an exception after 60 seconds and receiving correct HTTP response.
Does anyone know how can I configure HTTP provider to throw exception after the timeout set?
I'm using Fuse 3.4.0.4 and HTTP component 2009.01.0.4
Thanks for any help.
Matt