如何在 spring 集成中从 Axis2 获取响应消息

how can I get the response message from Axis2 in spring integration

我需要在 spring 集成中集成我的网络服务 (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);
  
 }

}

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

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

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

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

access<stream:stdout-channel-adapter id="messageChannelOUT"  append-newline="true" />

有人可以帮我吗?

  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);
    

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

它正在运行我的程序!!感谢您的帮助加里罗素!!!你的评论很有用。

最终代码为:

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);}

测试轴2

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);

}