Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/378.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 Spring Integration 3.0.1 Restful http入站网关不';t将请求体转换为对象_Java_Spring_Spring Integration - Fatal编程技术网

Java Spring Integration 3.0.1 Restful http入站网关不';t将请求体转换为对象

Java Spring Integration 3.0.1 Restful http入站网关不';t将请求体转换为对象,java,spring,spring-integration,Java,Spring,Spring Integration,我试图使用SpringIntegration(3.0.1)来实现一个RESTful服务,该服务支持XML和JSON作为请求和响应格式,使用intHTTP:inbound网关 我的代码基于Spring集成示例(尽管它不使用消息负载): 服务激活器类别: @Service("httpOrderGateway") public class HttpOrderGateway implements OrderGateway { private static final Logger LOGGE

我试图使用SpringIntegration(3.0.1)来实现一个RESTful服务,该服务支持XML和JSON作为请求和响应格式,使用intHTTP:inbound网关

我的代码基于Spring集成示例(尽管它不使用消息负载):

服务激活器类别:

@Service("httpOrderGateway")
public class HttpOrderGateway implements OrderGateway {

    private static final Logger LOGGER = Logger.getLogger(HttpOrderGateway.class);

    @Override
    public Message<CreateOrderResponse> createOrder(Message<CreateOrderRequest> orderRequest) {
        LOGGER.info("Received CreateOrderRequest headers: " + orderRequest.getHeaders());
        LOGGER.info("Received: " + orderRequest.getPayload());

        return MessageBuilder.withPayload(new CreateOrderResponse("Thank you for your order")).build();
    }

}
@服务(“httpOrderGateway”)
公共类HttpOrderGateway实现OrderGateway{
私有静态最终记录器Logger=Logger.getLogger(HttpOrderGateway.class);
@凌驾
公共消息createOrder(消息orderRequest){
info(“收到的CreateOrderRequest头文件:“+orderRequest.getHeaders()”);
LOGGER.info(“接收:”+orderRequest.getPayload());
return MessageBuilder.withPayload(新建CreateOrderResponse(“感谢您的订单”).build();
}
}
Spring集成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://www.springframework.org/schema/integration 
                            http://www.springframework.org/schema/integration/spring-integration.xsd
                            http://www.springframework.org/schema/integration/http 
                            http://www.springframework.org/schema/integration/http/spring-integration-http.xsd
                            http://www.springframework.org/schema/oxm 
                            http://www.springframework.org/schema/oxm/spring-oxm.xsd"
       xmlns:int="http://www.springframework.org/schema/integration"
       xmlns:oxm="http://www.springframework.org/schema/oxm"
       xmlns:int-http="http://www.springframework.org/schema/integration/http">

    <int:annotation-config />  

    <int:channel id="orderRequestChannel" />
    <int:channel id="orderResponseChannel" />

    <int-http:inbound-gateway id="inboundOrderRequestGateway" 
                              supported-methods="POST"
                              request-channel="orderRequestChannel"
                              reply-channel="orderResponseChannel"
                              view-name="/order"
                              path="/services/order"
                              reply-timeout="50000">
    </int-http:inbound-gateway>

    <bean class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver">
        <property name="order" value="1" />
        <property name="contentNegotiationManager">
            <bean class="org.springframework.web.accept.ContentNegotiationManagerFactoryBean">
                <property name="defaultContentType" value="application/json" />
                <property name="mediaTypes">
                    <map>
                        <entry key="json" value="application/json" />
                        <entry key="xml" value="application/xml" />
                    </map>
                </property>
            </bean>
        </property>
        <property name="defaultViews">
            <list>
                <bean class="com.anon.order.gateway.json.view.ExtendedMappingJacksonJsonView">
                    <property name="objectMapper" ref="jaxbJacksonObjectMapper" />
                </bean>
                <bean class="org.springframework.web.servlet.view.xml.MarshallingView">
                    <constructor-arg ref="marshaller" />
                </bean>
            </list>
        </property>
    </bean>

    <oxm:jaxb2-marshaller id="marshaller" contextPath="com.anon.order.gateway.marshalling.model.impl" />

    <int:service-activator id="orderGatewayActivator"
                               input-channel="orderRequestChannel"
                               output-channel="orderResponseChannel"
                               ref="httpOrderGateway" 
                               method="createOrder" 
                               requires-reply="true"
                               send-timeout="60000" />

    <bean id="jaxbJacksonObjectMapper" class="com.anon.order.gateway.json.JaxbJacksonObjectMapper" />

</beans>

当前,代码将注销:

Received: <CustomerServiceRequest><CustomerName>Robert Pulson</CustomerName></CustomerServiceRequest>
收到:罗伯特·普尔森
(或等效的JSON格式),并返回JSON或XML格式的响应,具体取决于Accept头,因此该部分正常工作

我已经阅读了以下基于以前版本的Spring Integration的类似问题:

但这使用了一个
入站通道适配器
,而不是像我这样使用
入站网关


如何配置入站网关以使用
marshaller
jaxbJacksonObjectMapper
(来自同一配置文件)要将原始请求正文转换为JSON/XML的
CreateOrderRequest
实例,请配置适当的
HttpMessageConverter
s,并使用
消息转换器
属性注入它们

另请参见
与默认转换器合并
属性

请参见
映射Jackson2HttpMessageConverter
(jackson 2)、
映射JacksonHttpMessageConverter
(jackson 1.x)和
封送HttpMessageConverter

此外,默认情况下,如果JAXB和Json消息转换器位于类路径上,则会自动使用它们。如果转换不需要任何特殊功能,您可以在网关上设置
请求有效负载类型


有关更多信息,请参阅。

感谢您的回复,但以上任何一项都没有产生任何影响。入站网关没有预期的类型属性。是否有计划使用转换正文的POST示例更新GIT中的rest http示例?对不起,输入错误,属性是
请求有效负载类型
。我只是通过添加
请求有效负载类型
,向我的分支推送了一个提交,显示
JSON->Map
。这就解决了问题-我感谢你的帮助,非常感谢。由于某些原因,请求负载类型在IDE中没有自动完成,所以我不知道我可以使用它。