【发布时间】:2016-02-16 12:36:41
【问题描述】:
我正在尝试制作一些小型消息翻译器,以将新类型的数据注入现有系统。为此,我将新的 XML 转换为内部类,执行操作,并将结果作为字符串返回。当我将答案部署为 XML 时没有问题,但目前我收到以下错误:
java.io.IOException: org.apache.camel.InvalidPayloadException: No body available of type: javax.xml.bind.JAXBElement but has value: 00 of type: java.lang.String on: Message: 00. Exchange[ID-60345-1455623194156-43-5][Message: 00]
我尝试替换产生类型,outType,通过将 Content-Type 设置为 text/plain 来调整标题,但它没有帮助。最初的 bindingMode 是 XML。我的目标是使用 POST 方法返回简单的字符串。
<restConfiguration component="netty4-http"
bindingMode="auto"
contextPath="/WebServices/rest"
enableCORS="true">
<endpointProperty key="nettySharedHttpServer" value="#sharedNettyHttpServer"/>
<dataFormatProperty key="prettyPrint" value="false"/>
</restConfiguration>
<!-- defines the rest services using the context-path /user -->
<rest path="/service"
consumes="application/xml"
produces="text/plain">
<description>REST service</description>
<post uri="/request"
type="org.company.generated.VmML"
outType="java.lang.String">
<route>
<to uri="bean:authenticationBean?method=checkAuthentication"/>
<bean ref="messageTranslator" method="vmmlToEntry"/>
<to uri="bean:Service?method=store"/>
<bean ref="messageTranslator" method="returnEntryToStringReplay"/>
</route>
</post>
</rest>
【问题讨论】:
-
设置
bindingMode="off"是否有效?那时你必须自己做 JAXB 解组,但如果这是你想做的,没有什么会干扰你返回一个纯字符串。 -
我没有尝试启动模式。我尝试了 xml、xml_json、自动。最后我删除了这个属性,它开始工作了。我不知道为什么它会覆盖我对单个休息定义的设置。
标签: java xml apache-camel blueprint-osgi