1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
|
public boolean handleRequest(MessageContext context) {
...
String faultStr = "Error when checking credential";
String faultCode = "faultCode";
if(userCredential == null){
soapMsgCtx.setProperty(FAULT_STR, faultStr);
soapMsgCtx.setProperty(FAULT_CODE, faultCode);
}
Credential credential = new Credential(userCredential);
if(credential != null){
try{
if(credential.isSecurityNeeded(userCredential)){
WebServiceSecurityManager.checkWSSecurity((SOAPMessageContext) context, credential);
}
} catch (Exception ex) {
soapMsgCtx.setProperty(FAULT_STR, faultStr);
soapMsgCtx.setProperty(FAULT_CODE, faultCode);
logger.logError("", faultStr, ex, ex.getMessage());
//throw new SOAPException("Error when checking credential");
throw new SOAPFaultException(null, faultStr, null, null);
}
}...
}
public boolean handleFault(MessageContext context) {
if (context instanceof SOAPMessageContext) {
try {
SOAPMessageContext soapMsgCtx = (SOAPMessageContext)context;
SOAPMessage soapMsg = soapMsgCtx.getMessage();
if (soapMsg == null) {
MessageFactory messageFactory = MessageFactory.newInstance();
soapMsg = messageFactory.createMessage();
soapMsgCtx.setMessage(soapMsg);
}
SOAPFault soapFault = soapMsg.getSOAPPart().getEnvelope().getBody().addFault();
String faultStr = (String)soapMsgCtx.getProperty(FAULT_STR);
String faultCode = (String)soapMsgCtx.getProperty(FAULT_CODE);
soapFault.setFaultString(faultStr);
soapFault.setFaultCode(faultCode);
} catch (Exception ex) {
throw new JAXRPCException();
}
}
return true;
} |
Partager