SoapFaultResponseInterceptor extends AbstractSoapInterceptor { @Override public void handleMessage(SoapMessage message) throws Fault { Fault f = (Fault) message.getContent(Exception.class); if (f == null) { return; } Throwable cause = f.getCause(); if (cause == null) { return; } f.setStatusCode(HTTP_OK_CODE); if (isClientException(cause)) { f.setFaultCode(new QName("Client")); } } SoapFaultResponseInterceptor(); @Override void handleMessage(SoapMessage message);  }
@Test public void whenSoapFaultHasNoCauseThenFaultStatusAndCodeRemainUnchanged() { Fault fault = mock(Fault.class); doReturn(null).when(fault).getCause(); doReturn(fault).when(message).getContent(any()); soapFaultResponseInterceptor.handleMessage(message); verify(fault).getCause(); verifyNoMoreInteractions(fault); }
@Test public void whenSoapFaultIsCausedByMalformedDocumentExceptionThenFaultStatusAndCodeAreChanged() { Fault fault = new Fault(new MalformedDocumentException()); doReturn(fault).when(message).getContent(any()); soapFaultResponseInterceptor.handleMessage(message); assertTrue(fault.getStatusCode() == 200); assertEquals("Client", fault.getFaultCode().toString()); }
@Test public void whenSoapFaultIsCausedByDocumentRequirementsExceptionThenFaultStatusAndCodeAreChanged() { Fault fault = new Fault(new DocumentRequirementsException()); doReturn(fault).when(message).getContent(any()); soapFaultResponseInterceptor.handleMessage(message); assertTrue(fault.getStatusCode() == 200); assertEquals("Client", fault.getFaultCode().toString()); }
@Test public void whenSoapFaultIsCausedByInvalidPolicyExceptionThenFaultStatusAndCodeAreChanged() { Fault fault = new Fault(new InvalidPolicyException("")); doReturn(fault).when(message).getContent(any()); soapFaultResponseInterceptor.handleMessage(message); assertTrue(fault.getStatusCode() == 200); assertEquals("Client", fault.getFaultCode().toString()); }
@Test public void whenSoapFaultIsCausedByUnmarshalExceptionThenFaultStatusAndCodeAreChanged() { Fault fault = new Fault(new UnmarshalException("Some message..")); doReturn(fault).when(message).getContent(any()); soapFaultResponseInterceptor.handleMessage(message); assertTrue(fault.getStatusCode() == 200); assertEquals("Client", fault.getFaultCode().toString()); }
@Test public void whenSoapFaultIsCausedByRESTValidationProxyRequestExceptionWithBadRequestStatusCodeThenFaultStatusAndCodeAreChanged() { Fault fault = new Fault(new RESTValidationProxyRequestException(null, null, HttpStatus.BAD_REQUEST)); doReturn(fault).when(message).getContent(any()); soapFaultResponseInterceptor.handleMessage(message); assertTrue(fault.getStatusCode() == 200); assertEquals("Client", fault.getFaultCode().toString()); }