2017-11-27 8 views
1

有効なSOAPリクエスト(wsimportによって生成されたクラス)の要求と応答を正常に記録できますが、例外がスローされたとき(要求のノードが無効なデータで埋められている場合)私は応答の詳細を得ることができましたが、私は生の応答のxml部分だけをキャプチャしたいと思います。私はSOAPFaultExceptionを試してみましたが、例外メッセージではなく、response.Howの本文を持つ完全なエンベロープだけが例外/エラーがスローされたXMLコンテンツで例外を捕捉します。リクエスト中の無効なデータに対するSOAPエラー応答をキャプチャする方法はありますか?

注:私はエラー(生の応答)を解析してxmlコンテンツを取得できることを知っていますが、以下のようなxmlコンテンツを取得する簡単な方法/方法があるかどうかは疑問です。コンテンツはより多くのを探索し、しようとした後(SOAP UIツールから捕捉応答)

<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing"> 
    <env:Header xmlns:env="http://www.w3.org/2003/05/soap-envelope"> 
     <wsa:Action>http://schemas.xmlsoap.org/ws/2004/08/addressing/fault</wsa:Action> 
     <wsa:MessageID>urn:uuid:xyz</wsa:MessageID> 
     <wsa:RelatesTo>urn:uuid:xyz</wsa:RelatesTo> 
     <wsa:To>http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous</wsa:To> 
    </env:Header> 
    <soap:Body> 
     <soap:Fault> 
     <soap:Code> 
      <soap:Value>soap:Sender</soap:Value> 
     </soap:Code> 
     <soap:Reason> 
      <soap:Text xml:lang="en">The 'http://www.fakexyz.com/schemas/xyz:xyz' element is invalid - The value '123' is invalid according to its datatype 'String' - The Pattern constraint failed. 
Please revise your data fields and make sure that message is correctly formatted.</soap:Text> 
     </soap:Reason> 
     <detail> 
      <faulttype>Schema</faulttype> 
     </detail> 
     </soap:Fault> 
    </soap:Body> 
</soap:Envelope> 

答えて

0

のようになります、私は、これはあなたが必要だったものをほとんど与え、我々はSoapHandlerインタフェースを実装する必要があり、クラスを持っている必要があることがわかりました。 以下のようにhandleFaultメソッドをオーバーライドしました。

public boolean handleFault(SOAPMessageContext context) { 
     System.out.println("==============================================RESPONSE(ERROR)=======================================\r\n"); 

     String[] abc= context.get(MessageContext.HTTP_RESPONSE_HEADERS).toString().split("],"); 

     for(String httpheader:abc) { 
      System.out.println(httpheader+"],"); 
     } 

     System.out.println("\r\n"); 

     SOAPMessage message= context.getMessage();     
     try {           
      Source source = message.getSOAPPart().getContent();    
      Transformer transformer = TransformerFactory.newInstance().newTransformer();    
      transformer.setOutputProperty(OutputKeys.INDENT, "yes"); 
      transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "3");             
      transformer.transform(source, new StreamResult(System.out)); 

     } catch (Exception e) {    
       System.out.println("Response has errors!!"); 
      } 
     return false; 
    } 

これは、フォーマットされたxmlとhttpヘッダーでエラー情報を表示しました。

関連する問題