如何使用XML类型发布,并在camel中以java.lang.String的形式获取答案?
我正在尝试制作一些小的消息转换器,将新类型的数据注入现有系统。为此,我将新XML转换为内部类,执行操作,并将结果作为字符串返回。当我将答案部署为XML时,没有问题,但目前我遇到以下错误:如何使用XML类型发布,并在camel中以java.lang.String的形式获取答案?,java,xml,apache-camel,blueprint-osgi,Java,Xml,Apache Camel,Blueprint Osgi,我正在尝试制作一些小的消息转换器,将新类型的数据注入现有系统。为此,我将新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.St
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]
我试图替换products type,outType,并将内容类型设置为text/plain来调整标题,但它没有发送帮助。最初的绑定模式是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=“auto”,因此我无法验证这是否真的是问题所在,但这对我来说是可行的:
<camelContext id="rest-test" allowUseOriginalMessage="false" xmlns="http://camel.apache.org/schema/blueprint" streamCache="false">
<dataFormats>
<jaxb id="jaxb" prettyPrint="false" contextPath="my.domain.classes" />
</dataFormats>
<restConfiguration component="jetty" scheme="http" host="0.0.0.0" port="9001" contextPath="/string/conversion" bindingMode="off" />
<rest path="/test" id="rest-string-conversion" produces="text/plain" consumes="application/xml">
<post>
<route>
<camel:unmarshal ref="jaxb"/>
<camel:transform>
<camel:simple>${body.eventId}</camel:simple>
</camel:transform>
<log message="Event ID: ${body}" loggingLevel="INFO" logName="string-conversion-test" />
</route>
</post>
</rest>
</camelContext>
可能您的响应确实包含字符串,但您的客户端被
内容类型标题弄糊涂了?我无法让我的示例使用bindingMode=“auto”,因此我无法验证这是否真的是问题所在,但这对我有效:
<camelContext id="rest-test" allowUseOriginalMessage="false" xmlns="http://camel.apache.org/schema/blueprint" streamCache="false">
<dataFormats>
<jaxb id="jaxb" prettyPrint="false" contextPath="my.domain.classes" />
</dataFormats>
<restConfiguration component="jetty" scheme="http" host="0.0.0.0" port="9001" contextPath="/string/conversion" bindingMode="off" />
<rest path="/test" id="rest-string-conversion" produces="text/plain" consumes="application/xml">
<post>
<route>
<camel:unmarshal ref="jaxb"/>
<camel:transform>
<camel:simple>${body.eventId}</camel:simple>
</camel:transform>
<log message="Event ID: ${body}" loggingLevel="INFO" logName="string-conversion-test" />
</route>
</post>
</rest>
</camelContext>
可能您的响应实际上确实包含字符串,但您的客户端会被内容类型
标题弄糊涂?如果您设置bindingMode=“off”
,它是否有效?然后,您必须自己执行JAXB解封送,但是如果您想这样做的话,任何事情都不应该干扰您返回一个普通字符串。我尝试了xml、xml_json和自动。最后,我删除了这个属性,它开始工作。我不知道为什么它会覆盖我对单个rest定义的设置。如果设置bindingMode=“off”
,它会工作吗?然后,您必须自己执行JAXB解封送,但是如果您想这样做的话,任何事情都不应该干扰您返回一个普通字符串。我尝试了xml、xml_json和自动。最后,我删除了这个属性,它开始工作。我不知道为什么它会覆盖我对单个rest定义的设置。我的rest客户端中的答案类型始终为纯文本/text我的rest客户端中的答案类型始终为纯文本/text