当调用 SOAPHandler 的handleFault(SOAPMessageContext context)方法时,任何人都可以解释一下吗? 我的处理程序类是
public class WebServiceHandler implements SOAPHandler<SOAPMessageContext> {
private void dumpSOAPMessage(SOAPMessage msg) {
if (msg == null) {
System.out.println("SOAP Message is null");
return;
}
System.out.println("");
System.out.println("--------------------");
System.out.println("DUMP OF SOAP MESSAGE");
System.out.println("--------------------");
try {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
msg.writeTo(baos);
System.out.println(baos.toString(getMessageEncoding(msg)));
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
public boolean handleMessage(SOAPMessageContext context) {
try {
dumpSOAPMessage(((SOAPMessageContext) context).getMessage());
} catch (Exception e) {
e.printStackTrace();
}
return true;
}
@Override
public boolean handleFault(SOAPMessageContext context) {
// TODO Auto-generated method stub
System.out.println("Inside handle fault:: " + context);
return true;
}
@Override
public void close(MessageContext context) {
// TODO Auto-generated method stub
}
@Override
public Set<QName> getHeaders() {
Set<QName> set = new HashSet<QName>();
return set;
} }
可以解释何时调用handleMessage和handleFault方法......?
答案 0 :(得分:2)
根据:http://docs.oracle.com/cd/E13222_01/wls/docs103/webserv_adv/handlers.html#wp222524
handleMessage:
调用Handler.handleMessage()方法来拦截SOAP 消息请求在后端处理之前和之后 成分
和
handleFault:
实现此方法以处理任何SOAP错误的处理 由handleMessage()方法生成,以及生成的错误 由后端组件。
答案 1 :(得分:1)
美好的一天
最近也遇到了这个问题,但没有找到任何正常答案
方法为您处理故障(2年后)
@Override
public boolean handleFault(SOAPMessageContext context) {
SOAPMessage message = context.getMessage();
SOAPBody body = message.getSOAPBody();
SOAPFault fault = body.getFault();
String code = fault.getFaultCode();
String faultString = fault.getFaultString();
Detail detail = fault.getDetail();
if(detail!=null){
Iterator<SOAPElement> iter = detail.getChildElements();
//Getting first level of detail
HashMap<String, String> detailMap = new HashMap<String, String>();
while(iter.hasNext()){
SOAPElement element = iter.next();
detailMap.put(element.getLocalName(), element.getValue());
}
//Logging or whatever
}
}
return true;
}