2013-01-09 60 views
3

我正在使用apache axis2在web服務上工作,並且我已生成所需的客戶端代碼。客戶端請求應該如下所示:如何將SOAP頭信息添加到使用apache axis2的java soap服務請求

`<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" 
xmlns:v2="http://www.huawei.com.cn/schema/common/v2_1" 
xmlns:loc="http://www.csapi.org/schema/parlayx/sms/notification_manager/v2_3/local"> 
<soapenv:Header> 
    <RequestSOAPHeader xmlns="http://www.huawei.com.cn/schema/common/v2_1"> 
     <spId>35000001</spId> 
     <spPassword>de96d901b3bad1db2aab76b7b0b202f2</spPassword> 
     <serviceId>0003062000001100</serviceId> 
     <timeStamp>20120731064245</timeStamp> 
    </RequestSOAPHeader> 
</soapenv:Header> 
<soapenv:Body> 
    <loc:startSmsNotification> 
     <loc:reference> 
      <endpoint>>http://10.138.30.153:9080/notify</endpoint> 
      <interfaceName>notifySmsReception</interfaceName> 
      <correlator>1232</correlator> 
     </loc:reference> 
     <loc:smsServiceActivationNumber>23424 
     </loc:smsServiceActivationNumber> <!--Optional: --> 
     <loc:criteria>Love</loc:criteria> 
    </loc:startSmsNotification> 
</soapenv:Body> 
</soapenv:Envelope>` 

我已經能夠將body消息添加到我的請求中,但不會添加soap頭信息。報頭信息對驗證請求是必需的。我如何在生成的客戶端代碼中將soap頭信息添加到我的soap請求中?

回答

2

嗨,馬丁,SDP材料不是現成的在互聯網上,但嘗試以下。

OMFactory fac = OMAbstractFactory.getOMFactory(); 
    SOAPFactory sfac = OMAbstractFactory.getSOAP11Factory(); 

    OMNamespace omNs = fac.createOMNamespace(nameSpace, "ns1"); 

    SOAPHeaderBlock block_RequestSOAPHeader = sfac.createSOAPHeaderBlock(
    SOAPHEADER_RequestSOAPHeader, omNs); 

    try 
    { 
     SOAPHeaderBlock block_spId = sfac.createSOAPHeaderBlock(SOAPHEADER_SPID, omNs); 
     block_spId.addChild(sfac.createOMText(spId)); 

     String md_password = md5Digest(spId, spPassword, timeStamp); 
     SOAPHeaderBlock block_spPassword = sfac.createSOAPHeaderBlock(SOAPHEADER_SPPASSWORD, omNs); 
     block_spPassword.addChild(sfac.createOMText(md_password)); 

     SOAPHeaderBlock block_timeStamp = sfac.createSOAPHeaderBlock(SOAPHEADER_TIMESTAMP, omNs); 
     block_timeStamp.addChild(sfac.createOMText(timeStamp)); 

     SOAPHeaderBlock block_serviceId = sfac.createSOAPHeaderBlock(SOAPHEADER_SERVICEID, omNs); 
     block_serviceId.addChild(sfac.createOMText("your text")); 


     SOAPHeaderBlock block_linkId = sfac.createSOAPHeaderBlock(SOAPHEADER_LINKID, omNs); 
     block_linkId.addChild(sfac.createOMText(linkID)); 

     SOAPHeaderBlock block_OA = sfac.createSOAPHeaderBlock(SOAPHEADER_OA, omNs); 
     block_OA.addChild(sfac.createOMText(OA)); 

     SOAPHeaderBlock block_FA = sfac.createSOAPHeaderBlock(SOAPHEADER_FA, omNs); 
     block_FA.addChild(sfac.createOMText(FA)); 

     block_RequestSOAPHeader.addChild(block_spId); 
     block_RequestSOAPHeader.addChild(block_spPassword); 
     block_RequestSOAPHeader.addChild(block_serviceId); 
     block_RequestSOAPHeader.addChild(block_timeStamp); 
     block_RequestSOAPHeader.addChild(block_linkId); 
     block_RequestSOAPHeader.addChild(block_OA); 
     block_RequestSOAPHeader.addChild(block_FA); 


     /* 
     * 
     * <soapenv:Header> 
     * <ns1:RequestSOAPHeader xmlns:ns1="http://www.xxxxxxxx.xxxxxx.xxxxxx/common/v2_1"> 
     *  <ns1:spId>your spid</tns:spId> 
     *  <ns1:spPassword>your password</tns:spPassword> 
     *  <ns1:timeStamp>your timestamp</tns:timeStamp> 
     *  <ns1:linkId>your linkid</tns:linkId> 
     *  <ns1:OA>tel:your msisdn1</tns:OA> 
     *  <ns1:FA>tel:msisdn1</tns:FA> 
     * </ns1:RequestSOAPHeader> 
     * </soapenv:Header> 
     */ 

     serviceClient.addHeader(block_RequestSOAPHeader); 
+0

如果您已添加標題,您可以請發佈答案,我也有同樣的問題。 – Azhar

+0

請指明您的意思,上面的代碼將在您的SOAPMessage中添加頭文件,執行時面臨什麼問題?你在用軸嗎? –