This topic provides an example of how to create and return a SOAP fault message from a GatewayFilter.filterResponse method.
Before you begin
Example
public FilterAction filterResponse(WSIFRequest wsifRequest, WSIFResponse wsifResponse) throws FilterException, WSGWException, RemoteException { // Construct the fault message WSIFMessage faultMessage = new WSIFDefaultMessage(); faultMessage.setObjectPart(WSIFConstants.SOAP_FAULT_ACTOR,"mySoapFaultActor"); faultMessage.setObjectPart(WSIFConstants.SOAP_FAULT_CODE,"mySoapFaultCode"); faultMessage.setObjectPart(WSIFConstants.SOAP_FAULT_STRING,"mySoapFaultString"); faultMessage.setObjectPart("stackTrace","myStackTraceDetails"); faultMessage.setObjectPart("otherDetails","myOtherDetails"); // repeat faultMessage.setObjectPart("aaaa","bbbb"); // for each additional detail element // Set the fault message into the wsifResponse object wsifResponse.setFaultMessage(faultMessage); wsifResponse.setIsFault(true); // Return the updated response in the filterAction object FilterAction filterAction = new FilterAction(); filterAction.setUpdatedResponse(wsifResponse); filterAction.setContinueProcessing(false); return filterAction; }
The previous example works with both the Apache SOAP and
the SOAP over HTTP channels. If you use the SOAP over HTTP channel,
the previous example returns the following SOAP fault response:
<?xml version="1.0" encoding="UTF-8"?> <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <soapenv:Body> <soapenv:Fault> <faultcode xmlns:ns1="http://xml.apache.org/axis/">ns1:mySoapFaultCode</faultcode> <faultstring>mySoapFaultString</faultstring> <faultactor>mySoapFaultActor</faultactor> <detail> <stackTrace>myStackTraceDetails</stackTrace> <otherDetails>myOtherDetails</otherDetails> </detail> </soapenv:Fault> </soapenv:Body> </soapenv:Envelope>