Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jonashackt/5282a1fdc263da6951fd to your computer and use it in GitHub Desktop.
Save jonashackt/5282a1fdc263da6951fd to your computer and use it in GitHub Desktop.
Apache CXF Interceptor for Custom SoapFaults
public class WeatherServiceXmlValidationInterceptor extends AbstractSoapInterceptor {
//...
public WeatherServiceXmlValidationInterceptor() {
super(Phase.PRE_STREAM);
}
@Override
public void handleMessage(SoapMessage soapMessage) throws Fault {
Fault fault = (Fault) soapMessage.getContent(Exception.class);
Throwable faultCause = fault.getCause();
String faultMessage = fault.getMessage();
if (containsFaultIndicatingNotSchemeCompliantXml(faultCause, faultMessage)) {
LOGGER.debug(FaultConst.SCHEME_VALIDATION_ERROR.getMessage() + ": {}", faultMessage);
WeatherSoapFaultHelper.buildWeatherFaultAndSet2SoapMessage(soapMessage, FaultConst.SCHEME_VALIDATION_ERROR);
}
if (containsFaultIndicatingSyntacticallyIncorrectXml(faultCause, faultMessage)) {
LOGGER.debug(FaultConst.SYNTACTICALLY_INCORRECT_XML_ERROR.getMessage() + ": {}", faultMessage);
WeatherSoapFaultHelper.buildWeatherFaultAndSet2SoapMessage(soapMessage, FaultConst.SYNTACTICALLY_INCORRECT_XML_ERROR);
}
}
//...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment