I am getting the following exception intermittently when the web service returns a fault.
faultCode argument for createFault was passed NULL
com.sun.xml.messaging.saaj.soap.ver1_1.SOAPFactory1_1Impl.createFault(SOAPFactory1_1Impl.java:87)
com.sun.xml.ws.fault.SOAP11Fault.getProtocolException(SOAP11Fault.java:179)
com.sun.xml.ws.fault.SOAPFaultBuilder.createException(SOAPFaultBuilder.java:108)
com.sun.xml.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:119)
com.sun.xml.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:89)
com.sun.xml.ws.client.sei.SEIStub.invoke(SEIStub.java:118)
I found the following link and it looks like a JAX-WS bug.
http://forums.java.net/node/675759
So, I added the following code in my client side handler.
public boolean handleFault(SOAPMessageContext smc) {
logger.info("Inside handleFault");
SOAPMessage message = smc.getMessage();
logger.info("Inbound
SOAP Message with Fault: ");
printSOAPMessageToLogger(message);
try{
QName fqn = message.getSOAPBody().getFault().getFaultCodeAsQName();
String namespace = fqn.getNamespaceURI();
logger.info("fault namespace: " + namespace);
if (namespace == null || namespace.length() == 0){
logger.info("missing namespace in soap fault: " );
namespace = "http://schemas.xmlsoap.org/soap/envelope/";
QName newFqn = new QName(namespace , fqn.getLocalPart());
smc.getMessage().getSOAPBody().getFault().setFaultCode(newFqn);
}
}catch (Exception ex) {
logger.error("Cannot modify Soap Fault: " , ex);
}
return true;
}
I have 2 questions.
1) In the above code, is it correct to set the fault namespace to
http://schemas.xmlsoap.org/soap/envelope/? I read it somewhere else that SOAP fault should have an empty namespace. Is this correct?
2) I am getting a NullPointerException in the line that has the code when fault is returned by the web service.
message.getSOAPBody().getFault().getFaultCodeAsQName();
I would appreciate if someone can help me. Thanks in advance.