Reputation: 31
I'm looking for a solution to make the exception thrown on the consumer side returned to the producer side when using Apache Camel - JMS Remoting.
I found there is a similar question asked already at Apache Camel JMS - Exceptions not returned to caller with request/reply.
So, I followed the answer there and I turned on the transferException option as Claus suggested but Camel still gives me an error - a different error, InvalidPayloadException which is caused by org.apache.camel.NoTypeConversionAvailableException - No type converter available to convert from type: org.apache.camel.RuntimeCamelException to the required type: long with value org.apache.camel.RuntimeCamelException: com.x.y.z.ServiceException: test].
So, it seems like I do get the exception over to the producer side as Claus suggested (the original exception's wrapped in RuntimeCalmelException). The problem is Camel tried to convert my exception into the return type which is long.
Is there a way to just let the exception bubbled all the way without being getting converted?
Here is the detail:
Interface: PricingService.java
public long getPrice(String id);
Consumer side: PricingServiceImpl.java
@Service("pricingService")
public class PricingServiceImpl {
public long getPrice(String id) {
//only throw an exception here for simplicity.
//Assuming ServiceException is serializable.
throw new ServiceException("test");
}
}
RouteBuilder:
public class MyRoutes extends RouteBuilder {
public void configure() throws Exception {
getContext().setTracing(true);
from("jms:queue:pricingService concurrentConsumers=25&transferException=true&transferExchange=true").to("pricingService");
}
}
Producer Side:
<camel:camelContext id="producer">
<camel:proxy id="pricingService"
serviceInterface="com.x.y.z.PricingService"
serviceUrl="jms:queue:pricingService?transferExchange=true"/>
</camel:camelContext>
So, on the producer side, when I call pricingService.getPrice("abc")
, I got an exception as follows:
org.apache.camel.InvalidPayloadException: No body available of type: long but has value: org.apache.camel.RuntimeCamelException: com.x.y.z.ServiceException: ERR_NOT_FOUND of type: org.apache.camel.RuntimeCamelException on: JmsMessage[JmsMessageID: ID:localhost.localdomain-35812-1368034706262-11:1:1:1:1]. Caused by: No type converter available to convert from type: org.apache.camel.RuntimeCamelException to the required type: long with value org.apache.camel.RuntimeCamelException: com.x.y.z.ServiceException: ERR_NOT_FOUND. Exchange[JmsMessage[JmsMessageID: ID:localhost.localdomain-35812-1368034706262-11:1:1:1:1]]. Caused by: [org.apache.camel.NoTypeConversionAvailableException - No type converter available to convert from type: org.apache.camel.RuntimeCamelException to the required type: long with value org.apache.camel.RuntimeCamelException: com.x.y.z.ServiceException: ERR_NOT_FOUND]
at org.apache.camel.impl.MessageSupport.getMandatoryBody(MessageSupport.java:101)
at org.apache.camel.component.bean.AbstractCamelInvocationHandler.getBody(AbstractCamelInvocationHandler.java:66)
at org.apache.camel.component.bean.AbstractCamelInvocationHandler.afterInvoke(AbstractCamelInvocationHandler.java:175)
at org.apache.camel.component.bean.AbstractCamelInvocationHandler$1.call(AbstractCamelInvocationHandler.java:112)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
at java.util.concurrent.FutureTask.run(FutureTask.java:138)
at org.apache.camel.component.bean.AbstractCamelInvocationHandler.invokeWithBody(AbstractCamelInvocationHandler.java:128)
at org.apache.camel.component.bean.CamelInvocationHandler.doInvokeProxy(CamelInvocationHandler.java:45)
at org.apache.camel.component.bean.AbstractCamelInvocationHandler.invoke(AbstractCamelInvocationHandler.java:82)
... 103 more
Caused by: org.apache.camel.NoTypeConversionAvailableException: No type converter available to convert from type: org.apache.camel.RuntimeCamelException to the required type: long with value org.apache.camel.RuntimeCamelException: com.x.y.z.ServiceException: ERR_NOT_FOUND
at org.apache.camel.impl.converter.BaseTypeConverterRegistry.mandatoryConvertTo(BaseTypeConverterRegistry.java:169)
at org.apache.camel.impl.MessageSupport.getMandatoryBody(MessageSupport.java:99)
... 111 more
Thanks!
UPDATE:
After adding transferException on the producer side, the exception that I got changed to the following. I could not really make out of this. It still tried to do the conversion... Please help. Thanks.
Caused by: org.apache.camel.InvalidPayloadException: No body available of type: long but has value: BeanInvocation public abstract long com.x.y.z.PricingService.getPrice(java.lang.String) throws com.x.y.z.ServiceException with [test]] of type: org.apache.camel.component.bean.BeanInvocation on: Message: test. Caused by: Error during type conversion from type: org.apache.camel.component.bean.BeanInvocation to the required type: long with value BeanInvocation public abstract long com.x.y.z.service.billing.PricingService.getPrice(java.lang.String) throws com.x.y.z.ServiceException with [test]] due java.lang.NumberFormatException: For input string: "test". Exchange[Message: test]. Caused by: [org.apache.camel.TypeConversionException - Error during type conversion from type: org.apache.camel.component.bean.BeanInvocation to the required type: long with value BeanInvocation public abstract long com.x.y.z.PricingService.getPrice(java.lang.String) throws com.x.y.z.ServiceException with [test]] due java.lang.NumberFormatException: For input string: "test"]
at org.apache.camel.impl.MessageSupport.getMandatoryBody(MessageSupport.java:101)
at org.apache.camel.component.bean.AbstractCamelInvocationHandler.getBody(AbstractCamelInvocationHandler.java:72)
at org.apache.camel.component.bean.AbstractCamelInvocationHandler.afterInvoke(AbstractCamelInvocationHandler.java:175)
at org.apache.camel.component.bean.AbstractCamelInvocationHandler$1.call(AbstractCamelInvocationHandler.java:112)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
at java.util.concurrent.FutureTask.run(FutureTask.java:138)
at org.apache.camel.component.bean.AbstractCamelInvocationHandler.invokeWithBody(AbstractCamelInvocationHandler.java:128)
at org.apache.camel.component.bean.CamelInvocationHandler.doInvokeProxy(CamelInvocationHandler.java:45)
at org.apache.camel.component.bean.AbstractCamelInvocationHandler.invoke(AbstractCamelInvocationHandler.java:82)
... 104 more
Caused by: org.apache.camel.TypeConversionException: Error during type conversion from type: org.apache.camel.component.bean.BeanInvocation to the required type: long with value BeanInvocation public abstract long com.x.y.z.PricingService.getPrice(java.lang.String) throws com.x.y.z.ServiceException with [test]] due java.lang.NumberFormatException: For input string: "test"
at org.apache.camel.impl.converter.BaseTypeConverterRegistry.mandatoryConvertTo(BaseTypeConverterRegistry.java:162)
at org.apache.camel.impl.MessageSupport.getMandatoryBody(MessageSupport.java:99)
... 112 more
Caused by: org.apache.camel.RuntimeCamelException: java.lang.NumberFormatException: For input string: "test"
at org.apache.camel.util.ObjectHelper.wrapRuntimeCamelException(ObjectHelper.java:1316)
at org.apache.camel.util.ObjectHelper.invokeMethod(ObjectHelper.java:962)
at org.apache.camel.impl.converter.StaticMethodTypeConverter.convertTo(StaticMethodTypeConverter.java:47)
at org.apache.camel.component.bean.BeanConverter.convertTo(BeanConverter.java:57)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
Upvotes: 3
Views: 2003
Reputation: 55550
You should set transferException=true on the producer side as well.
Upvotes: 1