Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/332.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 驼峰解组Rest响应异常_Java_Apache Camel - Fatal编程技术网

Java 驼峰解组Rest响应异常

Java 驼峰解组Rest响应异常,java,apache-camel,Java,Apache Camel,我面临着一个问题,从Rest呼叫中取消应答 我的camel-context.xml如下所示: <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:camel="http://camel.apache.org/schema/spring" xmlns:cxf="http://camel.apache.org/s

我面临着一个问题,从Rest呼叫中取消应答

我的camel-context.xml如下所示:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:camel="http://camel.apache.org/schema/spring"
    xmlns:cxf="http://camel.apache.org/schema/cxf"
    xmlns:osgi="http://www.springframework.org/schema/osgi"
    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://www.springframework.org/schema/osgi http://www.springframework.org/schema/osgi/spring-osgi.xsd       http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd       http://camel.apache.org/schema/cxf http://camel.apache.org/schema/cxf/camel-cxf-2.8.3.xsd">

    <bean class="com.myapp.MyProcessor" id="myResponseProcessor"/>

    <camelContext id="camelId" xmlns="http://camel.apache.org/schema/spring">

        <camel:route id="myServiceCreate">
            <!-- SKIPPING PREPARATION PART -->
            <log message="BODY ----- ${body}"/>
            <marshal>
                <json library="Jackson"/>
            </marshal>
            <setHeader headerName="CamelHttpMethod">
                <constant>POST</constant>
            </setHeader>
            <to uri="{{services.myuri}}/create"/>
            <log message="Message: ${body}"></log>
            <unmarshal>
                <json library="Jackson"  unmarshalTypeName="com.myapp.MyPojo"/>
            </unmarshal>
            <process id="_processMyResponse" ref="myResponseProcessor"/>
        </camel:route>
    </camelContext>
</beans>
我已尝试向字符串添加强制转换:

  <convertBodyTo type="String"/>

如何修复解组?

在删除日志记录后,解组开始工作的原因是主体类型为
InputStream
,这意味着第一次访问流后将刷新该流,在本例中为日志

如您所说,如果需要进行日志记录,则在日志记录之前,即在
之后立即将强制转换添加到字符串中

<to uri="{{services.myuri}}/create"/>
<convertBodyTo type="java.lang.String" />
<log message="Message: ${body}"></log>
<unmarshal>
    <json library="Jackson"  unmarshalTypeName="com.myapp.MyPojo"/>
</unmarshal>

编辑


我还找到了解释这一现象的常见问题。

当你用POJO解压时,你也能粘贴它吗?它与JSON匹配吗?请在这里签出我答案中的编辑部分。@Kepotx,Pojo是ok公共类MyPojo{@JsonProperty(“collectionId”)私有字符串collectionId;}@pvpkiran,tyried添加以下内容。在应用程序/json无效的情况下,您在路由的何处将强制转换添加到字符串?日志记录之前还是之后?
17:13:25.532 [http-nio-0.0.0.0-8080-exec-1] INFO  myServiceCreate - Message: {"collectionId":"123"}
<to uri="{{services.myuri}}/create"/>
<convertBodyTo type="java.lang.String" />
<log message="Message: ${body}"></log>
<unmarshal>
    <json library="Jackson"  unmarshalTypeName="com.myapp.MyPojo"/>
</unmarshal>