Hi Charles,
Current camel-cxf endpoint doesn't support async request out of box.
But as the camel-example-cxf-async showing, camel will create a thread
pool for the cxf client so you can use the camel async API on the
template side without dealing with other things.
Willem
Charles Moulliard wrote:
Thx.
Is the endpoint created every time we call the method asyncRequestBody() or
only the first time and next it is found from a cache ?
By the way, CXF/jetty does not like async :
17:35:43,635 | WARN | 8...@qtp-5791379-0 | PhaseInterceptorChain |
.cxf.phase.PhaseInterceptorChain 362 | Exception in handleFault on
interceptor
org.apache.cxf.binding.xml.interceptor.xmlfaultoutintercep...@4d8db0
org.apache.cxf.interceptor.Fault
at
org.apache.cxf.service.invoker.AbstractInvoker.createFault(AbstractInvoker.java:155)
at
org.apache.cxf.service.invoker.AbstractInvoker.invoke(AbstractInvoker.java:121)
at org.apache.cxf.jaxrs.JAXRSInvoker.invoke(JAXRSInvoker.java:130)
at org.apache.cxf.jaxrs.JAXRSInvoker.invoke(JAXRSInvoker.java:82)
at
org.apache.cxf.interceptor.ServiceInvokerInterceptor$1.run(ServiceInvokerInterceptor.java:58)
at
java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
at java.util.concurrent.FutureTask.run(FutureTask.java:138)
at
org.apache.cxf.workqueue.SynchronousExecutor.execute(SynchronousExecutor.java:37)
at
org.apache.cxf.interceptor.ServiceInvokerInterceptor.handleMessage(ServiceInvokerInterceptor.java:106)
at
org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:236)
at
org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:109)
at
org.apache.camel.component.cxf.cxfbean.CxfBeanDestination.process(CxfBeanDestination.java:85)
at
org.apache.camel.impl.ProcessorEndpoint.onExchange(ProcessorEndpoint.java:95)
at
org.apache.camel.impl.ProcessorEndpoint$1.process(ProcessorEndpoint.java:65)
at
org.apache.camel.processor.SendProcessor$1.doInProducer(SendProcessor.java:97)
at
org.apache.camel.processor.SendProcessor$1.doInProducer(SendProcessor.java:94)
at
org.apache.camel.impl.ProducerCache.doInProducer(ProducerCache.java:146)
at
org.apache.camel.processor.SendProcessor.doProcess(SendProcessor.java:94)
at
org.apache.camel.processor.SendProcessor.process(SendProcessor.java:82)
at
org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:67)
at
org.apache.camel.processor.DelegateProcessor.processNext(DelegateProcessor.java:53)
at
org.apache.camel.processor.DelegateProcessor.proceed(DelegateProcessor.java:82)
at
org.apache.camel.processor.interceptor.TraceInterceptor.process(TraceInterceptor.java:162)
at
org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:67)
at
org.apache.camel.processor.RedeliveryErrorHandler.processExchange(RedeliveryErrorHandler.java:223)
at
org.apache.camel.processor.RedeliveryErrorHandler.processErrorHandler(RedeliveryErrorHandler.java:153)
at
org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:91)
at
org.apache.camel.processor.DefaultErrorHandler.process(DefaultErrorHandler.java:49)
at
org.apache.camel.processor.DefaultChannel.process(DefaultChannel.java:206)
at
org.apache.camel.processor.UnitOfWorkProcessor.processNext(UnitOfWorkProcessor.java:54)
at
org.apache.camel.processor.DelegateProcessor.process(DelegateProcessor.java:48)
at
org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:67)
at
org.apache.camel.component.http.CamelServlet.service(CamelServlet.java:53)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:806)
at
org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:502)
at
org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:389)
at
org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:765)
at
org.mortbay.jetty.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:230)
at
org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
at org.mortbay.jetty.Server.handle(Server.java:326)
at
org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:534)
at
org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:864)
at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:539)
at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:212)
at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)
at
org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:409)
at
org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:520)
Caused by: java.lang.NullPointerException
at
org.apache.camel.example.reportincident.restful.ReportIncidentService.getIncidents2(ReportIncidentService.java:74)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at
org.apache.cxf.service.invoker.AbstractInvoker.performInvocation(AbstractInvoker.java:173)
at
org.apache.cxf.service.invoker.AbstractInvoker.invoke(AbstractInvoker.java:89)
... 46 more
@GET
@Path("/incidents2/")
public Incidents getIncidents2() {
Incidents l = new Incidents();
// Call the distant service to get result
Future future = producer.asyncRequestBody("jms:queue:inout", "GET");
/// LINE 74
// Check if we receive a feedback within 10 seconds
List<Incident> i;
try {
i = producer.extractFutureBody(future, 10000,
TimeUnit.MILLISECONDS, List.class);
} catch (TimeoutException e) {
return null;
}
l.setIncidents(i);
return l;
}
Charles Moulliard
Senior Enterprise Architect
Apache Camel Committer
*****************************
blog : http://cmoulliard.blogspot.com
twitter : http://twitter.com/cmoulliard
Linkedlin : http://www.linkedin.com/in/charlesmoulliard
Apache Camel Group :
http://www.linkedin.com/groups?home=&gid=2447439&trk=anet_ug_hm
On Thu, Dec 10, 2009 at 5:34 PM, Claus Ibsen <claus.ib...@gmail.com> wrote:
On Thu, Dec 10, 2009 at 5:30 PM, Charles Moulliard <cmoulli...@gmail.com>
wrote:
Awesome this new feature of Producer.
I presume that I must use future.get(timeout) //
http://java.sun.com/javase/6/docs/api/java/util/concurrent/Future.html#get%28long,%20java.util.concurrent.TimeUnit%29
to check if an answer has been received within the period defined.
Yes exactly.
Beware I think it throws an exception for timeout so you may need try
.. catch around it. And if the task failed the get() will throw an
ExecutionException with the cause wrapped. You can read all about it
in the javadocs for this Future API stuff.
Its only the consumer who have a timeout directly in Camel.
As its the Polling Consumer EIP
http://camel.apache.org/polling-consumer.html
Charles Moulliard
Senior Enterprise Architect
Apache Camel Committer
*****************************
blog : http://cmoulliard.blogspot.com
twitter : http://twitter.com/cmoulliard
Linkedlin : http://www.linkedin.com/in/charlesmoulliard
Apache Camel Group :
http://www.linkedin.com/groups?home=&gid=2447439&trk=anet_ug_hm
On Thu, Dec 10, 2009 at 5:07 PM, Claus Ibsen <claus.ib...@gmail.com>
wrote:
On Thu, Dec 10, 2009 at 4:55 PM, Charles Moulliard <
cmoulli...@gmail.com>
wrote:
If inside a camel bean we use a Producer to get the answer from a
distant
service which is available from a queue, can we define the timeout
that
our
service must wait before to return an answer ?
If you use a producer then you are in the mercy whether that component
offers some timeout.
eg. http based often offer timeout configs.
However with Camel you can use the asyncRequestBody and then use the
Future API from JDK where you have timeout support.
See more here
http://camel.apache.org/async
ex :
@EndpointInject(uri="jms:queue:inout")
ProducerTemplate producer;
public Incidents getIncidents() {
Incidents l = new Incidents();
// Call the distant service (= DAO Service) to get result
List<Incident> i = (List<Incident>) producer.requestBody(null);
//
How CAN I define a timeout here (if possible) ?
l.setIncidents(i);
return l;
}
<camel:route>
<camel:from uri="jetty:
http://localhost:8181?matchOnUriPrefix=true" />
<camel:to uri="cxfbean:reportIncidentServiceBean"/>
</camel:route>
<camel:route>
<camel:from uri="jms:queue:inout" />
<camel:bean ref="reportIncidentDAOService"
method="getReports"/>
</camel:route>
Regards,
Charles Moulliard
Senior Enterprise Architect
Apache Camel Committer
*****************************
blog : http://cmoulliard.blogspot.com
twitter : http://twitter.com/cmoulliard
Linkedlin : http://www.linkedin.com/in/charlesmoulliard
Apache Camel Group :
http://www.linkedin.com/groups?home=&gid=2447439&trk=anet_ug_hm
--
Claus Ibsen
Apache Camel Committer
Author of Camel in Action: http://www.manning.com/ibsen/
Open Source Integration: http://fusesource.com
Blog: http://davsclaus.blogspot.com/
Twitter: http://twitter.com/davsclaus
--
Claus Ibsen
Apache Camel Committer
Author of Camel in Action: http://www.manning.com/ibsen/
Open Source Integration: http://fusesource.com
Blog: http://davsclaus.blogspot.com/
Twitter: http://twitter.com/davsclaus