2017-11-27 23 views
1

유효한 비누 요청 (wsimport를 통해 생성 된 클래스)에 대한 요청 및 응답을 성공적으로 기록 할 수 있지만 예외가 발생하면 (요청의 노드가 유효하지 않은 데이터로 채워질 때) XML 내용을 캡처 할 수 없습니다. 응답의 세부 사항을 얻을 수 있지만 원시 응답의 xml 부분 만 캡처하려고합니다. SOAPFaultException 시도했다 그러나 그 예외/오류가 throw 된 XML 콘텐츠를 사용하여 예외를 캡처 할 response.How 본문 전체 봉투 대신 메시지 대신 예외 만 제공합니다.요청에 잘못된 데이터에 대한 비누 오류 응답을 캡처하는 방법은 무엇입니까?

참고 : 오류 (원시 응답)를 구문 분석하고 XML 콘텐츠를 가져올 수 있지만 아래의 XML 콘텐츠를 가져 오는 간단한 방법/방법이 있는지 궁금합니다. 내용은 (비누 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; 
    } 

이렇게하면 HTTP 헤더뿐만 아니라 형식이 지정된 xml로 오류 정보가 표시됩니다.