我有一个简单的路线,看起来像这样:
<route handleFault="true" streamCache="true" id="routeA">
<from uri="cxfrs://bean://simpleCxf" />
<log message="The message body contains ${body}"/>
<to uri="direct-vm:RouteB" />
</route>
<route handleFault="true" streamCache="true" id="routeB">
<from uri="direct-vm:RouteB" />
<bean ref="requestValidator" method="validateRequest" />
<log message="The input message ${body}" />
<bean ref="dbClient" method="queryDatabase" />
</route>
CXF 配置也非常简单:
<cxf:rsServer id="simpleCxf" address="/test"
loggingFeatureEnabled="true"
serviceClass="com.gogol.test.TestResource">
</cxf:rsServer>
此简单路由失败,出现以下异常
No type converter available to convert from type: org.apache.cxf.message.MessageContentsList to the required type: org.apache.camel.Exchange with value [com.gogol.test.resource.SimpleObject@773736ca]
这是消息历史记录,表明它在点失败
Message History
---------------------------------------------------------------------------------------------------------------------------------------
RouteId ProcessorId Processor Elapsed (ms)
[routeA] [routeA] [direct-vm://routeA ] [6]
[routeB] [log12 ] [log ] [2]
[routeB] [to9 ] [direct-vm:routeA ] [4]
[routeA] [bean26] [bean[ref:requestValidator method: validateRequest]] [2]
我认为问题是Camel试图将cxf生成的主体转换为Exchange对象。因为requestValidator类有一个签名为的方法:
public void validateRequest(Exchange exchange) thows SomeException.
但理想情况下,cxf 生成的消息应设置为 Exchange 中的主体。我是否正确,如果不是,那么上述例外的原因可能是什么?
编辑:
我使用的是CXF 3.0.4.redhat-621084版和CAMEL 2.15.1.redhat-62084版
{Caused by: org.apache.camel.InvalidPayloadException: No body available of type: org.apache.camel.Exchange but has value: [com.gogol.schema.TestResourcec@6b651b67] of type: org.apache.cxf.message.MessageContentsList on: Message: [com.gogol.schema.TestResourcec@6b651b67]. Caused by: No type converter available to convert from type: org.apache.cxf.message.MessageContentsList to the required type: org.apache.camel.Exchange with value [com.gogol.schema.TestResourcec@6b651b67]. Exchange[Message: [com.gogol.schema.TestResourcec@6b651b67]]. Caused by: [org.apache.camel.NoTypeConversionAvailableException - No type converter available to convert from type: org.apache.cxf.message.MessageContentsList to the required type: org.apache.camel.Exchange with value [com.gogol.schema.TestResourcec@6b651b67]]
at org.apache.camel.impl.MessageSupport.getMandatoryBody(MessageSupport.java:101)[198:org.apache.camel.camel-core:2.15.1.redhat-621084]
at org.apache.camel.builder.ExpressionBuilder$42.evaluate(ExpressionBuilder.java:1037)[198:org.apache.camel.camel-core:2.15.1.redhat-621084]
... 68 more
Caused by: org.apache.camel.NoTypeConversionAvailableException: No type converter available to convert from type: org.apache.cxf.message.MessageContentsList to the required type: org.apache.camel.Exchange with value [com.gogol.schema.TestResourcec@6b651b67]
at org.apache.camel.impl.converter.BaseTypeConverterRegistry.mandatoryConvertTo(BaseTypeConverterRegistry.java:177)[198:org.apache.camel.camel-core:2.15.1.redhat-621084]
at org.apache.camel.core.osgi.OsgiTypeConverter.mandatoryConvertTo(OsgiTypeConverter.java:122)[203:org.apache.camel.camel-spring:2.15.1.redhat-621084]
at org.apache.camel.impl.MessageSupport.getMandatoryBody(MessageSupport.java:99)[198:org.apache.camel.camel-core:2.15.1.redhat-621084]
... 69 more}
我不确定camel xml dsl如何正确格式化,但是您可以明确地告诉camel进行类型转换。您可以通过使用convertBodyTo调用来强制类型转换来测试您的理论。
from("myEndpoint")
.log("This is my previous object")
.convertBodyTo(TestResource.class)
.log("This is my object after a camel type conversion");