2013-03-25 90 views
0

我有這個問題:我試圖使用Apache的XmlRpc客戶端發送自定義XML請求。我XmlRpcClient的一個實例,它包含了一些方法被稱爲「執行」,並期待這樣的:如何使用XmlRpc客戶端自定義XML請求

public class RPCClient { 
    public static void main(String[] args) { 
     try { 
      XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl(); 
      config.setServerURL(new URL("http://localhost:8888/SOAP")); 

      XmlRpcClient client = new XmlRpcClient(); 
      client.setConfig(config); 

      Object[] params = new Object[]{new Integer(4), new Integer(3)}; 
      String myResponse = (String) client.execute("A_Method", params); 

      System.out.println("Suc " + myResponse); 

     } catch (Exception e) { 
      System.out.println("Err " + e.getMessage()); 
     } 
    } 
} 

而且它發出這樣的:

POST /SOAP HTTP/1.1 
Content-Type: text/xml 
User-Agent: Apache XML RPC 3.1.3 (Sun HTTP Transport) 
Cache-Control: no-cache 
Pragma: no-cache 
Host: *********** 
Accept: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2 
Connection: keep-alive 
Content-Length: 200 

<?xml version="1.0" encoding="UTF-8"?> 
    <methodCall> 
     <methodName>A_Method</methodName> 
     <params> 
     <param> 
      <value> 
       <i4>4</i4> 
      </value> 
     </param> 
     <param> 
      <value>3</value> 
     </param> 
     </params> 
    </methodCall> 

總之,這個客戶有沒有一個「執行「方法來接收一個簡單的字符串,或類似的東西。所以我的問題是我怎麼可以把我的自定義XML,應該是這樣的:提前

<soapenv:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:xsd="http://www.w3.org/2001/XMLSchema"xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"xmlns:rp="http://www.abcdef.com/GH"xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"> 
    <soapenv:Header> </soapenv:Header> 
    <soapenv:Body>  
     <rp:A_Methodsoapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">   
     <package xsi:type="xsd:string">string1</package>   
     <event xsi:type="xsd:string">string2</event>   
     <fields xsi:type="rp:ArrayOfKeyValuePair" soapenc:arrayType="rp:KeyValuePair[]">   
      <item xsi:type="rp:KeyValuePair">      
       <key xsi:type="xsd:string">string3</key>       
       <value xsi:type="xsd:string">123</value>   
      </item>   
     </fields>  
     </rp:A_Method> 
    </soapenv:Body></soapenv:Envelope> 

的感謝!

回答

0

Apache XML-RPC用於與XML-RPC協議進行通信。您嘗試發送的消息是SOAP,一種不同的協議(請參閱問題"What's the difference between XML-RPC and SOAP?")。

要發送此消息,您可以使用常規HTTP客戶端以純文本(如果它只是一條簡單消息)發送它,或者使用完整的SOAP庫。

+0

我知道這是一個相當古老的問題,但它是「XmlRpcClient」中排名最高的問題。 – BoppreH 2013-05-13 19:08:09