From b3623f008c022474fe40afaf46cc0e778e03329b Mon Sep 17 00:00:00 2001 From: Arjen Poutsma Date: Sat, 19 May 2007 01:46:45 +0000 Subject: [PATCH] Implemented #SWS-117: Allow SoapFaultMappingExceptionResolver to use strategy to obtain SoapFaultDefinition --- src/docbkx/server.xml | 85 ++++++++++++++++++++++++++++++++++++------- 1 file changed, 71 insertions(+), 14 deletions(-) diff --git a/src/docbkx/server.xml b/src/docbkx/server.xml index 588b031c..b8061014 100644 --- a/src/docbkx/server.xml +++ b/src/docbkx/server.xml @@ -2,7 +2,7 @@ - Creating a Web service with Spring-WS + Creating a Web service with Spring-WS
Introduction @@ -253,7 +253,7 @@ public class SampleEndpoint extends AbstractDomPayloadEndpoint { base classes which use alternative DOM APIs. Spring Web Services supports most DOM APIs, so that you can use the one you are familiar with. For instance, the AbstractJDomPayloadEndpoint allows you to use JDOM, and the - AbstractXomPayloadEndpoint uses XOM to handle the XML. All of these endpoints + AbstractXomPayloadEndpoint uses XOM to handle the XML. All of these endpoints have an invokeInternal method similar to above. Also, consider to use Spring-WS's XPath support to extract the information you need out of the payload, see . @@ -263,10 +263,10 @@ public class SampleEndpoint extends AbstractDomPayloadEndpoint { <classname>AbstractMarshallingPayloadEndpoint</classname> Rather than handling XML directly using DOM, you can use marshalling to convert the payload of the XML - message into a Java Object. Spring Web Services offers the - AbstractMarshallingPayloadEndpoint for this purpose, which is built on the - marshalling abstraction described in . The - AbstractMarshallingPayloadEndpoint has two properties: + message into a Java Object. Spring Web Services offers the + AbstractMarshallingPayloadEndpoint for this purpose, which is built on the + marshalling abstraction described in . The + AbstractMarshallingPayloadEndpoint has two properties: marshaller and unmarshaller, in which you can inject in the constructor or by setters. @@ -770,30 +770,87 @@ public class AnnotationOrderEndpoint { Finally, rather than expose the innards of your application by giving an exception and stack trace, you can handle the exception any way you want, e.g. return a SOAP fault with a specific fault code and string. + + Endpoint exception resolvers are automatically picked up by the MessageDispatcher, so + you don't have to configure them explicitely. + Besides implementing the EndpointExceptionResolver interface, which is only a matter of implementing the resolveException(MessageContext, endpoint, Exception) - method, you may also use the SoapFaultMappingExceptionResolver. + method, you may also use one of the default implementations. + The simples implementation is the SimpleSoapExceptionResolver, which simply + always creates a SOAP 1.1 Server or SOAP 1.2 Receiver Fault, and uses the exception message as the fault + string. + + + A more sophisticated implementation is the SoapFaultMappingExceptionResolver. This resolver enables you to take the class name of any exception that might be thrown and map it to a SOAP Fault, like so: - + + - + - SENDER,Invalid request + CLIENT,Invalid request ]]> - This configuration will map exceptions of type ValidationFailureException - to a sender side SOAP Fault with a fault string "Invalid request". - If any other exception occurs, it will return the default fault: a server side fault with fault string - "Server error". + + The key values and default endpoint use the format faultCode,faultString,locale, where + only the fault code is required. + If the fault string is not set, it will default to the exception message. + If the language is not set, it will default to English. + The configuration above will map exceptions of type ValidationFailureException + to a sender side SOAP Fault with a fault string "Invalid request": + + ]]> + SOAP-ENV:Client + Invalid request + ]]> +]]> + + If any other exception occurs, it will return the default fault: a server side fault with the exception + message as fault string. + + + Finally, it is possible to annotate exception classes with the @SoapFault + annotation, to indicate the SOAP Fault that should be returned whenever that exception is thrown. + The elements of the annotation include a fault code enumeration, fault string or reason, and language. Here + is an example exception: + + + + Whever the MyBusinessException is thrown with the constructor string + Oops! during endpoint invocation, it will result in + the following response: + + + + + SOAP-ENV:Server + Oops! + + +]]>