Some time ago I had to define a web service and write the web service implementation for a spring 3.0 project. The operations needed were quite simple.
In the past I have usually used axis 1 to offer web services. The results have not been very satisfying because the development has always been quite complex and the generated wsdl was not very clean. In a perfect developer world I would expect to write an easy configuration defining which existing services should be accessible and doing a convention overconfiguration for the mapping of the parameters. This configuration could be an xml configuration file or annotations at the java class. Something similar to the spring REST support would be nice.
Because spring was already used in the project and spring is usually simple and powerful, I decided to try spring web services. Also testing the newest spring technology is for my company OPITZ-CONSULTING, which is a spring partner, important 😉
For this example I chose:
– a method returning a version information string
– a method with a string and a date parameter returning a boolean
These really are basical needs for a web service.
After some research I found out that spring web services 2.0, which was at M3 and is now released, is the right version to be combined with spring 3.0.
First we define the xsd or the operation request and responses:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
<div><span style="color:#008080;"> 1</span> <span style="color:#0000FF;"><?</span><span style="color:#FF00FF;">xml version="1.0" encoding="UTF-8" standalone="no"</span><span style="color:#0000FF;">?></span><span style="color:#000000;"> </span><span style="color:#008080;"> 2</span> <span style="color:#000000;"></span><span style="color:#0000FF;"><</span><span style="color:#800000;">xs:schema </span><span style="color:#FF0000;">xmlns:testService</span><span style="color:#0000FF;">="http://ws.opitz-consulting.com/test/sws2/TestService"</span><span style="color:#FF0000;"> xmlns:xs</span><span style="color:#0000FF;">="http://www.w3.org/2001/XMLSchema"</span><span style="color:#FF0000;"> elementFormDefault</span><span style="color:#0000FF;">="qualified"</span><span style="color:#FF0000;"> targetNamespace</span><span style="color:#0000FF;">="http://ws.opitz-consulting.com/test/sws2/TestService"</span><span style="color:#0000FF;">></span><span style="color:#000000;"> </span><span style="color:#008080;"> 3</span> <span style="color:#000000;"> </span><span style="color:#0000FF;"><</span><span style="color:#800000;">xs:element </span><span style="color:#FF0000;">name</span><span style="color:#0000FF;">="checkValueRequest"</span><span style="color:#0000FF;">></span><span style="color:#000000;"> </span><span style="color:#008080;"> 4</span> <span style="color:#000000;"> </span><span style="color:#0000FF;"><</span><span style="color:#800000;">xs:complexType</span><span style="color:#0000FF;">></span><span style="color:#000000;"> </span><span style="color:#008080;"> 5</span> <span style="color:#000000;"> </span><span style="color:#0000FF;"><</span><span style="color:#800000;">xs:sequence</span><span style="color:#0000FF;">></span><span style="color:#000000;"> </span><span style="color:#008080;"> 6</span> <span style="color:#000000;"> </span><span style="color:#0000FF;"><</span><span style="color:#800000;">xs:element </span><span style="color:#FF0000;">name</span><span style="color:#0000FF;">="testToken"</span><span style="color:#FF0000;"> type</span><span style="color:#0000FF;">="xs:token"</span><span style="color:#0000FF;">/></span><span style="color:#000000;"> </span><span style="color:#008080;"> 7</span> <span style="color:#000000;"> </span><span style="color:#0000FF;"><</span><span style="color:#800000;">xs:element </span><span style="color:#FF0000;">name</span><span style="color:#0000FF;">="date"</span><span style="color:#FF0000;"> type</span><span style="color:#0000FF;">="xs:date"</span><span style="color:#0000FF;">/></span><span style="color:#000000;"> </span><span style="color:#008080;"> 8</span> <span style="color:#000000;"> </span><span style="color:#0000FF;"></</span><span style="color:#800000;">xs:sequence</span><span style="color:#0000FF;">></span><span style="color:#000000;"> </span><span style="color:#008080;"> 9</span> <span style="color:#000000;"> </span><span style="color:#0000FF;"></</span><span style="color:#800000;">xs:complexType</span><span style="color:#0000FF;">></span><span style="color:#000000;"> </span><span style="color:#008080;">10</span> <span style="color:#000000;"> </span><span style="color:#0000FF;"></</span><span style="color:#800000;">xs:element</span><span style="color:#0000FF;">></span><span style="color:#000000;"> </span><span style="color:#008080;">11</span> <span style="color:#000000;"> </span><span style="color:#0000FF;"><</span><span style="color:#800000;">xs:element </span><span style="color:#FF0000;">name</span><span style="color:#0000FF;">="checkValueResponse"</span><span style="color:#0000FF;">></span><span style="color:#000000;"> </span><span style="color:#008080;">12</span> <span style="color:#000000;"> </span><span style="color:#0000FF;"><</span><span style="color:#800000;">xs:complexType</span><span style="color:#0000FF;">></span><span style="color:#000000;"> </span><span style="color:#008080;">13</span> <span style="color:#000000;"> </span><span style="color:#0000FF;"><</span><span style="color:#800000;">xs:sequence</span><span style="color:#0000FF;">></span><span style="color:#000000;"> </span><span style="color:#008080;">14</span> <span style="color:#000000;"> </span><span style="color:#0000FF;"><</span><span style="color:#800000;">xs:element </span><span style="color:#FF0000;">name</span><span style="color:#0000FF;">="checkValueReturn"</span><span style="color:#FF0000;"> type</span><span style="color:#0000FF;">="xs:boolean"</span><span style="color:#0000FF;">/></span><span style="color:#000000;"> </span><span style="color:#008080;">15</span> <span style="color:#000000;"> </span><span style="color:#0000FF;"></</span><span style="color:#800000;">xs:sequence</span><span style="color:#0000FF;">></span><span style="color:#000000;"> </span><span style="color:#008080;">16</span> <span style="color:#000000;"> </span><span style="color:#0000FF;"></</span><span style="color:#800000;">xs:complexType</span><span style="color:#0000FF;">></span><span style="color:#000000;"> </span><span style="color:#008080;">17</span> <span style="color:#000000;"> </span><span style="color:#0000FF;"></</span><span style="color:#800000;">xs:element</span><span style="color:#0000FF;">></span><span style="color:#000000;"> </span><span style="color:#008080;">18</span> <span style="color:#000000;"> </span><span style="color:#0000FF;"><</span><span style="color:#800000;">xs:element </span><span style="color:#FF0000;">name</span><span style="color:#0000FF;">="getVersionRequest"</span><span style="color:#0000FF;">/></span><span style="color:#000000;"> </span><span style="color:#008080;">19</span> <span style="color:#000000;"> </span><span style="color:#0000FF;"><</span><span style="color:#800000;">xs:element </span><span style="color:#FF0000;">name</span><span style="color:#0000FF;">="getVersionResponse"</span><span style="color:#0000FF;">></span><span style="color:#000000;"> </span><span style="color:#008080;">20</span> <span style="color:#000000;"> </span><span style="color:#0000FF;"><</span><span style="color:#800000;">xs:complexType</span><span style="color:#0000FF;">></span><span style="color:#000000;"> </span><span style="color:#008080;">21</span> <span style="color:#000000;"> </span><span style="color:#0000FF;"><</span><span style="color:#800000;">xs:sequence</span><span style="color:#0000FF;">></span><span style="color:#000000;"> </span><span style="color:#008080;">22</span> <span style="color:#000000;"> </span><span style="color:#0000FF;"><</span><span style="color:#800000;">xs:element </span><span style="color:#FF0000;">name</span><span style="color:#0000FF;">="getVersionReturn"</span><span style="color:#FF0000;"> type</span><span style="color:#0000FF;">="xs:token"</span><span style="color:#0000FF;">/></span><span style="color:#000000;"> </span><span style="color:#008080;">23</span> <span style="color:#000000;"> </span><span style="color:#0000FF;"></</span><span style="color:#800000;">xs:sequence</span><span style="color:#0000FF;">></span><span style="color:#000000;"> </span><span style="color:#008080;">24</span> <span style="color:#000000;"> </span><span style="color:#0000FF;"></</span><span style="color:#800000;">xs:complexType</span><span style="color:#0000FF;">></span><span style="color:#000000;"> </span><span style="color:#008080;">25</span> <span style="color:#000000;"> </span><span style="color:#0000FF;"></</span><span style="color:#800000;">xs:element</span><span style="color:#0000FF;">></span><span style="color:#000000;"> </span><span style="color:#008080;">26</span> <span style="color:#000000;"></span><span style="color:#0000FF;"></</span><span style="color:#800000;">xs:schema</span><span style="color:#0000FF;">></span></div> |
The java methods of the spring bean containing the service has to be annotated.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
<div><span style="color:#008080;"> 1</span> <span style="color:#000000;">@Endpoint </span><span style="color:#008080;"> 2</span> <span style="color:#000000;">@Namespace(prefix </span><span style="color:#000000;">=</span><span style="color:#000000;"> </span><span style="color:#000000;">"</span><span style="color:#000000;">t</span><span style="color:#000000;">"</span><span style="color:#000000;">, uri </span><span style="color:#000000;">=</span><span style="color:#000000;"> </span><span style="color:#000000;">"</span><span style="color:#000000;">http://ws.opitz-consulting.com/test/sws2/TestService</span><span style="color:#000000;">"</span><span style="color:#000000;">) </span><span style="color:#008080;"> 3</span> <span style="color:#000000;"></span><span style="color:#0000FF;">public</span><span style="color:#000000;"> </span><span style="color:#0000FF;">class</span><span style="color:#000000;"> TestServiceEndpoint { </span><span style="color:#008080;"> 4</span> <span style="color:#000000;"> @TestService testService </span><span style="color:#000000;">=</span><span style="color:#000000;"> </span><span style="color:#0000FF;">null</span><span style="color:#000000;">; </span><span style="color:#008080;"> 5</span> <span style="color:#000000;"> @PayloadRoot(localPart </span><span style="color:#000000;">=</span><span style="color:#000000;"> </span><span style="color:#000000;">"</span><span style="color:#000000;">checkValueRequest</span><span style="color:#000000;">"</span><span style="color:#000000;">, namespace </span><span style="color:#000000;">=</span><span style="color:#000000;"> </span><span style="color:#000000;">"</span><span style="color:#000000;">http://ws.opitz-consulting.com/test/sws2/TestService</span><span style="color:#000000;">"</span><span style="color:#000000;">) </span><span style="color:#008080;"> 6</span> <span style="color:#000000;"> @ResponsePayload </span><span style="color:#008080;"> 7</span> <span style="color:#000000;"> </span><span style="color:#0000FF;">public</span><span style="color:#000000;"> </span><span style="color:#0000FF;">boolean</span><span style="color:#000000;"> checkValue( </span><span style="color:#008080;"> 8</span> <span style="color:#000000;"> </span><span style="color:#0000FF;">final</span><span style="color:#000000;"> @XPathParam(</span><span style="color:#000000;">"</span><span style="color:#000000;">/t:checkValueRequest/t:testToken</span><span style="color:#000000;">"</span><span style="color:#000000;">) String testToken, </span><span style="color:#008080;"> 9</span> <span style="color:#000000;"> </span><span style="color:#0000FF;">final</span><span style="color:#000000;"> @XPathParam(</span><span style="color:#000000;">"</span><span style="color:#000000;">/t:checkValueRequest/t:date</span><span style="color:#000000;">"</span><span style="color:#000000;">) Date date) { </span><span style="color:#008080;">10</span> <span style="color:#000000;"> </span><span style="color:#0000FF;">return</span><span style="color:#000000;"> </span><span style="color:#0000FF;">this</span><span style="color:#000000;">.testService.checkValue(testToken, date); </span><span style="color:#008080;">11</span> <span style="color:#000000;"> } </span><span style="color:#008080;">12</span> <span style="color:#000000;"> </span><span style="color:#008080;">13</span> <span style="color:#000000;"> @PayloadRoot(localPart </span><span style="color:#000000;">=</span><span style="color:#000000;"> </span><span style="color:#000000;">"</span><span style="color:#000000;">getVersionRequest</span><span style="color:#000000;">"</span><span style="color:#000000;">, namespace </span><span style="color:#000000;">=</span><span style="color:#000000;"> </span><span style="color:#000000;">"</span><span style="color:#000000;">http://ws.opitz-consulting.com/test/sws2/TestService</span><span style="color:#000000;">"</span><span style="color:#000000;">) </span><span style="color:#008080;">14</span> <span style="color:#000000;"> @ResponsePayload </span><span style="color:#008080;">15</span> <span style="color:#000000;"> </span><span style="color:#0000FF;">public</span><span style="color:#000000;"> String getVersion() { </span><span style="color:#008080;">16</span> <span style="color:#000000;"> </span><span style="color:#0000FF;">return</span><span style="color:#000000;"> </span><span style="color:#000000;">"</span><span style="color:#000000;">$Revision: 1.0 $</span><span style="color:#000000;">"</span><span style="color:#000000;">; </span><span style="color:#008080;">17</span> <span style="color:#000000;"> } </span><span style="color:#008080;">18</span> <span style="color:#000000;">}</span></div> |
This is the version I would like to look my java class like.
– The Endpoint annotation defines that the java class is a web service endpoint.
– The Namespace annotation defines the prefix t assigned to the given namespace.
– The PayloadRoot defines the name of the request part of the soap message and the namespace.
– With the XPathParam annotations are defined how the parameters are extracted from the received soap xml message. The parameter is an XPath-expression selecting the parameter.
– The ResponesPayload annotation tells spring web services to handle the response as a web service response message.
At the moment the documentation is very modest, most of the information was gained by reverse engineering the implementation. But I’m sure this will change in future.
The common spring webservice configuration looks like this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
<div><span style="color:#008080;"> 1</span> <span style="color:#0000FF;"><?</span><span style="color:#FF00FF;">xml version="1.0" encoding="UTF-8"</span><span style="color:#0000FF;">?></span><span style="color:#000000;"> </span><span style="color:#008080;"> 2</span> <span style="color:#000000;"></span><span style="color:#0000FF;"><</span><span style="color:#800000;">beans </span><span style="color:#FF0000;">xmlns</span><span style="color:#0000FF;">="http://www.springframework.org/schema/beans"</span><span style="color:#FF0000;"> </span><span style="color:#008080;"> 3</span> <span style="color:#FF0000;"> xmlns:xsi</span><span style="color:#0000FF;">="http://www.w3.org/2001/XMLSchema-instance"</span><span style="color:#FF0000;"> </span><span style="color:#008080;"> 4</span> <span style="color:#FF0000;"> xmlns:context</span><span style="color:#0000FF;">="http://www.springframework.org/schema/context"</span><span style="color:#FF0000;"> </span><span style="color:#008080;"> 5</span> <span style="color:#FF0000;"> xmlns:p</span><span style="color:#0000FF;">="http://www.springframework.org/schema/p"</span><span style="color:#FF0000;"> </span><span style="color:#008080;"> 6</span> <span style="color:#FF0000;"> xmlns:oxm</span><span style="color:#0000FF;">="http://www.springframework.org/schema/oxm"</span><span style="color:#FF0000;"> </span><span style="color:#008080;"> 7</span> <span style="color:#FF0000;"> xsi:schemaLocation</span><span style="color:#0000FF;">="http://www.springframework.org/schema/beans </span><span style="color:#008080;"> 8</span> <span style="color:#0000FF;"> http://www.springframework.org/schema/beans/spring-beans.xsd </span><span style="color:#008080;"> 9</span> <span style="color:#0000FF;"> http://www.springframework.org/schema/context </span><span style="color:#008080;">10</span> <span style="color:#0000FF;"> http://www.springframework.org/schema/context/spring-context.xsd"</span><span style="color:#0000FF;">></span><span style="color:#000000;"> </span><span style="color:#008080;">11</span> <span style="color:#000000;"> </span><span style="color:#008080;">12</span> <span style="color:#000000;"> </span><span style="color:#0000FF;"><</span><span style="color:#800000;">bean </span><span style="color:#FF0000;">class</span><span style="color:#0000FF;">="org.springframework.ws.server.endpoint.mapping.PayloadRootAnnotationMethodEndpointMapping"</span><span style="color:#FF0000;"> </span><span style="color:#0000FF;">/></span><span style="color:#000000;"> </span><span style="color:#008080;">13</span> <span style="color:#000000;"> </span><span style="color:#008080;">14</span> <span style="color:#000000;"> </span><span style="color:#0000FF;"><</span><span style="color:#800000;">bean </span><span style="color:#FF0000;">class</span><span style="color:#0000FF;">="org.springframework.ws.server.endpoint.adapter.DefaultMethodEndpointAdapter"</span><span style="color:#0000FF;">></span><span style="color:#000000;"> </span><span style="color:#008080;">15</span> <span style="color:#000000;"> </span><span style="color:#0000FF;"><</span><span style="color:#800000;">property </span><span style="color:#FF0000;">name</span><span style="color:#0000FF;">="methodArgumentResolvers"</span><span style="color:#0000FF;">></span><span style="color:#000000;"> </span><span style="color:#008080;">16</span> <span style="color:#000000;"> </span><span style="color:#0000FF;"><</span><span style="color:#800000;">list</span><span style="color:#0000FF;">></span><span style="color:#000000;"> </span><span style="color:#008080;">17</span> <span style="color:#000000;"> </span><span style="color:#0000FF;"><</span><span style="color:#800000;">bean </span><span style="color:#FF0000;">class</span><span style="color:#0000FF;">="org.springframework.ws.server.endpoint.adapter.method.XPathParamMethodArgumentResolver"</span><span style="color:#FF0000;"> </span><span style="color:#0000FF;">></span><span style="color:#000000;"> </span><span style="color:#008080;">18</span> <span style="color:#000000;"> </span><span style="color:#0000FF;"><</span><span style="color:#800000;">property </span><span style="color:#FF0000;">name</span><span style="color:#0000FF;">="conversionService"</span><span style="color:#FF0000;"> ref</span><span style="color:#0000FF;">="conversionService"</span><span style="color:#FF0000;"> </span><span style="color:#0000FF;">/></span><span style="color:#000000;"> </span><span style="color:#008080;">19</span> <span style="color:#000000;"> </span><span style="color:#0000FF;"></</span><span style="color:#800000;">bean</span><span style="color:#0000FF;">></span><span style="color:#000000;"> </span><span style="color:#008080;">20</span> <span style="color:#000000;"> </span><span style="color:#0000FF;"></</span><span style="color:#800000;">list</span><span style="color:#0000FF;">></span><span style="color:#000000;"> </span><span style="color:#008080;">21</span> <span style="color:#000000;"> </span><span style="color:#0000FF;"></</span><span style="color:#800000;">property</span><span style="color:#0000FF;">></span><span style="color:#000000;"> </span><span style="color:#008080;">22</span> <span style="color:#000000;"> </span><span style="color:#0000FF;"><</span><span style="color:#800000;">property </span><span style="color:#FF0000;">name</span><span style="color:#0000FF;">="methodReturnValueHandlers"</span><span style="color:#0000FF;">></span><span style="color:#000000;"> </span><span style="color:#008080;">23</span> <span style="color:#000000;"> </span><span style="color:#0000FF;"><</span><span style="color:#800000;">list</span><span style="color:#0000FF;">></span><span style="color:#000000;"> </span><span style="color:#008080;">24</span> <span style="color:#000000;"> </span><span style="color:#0000FF;"><</span><span style="color:#800000;">bean </span><span style="color:#FF0000;">class</span><span style="color:#0000FF;">="com.oc.ws.utils.SimplePayloadMethodReturnValueHandler"</span><span style="color:#FF0000;"> </span><span style="color:#0000FF;">></span><span style="color:#000000;"> </span><span style="color:#008080;">25</span> <span style="color:#000000;"> </span><span style="color:#0000FF;"><</span><span style="color:#800000;">property </span><span style="color:#FF0000;">name</span><span style="color:#0000FF;">="conversionService"</span><span style="color:#FF0000;"> ref</span><span style="color:#0000FF;">="conversionService"</span><span style="color:#FF0000;"> </span><span style="color:#0000FF;">/></span><span style="color:#000000;"> </span><span style="color:#008080;">26</span> <span style="color:#000000;"> </span><span style="color:#0000FF;"></</span><span style="color:#800000;">bean</span><span style="color:#0000FF;">></span><span style="color:#000000;"> </span><span style="color:#008080;">27</span> <span style="color:#000000;"> </span><span style="color:#0000FF;"></</span><span style="color:#800000;">list</span><span style="color:#0000FF;">></span><span style="color:#000000;"> </span><span style="color:#008080;">28</span> <span style="color:#000000;"> </span><span style="color:#0000FF;"></</span><span style="color:#800000;">property</span><span style="color:#0000FF;">></span><span style="color:#000000;"> </span><span style="color:#008080;">29</span> <span style="color:#000000;"> </span><span style="color:#0000FF;"></</span><span style="color:#800000;">bean</span><span style="color:#0000FF;">></span><span style="color:#000000;"> </span><span style="color:#008080;">30</span> <span style="color:#000000;"> </span><span style="color:#008080;">31</span> <span style="color:#000000;"> </span><span style="color:#0000FF;"><</span><span style="color:#800000;">bean </span><span style="color:#FF0000;">id</span><span style="color:#0000FF;">="conversionService"</span><span style="color:#FF0000;"> class</span><span style="color:#0000FF;">="com.oc.ws.utils.XMLConversionServiceFactory"</span><span style="color:#FF0000;"> factory-method</span><span style="color:#0000FF;">="createXMLConversionService"</span><span style="color:#FF0000;"> </span><span style="color:#0000FF;">/></span><span style="color:#000000;"> </span><span style="color:#008080;">32</span> <span style="color:#000000;"> </span><span style="color:#008080;">33</span> <span style="color:#000000;"> </span><span style="color:#008000;"><!--</span><span style="color:#008000;"> Dont't use JBoss implementation, looses the return value </span><span style="color:#008000;">--></span><span style="color:#000000;"> </span><span style="color:#008080;">34</span> <span style="color:#000000;"> </span><span style="color:#0000FF;"><</span><span style="color:#800000;">bean </span><span style="color:#FF0000;">id</span><span style="color:#0000FF;">="messageFactory"</span><span style="color:#FF0000;"> class</span><span style="color:#0000FF;">="org.springframework.ws.soap.saaj.SaajSoapMessageFactory"</span><span style="color:#0000FF;">></span><span style="color:#000000;"> </span><span style="color:#008080;">35</span> <span style="color:#000000;"> </span><span style="color:#0000FF;"><</span><span style="color:#800000;">property </span><span style="color:#FF0000;">name</span><span style="color:#0000FF;">="messageFactory"</span><span style="color:#0000FF;">></span><span style="color:#000000;"> </span><span style="color:#008080;">36</span> <span style="color:#000000;"> </span><span style="color:#0000FF;"><</span><span style="color:#800000;">bean </span><span style="color:#FF0000;">class</span><span style="color:#0000FF;">="com.sun.xml.internal.messaging.saaj.soap.ver1_1.SOAPMessageFactory1_1Impl"</span><span style="color:#0000FF;">/></span><span style="color:#000000;"> </span><span style="color:#008080;">37</span> <span style="color:#000000;"> </span><span style="color:#0000FF;"></</span><span style="color:#800000;">property</span><span style="color:#0000FF;">></span><span style="color:#000000;"> </span><span style="color:#008080;">38</span> <span style="color:#000000;"> </span><span style="color:#0000FF;"></</span><span style="color:#800000;">bean</span><span style="color:#0000FF;">></span><span style="color:#000000;"> </span><span style="color:#008080;">39</span> <span style="color:#000000;"> </span><span style="color:#008080;">40</span> <span style="color:#000000;"></span><span style="color:#0000FF;"></</span><span style="color:#800000;">beans</span><span style="color:#0000FF;">></span></div> |
– We use annotations to define the endpoints
– The mapping of the method parameters is done by XPath-Expressions
– The conversions of the xml datatypes to the java world is done by a conversion service. More about this later.
– The mapping of the return values is done by a default mapping handler using the conversion service. More about this later.
– The example is deployed on JBoss but by using the JBoss message factory implementation causes a loss of the return value during the web service call.
The spring configuration for our TestService:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
<div><span style="color:#008080;"> 1</span> <span style="color:#0000FF;"><?</span><span style="color:#FF00FF;">xml version="1.0" encoding="UTF-8"</span><span style="color:#0000FF;">?></span><span style="color:#000000;"> </span><span style="color:#008080;"> 2</span> <span style="color:#000000;"></span><span style="color:#0000FF;"><</span><span style="color:#800000;">beans </span><span style="color:#FF0000;">xmlns</span><span style="color:#0000FF;">="http://www.springframework.org/schema/beans"</span><span style="color:#FF0000;"> </span><span style="color:#008080;"> 3</span> <span style="color:#FF0000;"> xmlns:xsi</span><span style="color:#0000FF;">="http://www.w3.org/2001/XMLSchema-instance"</span><span style="color:#FF0000;"> </span><span style="color:#008080;"> 4</span> <span style="color:#FF0000;"> xmlns:context</span><span style="color:#0000FF;">="http://www.springframework.org/schema/context"</span><span style="color:#FF0000;"> </span><span style="color:#008080;"> 5</span> <span style="color:#FF0000;"> xmlns:p</span><span style="color:#0000FF;">="http://www.springframework.org/schema/p"</span><span style="color:#FF0000;"> </span><span style="color:#008080;"> 6</span> <span style="color:#FF0000;"> xmlns:oxm</span><span style="color:#0000FF;">="http://www.springframework.org/schema/oxm"</span><span style="color:#FF0000;"> </span><span style="color:#008080;"> 7</span> <span style="color:#FF0000;"> xsi:schemaLocation</span><span style="color:#0000FF;">="http://www.springframework.org/schema/beans </span><span style="color:#008080;"> 8</span> <span style="color:#0000FF;"> http://www.springframework.org/schema/beans/spring-beans.xsd </span><span style="color:#008080;"> 9</span> <span style="color:#0000FF;"> http://www.springframework.org/schema/context </span><span style="color:#008080;">10</span> <span style="color:#0000FF;"> http://www.springframework.org/schema/context/spring-context.xsd"</span><span style="color:#0000FF;">></span><span style="color:#000000;"> </span><span style="color:#008080;">11</span> <span style="color:#000000;"> </span><span style="color:#008080;">12</span> <span style="color:#000000;"> </span><span style="color:#008080;">13</span> <span style="color:#000000;"> </span><span style="color:#0000FF;"><</span><span style="color:#800000;">bean </span><span style="color:#FF0000;">id</span><span style="color:#0000FF;">="testServiceWS"</span><span style="color:#FF0000;"> class</span><span style="color:#0000FF;">="org.springframework.ws.wsdl.wsdl11.DefaultWsdl11Definition"</span><span style="color:#0000FF;">></span><span style="color:#000000;"> </span><span style="color:#008080;">14</span> <span style="color:#000000;"> </span><span style="color:#0000FF;"><</span><span style="color:#800000;">property </span><span style="color:#FF0000;">name</span><span style="color:#0000FF;">="schema"</span><span style="color:#FF0000;"> ref</span><span style="color:#0000FF;">="testServiceSchema"</span><span style="color:#0000FF;">/></span><span style="color:#000000;"> </span><span style="color:#008080;">15</span> <span style="color:#000000;"> </span><span style="color:#0000FF;"><</span><span style="color:#800000;">property </span><span style="color:#FF0000;">name</span><span style="color:#0000FF;">="portTypeName"</span><span style="color:#FF0000;"> value</span><span style="color:#0000FF;">="SenderService"</span><span style="color:#0000FF;">/></span><span style="color:#000000;"> </span><span style="color:#008080;">16</span> <span style="color:#000000;"> </span><span style="color:#0000FF;"><</span><span style="color:#800000;">property </span><span style="color:#FF0000;">name</span><span style="color:#0000FF;">="locationUri"</span><span style="color:#FF0000;"> value</span><span style="color:#0000FF;">="http://localhost:8888/test/service/testServiceWS"</span><span style="color:#0000FF;">/></span><span style="color:#000000;"> </span><span style="color:#008080;">17</span> <span style="color:#000000;"> </span><span style="color:#0000FF;"><</span><span style="color:#800000;">property </span><span style="color:#FF0000;">name</span><span style="color:#0000FF;">="targetNamespace"</span><span style="color:#FF0000;"> value</span><span style="color:#0000FF;">="http://ws.opitz-consulting.com/test/sws2/TestService"</span><span style="color:#0000FF;">/></span><span style="color:#000000;"> </span><span style="color:#008080;">18</span> <span style="color:#000000;"> </span><span style="color:#0000FF;"></</span><span style="color:#800000;">bean</span><span style="color:#0000FF;">></span><span style="color:#000000;"> </span><span style="color:#008080;">19</span> <span style="color:#000000;"> </span><span style="color:#008080;">20</span> <span style="color:#000000;"> </span><span style="color:#0000FF;"><</span><span style="color:#800000;">bean </span><span style="color:#FF0000;">id</span><span style="color:#0000FF;">="testServiceSchema"</span><span style="color:#FF0000;"> class</span><span style="color:#0000FF;">="org.springframework.xml.xsd.SimpleXsdSchema"</span><span style="color:#0000FF;">></span><span style="color:#000000;"> </span><span style="color:#008080;">21</span> <span style="color:#000000;"> </span><span style="color:#0000FF;"><</span><span style="color:#800000;">property </span><span style="color:#FF0000;">name</span><span style="color:#0000FF;">="xsd"</span><span style="color:#FF0000;"> value</span><span style="color:#0000FF;">="classpath:/de/oc/test/sws2/ws/server/testService.xsd"</span><span style="color:#0000FF;">/></span><span style="color:#000000;"> </span><span style="color:#008080;">22</span> <span style="color:#000000;"> </span><span style="color:#0000FF;"></</span><span style="color:#800000;">bean</span><span style="color:#0000FF;">></span><span style="color:#000000;"> </span><span style="color:#008080;">23</span> <span style="color:#000000;"> </span><span style="color:#008080;">24</span> <span style="color:#000000;"> </span><span style="color:#0000FF;"><</span><span style="color:#800000;">bean </span><span style="color:#FF0000;">id</span><span style="color:#0000FF;">="testServiceEndpoint"</span><span style="color:#FF0000;"> class</span><span style="color:#0000FF;">="de.oc.test.sws2.ws.server.TestServiceEndpoint"</span><span style="color:#0000FF;">></span><span style="color:#000000;"> </span><span style="color:#008080;">25</span> <span style="color:#000000;"> </span><span style="color:#0000FF;"><</span><span style="color:#800000;">constructor-arg </span><span style="color:#FF0000;">ref</span><span style="color:#0000FF;">="testService"</span><span style="color:#0000FF;">/></span><span style="color:#000000;"> </span><span style="color:#008080;">26</span> <span style="color:#000000;"> </span><span style="color:#0000FF;"></</span><span style="color:#800000;">bean</span><span style="color:#0000FF;">></span><span style="color:#000000;"> </span><span style="color:#008080;">27</span> <span style="color:#000000;"> </span><span style="color:#008080;">28</span> <span style="color:#000000;"> </span><span style="color:#0000FF;"><</span><span style="color:#800000;">bean </span><span style="color:#FF0000;">id</span><span style="color:#0000FF;">="testServiceValidator"</span><span style="color:#FF0000;"> class</span><span style="color:#0000FF;">="org.springframework.ws.soap.server.endpoint.interceptor.PayloadValidatingInterceptor"</span><span style="color:#0000FF;">></span><span style="color:#000000;"> </span><span style="color:#008080;">29</span> <span style="color:#000000;"> </span><span style="color:#0000FF;"><</span><span style="color:#800000;">property </span><span style="color:#FF0000;">name</span><span style="color:#0000FF;">="schema"</span><span style="color:#FF0000;"> value</span><span style="color:#0000FF;">="classpath:/de/oc/test/sws2/ws/server/testService.xsd"</span><span style="color:#0000FF;">/></span><span style="color:#000000;"> </span><span style="color:#008080;">30</span> <span style="color:#000000;"> </span><span style="color:#0000FF;"><</span><span style="color:#800000;">property </span><span style="color:#FF0000;">name</span><span style="color:#0000FF;">="validateRequest"</span><span style="color:#FF0000;"> value</span><span style="color:#0000FF;">="true"</span><span style="color:#0000FF;">/></span><span style="color:#000000;"> </span><span style="color:#008080;">31</span> <span style="color:#000000;"> </span><span style="color:#0000FF;"><</span><span style="color:#800000;">property </span><span style="color:#FF0000;">name</span><span style="color:#0000FF;">="validateResponse"</span><span style="color:#FF0000;"> value</span><span style="color:#0000FF;">="false"</span><span style="color:#0000FF;">/></span><span style="color:#000000;"> </span><span style="color:#008080;">32</span> <span style="color:#000000;"> </span><span style="color:#0000FF;"></</span><span style="color:#800000;">bean</span><span style="color:#0000FF;">></span><span style="color:#000000;"> </span><span style="color:#008080;">33</span> <span style="color:#000000;"> </span><span style="color:#008080;">34</span> <span style="color:#000000;"></span><span style="color:#0000FF;"></</span><span style="color:#800000;">beans</span><span style="color:#0000FF;">></span><span style="color:#000000;"> </span></div> |
Here is nothing special.
Now to the two custom generic implementations. I don’t know why such an implementation is not already provided with spring (or in case it is provided, I haven’t found it yet). They make the implementation and the usage much easier.
The XMLConversionServiceFactory provides a service converting java types to default xml types. These are the default spring converters plus additional converters for java.util.Date and java.util.Calendar.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 |
<div><span style="color:#008080;"> 1</span> <span style="color:#0000FF;">package</span><span style="color:#000000;"> com.oc.ws.utils; </span><span style="color:#008080;"> 2</span> <span style="color:#000000;"> </span><span style="color:#008080;"> 3</span> <span style="color:#000000;"></span><span style="color:#0000FF;">import</span><span style="color:#000000;"> java.text.DateFormat; </span><span style="color:#008080;"> 4</span> <span style="color:#000000;"></span><span style="color:#0000FF;">import</span><span style="color:#000000;"> java.text.ParseException; </span><span style="color:#008080;"> 5</span> <span style="color:#000000;"></span><span style="color:#0000FF;">import</span><span style="color:#000000;"> java.text.SimpleDateFormat; </span><span style="color:#008080;"> 6</span> <span style="color:#000000;"></span><span style="color:#0000FF;">import</span><span style="color:#000000;"> java.util.Calendar; </span><span style="color:#008080;"> 7</span> <span style="color:#000000;"></span><span style="color:#0000FF;">import</span><span style="color:#000000;"> java.util.Date; </span><span style="color:#008080;"> 8</span> <span style="color:#000000;"></span><span style="color:#0000FF;">import</span><span style="color:#000000;"> java.util.GregorianCalendar; </span><span style="color:#008080;"> 9</span> <span style="color:#000000;"> </span><span style="color:#008080;"> 10</span> <span style="color:#000000;"></span><span style="color:#0000FF;">import</span><span style="color:#000000;"> org.springframework.core.convert.converter.Converter; </span><span style="color:#008080;"> 11</span> <span style="color:#000000;"></span><span style="color:#0000FF;">import</span><span style="color:#000000;"> org.springframework.core.convert.support.ConversionServiceFactory; </span><span style="color:#008080;"> 12</span> <span style="color:#000000;"></span><span style="color:#0000FF;">import</span><span style="color:#000000;"> org.springframework.core.convert.support.GenericConversionService; </span><span style="color:#008080;"> 13</span> <span style="color:#000000;"> </span><span style="color:#008080;"> 14</span> <span style="color:#000000;"></span><span style="color:#008000;">/**</span><span style="color:#008000;"> </span><span style="color:#008080;"> 15</span> <span style="color:#008000;"> * {</span><span style="color:#808080;">@link</span><span style="color:#008000;"> ConversionServiceFactory} with additional {</span><span style="color:#808080;">@link</span><span style="color:#008000;"> Converter}s for creating xml documents. </span><span style="color:#008080;"> 16</span> <span style="color:#008000;"> * </span><span style="color:#008080;"> 17</span> <span style="color:#008000;"> * </span><span style="color:#808080;">@author</span><span style="color:#008000;"> bma (Opitz Consulting) </span><span style="color:#008080;"> 18</span> <span style="color:#008000;"> * </span><span style="color:#808080;">@version</span><span style="color:#008000;"> $Revision: 1.8 $ </span><span style="color:#008080;"> 19</span> <span style="color:#008000;"> * @date 14.10.2010 </span><span style="color:#008080;"> 20</span> <span style="color:#008000;"> </span><span style="color:#008000;">*/</span><span style="color:#000000;"> </span><span style="color:#008080;"> 21</span> <span style="color:#000000;"> </span><span style="color:#008080;"> 22</span> <span style="color:#000000;"></span><span style="color:#0000FF;">public</span><span style="color:#000000;"> </span><span style="color:#0000FF;">class</span><span style="color:#000000;"> XMLConversionServiceFactory </span><span style="color:#0000FF;">extends</span><span style="color:#000000;"> ConversionServiceFactory </span><span style="color:#008080;"> 23</span> <span style="color:#000000;">{ </span><span style="color:#008080;"> 24</span> <span style="color:#000000;"> </span><span style="color:#008000;">/**</span><span style="color:#008000;"> sVersionId of the class XMLConversionServiceFactory. </span><span style="color:#008000;">*/</span><span style="color:#000000;"> </span><span style="color:#008080;"> 25</span> <span style="color:#000000;"> </span><span style="color:#0000FF;">public</span><span style="color:#000000;"> </span><span style="color:#0000FF;">static</span><span style="color:#000000;"> </span><span style="color:#0000FF;">final</span><span style="color:#000000;"> String sVersionId </span><span style="color:#000000;">=</span><span style="color:#000000;"> </span><span style="color:#000000;">"</span><span style="color:#000000;">$Revision: 1.8 $</span><span style="color:#000000;">"</span><span style="color:#000000;">; </span><span style="color:#008080;"> 26</span> <span style="color:#000000;"> </span><span style="color:#008080;"> 27</span> <span style="color:#000000;"> </span><span style="color:#008000;">/**</span><span style="color:#008000;"> Log for output of messages of the class XMLConversionServiceFactory </span><span style="color:#008000;">*/</span><span style="color:#000000;"> </span><span style="color:#008080;"> 28</span> <span style="color:#000000;"> </span><span style="color:#008000;">//</span><span style="color:#008000;"> private static Log log = LogFactory.getLog(XMLConversionServiceFactory.class);</span><span style="color:#008000;"> </span><span style="color:#008080;"> 29</span> <span style="color:#008000;"></span><span style="color:#000000;"> </span><span style="color:#008080;"> 30</span> <span style="color:#000000;"> </span><span style="color:#0000FF;">private</span><span style="color:#000000;"> </span><span style="color:#0000FF;">static</span><span style="color:#000000;"> ThreadLocal</span><span style="color:#000000;"><</span><span style="color:#000000;">DateFormat</span><span style="color:#000000;">></span><span style="color:#000000;"> formatDate </span><span style="color:#000000;">=</span><span style="color:#000000;"> </span><span style="color:#0000FF;">new</span><span style="color:#000000;"> ThreadLocal</span><span style="color:#000000;"><</span><span style="color:#000000;">DateFormat</span><span style="color:#000000;">></span><span style="color:#000000;">(); </span><span style="color:#008080;"> 31</span> <span style="color:#000000;"> </span><span style="color:#008080;"> 32</span> <span style="color:#000000;"> </span><span style="color:#0000FF;">private</span><span style="color:#000000;"> </span><span style="color:#0000FF;">static</span><span style="color:#000000;"> ThreadLocal</span><span style="color:#000000;"><</span><span style="color:#000000;">DateFormat</span><span style="color:#000000;">></span><span style="color:#000000;"> formatDateTimezone </span><span style="color:#000000;">=</span><span style="color:#000000;"> </span><span style="color:#0000FF;">new</span><span style="color:#000000;"> ThreadLocal</span><span style="color:#000000;"><</span><span style="color:#000000;">DateFormat</span><span style="color:#000000;">></span><span style="color:#000000;">(); </span><span style="color:#008080;"> 33</span> <span style="color:#000000;"> </span><span style="color:#008080;"> 34</span> <span style="color:#000000;"> </span><span style="color:#0000FF;">private</span><span style="color:#000000;"> </span><span style="color:#0000FF;">static</span><span style="color:#000000;"> ThreadLocal</span><span style="color:#000000;"><</span><span style="color:#000000;">DateFormat</span><span style="color:#000000;">></span><span style="color:#000000;"> formatDateTime </span><span style="color:#000000;">=</span><span style="color:#000000;"> </span><span style="color:#0000FF;">new</span><span style="color:#000000;"> ThreadLocal</span><span style="color:#000000;"><</span><span style="color:#000000;">DateFormat</span><span style="color:#000000;">></span><span style="color:#000000;">(); </span><span style="color:#008080;"> 35</span> <span style="color:#000000;"> </span><span style="color:#008080;"> 36</span> <span style="color:#000000;"> </span><span style="color:#0000FF;">private</span><span style="color:#000000;"> </span><span style="color:#0000FF;">static</span><span style="color:#000000;"> ThreadLocal</span><span style="color:#000000;"><</span><span style="color:#000000;">DateFormat</span><span style="color:#000000;">></span><span style="color:#000000;"> formatDateTimeTimezone </span><span style="color:#000000;">=</span><span style="color:#000000;"> </span><span style="color:#0000FF;">new</span><span style="color:#000000;"> ThreadLocal</span><span style="color:#000000;"><</span><span style="color:#000000;">DateFormat</span><span style="color:#000000;">></span><span style="color:#000000;">(); </span><span style="color:#008080;"> 37</span> <span style="color:#000000;"> </span><span style="color:#008080;"> 38</span> <span style="color:#000000;"> </span><span style="color:#008000;">/**</span><span style="color:#008000;"> </span><span style="color:#008080;"> 39</span> <span style="color:#008000;"> * Returns the value of the field 'formatDate'. </span><span style="color:#008080;"> 40</span> <span style="color:#008000;"> * </span><span style="color:#008080;"> 41</span> <span style="color:#008000;"> * </span><span style="color:#808080;">@return</span><span style="color:#008000;"> Value of the field 'formatDate' </span><span style="color:#008080;"> 42</span> <span style="color:#008000;"> </span><span style="color:#008000;">*/</span><span style="color:#000000;"> </span><span style="color:#008080;"> 43</span> <span style="color:#000000;"> </span><span style="color:#0000FF;">private</span><span style="color:#000000;"> </span><span style="color:#0000FF;">static</span><span style="color:#000000;"> DateFormat getFormatDate() </span><span style="color:#008080;"> 44</span> <span style="color:#000000;"> { </span><span style="color:#008080;"> 45</span> <span style="color:#000000;"> DateFormat result </span><span style="color:#000000;">=</span><span style="color:#000000;"> XMLConversionServiceFactory.formatDate.get(); </span><span style="color:#008080;"> 46</span> <span style="color:#000000;"> </span><span style="color:#0000FF;">if</span><span style="color:#000000;"> (result </span><span style="color:#000000;">==</span><span style="color:#000000;"> </span><span style="color:#0000FF;">null</span><span style="color:#000000;">) </span><span style="color:#008080;"> 47</span> <span style="color:#000000;"> { </span><span style="color:#008080;"> 48</span> <span style="color:#000000;"> result </span><span style="color:#000000;">=</span><span style="color:#000000;"> </span><span style="color:#0000FF;">new</span><span style="color:#000000;"> SimpleDateFormat(</span><span style="color:#000000;">"</span><span style="color:#000000;">yyyy-MM-dd</span><span style="color:#000000;">"</span><span style="color:#000000;">); </span><span style="color:#008080;"> 49</span> <span style="color:#000000;"> XMLConversionServiceFactory.formatDate.set(result); </span><span style="color:#008080;"> 50</span> <span style="color:#000000;"> } </span><span style="color:#008080;"> 51</span> <span style="color:#000000;"> </span><span style="color:#0000FF;">return</span><span style="color:#000000;"> result; </span><span style="color:#008080;"> 52</span> <span style="color:#000000;"> } </span><span style="color:#008080;"> 53</span> <span style="color:#000000;"> </span><span style="color:#008080;"> 54</span> <span style="color:#000000;"> </span><span style="color:#008000;">/**</span><span style="color:#008000;"> </span><span style="color:#008080;"> 55</span> <span style="color:#008000;"> * Returns the value of the field 'getFormatDateTimezone'. </span><span style="color:#008080;"> 56</span> <span style="color:#008000;"> * </span><span style="color:#008080;"> 57</span> <span style="color:#008000;"> * </span><span style="color:#808080;">@return</span><span style="color:#008000;"> Value of the field 'getFormatDateTimezone' </span><span style="color:#008080;"> 58</span> <span style="color:#008000;"> </span><span style="color:#008000;">*/</span><span style="color:#000000;"> </span><span style="color:#008080;"> 59</span> <span style="color:#000000;"> </span><span style="color:#0000FF;">private</span><span style="color:#000000;"> </span><span style="color:#0000FF;">static</span><span style="color:#000000;"> DateFormat getFormatDateTimezone() </span><span style="color:#008080;"> 60</span> <span style="color:#000000;"> { </span><span style="color:#008080;"> 61</span> <span style="color:#000000;"> DateFormat result </span><span style="color:#000000;">=</span><span style="color:#000000;"> XMLConversionServiceFactory.formatDateTimezone.get(); </span><span style="color:#008080;"> 62</span> <span style="color:#000000;"> </span><span style="color:#0000FF;">if</span><span style="color:#000000;"> (result </span><span style="color:#000000;">==</span><span style="color:#000000;"> </span><span style="color:#0000FF;">null</span><span style="color:#000000;">) </span><span style="color:#008080;"> 63</span> <span style="color:#000000;"> { </span><span style="color:#008080;"> 64</span> <span style="color:#000000;"> result </span><span style="color:#000000;">=</span><span style="color:#000000;"> </span><span style="color:#0000FF;">new</span><span style="color:#000000;"> SimpleDateFormat(</span><span style="color:#000000;">"</span><span style="color:#000000;">yyyy-MM-ddZ</span><span style="color:#000000;">"</span><span style="color:#000000;">); </span><span style="color:#008080;"> 65</span> <span style="color:#000000;"> XMLConversionServiceFactory.formatDateTimezone.set(result); </span><span style="color:#008080;"> 66</span> <span style="color:#000000;"> } </span><span style="color:#008080;"> 67</span> <span style="color:#000000;"> </span><span style="color:#0000FF;">return</span><span style="color:#000000;"> result; </span><span style="color:#008080;"> 68</span> <span style="color:#000000;"> } </span><span style="color:#008080;"> 69</span> <span style="color:#000000;"> </span><span style="color:#008080;"> 70</span> <span style="color:#000000;"> </span><span style="color:#008000;">/**</span><span style="color:#008000;"> </span><span style="color:#008080;"> 71</span> <span style="color:#008000;"> * Returns the value of the field 'formatDateTime'. </span><span style="color:#008080;"> 72</span> <span style="color:#008000;"> * </span><span style="color:#008080;"> 73</span> <span style="color:#008000;"> * </span><span style="color:#808080;">@return</span><span style="color:#008000;"> Value of the field 'formatDateTime' </span><span style="color:#008080;"> 74</span> <span style="color:#008000;"> </span><span style="color:#008000;">*/</span><span style="color:#000000;"> </span><span style="color:#008080;"> 75</span> <span style="color:#000000;"> </span><span style="color:#0000FF;">private</span><span style="color:#000000;"> </span><span style="color:#0000FF;">static</span><span style="color:#000000;"> DateFormat getFormatDateTime() </span><span style="color:#008080;"> 76</span> <span style="color:#000000;"> { </span><span style="color:#008080;"> 77</span> <span style="color:#000000;"> DateFormat result </span><span style="color:#000000;">=</span><span style="color:#000000;"> XMLConversionServiceFactory.formatDateTime.get(); </span><span style="color:#008080;"> 78</span> <span style="color:#000000;"> </span><span style="color:#0000FF;">if</span><span style="color:#000000;"> (result </span><span style="color:#000000;">==</span><span style="color:#000000;"> </span><span style="color:#0000FF;">null</span><span style="color:#000000;">) </span><span style="color:#008080;"> 79</span> <span style="color:#000000;"> { </span><span style="color:#008080;"> 80</span> <span style="color:#000000;"> result </span><span style="color:#000000;">=</span><span style="color:#000000;"> </span><span style="color:#0000FF;">new</span><span style="color:#000000;"> SimpleDateFormat(</span><span style="color:#000000;">"</span><span style="color:#000000;">yyyy-MM-dd'T'HH:mm:ss</span><span style="color:#000000;">"</span><span style="color:#000000;">); </span><span style="color:#008080;"> 81</span> <span style="color:#000000;"> XMLConversionServiceFactory.formatDateTime.set(result); </span><span style="color:#008080;"> 82</span> <span style="color:#000000;"> } </span><span style="color:#008080;"> 83</span> <span style="color:#000000;"> </span><span style="color:#0000FF;">return</span><span style="color:#000000;"> result; </span><span style="color:#008080;"> 84</span> <span style="color:#000000;"> } </span><span style="color:#008080;"> 85</span> <span style="color:#000000;"> </span><span style="color:#008080;"> 86</span> <span style="color:#000000;"> </span><span style="color:#008000;">/**</span><span style="color:#008000;"> </span><span style="color:#008080;"> 87</span> <span style="color:#008000;"> * Returns the value of the field 'formatDateTimeTimezone'. </span><span style="color:#008080;"> 88</span> <span style="color:#008000;"> * </span><span style="color:#008080;"> 89</span> <span style="color:#008000;"> * </span><span style="color:#808080;">@return</span><span style="color:#008000;"> Value of the field 'formatDateTimeTimezone' </span><span style="color:#008080;"> 90</span> <span style="color:#008000;"> </span><span style="color:#008000;">*/</span><span style="color:#000000;"> </span><span style="color:#008080;"> 91</span> <span style="color:#000000;"> </span><span style="color:#0000FF;">private</span><span style="color:#000000;"> </span><span style="color:#0000FF;">static</span><span style="color:#000000;"> DateFormat getFormatDateTimeTimezone() </span><span style="color:#008080;"> 92</span> <span style="color:#000000;"> { </span><span style="color:#008080;"> 93</span> <span style="color:#000000;"> DateFormat result </span><span style="color:#000000;">=</span><span style="color:#000000;"> XMLConversionServiceFactory.formatDateTimeTimezone.get(); </span><span style="color:#008080;"> 94</span> <span style="color:#000000;"> </span><span style="color:#0000FF;">if</span><span style="color:#000000;"> (result </span><span style="color:#000000;">==</span><span style="color:#000000;"> </span><span style="color:#0000FF;">null</span><span style="color:#000000;">) </span><span style="color:#008080;"> 95</span> <span style="color:#000000;"> { </span><span style="color:#008080;"> 96</span> <span style="color:#000000;"> result </span><span style="color:#000000;">=</span><span style="color:#000000;"> </span><span style="color:#0000FF;">new</span><span style="color:#000000;"> SimpleDateFormat(</span><span style="color:#000000;">"</span><span style="color:#000000;">yyyy-MM-dd'T'HH:mm:ssZ</span><span style="color:#000000;">"</span><span style="color:#000000;">); </span><span style="color:#008080;"> 97</span> <span style="color:#000000;"> XMLConversionServiceFactory.formatDateTimeTimezone.set(result); </span><span style="color:#008080;"> 98</span> <span style="color:#000000;"> } </span><span style="color:#008080;"> 99</span> <span style="color:#000000;"> </span><span style="color:#0000FF;">return</span><span style="color:#000000;"> result; </span><span style="color:#008080;">100</span> <span style="color:#000000;"> } </span><span style="color:#008080;">101</span> <span style="color:#000000;"> </span><span style="color:#008080;">102</span> <span style="color:#000000;"> </span><span style="color:#008000;">/**</span><span style="color:#008000;"> </span><span style="color:#008080;">103</span> <span style="color:#008000;"> * Converter for converting Calendar to xs:date and xs:dateTime strings. </span><span style="color:#008080;">104</span> <span style="color:#008000;"> * </span><span style="color:#008080;">105</span> <span style="color:#008000;"> * </span><span style="color:#808080;">@author</span><span style="color:#008000;"> Bernhard Mähr (Opitz Consulting) </span><span style="color:#008080;">106</span> <span style="color:#008000;"> * </span><span style="color:#808080;">@version</span><span style="color:#008000;"> $Revision: 1.8 $ </span><span style="color:#008080;">107</span> <span style="color:#008000;"> * @date 15.10.2010 </span><span style="color:#008080;">108</span> <span style="color:#008000;"> </span><span style="color:#008000;">*/</span><span style="color:#000000;"> </span><span style="color:#008080;">109</span> <span style="color:#000000;"> </span><span style="color:#0000FF;">private</span><span style="color:#000000;"> </span><span style="color:#0000FF;">static</span><span style="color:#000000;"> </span><span style="color:#0000FF;">class</span><span style="color:#000000;"> CalendarToStringConverter </span><span style="color:#0000FF;">implements</span><span style="color:#000000;"> Converter</span><span style="color:#000000;"><</span><span style="color:#000000;">Calendar, String</span><span style="color:#000000;">></span><span style="color:#000000;"> </span><span style="color:#008080;">110</span> <span style="color:#000000;"> { </span><span style="color:#008080;">111</span> <span style="color:#000000;"> </span><span style="color:#008080;">112</span> <span style="color:#000000;"> @Override </span><span style="color:#008080;">113</span> <span style="color:#000000;"> </span><span style="color:#0000FF;">public</span><span style="color:#000000;"> String convert(</span><span style="color:#0000FF;">final</span><span style="color:#000000;"> Calendar source) </span><span style="color:#008080;">114</span> <span style="color:#000000;"> { </span><span style="color:#008080;">115</span> <span style="color:#000000;"> String result </span><span style="color:#000000;">=</span><span style="color:#000000;"> </span><span style="color:#0000FF;">null</span><span style="color:#000000;">; </span><span style="color:#008080;">116</span> <span style="color:#000000;"> </span><span style="color:#0000FF;">if</span><span style="color:#000000;"> (source.isSet(Calendar.HOUR)) </span><span style="color:#008080;">117</span> <span style="color:#000000;"> { </span><span style="color:#008080;">118</span> <span style="color:#000000;"> result </span><span style="color:#000000;">=</span><span style="color:#000000;"> XMLConversionServiceFactory.getFormatDateTimeTimezone().format(source); </span><span style="color:#008080;">119</span> <span style="color:#000000;"> } </span><span style="color:#008080;">120</span> <span style="color:#000000;"> </span><span style="color:#0000FF;">else</span><span style="color:#000000;"> </span><span style="color:#008080;">121</span> <span style="color:#000000;"> { </span><span style="color:#008080;">122</span> <span style="color:#000000;"> result </span><span style="color:#000000;">=</span><span style="color:#000000;"> XMLConversionServiceFactory.getFormatDateTimezone().format(source); </span><span style="color:#008080;">123</span> <span style="color:#000000;"> } </span><span style="color:#008080;">124</span> <span style="color:#000000;"> </span><span style="color:#0000FF;">return</span><span style="color:#000000;"> result; </span><span style="color:#008080;">125</span> <span style="color:#000000;"> } </span><span style="color:#008080;">126</span> <span style="color:#000000;"> </span><span style="color:#008080;">127</span> <span style="color:#000000;"> } </span><span style="color:#008080;">128</span> <span style="color:#000000;"> </span><span style="color:#008080;">129</span> <span style="color:#000000;"> </span><span style="color:#008000;">/**</span><span style="color:#008000;"> </span><span style="color:#008080;">130</span> <span style="color:#008000;"> * Converter for converting xs:date and xs:dateTime strings to Calendar objects. </span><span style="color:#008080;">131</span> <span style="color:#008000;"> * </span><span style="color:#008080;">132</span> <span style="color:#008000;"> * </span><span style="color:#808080;">@author</span><span style="color:#008000;"> Bernhard Mähr (Opitz Consulting) </span><span style="color:#008080;">133</span> <span style="color:#008000;"> * </span><span style="color:#808080;">@version</span><span style="color:#008000;"> $Revision: 1.8 $ </span><span style="color:#008080;">134</span> <span style="color:#008000;"> * @date 15.10.2010 </span><span style="color:#008080;">135</span> <span style="color:#008000;"> </span><span style="color:#008000;">*/</span><span style="color:#000000;"> </span><span style="color:#008080;">136</span> <span style="color:#000000;"> </span><span style="color:#0000FF;">private</span><span style="color:#000000;"> </span><span style="color:#0000FF;">static</span><span style="color:#000000;"> </span><span style="color:#0000FF;">class</span><span style="color:#000000;"> StringToCalendarConverter </span><span style="color:#0000FF;">implements</span><span style="color:#000000;"> Converter</span><span style="color:#000000;"><</span><span style="color:#000000;">String, Calendar</span><span style="color:#000000;">></span><span style="color:#000000;"> </span><span style="color:#008080;">137</span> <span style="color:#000000;"> { </span><span style="color:#008080;">138</span> <span style="color:#000000;"> </span><span style="color:#008080;">139</span> <span style="color:#000000;"> @Override </span><span style="color:#008080;">140</span> <span style="color:#000000;"> </span><span style="color:#0000FF;">public</span><span style="color:#000000;"> Calendar convert(</span><span style="color:#0000FF;">final</span><span style="color:#000000;"> String source) </span><span style="color:#008080;">141</span> <span style="color:#000000;"> { </span><span style="color:#008080;">142</span> <span style="color:#000000;"> Calendar result </span><span style="color:#000000;">=</span><span style="color:#000000;"> </span><span style="color:#0000FF;">null</span><span style="color:#000000;">; </span><span style="color:#008080;">143</span> <span style="color:#000000;"> </span><span style="color:#0000FF;">if</span><span style="color:#000000;"> ((source </span><span style="color:#000000;">!=</span><span style="color:#000000;"> </span><span style="color:#0000FF;">null</span><span style="color:#000000;">) </span><span style="color:#000000;">&&</span><span style="color:#000000;"> (source.trim().length() </span><span style="color:#000000;">></span><span style="color:#000000;"> </span><span style="color:#000000;">0</span><span style="color:#000000;">)) </span><span style="color:#008080;">144</span> <span style="color:#000000;"> { </span><span style="color:#008080;">145</span> <span style="color:#000000;"> </span><span style="color:#0000FF;">try</span><span style="color:#000000;"> </span><span style="color:#008080;">146</span> <span style="color:#000000;"> { </span><span style="color:#008080;">147</span> <span style="color:#000000;"> String trimedSource </span><span style="color:#000000;">=</span><span style="color:#000000;"> source.trim(); </span><span style="color:#008080;">148</span> <span style="color:#000000;"> </span><span style="color:#0000FF;">if</span><span style="color:#000000;"> (trimedSource.startsWith(</span><span style="color:#000000;">"</span><span style="color:#000000;">-</span><span style="color:#000000;">"</span><span style="color:#000000;">)) </span><span style="color:#008080;">149</span> <span style="color:#000000;"> { </span><span style="color:#008080;">150</span> <span style="color:#000000;"> trimedSource </span><span style="color:#000000;">=</span><span style="color:#000000;"> trimedSource.substring(</span><span style="color:#000000;">1</span><span style="color:#000000;">); </span><span style="color:#008080;">151</span> <span style="color:#000000;"> } </span><span style="color:#008080;">152</span> <span style="color:#000000;"> Date date </span><span style="color:#000000;">=</span><span style="color:#000000;"> </span><span style="color:#0000FF;">null</span><span style="color:#000000;">; </span><span style="color:#008080;">153</span> <span style="color:#000000;"> </span><span style="color:#0000FF;">if</span><span style="color:#000000;"> (trimedSource.length() </span><span style="color:#000000;">==</span><span style="color:#000000;"> </span><span style="color:#000000;">10</span><span style="color:#000000;">) </span><span style="color:#008080;">154</span> <span style="color:#000000;"> { </span><span style="color:#008080;">155</span> <span style="color:#000000;"> date </span><span style="color:#000000;">=</span><span style="color:#000000;"> XMLConversionServiceFactory.getFormatDate().parse(trimedSource); </span><span style="color:#008080;">156</span> <span style="color:#000000;"> } </span><span style="color:#008080;">157</span> <span style="color:#000000;"> </span><span style="color:#0000FF;">else</span><span style="color:#000000;"> </span><span style="color:#0000FF;">if</span><span style="color:#000000;"> (trimedSource.length() </span><span style="color:#000000;">==</span><span style="color:#000000;"> </span><span style="color:#000000;">17</span><span style="color:#000000;">) </span><span style="color:#008080;">158</span> <span style="color:#000000;"> { </span><span style="color:#008080;">159</span> <span style="color:#000000;"> date </span><span style="color:#000000;">=</span><span style="color:#000000;"> XMLConversionServiceFactory.getFormatDateTimezone().parse(trimedSource); </span><span style="color:#008080;">160</span> <span style="color:#000000;"> } </span><span style="color:#008080;">161</span> <span style="color:#000000;"> </span><span style="color:#0000FF;">else</span><span style="color:#000000;"> </span><span style="color:#0000FF;">if</span><span style="color:#000000;"> (trimedSource.length() </span><span style="color:#000000;">==</span><span style="color:#000000;"> </span><span style="color:#000000;">19</span><span style="color:#000000;">) </span><span style="color:#008080;">162</span> <span style="color:#000000;"> { </span><span style="color:#008080;">163</span> <span style="color:#000000;"> date </span><span style="color:#000000;">=</span><span style="color:#000000;"> XMLConversionServiceFactory.getFormatDateTime().parse(trimedSource); </span><span style="color:#008080;">164</span> <span style="color:#000000;"> } </span><span style="color:#008080;">165</span> <span style="color:#000000;"> </span><span style="color:#0000FF;">else</span><span style="color:#000000;"> </span><span style="color:#008080;">166</span> <span style="color:#000000;"> { </span><span style="color:#008080;">167</span> <span style="color:#000000;"> date </span><span style="color:#000000;">=</span><span style="color:#000000;"> XMLConversionServiceFactory.getFormatDateTimeTimezone().parse(trimedSource); </span><span style="color:#008080;">168</span> <span style="color:#000000;"> } </span><span style="color:#008080;">169</span> <span style="color:#000000;"> result </span><span style="color:#000000;">=</span><span style="color:#000000;"> </span><span style="color:#0000FF;">new</span><span style="color:#000000;"> GregorianCalendar(); </span><span style="color:#008080;">170</span> <span style="color:#000000;"> result.setTime(date); </span><span style="color:#008080;">171</span> <span style="color:#000000;"> } </span><span style="color:#008080;">172</span> <span style="color:#000000;"> </span><span style="color:#0000FF;">catch</span><span style="color:#000000;"> (</span><span style="color:#0000FF;">final</span><span style="color:#000000;"> ParseException pex) </span><span style="color:#008080;">173</span> <span style="color:#000000;"> { </span><span style="color:#008080;">174</span> <span style="color:#000000;"> </span><span style="color:#0000FF;">throw</span><span style="color:#000000;"> </span><span style="color:#0000FF;">new</span><span style="color:#000000;"> IllegalArgumentException( </span><span style="color:#008080;">175</span> <span style="color:#000000;"> </span><span style="color:#000000;">"</span><span style="color:#000000;">Can only convert a [String] with format [-]CCYY-MM-DDThh:mm:ss[Z|(+|-)hh:mm] or [-]CCYY-MM-DD[Z|(+|-)hh:mm] to a [date]; string value '</span><span style="color:#000000;">"</span><span style="color:#000000;"> </span><span style="color:#008080;">176</span> <span style="color:#000000;"> </span><span style="color:#000000;">+</span><span style="color:#000000;"> source </span><span style="color:#000000;">+</span><span style="color:#000000;"> </span><span style="color:#000000;">"</span><span style="color:#000000;">' has unknown format.</span><span style="color:#000000;">"</span><span style="color:#000000;">); </span><span style="color:#008080;">177</span> <span style="color:#000000;"> } </span><span style="color:#008080;">178</span> <span style="color:#000000;"> } </span><span style="color:#008080;">179</span> <span style="color:#000000;"> </span><span style="color:#0000FF;">return</span><span style="color:#000000;"> result; </span><span style="color:#008080;">180</span> <span style="color:#000000;"> } </span><span style="color:#008080;">181</span> <span style="color:#000000;"> </span><span style="color:#008080;">182</span> <span style="color:#000000;"> } </span><span style="color:#008080;">183</span> <span style="color:#000000;"> </span><span style="color:#008080;">184</span> <span style="color:#000000;"> </span><span style="color:#008000;">/**</span><span style="color:#008000;"> </span><span style="color:#008080;">185</span> <span style="color:#008000;"> * {</span><span style="color:#808080;">@inheritDoc</span><span style="color:#008000;">} </span><span style="color:#008080;">186</span> <span style="color:#008000;"> </span><span style="color:#008000;">*/</span><span style="color:#000000;"> </span><span style="color:#008080;">187</span> <span style="color:#000000;"> </span><span style="color:#0000FF;">public</span><span style="color:#000000;"> </span><span style="color:#0000FF;">static</span><span style="color:#000000;"> GenericConversionService createXMLConversionService() </span><span style="color:#008080;">188</span> <span style="color:#000000;"> { </span><span style="color:#008080;">189</span> <span style="color:#000000;"> </span><span style="color:#0000FF;">final</span><span style="color:#000000;"> GenericConversionService conversionService </span><span style="color:#000000;">=</span><span style="color:#000000;"> ConversionServiceFactory.createDefaultConversionService(); </span><span style="color:#008080;">190</span> <span style="color:#000000;"> conversionService.addConverter(</span><span style="color:#0000FF;">new</span><span style="color:#000000;"> XMLConversionServiceFactory.CalendarToStringConverter()); </span><span style="color:#008080;">191</span> <span style="color:#000000;"> conversionService.addConverter(</span><span style="color:#0000FF;">new</span><span style="color:#000000;"> Converter</span><span style="color:#000000;"><</span><span style="color:#000000;">Date, String</span><span style="color:#000000;">></span><span style="color:#000000;">() </span><span style="color:#008080;">192</span> <span style="color:#000000;"> { </span><span style="color:#008080;">193</span> <span style="color:#000000;"> CalendarToStringConverter internalConverter </span><span style="color:#000000;">=</span><span style="color:#000000;"> </span><span style="color:#0000FF;">new</span><span style="color:#000000;"> XMLConversionServiceFactory.CalendarToStringConverter(); </span><span style="color:#008080;">194</span> <span style="color:#000000;"> </span><span style="color:#008080;">195</span> <span style="color:#000000;"> @Override </span><span style="color:#008080;">196</span> <span style="color:#000000;"> </span><span style="color:#0000FF;">public</span><span style="color:#000000;"> String convert(</span><span style="color:#0000FF;">final</span><span style="color:#000000;"> Date source) </span><span style="color:#008080;">197</span> <span style="color:#000000;"> { </span><span style="color:#008080;">198</span> <span style="color:#000000;"> </span><span style="color:#0000FF;">final</span><span style="color:#000000;"> Calendar cal </span><span style="color:#000000;">=</span><span style="color:#000000;"> </span><span style="color:#0000FF;">new</span><span style="color:#000000;"> GregorianCalendar(); </span><span style="color:#008080;">199</span> <span style="color:#000000;"> cal.setTime(source); </span><span style="color:#008080;">200</span> <span style="color:#000000;"> </span><span style="color:#0000FF;">return</span><span style="color:#000000;"> </span><span style="color:#0000FF;">this</span><span style="color:#000000;">.internalConverter.convert(cal); </span><span style="color:#008080;">201</span> <span style="color:#000000;"> } </span><span style="color:#008080;">202</span> <span style="color:#000000;"> }); </span><span style="color:#008080;">203</span> <span style="color:#000000;"> conversionService.addConverter(</span><span style="color:#0000FF;">new</span><span style="color:#000000;"> StringToCalendarConverter()); </span><span style="color:#008080;">204</span> <span style="color:#000000;"> conversionService.addConverter(</span><span style="color:#0000FF;">new</span><span style="color:#000000;"> Converter</span><span style="color:#000000;"><</span><span style="color:#000000;">String, Date</span><span style="color:#000000;">></span><span style="color:#000000;">() </span><span style="color:#008080;">205</span> <span style="color:#000000;"> { </span><span style="color:#008080;">206</span> <span style="color:#000000;"> StringToCalendarConverter internalConverter </span><span style="color:#000000;">=</span><span style="color:#000000;"> </span><span style="color:#0000FF;">new</span><span style="color:#000000;"> StringToCalendarConverter(); </span><span style="color:#008080;">207</span> <span style="color:#000000;"> </span><span style="color:#008080;">208</span> <span style="color:#000000;"> @Override </span><span style="color:#008080;">209</span> <span style="color:#000000;"> </span><span style="color:#0000FF;">public</span><span style="color:#000000;"> Date convert(</span><span style="color:#0000FF;">final</span><span style="color:#000000;"> String source) </span><span style="color:#008080;">210</span> <span style="color:#000000;"> { </span><span style="color:#008080;">211</span> <span style="color:#000000;"> </span><span style="color:#0000FF;">return</span><span style="color:#000000;"> </span><span style="color:#0000FF;">this</span><span style="color:#000000;">.internalConverter.convert(source).getTime(); </span><span style="color:#008080;">212</span> <span style="color:#000000;"> } </span><span style="color:#008080;">213</span> <span style="color:#000000;"> }); </span><span style="color:#008080;">214</span> <span style="color:#000000;"> </span><span style="color:#0000FF;">return</span><span style="color:#000000;"> conversionService; </span><span style="color:#008080;">215</span> <span style="color:#000000;"> } </span><span style="color:#008080;">216</span> <span style="color:#000000;"> </span><span style="color:#008080;">217</span> <span style="color:#000000;">}</span></div> |
The SimplePayloadMethodReturnValueHandler is a generic MethodProcessor converting the return value of the java method call to the web service call payload.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 |
<div><span style="color:#008080;"> 1</span> <span style="color:#0000FF;">package</span><span style="color:#000000;"> com.oc.ws.utils; </span><span style="color:#008080;"> 2</span> <span style="color:#000000;"> </span><span style="color:#008080;"> 3</span> <span style="color:#000000;"></span><span style="color:#0000FF;">import</span><span style="color:#000000;"> javax.xml.parsers.DocumentBuilder; </span><span style="color:#008080;"> 4</span> <span style="color:#000000;"></span><span style="color:#0000FF;">import</span><span style="color:#000000;"> javax.xml.parsers.DocumentBuilderFactory; </span><span style="color:#008080;"> 5</span> <span style="color:#000000;"></span><span style="color:#0000FF;">import</span><span style="color:#000000;"> javax.xml.transform.Source; </span><span style="color:#008080;"> 6</span> <span style="color:#000000;"></span><span style="color:#0000FF;">import</span><span style="color:#000000;"> javax.xml.transform.dom.DOMSource; </span><span style="color:#008080;"> 7</span> <span style="color:#000000;"> </span><span style="color:#008080;"> 8</span> <span style="color:#000000;"></span><span style="color:#0000FF;">import</span><span style="color:#000000;"> org.springframework.core.MethodParameter; </span><span style="color:#008080;"> 9</span> <span style="color:#000000;"></span><span style="color:#0000FF;">import</span><span style="color:#000000;"> org.springframework.core.convert.ConversionService; </span><span style="color:#008080;"> 10</span> <span style="color:#000000;"></span><span style="color:#0000FF;">import</span><span style="color:#000000;"> org.springframework.core.convert.support.ConversionServiceFactory; </span><span style="color:#008080;"> 11</span> <span style="color:#000000;"></span><span style="color:#0000FF;">import</span><span style="color:#000000;"> org.springframework.ws.server.endpoint.adapter.method.AbstractPayloadSourceMethodProcessor; </span><span style="color:#008080;"> 12</span> <span style="color:#000000;"></span><span style="color:#0000FF;">import</span><span style="color:#000000;"> org.springframework.ws.server.endpoint.annotation.Namespace; </span><span style="color:#008080;"> 13</span> <span style="color:#000000;"></span><span style="color:#0000FF;">import</span><span style="color:#000000;"> org.springframework.ws.server.endpoint.annotation.PayloadRoot; </span><span style="color:#008080;"> 14</span> <span style="color:#000000;"></span><span style="color:#0000FF;">import</span><span style="color:#000000;"> org.w3c.dom.Document; </span><span style="color:#008080;"> 15</span> <span style="color:#000000;"></span><span style="color:#0000FF;">import</span><span style="color:#000000;"> org.w3c.dom.Element; </span><span style="color:#008080;"> 16</span> <span style="color:#000000;"></span><span style="color:#0000FF;">import</span><span style="color:#000000;"> org.w3c.dom.Node; </span><span style="color:#008080;"> 17</span> <span style="color:#000000;"></span><span style="color:#0000FF;">import</span><span style="color:#000000;"> org.w3c.dom.NodeList; </span><span style="color:#008080;"> 18</span> <span style="color:#000000;"> </span><span style="color:#008080;"> 19</span> <span style="color:#000000;"></span><span style="color:#008000;">/**</span><span style="color:#008000;"> </span><span style="color:#008080;"> 20</span> <span style="color:#008000;"> * A MethodProcessor converting return values. If the Return value is one of the types </span><span style="color:#008080;"> 21</span> <span style="color:#008000;"> * <ul> </span><span style="color:#008080;"> 22</span> <span style="color:#008000;"> * <li>boolean or Boolean</li> </span><span style="color:#008080;"> 23</span> <span style="color:#008000;"> * <li>double or Double</li> </span><span style="color:#008080;"> 24</span> <span style="color:#008000;"> * <li>Node</li> </span><span style="color:#008080;"> 25</span> <span style="color:#008000;"> * <li>NodeList</li> </span><span style="color:#008080;"> 26</span> <span style="color:#008000;"> * <li>String</li> </span><span style="color:#008080;"> 27</span> <span style="color:#008000;"> * </ul> </span><span style="color:#008080;"> 28</span> <span style="color:#008000;"> * the processer converts the value to the source. For other types the conversionService (default {</span><span style="color:#808080;">@link</span><span style="color:#008000;"> </span><span style="color:#008080;"> 29</span> <span style="color:#008000;"> * ConversionServiceFactory.createDefaultConversionService()}) is used. Example of configuration: <code> </span><span style="color:#008080;"> 30</span> <span style="color:#008000;"> * <bean class="org.springframework.ws.server.endpoint.adapter.DefaultMethodEndpointAdapter"> </span><span style="color:#008080;"> 31</span> <span style="color:#008000;"> * <property name="methodArgumentResolvers"> </span><span style="color:#008080;"> 32</span> <span style="color:#008000;"> * <list> </span><span style="color:#008080;"> 33</span> <span style="color:#008000;"> * <bean class="org.springframework.ws.server.endpoint.adapter.method.XPathParamMethodArgumentResolver" > </span><span style="color:#008080;"> 34</span> <span style="color:#008000;"> * <property name="conversionService" ref="conversionService" /> </span><span style="color:#008080;"> 35</span> <span style="color:#008000;"> * </bean> </span><span style="color:#008080;"> 36</span> <span style="color:#008000;"> * </list> </span><span style="color:#008080;"> 37</span> <span style="color:#008000;"> * </property> </span><span style="color:#008080;"> 38</span> <span style="color:#008000;"> * <property name="methodReturnValueHandlers"> </span><span style="color:#008080;"> 39</span> <span style="color:#008000;"> * <list> </span><span style="color:#008080;"> 40</span> <span style="color:#008000;"> * <bean class="com.oc.ws.utils.SimplePayloadMethodReturnValueHandler" > </span><span style="color:#008080;"> 41</span> <span style="color:#008000;"> * <property name="conversionService" ref="conversionService" /> </span><span style="color:#008080;"> 42</span> <span style="color:#008000;"> * </bean> </span><span style="color:#008080;"> 43</span> <span style="color:#008000;"> * </list> </span><span style="color:#008080;"> 44</span> <span style="color:#008000;"> * </property> </span><span style="color:#008080;"> 45</span> <span style="color:#008000;"> * </bean> </span><span style="color:#008080;"> 46</span> <span style="color:#008000;"> * </code> </span><span style="color:#008080;"> 47</span> <span style="color:#008000;"> * </span><span style="color:#008080;"> 48</span> <span style="color:#008000;"> * </span><span style="color:#808080;">@author</span><span style="color:#008000;"> bma (Opitz Consulting) </span><span style="color:#008080;"> 49</span> <span style="color:#008000;"> * </span><span style="color:#808080;">@version</span><span style="color:#008000;"> $Revision: 1.8 $ </span><span style="color:#008080;"> 50</span> <span style="color:#008000;"> * @date 08.10.2010 </span><span style="color:#008080;"> 51</span> <span style="color:#008000;"> </span><span style="color:#008000;">*/</span><span style="color:#000000;"> </span><span style="color:#008080;"> 52</span> <span style="color:#000000;"> </span><span style="color:#008080;"> 53</span> <span style="color:#000000;"></span><span style="color:#0000FF;">public</span><span style="color:#000000;"> </span><span style="color:#0000FF;">class</span><span style="color:#000000;"> SimplePayloadMethodReturnValueHandler </span><span style="color:#0000FF;">extends</span><span style="color:#000000;"> AbstractPayloadSourceMethodProcessor </span><span style="color:#008080;"> 54</span> <span style="color:#000000;">{ </span><span style="color:#008080;"> 55</span> <span style="color:#000000;"> </span><span style="color:#008080;"> 56</span> <span style="color:#000000;"> </span><span style="color:#008000;">/**</span><span style="color:#008000;"> sVersionId of the class SimplePayloadMethodReturnValueHandler. </span><span style="color:#008000;">*/</span><span style="color:#000000;"> </span><span style="color:#008080;"> 57</span> <span style="color:#000000;"> </span><span style="color:#0000FF;">public</span><span style="color:#000000;"> </span><span style="color:#0000FF;">static</span><span style="color:#000000;"> </span><span style="color:#0000FF;">final</span><span style="color:#000000;"> String sVersionId </span><span style="color:#000000;">=</span><span style="color:#000000;"> </span><span style="color:#000000;">"</span><span style="color:#000000;">$Revision: 1.8 $</span><span style="color:#000000;">"</span><span style="color:#000000;">; </span><span style="color:#008080;"> 58</span> <span style="color:#000000;"> </span><span style="color:#008080;"> 59</span> <span style="color:#000000;"> </span><span style="color:#008000;">/**</span><span style="color:#008000;"> Log for output of messages of the class SimplePayloadMethodReturnValueHandler </span><span style="color:#008000;">*/</span><span style="color:#000000;"> </span><span style="color:#008080;"> 60</span> <span style="color:#000000;"> </span><span style="color:#008000;">//</span><span style="color:#008000;"> private static Log log = LogFactory.getLog(SimplePayloadMethodReturnValueHandler.class);</span><span style="color:#008000;"> </span><span style="color:#008080;"> 61</span> <span style="color:#008000;"></span><span style="color:#000000;"> </span><span style="color:#008080;"> 62</span> <span style="color:#000000;"> </span><span style="color:#008000;">/**</span><span style="color:#008000;"> The conversion service to use. </span><span style="color:#008000;">*/</span><span style="color:#000000;"> </span><span style="color:#008080;"> 63</span> <span style="color:#000000;"> </span><span style="color:#0000FF;">private</span><span style="color:#000000;"> ConversionService conversionService </span><span style="color:#000000;">=</span><span style="color:#000000;"> ConversionServiceFactory.createDefaultConversionService(); </span><span style="color:#008080;"> 64</span> <span style="color:#000000;"> </span><span style="color:#008080;"> 65</span> <span style="color:#000000;"> </span><span style="color:#008000;">/**</span><span style="color:#008000;"> </span><span style="color:#008080;"> 66</span> <span style="color:#008000;"> * Sets the value of the field 'conversionService' to the given value. </span><span style="color:#008080;"> 67</span> <span style="color:#008000;"> * </span><span style="color:#008080;"> 68</span> <span style="color:#008000;"> * </span><span style="color:#808080;">@param</span><span style="color:#008000;"> conversionService </span><span style="color:#008080;"> 69</span> <span style="color:#008000;"> * Value the field 'conversionService' should get </span><span style="color:#008080;"> 70</span> <span style="color:#008000;"> </span><span style="color:#008000;">*/</span><span style="color:#000000;"> </span><span style="color:#008080;"> 71</span> <span style="color:#000000;"> </span><span style="color:#0000FF;">public</span><span style="color:#000000;"> </span><span style="color:#0000FF;">void</span><span style="color:#000000;"> setConversionService(</span><span style="color:#0000FF;">final</span><span style="color:#000000;"> ConversionService conversionService) </span><span style="color:#008080;"> 72</span> <span style="color:#000000;"> { </span><span style="color:#008080;"> 73</span> <span style="color:#000000;"> </span><span style="color:#0000FF;">this</span><span style="color:#000000;">.conversionService </span><span style="color:#000000;">=</span><span style="color:#000000;"> conversionService; </span><span style="color:#008080;"> 74</span> <span style="color:#000000;"> } </span><span style="color:#008080;"> 75</span> <span style="color:#000000;"> </span><span style="color:#008080;"> 76</span> <span style="color:#000000;"> </span><span style="color:#008000;">/**</span><span style="color:#008000;"> </span><span style="color:#008080;"> 77</span> <span style="color:#008000;"> * {</span><span style="color:#808080;">@inheritDoc</span><span style="color:#008000;">} </span><span style="color:#008080;"> 78</span> <span style="color:#008000;"> * </span><span style="color:#008080;"> 79</span> <span style="color:#008000;"> * </span><span style="color:#808080;">@see</span><span style="color:#008000;"> org.springframework.ws.server.endpoint.adapter.method.AbstractPayloadMethodProcessor#supportsResponsePayloadReturnType(org.springframework.core.MethodParameter) </span><span style="color:#008080;"> 80</span> <span style="color:#008000;"> </span><span style="color:#008000;">*/</span><span style="color:#000000;"> </span><span style="color:#008080;"> 81</span> <span style="color:#000000;"> @Override </span><span style="color:#008080;"> 82</span> <span style="color:#000000;"> </span><span style="color:#0000FF;">protected</span><span style="color:#000000;"> </span><span style="color:#0000FF;">boolean</span><span style="color:#000000;"> supportsResponsePayloadReturnType(</span><span style="color:#0000FF;">final</span><span style="color:#000000;"> MethodParameter methodparameter) </span><span style="color:#008080;"> 83</span> <span style="color:#000000;"> { </span><span style="color:#008080;"> 84</span> <span style="color:#000000;"> </span><span style="color:#0000FF;">boolean</span><span style="color:#000000;"> result </span><span style="color:#000000;">=</span><span style="color:#000000;"> </span><span style="color:#0000FF;">false</span><span style="color:#000000;">; </span><span style="color:#008080;"> 85</span> <span style="color:#000000;"> </span><span style="color:#0000FF;">final</span><span style="color:#000000;"> Class</span><span style="color:#000000;"><?></span><span style="color:#000000;"> parameterType </span><span style="color:#000000;">=</span><span style="color:#000000;"> methodparameter.getParameterType(); </span><span style="color:#008080;"> 86</span> <span style="color:#000000;"> </span><span style="color:#0000FF;">if</span><span style="color:#000000;"> (Boolean.</span><span style="color:#0000FF;">class</span>< |