diff --git a/src/docbkx/client.xml b/src/docbkx/client.xml index 04e6798d..fe416e94 100644 --- a/src/docbkx/client.xml +++ b/src/docbkx/client.xml @@ -7,7 +7,7 @@ Introduction Spring-WS provides a client-side Web service API that allows for consistent, XML-driven access to - Web services. It also caters for the use of marshallers and unmarshallers + Web services. It also caters for the use of marshallers and unmarshallers so that your service tier code can deal exclusively with Java objects. @@ -284,7 +284,9 @@ public class WebServiceClient { WebServiceTemplate class delegates the conversion of the request object to XML to a Marshaller, and the conversion of the response XML to an object to an Unmarshaller. (For more information - about marshalling and unmarshaller, refer to .) By using the + about marshalling and unmarshaller, refer to + the Spring documentation.) + By using the marshallers, your application code can focus on the business object that is being sent or received and not be concerned with the details of how it is represented as XML. In order to use the marshalling functionality, you have to set a marshaller and unmarshaller with the diff --git a/src/docbkx/index.xml b/src/docbkx/index.xml index 10589a9d..68cd73d0 100644 --- a/src/docbkx/index.xml +++ b/src/docbkx/index.xml @@ -59,16 +59,14 @@ to both client- and server-side WS, a chapter devoted to the specifics of writing server-side Web services, a chapter about using Web services on - the client-side, and chapters on using - WS-Security and - Object/XML mapping. + the client-side, and a chapters on using + WS-Security. - Other Resources diff --git a/src/docbkx/oxm.xml b/src/docbkx/oxm.xml deleted file mode 100644 index 298b65f7..00000000 --- a/src/docbkx/oxm.xml +++ /dev/null @@ -1,747 +0,0 @@ - - - - Marshalling XML using O/X Mappers - -
- Introduction - - In this chapter, we will describe Spring's Object/XML Mapping support. Object/XML Mapping, or O/X mapping - for short, is the act of converting an XML document to and from an object. This conversion process is also - known as XML Marshalling, or XML Serialization. This chapter uses these terms interchangeably. - - - Within the field of O/X mapping, a marshaller is responsible for serializing an - object (graph) to XML. In similar fashion, an unmarshaller deserializes the XML to an - object graph. This XML can take the form of a DOM document, an input or output stream, or a SAX handler. - - Some of the benefits of using Spring for your O/X mapping needs are: - - Ease of configuration - - Spring's bean factory makes it easy to configure marshallers, without needing to construct JAXB context, - JiBX binding factories, etc. The marshallers can be configured as any other bean in your application - context. Additionally, XML Schema-based configuration is available for a number of marshallers, making - the configuration even simpler. - - - - Consistent Interfaces - - Spring's O/X mapping operates through two global interfaces: the - Marshaller and Unmarshaller interface. - These abstractions allow you to switch O/X mapping - frameworks with relative ease, with little or no changes required on the classes that do the - marshalling. This approach has the additional benefit of making it possible to do XML marshalling with - a mix-and-match approach (e.g. some marshalling performed using JAXB, other using XMLBeans) in a - non-intrusive fashion, leveraging the strength of each technology. - - - - Consistent Exception Hierarchy - - Spring provides a conversion from exceptions from the underlying O/X mapping tool to its own exception - hierarchy with the XmlMappingException as the root exception. As can be expected, - these runtime exceptions wrap the original exception so no information is lost. - - -
-
- Marshaller and Unmarshaller - - As stated in the introduction, a marshaller serializes an object to XML, and an - unmarshaller deserializes XML stream to an object. In this section, we will describe - the two Spring interfaces used for this purpose. - -
- Marshaller - - Spring abstracts all marshalling operations behind the - org.springframework.oxm.Marshaller interface, the main methods of which - is listed below. - - The Marshaller interface has one main method, which marshals the given - object to a given javax.xml.transform.Result. Result is a tagging - interface that basically represents an XML output abstraction: concrete implementations wrap various XML - representations, as indicated in the table below. - - - - - javax.xml.transform.Result implementation - Wraps XML representation - - - - - javax.xml.transform.dom.DOMResult - org.w3c.dom.Node - - - javax.xml.transform.sax.SAXResult - org.xml.sax.ContentHandler - - - javax.xml.transform.stream.StreamResult - - java.io.File, - java.io.OutputStream, or - java.io.Writer - - - - - - - - Although the marshal method accepts a plain object as its first - parameter, most Marshaller implementations cannot handle arbitrary - objects. Instead, an object class must be mapped in a mapping file, registered with the - marshaller, or have a common base class. Refer to the further sections in this chapter to - determine how your O/X technology of choice manages this. - - - -
-
- Unmarshaller - - Similar to the Marshaller, there is the - org.springframework.oxm.Unmarshaller interface. - - This interface also has one method, which reads from the given - javax.xml.transform.Source (an XML input abstraction), and returns the - object read. As with Result, Source is a tagging interface that has three concrete implementations. Each - wraps a different XML representation, as indicated in the table below. - - - - - javax.xml.transform.Source implementation - Wraps XML representation - - - - - javax.xml.transform.dom.DOMSource - org.w3c.dom.Node - - - javax.xml.transform.sax.SAXSource - - org.xml.sax.InputSource, and - org.xml.sax.XMLReader - - - - javax.xml.transform.stream.StreamSource - - java.io.File, - java.io.InputStream, or - java.io.Reader - - - - - - -
- - Even though there are two separate marshalling interfaces (Marshaller - and Unmarshaller), all implementations found in Spring-WS implement both in - one class. This means that you can wire up one marshaller class and refer to it both as a marshaller and an - unmarshaller in your applicationContext.xml. - -
- XmlMappingException - - Spring converts exceptions from the underlying O/X mapping tool to its own exception hierarchy with the - XmlMappingException as the root exception. As can be expected, these runtime - exceptions wrap the original exception so no information will be lost. - - - Additionally, the MarshallingFailureException and - UnmarshallingFailureException provide a distinction between marshalling and - unmarshalling operations, even though the underlying O/X mapping tool does not do so. - - - The O/X Mapping exception hierarchy is shown in the following figure: - - - - - - - - - - O/X Mapping exception hierarchy - - - - -
-
-
- Using Marshaller and Unmarshaller - - Spring's OXM can be used for a wide variety of situations. In the following example, we will use it to - marshal the settings of a Spring-managed application as an XML file. We will use a simple JavaBean to - represent the settings: - - - - The application class uses this bean to store its settings. Besides a main method, the class has two - methods: saveSettings saves the settings bean to a file named - settings.xml, and loadSettings loads these settings again. A - main method constructs a Spring application context, and calls these two methods. - - The Application requires both a marshaller - and unmarshaller property to be set. We can do so using the following - applicationContext.xml: - - - - - - - -]]> - This application context uses Castor, but we could have used any of the other marshaller instances described - later in this chapter. Note that Castor does not require any further configuration by default, so the bean - definition is rather simple. Also note that the CastorMarshaller implements both - Marshaller and Unmarshaller, so we can refer - to the castorMarshaller bean in both the marshaller and - unmarshaller property of the application. - - - This sample application produces the following settings.xml file: - - -]]> - -
-
- XML Schema-based Configuration - - Marshallers could be configured more concisely using tags from the OXM namespace. - To make these tags available, the appropriate schema has to be referenced first in the preamble of the XML configuration file. - The emboldened text in the below snippet references the OXM schema: - - - - -]]> - - Currently, the following tags are available: - - - jaxb1-marshaller - - - jaxb2-marshaller - - - xmlbeans-marshaller - - - jibx-marshaller - - - - - Each tag will be explained in its respective marshaller's section. As an example though, here is how - the configuration of a JAXB2 marshaller might look like: - - ]]> -
-
- JAXB - - The JAXB binding compiler translates a W3C XML Schema into one or more Java classes, a - jaxb.properties file, and possibly other files, depending on the specific - implementation of JAXB. Alternatively, JAXB2 offers a way to generate a schema from annotated Java classes. - - - Spring supports both the JAXB 1.0 and the JAXB 2.0 API as XML marshalling strategies, following the - Marshaller and Unmarshaller - interfaces described in . The corresponding integration - classes reside in the org.springframework.oxm.jaxb package. - -
- Jaxb1Marshaller - - The Jaxb1Marshaller class implements both the Spring - Marshaller and Unmarshallerinterface. It - requires a context path to operate, which you can set using the contextPath - property. The context path is a list of colon (:) separated Java package names that contain schema - derived classes. The marshaller has an additional validating property which - defines whether to validate incoming XML. - - - The next sample bean configuration shows how to configure a JaxbMarshaller - using the classes generated to org.springframework.ws.samples.airline.schema. - - - - - - - ... - -]]> -
- XML Schema-based Configuration - - The jaxb1-marshaller tag configures a org.springframework.oxm.jaxb.Jaxb1Marshaller. - Here is an example: - - ]]> - - Available attributes are: - - - - - - - - Attribute - Description - Required - - - - - id - the id of the marshaller - no - - - contextPath - the JAXB Context path - yes - - - validating - indicates whether the incoming XML should be validated - no - - - - - -
-
-
- Jaxb2Marshaller - - The Jaxb2Marshaller can be configured using the same - contextPath property as the Jaxb1Marshaller. However, it - also offers a classesToBeBound property, which allows you to set an array of - classes to be supported by the marshaller. Schema validation is performed by specifying one or more - schema resource to the bean, like so: - - - - - - - org.springframework.oxm.jaxb.Flight - org.springframework.oxm.jaxb.Flights - - - - - ... - -]]> -
- XML Schema-based Configuration - - The jaxb2-marshaller tag configures a org.springframework.oxm.jaxb.Jaxb2Marshaller. - Here is an example: - - ]]> - - Alternatively, the list of classes to bind can be provided to the marshaller via the class-to-be-bound child tag: - - - - - ... - - ]]> - - Available attributes are: - - - - - - - - Attribute - Description - Required - - - - - id - the id of the marshaller - no - - - contextPath - the JAXB Context path - no - - - - - -
-
-
-
- Castor - - Castor XML mapping is an open source XML binding framework. It allows you to transform the data contained in - a java object model into/from an XML document. By default, it does not require any further configuration, - though a mapping file can be used to have more control over the behavior of Castor. - - - For more information on Castor, refer to the - Castor web site. The Spring integration classes reside in the - org.springframework.oxm.castor package. - -
- CastorMarshaller - - As with JAXB, the CastorMarshaller implements both the - Marshaller and Unmarshaller interface. - It can be wired up as follows: - - - - - ... - -]]> -
-
- Mapping - - Although it is possible to rely on Castor's default marshalling behavior, it might be necessary to have - more control over it. This can be accomplished using a Castor mapping file. For more information, refer - to Castor XML Mapping. - - - The mapping can be set using the mappingLocation resource property, indicated - below with a classpath resource. - - - - - - -]]> -
-
- -
- XMLBeans - - XMLBeans is an XML binding tool that has full XML Schema support, and offers full XML Infoset - fidelity. It takes a different approach to that of most other O/X mapping frameworks, in that - all classes that are generated from an XML Schema are all derived from - XmlObject, and contain XML binding information in them. - - - For more information on XMLBeans, refer to the - XMLBeans web site . The Spring-WS integration classes reside - in the org.springframework.oxm.xmlbeans package. - -
- XmlBeansMarshaller - - The XmlBeansMarshaller - implements both the Marshaller - and Unmarshaller - interfaces. It can be configured as follows: - - - - - ... - -]]> - - - Note that the XmlBeansMarshaller - can only marshal objects of type XmlObject, - and not every java.lang.Object. - - -
- XML Schema-based Configuration - - The xmlbeans-marshaller tag configures a org.springframework.oxm.xmlbeans.XmlBeansMarshaller. - Here is an example: - - ]]> - - Available attributes are: - - - - - - - - Attribute - Description - Required - - - - - id - the id of the marshaller - no - - - options - the bean name of the XmlOptions that is to be used for this marshaller. Typically a - XmlOptionsFactoryBean definition - no - - - - - -
-
- - -
- -
- JiBX - - The JiBX framework offers a solution similar to that which JDO provides for ORM: a binding definition defines the - rules for how your Java objects are converted to or from XML. After preparing the binding and compiling the - classes, a JiBX binding compiler enhances the class files, and adds code to handle converting instances of - the classes from or to XML. - - - For more information on JiBX, refer to the - JiBX web site. The Spring integration classes reside in the - org.springframework.oxm.jibx package. - -
- JibxMarshaller - - The JibxMarshaller class implements both the - Marshaller and Unmarshaller interface. - To operate, it requires the name of the class to marshall in, which you can set using the - targetClass property. Optionally, you can set the binding name using the - bindingName property. In the next sample, we bind the - Flights class: - - - - - org.springframework.oxm.jibx.Flights - - - ... -]]> - - A JibxMarshaller is configured for a single class. If you want to marshal - multiple classes, you have to configure multiple JibxMarshallers with - different targetClass property values. - -
- XML Schema-based Configuration - - The jibx-marshaller tag configures a org.springframework.oxm.jibx.JibxMarshaller. - Here is an example: - - ]]> - - Available attributes are: - - - - - - - - Attribute - Description - Required - - - - - id - the id of the marshaller - no - - - target-class - the target class for this marshaller - yes - - - bindingName - the binding name used by this marshaller - no - - - - - -
-
-
-
- XStream - - XStream is a simple library to serialize objects to XML and back again. It does not require any mapping, and - generates clean XML. - - - For more information on XStream, refer to the - XStream web site. The Spring integration classes reside in the - org.springframework.oxm.xstream package. - -
- XStreamMarshaller - - The XStreamMarshaller does not require any configuration, and can be configured - in an application context directly. To further customize the XML, you can set an - alias map, which consists of string aliases mapped to classes: - - - - - - - org.springframework.oxm.xstream.Flight - - - - ... - -]]> - - - Note that XStream is an XML serialization library, not a data binding library. Therefore, it has - limited namespace support. As such, it is rather unsuitable for usage within Web services. - - -
-
-
diff --git a/src/docbkx/preface.xml b/src/docbkx/preface.xml index 3400007f..5c029957 100644 --- a/src/docbkx/preface.xml +++ b/src/docbkx/preface.xml @@ -16,11 +16,10 @@ on this XML, and not on Java. - Spring Web Services focusses on creating these document-driven Web services. + Spring Web Services focuses on creating these document-driven Web services. Spring Web Services facilitates contract-first SOAP service development, allowing for the creation of flexible web services using one of the many ways to manipulate XML payloads. - Spring-WS provides a powerful message dispatching framework, various XML marshalling techniques that can be used outside a Web service environment, a message dispatching framework, a WS-Security solution that integrates with your existing application security solution, and a Client-side API that follows the familiar Spring template pattern. diff --git a/src/docbkx/resources/images/spring-deps.png b/src/docbkx/resources/images/spring-deps.png index b65bfc06..cf1caa2c 100644 Binary files a/src/docbkx/resources/images/spring-deps.png and b/src/docbkx/resources/images/spring-deps.png differ diff --git a/src/docbkx/server.xml b/src/docbkx/server.xml index a672ab30..6dd5c938 100644 --- a/src/docbkx/server.xml +++ b/src/docbkx/server.xml @@ -24,7 +24,7 @@ Spring-WS's XML handling is extremely flexible. An endpoint can choose from a large amount of XML handling libraries supported by Spring-WS, including the DOM family (W3C DOM, JDOM, dom4j, and XOM), SAX or StAX for faster performance, XPath to extract information from the message, or even - marshalling techniques (JAXB, Castor, XMLBeans, JiBX, or XStream) to convert + marshalling techniques (JAXB, Castor, XMLBeans, JiBX, or XStream) to convert the XML to objects and vice-versa. @@ -314,18 +314,6 @@ the dispatcher servlet does not load the default adapters, and is unable to handle standard Spring-MVC Controllers. Therefore, we add the SimpleControllerHandlerAdapter at the end. - - - By default, the Spring MVC DispatcherServlet configures the following - handler adapters in version 2.5: - - org.springframework.web.servlet.mvc.HttpRequestHandlerAdapter - org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter - org.springframework.web.servlet.mvc.throwaway.ThrowawayControllerHandlerAdapter - org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter - - - In a similar fashion, you can wire up a WsdlDefinitionHandlerAdapter to make sure @@ -669,7 +657,7 @@ public class SampleEndpoint extends AbstractDomPayloadEndpoint { 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 + Spring's OXM package. The AbstractMarshallingPayloadEndpoint has two properties: marshaller and unmarshaller, in which you can inject in the constructor or by setters. @@ -721,7 +709,9 @@ public class MarshallingOrderEndpoint extends AbstractMarshallingPayloadEndpoint ]]><!-- Other beans, such as the endpoint mapping -->]]> - In this sample, we configure a Jaxb2Marshaller for the + In this sample, we configure a + Jaxb2Marshaller + for the OrderRequest and Order classes, and inject that marshaller together with the DefaultOrderService into our endpoint. This business service is not shown, but @@ -756,7 +746,8 @@ public class MarshallingOrderEndpoint extends AbstractMarshallingPayloadEndpoint ]]> - Instead of JAXB 2, we could have used any of the other marshallers described in . + Instead of JAXB 2, we could have used any Spring OXM marshallers. The only thing that would change in the above example is the configuration of the marshaller bean. diff --git a/src/docbkx/tutorial.xml b/src/docbkx/tutorial.xml index c307cca5..ebabaf18 100644 --- a/src/docbkx/tutorial.xml +++ b/src/docbkx/tutorial.xml @@ -620,7 +620,7 @@ public class HolidayEndpoint extends AbstractJDomPayloadEndpoint { Using JDOM is just one of the options to handle the XML: other options include DOM, dom4j, XOM, - SAX, and StAX, but also marshalling techniques like JAXB, Castor, XMLBeans, + SAX, and StAX, but also marshalling techniques like JAXB, Castor, XMLBeans, JiBX, and XStream. We chose JDOM because it gives us access to the raw XML, and because it is based on classes (not interfaces and factory methods as with W3C DOM and dom4j), which makes the code less verbose. We use XPath because it is less fragile than marshalling technologies: we don't diff --git a/src/docbkx/what-is-spring-ws.xml b/src/docbkx/what-is-spring-ws.xml index 82c48d01..b73117e3 100644 --- a/src/docbkx/what-is-spring-ws.xml +++ b/src/docbkx/what-is-spring-ws.xml @@ -79,9 +79,8 @@
Runtime environment - Spring Web Services runs within a standard Java 1.3 Runtime Environment. It also supports Java 5.0, - although the Java types which are specific to this release are packaged in a separate modules with the - suffix "tiger" in their JAR filename. Note that the security module also requires Java 5. + Spring Web Services requires a standard Java 1.5 Runtime Environment. Java 1.6 is also supported. + Spring-WS also requires Spring 3.0 or higher. Spring-WS consists of a number of modules, which are described in the remainder of this section. @@ -96,7 +95,7 @@ - The Core package (spring-ws-core.jar and spring-ws-core-tiger.jar) + The Core package (spring-ws-core.jar) is the central part of the Spring's Web services functionality. It provides the central WebServiceMessage and @@ -110,22 +109,14 @@ The Security package (spring-ws-security.jar) provides a WS-Security implementation that integrates with the core Web service package. It allows you to add principal tokens, sign, and decrypt and encrypt SOAP - messages. Addtionally, it allows you to leverage your existing Acegi security implementation for + messages. Additionally, it allows you to leverage your existing Spring Security security implementation for authentication and authorization. - - - The OXM package (spring-oxm.jar and - spring-oxm-tiger.jar) provides integration for popular XML marshalling APIs, including - JAXB 1 and 2. Using the OXM package means that you benefit from a unified exception hierarchy, and can wire - up your favorite XML marshalling technology easily. - - The following figure illustrates the Spring-WS modules and the dependencies between them. Arrows indicate - dependencies, i.e. Spring-WS Core depends on Spring-XML and Spring-OXM. + dependencies, i.e. Spring-WS Core depends on Spring-XML and the OXM module found in Spring 3.