2013-05-09 77 views
3

我正在寻找一种解决方案,以便在使用Apache Camel - JMS Remoting时,使消费者端抛出的异常返回到生产者端。Apache Camel - JMS Remoting:异常不会抛回生产者

我发现在Apache Camel JMS - Exceptions not returned to caller with request/reply处有一个类似的问题。

所以,我跟着那里的答案,我打开了传递异常选项,因为克劳斯建议,但骆驼仍然给我一个错误 - 一个不同的错误,由org.apache.camel.NoTypeConversionAvailableException引起的InvalidPayloadException - 没有类型转换器可用从类型:org.apache.camel.RuntimeCamelException转换为所需的类型:long,值为org.apache.camel.RuntimeCamelException:com.xyzServiceException:test]。

因此,看起来我确实像克劳斯所说的那样把异常交给了生产者端(原始异常包裹在RuntimeCalmelException中)。问题是Camel试图将我的异常转换为很长的返回类型。

有没有办法让异常一直冒泡而不被转换?

这里是细节:

接口: PricingService.java

public long getPrice(String id); 

消费侧: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"); 
     } 
    } 

制片方:

<camel:camelContext id="producer"> 
     <camel:proxy id="pricingService" 
      serviceInterface="com.x.y.z.PricingService" 
      serviceUrl="jms:queue:pricingService?transferExchange=true"/> 
    </camel:camelContext> 

因此,在制片方,当我打电话pricingService.getPrice("abc"),我得到了一个异常,如下所示:

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 

谢谢!

UPDATE:

在制片方加入transferException,把我弄得改变为如下异常后。我无法真正解决这个问题。它仍然试图做转换...请帮助。谢谢。

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) 

回答

1

您应该在生产者端也设置transferException = true。

+0

感谢您的回复。我尝试过,但仍然有一个InvalidPayloadException,虽然底层的异常有点不同:org.apache.camel.InvalidPayloadException:没有可用的类型:long但有值:BeanInvocation public abstract long com.xyzPricingService.getPrice(java.lang .String)抛出类型为[org.apache.camel.component.bean.BeanInvocation – user2368059 2013-05-10 16:50:25

+0

]的[test]]的com.xyzServiceException。我更新了包含堆栈跟踪在内的异常问题。它在评论部分中不太易读。任何输入将不胜感激。谢谢! – user2368059 2013-05-10 17:12:15