Spring Integration 3.0版:Web服务请求和响应

时间:2016-01-14 14:05:12

标签: java spring web-services spring-integration synchronous

这里是我的要求,我有一个Web服务,当有请求时,它会通过验证然后转换,最后到请求MQ队列。

我的要求是我将等待几秒钟的响应,我将从响应MQ Queue获得响应,我需要从MQ Queue获取消息并将其发送到响应通道。所以它是同步的,如果我在当前线程正在等待的特定时间间隔内没有得到响应,我将发送错误作为响应。

以下配置一直有效,直到我发送请求,但无法将消息驱动的通道适配器绑定到我的reponseChannel。

这是我的申请背景

<bean id="validatingInterceptor"
    class="org.springframework.ws.soap.server.endpoint.interceptor.PayloadValidatingInterceptor">
    <property name="xsdSchema" ref="schema" />
    <property name="validateRequest" value="true" />
    <property name="validateResponse" value="true" />
</bean>

<bean id="loggingInterceptor"
    class="org.springframework.ws.server.endpoint.interceptor.PayloadLoggingInterceptor"></bean>

<bean id="myServiceDef"
    class="org.springframework.ws.wsdl.wsdl11.DefaultWsdl11Definition">
    <property name="schema" ref="schema" />
    <property name="portTypeName" value="myServiceGateway" />
    <property name="locationUri" value="http://localhost:8080/myapp/getData" />
</bean>

<bean id="schema" class="org.springframework.xml.xsd.SimpleXsdSchema">
    <property name="xsd" value="classpath:Request.xsd" />
</bean>

<bean id="myService" class="a.b.c.d.MyServiceResponder" />

<int:channel id="requestChannel" />
<int:channel id="responseChannel" />

<int-ws:inbound-gateway id="myServiceGateway"
    request-channel="requestChannel" reply-channel="responseChannel"
    error-channel="errorChannel" reply-timeout="10000" />


<int:service-activator id="myServiceActivator"
    ref="myService" input-channel="requestChannel" output-channel="transformData" />

<int:channel id="transformData" />

<int-xml:xslt-transformer id="transformChannel"
    input-channel="transformData" output-channel="initiaterChannel"
    xsl-resource="classpath:my.xsl" />

<int:channel id="initiaterChannel" />
<int:channel id="outputJMS" />

<int-jms:outbound-gateway   id="jmsOutGateway"
                request-destination="destinationQueue"
                request-channel="initiaterChannel"
                reply-channel="responseChannel"
                connection-factory="jmsQueueConnectionFactoryCached"
                reply-timeout="10000"
                receive-timeout="10000"
                correlation-key="JMSCorrelationID" />

<bean id="destinationQueue" class="com.ibm.mq.jms.MQQueue">
    <property name="baseQueueName" value="${mqJavaProducerQueueName}" />
    <property name="targetClient" value="1" />
</bean>

<!-- 
  RESPONSE time 10 sec, if any message in myOutputQueueName, then response has been sent to ws client,
  else an error response sent.
  myOutputQueueName get the response from other 3rd party
--> 

<int-jms:inbound-gateway id="gate11" request-channel="outputJMS"
    request-destination-name="${myOutputQueueName}" 
    auto-startup="true"
    error-channel="errorChannel"
    reply-timeout="10000"
    request-timeout="10000"
    reply-channel="responseChannel"  connection-factory="jmsQueueConnectionFactoryCached" />

<int-xml:validating-filter discard-channel="errorChannel"
                           id="inputValidator" 
                           input-channel="outputJMS" 
                           output-channel="validatedchema"
                           schema-location="classpath:Message.xsd" 
                           schema-type="xml-schema"
                           throw-exception-on-rejection="true" />


<int:channel id="validatedchema" />

<int-xml:xslt-transformer id="transformChannel"
                          input-channel="validatedchema" 
                          output-channel="transformOutput"
                          xsl-resource="classpath:output.xsl" />

<int:channel id="transformOutput" />

<int-xml:validating-filter discard-channel="errorChannel"
                           id="outputValidator" 
                           input-channel="transformOutput"
                           output-channel="responseChannel" 
                           schema-location="classpath:Response.xsd"
                           schema-type="xml-schema" 
                           throw-exception-on-rejection="true" />

我的服务激活器,它实际上发送请求以请求MQ队列并等待响应。

MyReplyService.java
@ServiceActivator
    public Message<?> sendRequest(Message<?> message) {
    outputJMS.send(....);

   return responseToWSClient;

无论我在responseToWSClient中返回什么,实际上都是由WS客户端接收的。 我在这里缺少的是在我的服务激活器中获得transformToOutput通道的响应。请建议。

我已经编辑了我的应用程序上下文,但我仍然无法实现我的目标。我想我没有得到你的帮助。 @gary和@Artem

我的WS客户端期望响应,并且请求进入队列,并且我从其他第三方获得响应队列[IBM MQ Q]的响应,并且在发送请求之后我的请求等待响应响应队列,如果有任何消息读取它,并在一些转换和验证后将其作为响应发送给ws客户端。通过这种配置,我不再使用MyReplyService了。

我编辑的上述应用程序上下文添加了网关。我想我搞砸了什么。请重新建议。

0 个答案:

没有答案