【问题标题】:how can I get the response message from Axis2 in spring integration如何在春季集成中从 Axis2 获取响应消息
【发布时间】:2015-11-10 22:44:40
【问题描述】:

我需要在 spring 集成中集成我的 webservice (Axis2):我有 spring-axis2-message.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/integration"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns:beans="http://www.springframework.org/schema/beans"
	xmlns:stream="http://www.springframework.org/schema/integration/stream"
	xmlns:ws="http://www.springframework.org/schema/integration/ws"
	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/stream
			http://www.springframework.org/schema/integration/stream/spring-integration-stream.xsd
			http://www.springframework.org/schema/integration/ws
			http://www.springframework.org/schema/integration/ws/spring-integration-ws.xsd">

	<chain input-channel="messageChannelIN" output-channel="messageChannelOUT">
		<ws:header-enricher    >
			<ws:soap-action value="getMessageService"/>
		</ws:header-enricher>
		<ws:outbound-gateway uri="http://localhost:8080/axis2-webservice/services/wservices?wsdl" reply-channel="messageChannelOUT"/>
	</chain>
	

	<!-- The response from the service is logged to the console. -->
	<stream:stdout-channel-adapter id="messageChannelOUT"  append-newline="true" />
	
</beans:beans>

还有一个TestAxis2.java

package org.neos.spring.test;

import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.integration.support.MessageBuilder;
import org.springframework.integration.support.channel.BeanFactoryChannelResolver;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageChannel;
import org.springframework.messaging.core.DestinationResolver;


public class TestAxis2 {

	public static void main(String[] args) {
		ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
				"/META-INF/spring/integration/spring-axis2-message.xml");
		DestinationResolver<MessageChannel> channelResolver = new BeanFactoryChannelResolver(context);

		String requestXml = 
				"<getMessageService xmlns=\"http://service.ws.axis2.neos.org\">" + 
						"<name>HUGO</name>"
				+ "</getMessageService>";

		// Create the Message object
		Message<String> message = MessageBuilder.withPayload(requestXml).build();

		// Send the Message to the handler's input channel
		MessageChannel channel = channelResolver.resolveDestination("messageChannelIN");
		channel.send(message);
		
	}

}

程序运行得很好,我可以在控制台中看到下一个响应:

&lt;?xml version="1.0" encoding="UTF-8"?&gt;&lt;ns:getMessageServiceResponse xmlns:ns="http://service.ws.axis2.neos.org"&gt;&lt;ns:return&gt;HELLO HUGO!, WELCOME TO WEBSERVICE AXIS1 hola&lt;/ns:return&gt;&lt;/ns:getMessageServiceResponse&gt;

我的问题是我如何操作/如何在 Java 程序中获得响应,因为我需要响应。我尝试了很多事情,但不幸的是什么都没做我只能在控制台中看到响应,但我需要操纵响应。

我不知道如何访问此配置或是否需要配置其他内容。

access&lt;stream:stdout-channel-adapter id="messageChannelOUT"  append-newline="true" /&gt;

谁能帮帮我?

【问题讨论】:

    标签: spring spring-integration


    【解决方案1】:
    1. 使用Messaging Gateway。

      public interface Gateway
      
          String sendAndReceive(String out);
      
      }
      
      <int:gateway service-interface="foo.Gateway" 
           default-request-channel="messageChannelIN" />
      
    2. 从链中删除output-channel

    3. 回复将通过网关返回给调用者

      Gatweway gw = context.getBean(Gateway.class);
      ...
      String reply = gw.sendAndReceive(requestXml);
      

    这样做的好处是不会将您的应用程序暴露给消息传递基础架构。

    【讨论】:

    • 谢谢加里·拉塞尔!!
    【解决方案2】:

    它现在正在运行我的程序!!。感谢您的帮助加里·拉塞尔!!!你的 cmets 非常有用。

    最后的代码是:

    xml配置

    ........
    <chain input-channel="messageChannelIN">
        <ws:header-enricher>
            <ws:soap-action value="getMessageService"/>
        </ws:header-enricher>
        <ws:outbound-gateway uri="http://localhost:8080/axis2-webservice/services/wservices?wsdl" />
    </chain>
    
    <gateway id="messageChannelOUT" service-interface="org.neos.spring.ws.service.GatewayAxis" default-request-channel="messageChannelIN"/>
    

    Java 代码:

    public interface GatewayAxis {
      @Gateway
      String sendAndReceive(String out);}
    

    TestAxis2

    public static void main(String[] args) {
        ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
                "/META-INF/spring/integration/spring-axis2-message.xml");
    
        GatewayAxis gateway = context.getBean(GatewayAxis.class);
    
        String requestXml = 
                "<getMessageService xmlns=\"http://service.ws.axis2.neos.org\">" + 
                        "<name>HUGO</name>"
                + "</getMessageService>";
        String reply = gateway.sendAndReceive(requestXml);
        System.out.println(reply);
    
    }
    

    【讨论】:

      猜你喜欢
      • 2019-02-15
      • 1970-01-01
      • 2017-07-28
      • 2019-08-05
      • 1970-01-01
      • 1970-01-01
      • 2017-10-17
      • 1970-01-01
      • 2016-01-17
      相关资源
      最近更新 更多