private String getMessageValueIfThere(Fault exceptionFault) { if(exceptionFault.getMessage() != null) { return exceptionFault.getMessage(); } return UNKNOWN_ERROR; }
Client client = ClientBuilder.newBuilder(); WebTarget target = client.target(url); Response response = target.request.accept(MediaType.APPLICATION_XML).get(); Fault fault = response.readEntity(Fault.class); String message = fault.getMessage();
final String faultMessage = fault.getMessage();
public class CustomSoapFaultOutInterceptor extends AbstractSoapInterceptor { private static final Log logger = LogFactory.getLog(CustomSoapFaultOutInterceptor.class); public CustomSoapFaultOutInterceptor() { super(Phase.MARSHAL); getAfter().add(Soap11FaultOutInterceptor.class.getName()); } @Override public void handleMessage(SoapMessage message) throws Fault { Fault fault = (Fault) message.getContent(Exception.class); logger.error(fault.getMessage(), fault); //delete the Mule Exception to have the one throw by the component in the SoapMessage Throwable t = getOriginalCause(fault.getCause()); fault.setMessage(t.getMessage()); } private Throwable getOriginalCause(Throwable t) { if (t.getCause() == null || t.getCause().equals(t)) return t; else return getOriginalCause(t.getCause()); } } //And then this into mule-config. <cxf:jaxws-service> <cxf:outFaultInterceptors> <spring:bean class="is.tr.mule.interceptor.CustomSoapFaultOutInterceptor"/> </cxf:outFaultInterceptors> </cxf:jaxws-service>
public static XMLFault createFault(Fault f) { if (f instanceof XMLFault) { return (XMLFault) f; } Throwable th = f.getCause(); XMLFault xmlFault = new XMLFault(new Message(f.getMessage(), (ResourceBundle) null), th); xmlFault.setDetail(f.getDetail()); return xmlFault; }
private Object handleFault(Fault ex, Message inMessage, ClassResourceInfo cri, Method methodToInvoke) { String errorMessage = ex.getMessage(); if (errorMessage != null && cri != null && errorMessage.contains(PROXY_INVOCATION_ERROR_FRAGMENT)) { org.apache.cxf.common.i18n.Message errorM = new org.apache.cxf.common.i18n.Message("PROXY_INVOCATION_FAILURE", BUNDLE, methodToInvoke, cri.getServiceClass().getName()); LOG.severe(errorM.toString()); } Response excResponse = JAXRSUtils.convertFaultToResponse(ex.getCause() == null ? ex : ex.getCause(), inMessage); if (excResponse == null) { inMessage.getExchange().put(Message.PROPOGATE_EXCEPTION, ExceptionUtils.propogateException(inMessage)); throw ex; } return new MessageContentsList(excResponse); }
public static JbiFault createFault(Fault f) { if (f instanceof JbiFault) { return (JbiFault) f; } Throwable th = f.getCause(); JbiFault jbiFault = new JbiFault(new Message(f.getMessage(), (ResourceBundle) null), th); jbiFault.setDetail(f.getDetail()); return jbiFault; }
public static void buildWeatherFaultAndSet2SoapMessage(SoapMessage message, FaultConst faultContent) { Fault exceptionFault = (Fault) message.getContent(Exception.class); String originalFaultMessage = exceptionFault.getMessage(); exceptionFault.setMessage(faultContent.getMessage()); exceptionFault.setDetail(createFaultDetailWithWeatherException(originalFaultMessage, faultContent)); message.setContent(Exception.class, exceptionFault); }
public static NMRFault createFault(Fault f) { if (f instanceof NMRFault) { return (NMRFault) f; } Throwable th = f.getCause(); NMRFault jbiFault = new NMRFault(new Message(f.getMessage(), (ResourceBundle) null), th); jbiFault.setDetail(f.getDetail()); return jbiFault; }
public static JBIFault createFault(Fault f) { if (f instanceof JBIFault) { return (JBIFault) f; } Throwable th = f.getCause(); JBIFault jbiFault = new JBIFault(new Message(f.getMessage(), (ResourceBundle) null), th); jbiFault.setDetail(f.getDetail()); return jbiFault; }
public static void buildWeatherFaultAndSet2SoapMessage(SoapMessage message, FaultConst faultContent) { Fault exceptionFault = (Fault) message.getContent(Exception.class); String originalFaultMessage = exceptionFault.getMessage(); exceptionFault.setMessage(faultContent.getMessage()); exceptionFault.setDetail(createFaultDetailWithWeatherException(originalFaultMessage, faultContent)); message.setContent(Exception.class, exceptionFault); }
public static XMLFault createFault(Fault f) { if (f instanceof XMLFault) { return (XMLFault) f; } Throwable th = f.getCause(); XMLFault xmlFault = new XMLFault(new Message(f.getMessage(), (ResourceBundle) null), th); xmlFault.setDetail(f.getDetail()); return xmlFault; }
private MuleException wrapException(MuleEvent event, Throwable ex, boolean alwaysReturnMessagingException) { if (ex instanceof MessagingException) { return (MessagingException) ex; } if (ex instanceof Fault) { // Because of CXF API, MuleExceptions can be wrapped in a Fault, in that case we should return the mule exception Fault fault = (Fault) ex; if(fault.getCause() instanceof MuleException) { MuleException muleException = (MuleException) fault.getCause(); return alwaysReturnMessagingException ? new MessagingException(event, muleException, this) : muleException; } return new DispatchException(MessageFactory.createStaticMessage(fault.getMessage()), event, this, fault); } return new DispatchException(MessageFactory.createStaticMessage(ExceptionHelper.getRootException(ex).getMessage()), event, this, ex); }
fc = v.getReceiver(); SoapFault soapFault = new SoapFault(new Message(f.getMessage(), (ResourceBundle)null), f.getCause(), fc);
fc = v.getReceiver(); SoapFault soapFault = new SoapFault(new Message(f.getMessage(), (ResourceBundle)null), f.getCause(), fc);
@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)) { LOG.schemaValidationError(FaultConst.SCHEME_VALIDATION_ERROR, faultMessage); WeatherSoapFaultHelper.buildWeatherFaultAndSet2SoapMessage(soapMessage, FaultConst.SCHEME_VALIDATION_ERROR); } else if (containsFaultIndicatingSyntacticallyIncorrectXml(faultCause)) { LOG.schemaValidationError(FaultConst.SYNTACTICALLY_INCORRECT_XML_ERROR, faultMessage); WeatherSoapFaultHelper.buildWeatherFaultAndSet2SoapMessage(soapMessage, FaultConst.SYNTACTICALLY_INCORRECT_XML_ERROR); } }
@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)) { LOG.schemaValidationError(FaultConst.SCHEME_VALIDATION_ERROR, faultMessage); WeatherSoapFaultHelper.buildWeatherFaultAndSet2SoapMessage(soapMessage, FaultConst.SCHEME_VALIDATION_ERROR); } else if (containsFaultIndicatingSyntacticallyIncorrectXml(faultCause)) { LOG.schemaValidationError(FaultConst.SYNTACTICALLY_INCORRECT_XML_ERROR, faultMessage); WeatherSoapFaultHelper.buildWeatherFaultAndSet2SoapMessage(soapMessage, FaultConst.SYNTACTICALLY_INCORRECT_XML_ERROR); } }
private Object handleFault(Fault ex, Message inMessage, ClassResourceInfo cri, Method methodToInvoke) { String errorMessage = ex.getMessage(); if (errorMessage != null && cri != null && errorMessage.contains(PROXY_INVOCATION_ERROR_FRAGMENT)) { org.apache.cxf.common.i18n.Message errorM = new org.apache.cxf.common.i18n.Message("PROXY_INVOCATION_FAILURE", BUNDLE, methodToInvoke, cri.getServiceClass().getName()); LOG.severe(errorM.toString()); } Response excResponse = JAXRSUtils.convertFaultToResponse(ex.getCause(), inMessage); if (excResponse == null) { ProviderFactory.getInstance(inMessage).clearThreadLocalProxies(); ClassResourceInfo criRoot = (ClassResourceInfo)inMessage.getExchange().get(JAXRSUtils.ROOT_RESOURCE_CLASS); if (criRoot != null) { criRoot.clearThreadLocalProxies(); } inMessage.getExchange().put(Message.PROPOGATE_EXCEPTION, ExceptionUtils.propogateException(inMessage)); throw ex; } return new MessageContentsList(excResponse); }
private Object[] invoke(SoapRequest request, Exchange exchange, MessageDispatcher dispatcher) { String operation = request.getOperation(); XMLStreamReader xmlBody = getXmlBody(request); try { Map<String, Object> ctx = getInvocationContext(request, dispatcher); return client.invoke(getInvocationOperation(), new Object[] {xmlBody}, ctx, exchange); } catch (SoapFault sf) { throw new SoapFaultException(sf.getFaultCode(), sf.getSubCode(), parseExceptionDetail(sf.getDetail()).orElse(null), sf.getReason(), sf.getNode(), sf.getRole(), sf); } catch (Fault f) { if (f.getMessage().contains("COULD_NOT_READ_XML")) { throw new BadRequestException("Error consuming the operation [" + operation + "], the request body is not a valid XML"); } throw new SoapFaultException(f.getFaultCode(), parseExceptionDetail(f.getDetail()).orElse(null), f); } catch (DispatchingException e) { throw e; } catch (OperationNotFoundException e) { String location = wsdlModel.getLocation(); throw new BadRequestException("The provided [" + operation + "] does not exist in the WSDL file [" + location + "]", e); } catch (Exception e) { throw new SoapServiceException("Unexpected error while consuming the web service operation [" + operation + "]", e); } }
@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)) { LOG.schemaValidationError(FaultType.SCHEME_VALIDATION_ERROR, faultMessage); soapFaultBuilder.buildCustomFaultAndSet2SoapMessage(soapMessage, FaultType.SCHEME_VALIDATION_ERROR); } else if (containsFaultIndicatingSyntacticallyIncorrectXml(faultCause)) { LOG.schemaValidationError(FaultType.SYNTACTICALLY_INCORRECT_XML_ERROR, faultMessage); soapFaultBuilder.buildCustomFaultAndSet2SoapMessage(soapMessage, FaultType.SYNTACTICALLY_INCORRECT_XML_ERROR); } else if(someOtherErrorOccured(faultCause)) { // Some other Error occured, we don´t know. But we want to react with a Custom Error-Message LOG.errorOccuredInBackendProcessing(faultCause); soapFaultBuilder.buildCustomFaultAndSet2SoapMessage(soapMessage, FaultType.BACKEND_PROCESSING_FAILED); } }