SoapFaultMappingExceptionResolver extends AbstractSoapFaultDefinitionExceptionResolver { public void setExceptionMappings(Properties mappings) { for (Map.Entry<Object, Object> entry : mappings.entrySet()) { if (entry.getKey() instanceof String && entry.getValue() instanceof String) { exceptionMappings.put((String) entry.getKey(), (String) entry.getValue()); } } }  void setExceptionMappings(Properties mappings);  }
@Test public void testResolveExceptionClientSoap11() throws Exception { Properties mappings = new Properties(); mappings.setProperty(Exception.class.getName(), "SERVER, Server error"); mappings.setProperty(RuntimeException.class.getName(), "CLIENT, Client error"); resolver.setExceptionMappings(mappings); MessageFactory messageFactory = MessageFactory.newInstance(SOAPConstants.SOAP_1_1_PROTOCOL); SOAPMessage message = messageFactory.createMessage(); SoapMessageFactory factory = new SaajSoapMessageFactory(messageFactory); MessageContext context = new DefaultMessageContext(new SaajSoapMessage(message), factory); boolean result = resolver.resolveException(context, null, new IllegalArgumentException("bla")); Assert.assertTrue("resolveException returns false", result); Assert.assertTrue("Context has no response", context.hasResponse()); SoapMessage response = (SoapMessage) context.getResponse(); Assert.assertTrue("Response has no fault", response.getSoapBody().hasFault()); Soap11Fault fault = (Soap11Fault) response.getSoapBody().getFault(); Assert.assertEquals("Invalid fault code on fault", SoapVersion.SOAP_11.getClientOrSenderFaultName(), fault.getFaultCode()); Assert.assertEquals("Invalid fault string on fault", "Client error", fault.getFaultStringOrReason()); Assert.assertNull("Detail on fault", fault.getFaultDetail()); }
@Test public void testResolveExceptionSenderSoap12() throws Exception { Properties mappings = new Properties(); mappings.setProperty(Exception.class.getName(), "RECEIVER, Receiver error, en"); mappings.setProperty(RuntimeException.class.getName(), "SENDER, Sender error, en"); resolver.setExceptionMappings(mappings); MessageFactory messageFactory = MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL); SOAPMessage message = messageFactory.createMessage(); SoapMessageFactory factory = new SaajSoapMessageFactory(messageFactory); MessageContext context = new DefaultMessageContext(new SaajSoapMessage(message), factory); boolean result = resolver.resolveException(context, null, new IllegalArgumentException("bla")); Assert.assertTrue("resolveException returns false", result); Assert.assertTrue("Context has no response", context.hasResponse()); SoapMessage response = (SoapMessage) context.getResponse(); Assert.assertTrue("Response has no fault", response.getSoapBody().hasFault()); Soap12Fault fault = (Soap12Fault) response.getSoapBody().getFault(); Assert.assertEquals("Invalid fault code on fault", SoapVersion.SOAP_12.getClientOrSenderFaultName(), fault.getFaultCode()); Assert.assertEquals("Invalid fault string on fault", "Sender error", fault.getFaultReasonText(Locale.ENGLISH)); Assert.assertNull("Detail on fault", fault.getFaultDetail()); }
@Test public void testResolveExceptionServerSoap11() throws Exception { Properties mappings = new Properties(); mappings.setProperty(Exception.class.getName(), "CLIENT, Client error"); mappings.setProperty(RuntimeException.class.getName(), "SERVER, Server error"); resolver.setExceptionMappings(mappings); MessageFactory messageFactory = MessageFactory.newInstance(SOAPConstants.SOAP_1_1_PROTOCOL); SOAPMessage message = messageFactory.createMessage(); SoapMessageFactory factory = new SaajSoapMessageFactory(messageFactory); MessageContext context = new DefaultMessageContext(new SaajSoapMessage(message), factory); boolean result = resolver.resolveException(context, null, new IllegalArgumentException("bla")); Assert.assertTrue("resolveException returns false", result); Assert.assertTrue("Context has no response", context.hasResponse()); SoapMessage response = (SoapMessage) context.getResponse(); Assert.assertTrue("Response has no fault", response.getSoapBody().hasFault()); Soap11Fault fault = (Soap11Fault) response.getSoapBody().getFault(); Assert.assertEquals("Invalid fault code on fault", SoapVersion.SOAP_11.getServerOrReceiverFaultName(), fault.getFaultCode()); Assert.assertEquals("Invalid fault string on fault", "Server error", fault.getFaultStringOrReason()); Assert.assertNull("Detail on fault", fault.getFaultDetail()); }
@Test public void testResolveExceptionReceiverSoap12() throws Exception { Properties mappings = new Properties(); mappings.setProperty(Exception.class.getName(), "SENDER, Sender error"); mappings.setProperty(RuntimeException.class.getName(), "RECEIVER, Receiver error"); resolver.setExceptionMappings(mappings); MessageFactory messageFactory = MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL); SOAPMessage message = messageFactory.createMessage(); SoapMessageFactory factory = new SaajSoapMessageFactory(messageFactory); MessageContext context = new DefaultMessageContext(new SaajSoapMessage(message), factory); boolean result = resolver.resolveException(context, null, new IllegalArgumentException("bla")); Assert.assertTrue("resolveException returns false", result); Assert.assertTrue("Context has no response", context.hasResponse()); SoapMessage response = (SoapMessage) context.getResponse(); Assert.assertTrue("Response has no fault", response.getSoapBody().hasFault()); Soap12Fault fault = (Soap12Fault) response.getSoapBody().getFault(); Assert.assertEquals("Invalid fault code on fault", SoapVersion.SOAP_12.getServerOrReceiverFaultName(), fault.getFaultCode()); Assert.assertEquals("Invalid fault string on fault", "Receiver error", fault.getFaultReasonText(Locale.ENGLISH)); Assert.assertNull("Detail on fault", fault.getFaultDetail()); }
@Test public void testResolveExceptionDefault() throws Exception { Properties mappings = new Properties(); mappings.setProperty(SoapMessageException.class.getName(), "SERVER,Server error"); resolver.setExceptionMappings(mappings); SoapFaultDefinition defaultFault = new SoapFaultDefinition(); defaultFault.setFaultCode(SoapFaultDefinition.CLIENT); resolver.setDefaultFault(defaultFault); MessageFactory messageFactory = MessageFactory.newInstance(SOAPConstants.SOAP_1_1_PROTOCOL); SOAPMessage message = messageFactory.createMessage(); SoapMessageFactory factory = new SaajSoapMessageFactory(messageFactory); MessageContext context = new DefaultMessageContext(new SaajSoapMessage(message), factory); boolean result = resolver.resolveException(context, null, new IllegalArgumentException("bla")); Assert.assertTrue("resolveException returns false", result); Assert.assertTrue("Context has no response", context.hasResponse()); SoapMessage response = (SoapMessage) context.getResponse(); Assert.assertTrue("Response has no fault", response.getSoapBody().hasFault()); Soap11Fault fault = (Soap11Fault) response.getSoapBody().getFault(); Assert.assertEquals("Invalid fault code on fault", SoapVersion.SOAP_11.getClientOrSenderFaultName(), fault.getFaultCode()); Assert.assertEquals("Invalid fault string on fault", "bla", fault.getFaultStringOrReason()); Assert.assertNull("Detail on fault", fault.getFaultDetail()); result = resolver.resolveException(context, null, new IllegalArgumentException()); Assert.assertTrue("resolveException returns false", result); Assert.assertTrue("Context has no response", context.hasResponse()); response = (SoapMessage) context.getResponse(); Assert.assertTrue("Response has no fault", response.getSoapBody().hasFault()); fault = (Soap11Fault) response.getSoapBody().getFault(); Assert.assertEquals("Invalid fault code on fault", SoapVersion.SOAP_11.getClientOrSenderFaultName(), fault.getFaultCode()); Assert.assertEquals("Invalid fault string on fault", "java.lang.IllegalArgumentException", fault.getFaultStringOrReason()); Assert.assertNull("Detail on fault", fault.getFaultDetail()); }
@Test public void testResolveNoMessageException() throws Exception { Properties mappings = new Properties(); mappings.setProperty(IOException.class.getName(), "SERVER"); resolver.setExceptionMappings(mappings); MessageFactory messageFactory = MessageFactory.newInstance(SOAPConstants.SOAP_1_1_PROTOCOL); SOAPMessage message = messageFactory.createMessage(); SoapMessageFactory factory = new SaajSoapMessageFactory(messageFactory); MessageContext context = new DefaultMessageContext(new SaajSoapMessage(message), factory); boolean result = resolver.resolveException(context, null, new IOException()); Assert.assertTrue("resolveException returns false", result); Assert.assertTrue("Context has no response", context.hasResponse()); SoapMessage response = (SoapMessage) context.getResponse(); Assert.assertTrue("Response has no fault", response.getSoapBody().hasFault()); Soap11Fault fault = (Soap11Fault) response.getSoapBody().getFault(); Assert.assertEquals("Invalid fault code on fault", SoapVersion.SOAP_11.getServerOrReceiverFaultName(), fault.getFaultCode()); Assert.assertEquals("Invalid fault string on fault", "java.io.IOException", fault.getFaultStringOrReason()); Assert.assertNull("Detail on fault", fault.getFaultDetail()); }