当前位置: 首页 > 知识库问答 >
问题:

Spring Integration Http入站网关发送空白json应答

王楚青
2023-03-14

下面使用Spring integration 2.2.6的代码

我想通过应答通道将响应发送回入站网关。我正在发送来自服务激活器的回复。但是Spring不能设置响应,而是返回空消息

<int-http:inbound-gateway id="entryHttpInboundGateway"
        request-channel="entryInputChannel" path="/service/getSE/{uuid}" reply-channel="entryInboundReplyChannel"
        request-payload-type="com.test.ServiceEvent" mapped-response-headers="eventUUID, HTTP_RESPONSE_HEADERS"
        supported-methods="GET, POST"  reply-timeout="1000" view-name="/process/plain2">
        <int-http:header name="eventUUID" expression="#pathVariables.uuid"/>
 </int-http:inbound-gateway>

<bean class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver" p:order="1" 
        p:defaultContentType="application/json">
        <property name="defaultViews">
            <list>
                <bean class="org.springframework.web.servlet.view.json.MappingJacksonJsonView" />
            </list>
        </property>
</bean>

<int:service-activator id="sv2" input-channel="entryInputChannel" output-channel="outputChannel"
    method="sendReply" requires-reply="true" ref="checkService">
  </int:service-activator>

 <bean id="checkService" class="com.test.CheckService" />
// Preparing the message to be sent to reply channel
     InboundReplyResponse inboundReplyResponse = new InboundReplyResponse();
        inboundReplyResponse.setMessage("Success");
        inboundReplyResponse.setEventUUID("12345");

    Map<String, Object> responseHeaderMap = new HashMap<String, Object>();
                    responseHeaderMap.put("eventUUID",eventUUID);
                    responseHeaderMap.put("Content-Type","application/json");

    GenericMessage<InboundReplyResponse> message = new GenericMessage<InboundReplyResponse>(inboundReplyResponse,responseHeaderMap);


    //Reply queue -> entryInboundReplyChannel
        MessageChannel entryInboundReplyChannel =  (MessageChannel) AppFactory.getApplicationContext().getBean("entryInboundReplyChannel");

    entryInboundReplyChannel.send(message);
 <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/spring-integration-context.xml</param-value>
    </context-param>


    <servlet>
        <servlet-name>ssTesting</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>

  <servlet-mapping>    
        <servlet-name>ssTesting</servlet-name>    
        <url-pattern>/service/*</url-pattern>  
    </servlet-mapping>
<Empty JSON content>

共有1个答案

柯良骏
2023-03-14

你的代码看起来很糟糕。

您可以直接发送到entryInboundReplyChannel,前提是您在网关的调用线程中。因为网关的SendandReceive依赖于MessageHeaders中的TemporaryReplyChannel。最后一个独立于入站网关上显式的应答通道

为什么不将EntryInboundReplyChannel用作 output-channel,而是返回来自SendReply方法的消息,并仅仅依靠Framewrok功能来正确地修改流呢?

我不手动使用entryInboundReplyChannel.send(message)

 类似资料:
  • 请,一些帮助部署Laravel 5.2网站,在下面的错误消息public_html/error_log: [21-Mar-2017 07:39:30 America/Chicago]PHP致命错误:require():无法打开required'/home/exoweb/public_html/allos/bootstrap/autoload。php'(include_path='。:/opt/al

  • 我正在尝试将spring集成配置为向队列发送消息,然后接收消息,即非常简单的事情: 我认为解耦所必需的是在流程的两端都有一个消息网关。因此,我的第一次尝试(有效)如下所示: 其中MessageReceiverHandler()是扩展AbstractMessageHandler的bean。 所以上面我们有一个用于出站消息的消息网关。我假设我们也应该有一个用于入站消息的网关,允许我们将传入消息处理与应

  • 我尝试使用以下代码,得到了回应:状态:405方法不允许。这是我的Http请求:http://localhost:8090/services/test?name=test.代码或http请求有什么问题?

  • 我不熟悉Spring集成。我正在尝试使用http入站网关构建一个简单的应用程序。下面是我得到的运行时异常。 下面是代码文件。 波约 服务 } 服务激活器 } 存储库 请帮助我,我正在试图找到异常发生的原因,但无法解决。提前谢谢。 集成文件。

  • 我在http://eiglaw.com上遇到了一个问题--在iPhone的屏幕右侧显示了一个大约25px宽的空白/边框。我研究了stackoverflow上的问题,这些帖子是相关的,但当我尝试提供的各种解决方案时,我都无法修复该问题: iPhone上的响应式网站-从景观到肖像旋转时不需要的空白 在iPhone Safari中呈现右白色边距的网站正文背景 缩放时页眉右侧有空白 我在iPad上也遇到过