2017-01-12 73 views
0

私はSOAP URLをテストしようとしています。しかし、私は石鹸リクエストを送信するたびに質問に記載されているようにエラー応答を得ています。示すように私のコードは次のとおりです。レスポンスのスローエラー:サーバーがHTTPヘッダーSOAPActionの値を認識しませんでした

public static void main(String[] args) { 
    try { 
     SOAPConnectionFactory sfc = SOAPConnectionFactory.newInstance(); 
     SOAPConnection connection = sfc.createConnection(); 

     MessageFactory mf = MessageFactory.newInstance(); 
     SOAPMessage sm = mf.createMessage(); 
     SOAPPart soapPart = sm.getSOAPPart(); 

     // SOAP Envelope 
     SOAPEnvelope envelope = soapPart.getEnvelope(); 
     envelope.addNamespaceDeclaration("xsi", "http://www.w3.org/2001/XMLSchema-instance"); 
     envelope.addNamespaceDeclaration("xsd", "http://www.w3.org/2001/XMLSchema"); 

     SOAPHeader sh = sm.getSOAPHeader(); 
     SOAPBody sb = sm.getSOAPBody(); 
     sh.detachNode(); 
     QName postageLabelXML = new QName("www.envmgr.com/LabelService", "GetPostageLabelXML"); 

     SOAPBodyElement bodyElement = sb.addBodyElement(postageLabelXML); 
     QName qn = new QName("LabelRequestXML"); 
     SOAPElement quotation = bodyElement.addChildElement(qn); 
     QName qnLabelRequest = new QName("LabelRequest"); 
     SOAPElement qnLabelRequestQuotation = quotation.addChildElement(qnLabelRequest); 

     MimeHeaders mimeHeaders = sm.getMimeHeaders(); 
     mimeHeaders.addHeader("Host", "https://elstestserver.endicia.com"); 
     mimeHeaders.addHeader("Content-Length", "65536"); 
     mimeHeaders.addHeader("Content-Type", "text/xml; charset=utf-8"); 
     mimeHeaders.addHeader("SOAPAction", "http://www.envmgr.com/LabelService/GetPostageLabelXML"); 

     System.out.println("\n Soap Request:\n"); 
     sm.writeTo(System.out); 
     System.out.println(); 

     URL endpoint = new URL("https://elstestserver.endicia.com/LabelService/EwsLabelService.asmx"); 
     SOAPMessage response = connection.call(sm, endpoint); 
     ByteArrayOutputStream out = new ByteArrayOutputStream(); 
     response.writeTo(out); 
     String strMsg = new String(out.toByteArray()); 
     System.out.println(response.getContentDescription()); 
     System.out.println("xml -= " + strMsg); 
    } catch (Exception ex) { 
     ex.printStackTrace(); 
    } 
} 

上記のコードは要求として、次のXML生成:

<?xml version="1.0" encoding="UTF-8"?> 
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 
    <SOAP-ENV:Body> 
     <GetPostageLabelXML xmlns="www.envmgr.com/LabelService"> 
     <LabelRequestXML> 
      <LabelRequest /> 
     </LabelRequestXML> 
     </GetPostageLabelXML> 
    </SOAP-ENV:Body> 
</SOAP-ENV:Envelope> 

を必要なXMLは次のとおりです。この中には現在約2時間を過ごした後

POST /LabelService/EwsLabelService.asmx HTTP/1.1 
Host: elstestserver.endicia.com 
Content-Type: text/xml; charset=utf-8 
Content-Length: length 
SOAPAction: "www.envmgr.com/LabelService/GetPostageLabelXML" 

<?xml version="1.0" encoding="utf-8"?> 
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> 
    <soap:Body> 
    <GetPostageLabelXML xmlns="www.envmgr.com/LabelService"> 
     <LabelRequestXML> 
     <LabelRequest>...some xml </LabelRequest> 
     </LabelRequestXML> 
    </GetPostageLabelXML> 
    </soap:Body> 
</soap:Envelope> 

問題私はこのエラー応答の背後にある本当の問題を推測できません:

<?xml version="1.0" encoding="UTF-8"?> 
    <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"  xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 
     <soap:Body> 
      <soap:Fault> 
       <faultcode>soap:Client</faultcode> 
       <faultstring>Server did not recognize the value of HTTP Header SOAPAction: .</faultstring> 
      <detail /> 
      </soap:Fault> 
     </soap:Body> 
    </soap:Envelope> 

このコードに誤りがある場合は、教えてください。

答えて

0

私が追加された 'のhttp://' を追加しました://サフィックス私は、HTTPを削除する場合それはうまく働いた私の

mimeHeaders.addHeader("SOAPAction", "http://www.envmgr.com/LabelService/GetPostageLabelXML"); 

に。変更された行は

mimeHeaders.addHeader("SOAPAction", "www.envmgr.com/LabelService/GetPostageLabelXML");