Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java ApacheCamel-JMS远程处理:未将异常抛出回生产者_Java_Spring_Jms_Apache Camel_Spring Remoting - Fatal编程技术网

Java ApacheCamel-JMS远程处理:未将异常抛出回生产者

Java ApacheCamel-JMS远程处理:未将异常抛出回生产者,java,spring,jms,apache-camel,spring-remoting,Java,Spring,Jms,Apache Camel,Spring Remoting,我正在寻找一种解决方案,使消费者端抛出的异常在使用ApacheCamel-JMS远程处理时返回到生产者端 我发现有一个类似的问题已经被问到了 所以,我按照那里的答案,按照克劳斯的建议打开了transferException选项,但是Camel仍然给了我一个错误——一个不同的错误,由org.apache.camel.NoTypeConversionAvailableException引起的InvalidPayloadException-没有可用的类型转换器可将类型:org.apache.camel

我正在寻找一种解决方案,使消费者端抛出的异常在使用ApacheCamel-JMS远程处理时返回到生产者端

我发现有一个类似的问题已经被问到了

所以,我按照那里的答案,按照克劳斯的建议打开了transferException选项,但是Camel仍然给了我一个错误——一个不同的错误,由org.apache.camel.NoTypeConversionAvailableException引起的InvalidPayloadException-没有可用的类型转换器可将类型:org.apache.camel.RuntimeCamelException转换为所需类型:long,值为org.apache.camel.RuntimeCamelException:com.x.y.z.ServiceException:test]

因此,似乎我确实按照克劳斯的建议将异常转移到了生产者端(最初的异常被包装在RuntimeCalmeException中)。问题是我试图将我的异常转换为长返回类型

有没有一种方法可以让异常一直冒泡而不被转换

详情如下:

接口: 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>
谢谢

更新:

在producer端添加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)

您还应该在制作人端设置transferException=true。

谢谢您的回复。我试过了,但仍然得到了一个InvalidPayloadException,尽管底层异常有点不同:org.apache.camel.InvalidPayloadException:没有类型为:long但有值的正文:BeaniNotification public abstract long com.x.y.z.PricingService.getPrice(java.lang.String)抛出com.x.y.z.ServiceException和[test]]类型:org.apache.camel.component.bean.Beanin我更新了这个问题,但出现了包括堆栈跟踪在内的异常。评论部分的可读性不太好。如有任何意见,将不胜感激。谢谢
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)