繁体   English   中英

Java Axis2发送SOAP响应

[英]Java Axis2 send SOAP response

我正在尝试在收到请求后发送SOAP消息。 在Eclipse Mars 2中,我从.wsdl生成Java Bean Skeleton。 .wsdl仅具有一个名为send操作。 Axis2生成所有类和.xml文件后, MyServiceSkeleton.java了一个名为MyServiceSkeleton.java类,其中send()方法在其中。

在这种方法中,我可以接收SOAP请求并使用以下代码提取xml数据:

String xml = myServiceClass.getOMElement(null, OMAbstractFactory.getOMFactory()).toStringWithConsume();

我现在想制作一条新的SOAP消息,并将响应发送回请求者或给定的IP地址/ URL。 基本上,我有一个XML字符串,它是使用请求中的数据制成的,我想将其转换为SOAP消息,然后将SOAP消息发送到某个地方。

我假设我必须向要发送到的服务器发出请求。 我尝试了这个:

public void soapConnection() {
    try {
        SOAPConnectionFactory soapConnectionFactory = SOAPConnectionFactory.newInstance();
        SOAPConnection soapConnection = soapConnectionFactory.createConnection();

        // Send to server
        String url = "some ip address or url";
        soapConnection.call(createSOAPRequest(), url);
        soapConnection.close();

    } catch (Exception e) {
        e.printStackTrace();
    }
}

public SOAPMessage createSOAPRequest() throws Exception {
    MessageFactory messageFactory = MessageFactory.newInstance();
    SOAPMessage soapMessage = messageFactory.createMessage();
    SOAPPart soapPart = soapMessage.getSOAPPart();

    String uri = "some uri";
    SOAPEnvelope envelope = soapPart.getEnvelope();
    envelope.addNamespaceDeclaration("ns1", uri);

    // Take XML String and turn into envelope

    soapMessage.saveChanges();

    return soapMessage;     
}

我不知道如何在soapMessage.saveChanges()之前soapMessage.saveChanges()部分代码。 任何帮助,将不胜感激。

您可以通过更改服务方法返回类型(服务方法是使用服务的外部用户公开的方法)将文件或对象发送回调用方。 有关更多详细信息,请参见此问题的答案 Java中的SOAP错误处理

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM