簡體   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