我有一个带有 apache camel 的 springboot 应用程序。在其中我有一个骆驼上下文。我正在尝试通过 curl 发送带有密钥对值的 json 并通过路由处理它。
发送数据:
curl --header "Content-Type: application/json" -X POST -d '{"msgId=EB2C7265-EF68-4F8F-A709-BEE2C52E842B", "ticket":"ERR001"}' http://lcalhost:8888/api/erroradmin
骆驼上下文.xml:
<?xml version="1.0" encoding="utf-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">
<camelContext xmlns="http://camel.apache.org/schema/spring" useMDCLogging="true">
<properties>
<property key="CamelLogEipName" value="ThisLogger"/>
</properties>
<dataFormats>
<!-- here we define a Json data format with the id jack and that it should use the TestPojo as the class type when
doing unmarshal. The unmarshalTypeName is optional, if not provided Camel will use a Map as the type -->
<json id="jack" library="Jackson" unmarshalTypeName="java.util.HashMap"/>
</dataFormats>
<restConfiguration component="jetty" port="8888" bindingMode="json">
<dataFormatProperty key="prettyPrint" value="true"/>
</restConfiguration>
<rest path="/api/erroradmin">
<get uri="{id}">
<to uri="direct:processErrorAdminGet"/>
</get>
<post>
<to uri="direct:processErrorAdminPost"/>
</post>
</rest>
<route id="processErrorAdminPost">
<from uri="direct:processErrorAdminPost"/>
<log message="Route(processErrorAdminPost): ${body}"/>
<unmarshal>
<custom ref="jack"/>
</unmarshal>
<log message="Route(processErrorAdminPost): ${body}"/>
</route>
</camelContext>
</beans>
我得到以下堆栈跟踪:
org.apache.camel.InvalidPayloadException:没有可用类型的主体:java.io.InputStream 但具有值:{msgId=D507B9EE-176D-4F3C-88E7-9E36CC2B9731,ticket=ERR001} 类型:java.util.LinkedHashMap on: HttpMessage@0x28c1a31a。原因:没有类型转换器可用于将类型:java.util.LinkedHashMap 转换为所需的类型:java.io.InputStream,值为 {msgId=D507B9EE-176D-4F3C-88E7-9E36CC2B9731,ticket=ERR001}。交换 [09395660-c947-47f1-b00f-d0d3030a39d1]。原因:[org.apache.camel.NoTypeConversionAvailableException - 没有类型转换器可用于从类型:java.util.LinkedHashMap 转换为所需类型:java.io.InputStream,值为 {msgId=D507B9EE-176D-4F3C-88E7-9E36CC2B9731 , 票=ERR001}]