1 <?xml version="1.0" encoding="UTF-8"?>
 
   2 <beans xmlns="http://www.springframework.org/schema/beans"
 
   3     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
 
   4     xmlns:context="http://www.springframework.org/schema/context"
 
   5     xmlns:sws="http://www.springframework.org/schema/web-services"
 
   6     xmlns:oxm="http://www.springframework.org/schema/oxm" 
 
   7     xmlns:aop="http://www.springframework.org/schema/aop"
 
   8     xmlns:util="http://www.springframework.org/schema/util"
 
  10     xsi:schemaLocation="http://www.springframework.org/schema/beans 
 
  11         http://www.springframework.org/schema/beans/spring-beans.xsd
 
  12         http://www.springframework.org/schema/context 
 
  13         http://www.springframework.org/schema/context/spring-context.xsd
 
  14         http://www.springframework.org/schema/web-services 
 
  15         http://www.springframework.org/schema/web-services/web-services.xsd
 
  16         http://www.springframework.org/schema/oxm 
 
  17         http://www.springframework.org/schema/oxm/spring-oxm.xsd
 
  18         http://www.springframework.org/schema/util
 
  19         http://www.springframework.org/schema/util/spring-util.xsd">
 
  22         This file is an example about how someone should write code in order to send and
 
  23         receive data from the Web Services.
 
  26     <!-- Searches for beans in packages (instead of XML configuration we can use in this way annotations like @Service, @Component, etc, etc)  --> 
 
  27     <context:component-scan base-package="de.spring.webservices"/>
 
  30         Three ways of using a marshallers/unmarshallers.
 
  32         1. No declarar nada en el XML y dejar que Spring lo haga internamente todo por nosotros.
 
  33         Esto equivale a esta configuracion en XML
 
  35         <oxm:jaxb2-marshaller id="marshaller" context-path="de.spring.webservices"/>
 
  36         El context-path Spring supongo que lo rellena automáticamente en base al component-scan declarado arriba.
 
  38         2. Especificando el context-path para ser escaneado por Spring usando anotaciones. Esto
 
  41         <oxm:jaxb2-marshaller id="marshaller" context-path="de.spring.webservices.auto"/>
 
  42         Esto es lo mismo que haría Spring si no declaramos nada en el XML pero así tenemos opción de
 
  43         de especificar un context-path en concreto.
 
  45         3. Especificando la implementación concreta del marshaller.
 
  46         Con esta opción además puedo usar packagesToScan, contest-path si no recuerdo mal tenía problemas
 
  47         cuando había dos ObjectFactory con el mismo package. Uno está en globalxsds y otro en este proyecto.
 
  48         De todos modos, probablemente habría que usar un package distinto para lo que hay
 
  49         en globalxsds (quizás incluso basado en el namespace del xsd) y así podría evitar esta configuración. 
 
  51         <bean id="marshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshaller">
 
  53                 maven-jaxb2-plugin for WSDL DOES generate again the objects in web-services-spring-jaxb2-globalxsds :(
 
  54                 So we MAY NOT scan everything because there is more than one class representing
 
  55                 the same XML element. :(
 
  57                 We scan the objects generated in this package.
 
  59         <property name="packagesToScan" value="de.spring.webservices.client.auto"/>
 
  63     <!-- Required in order to use SOAP 1.2
 
  64          id="messageFactory" is not a random choice, if you use another name it will not work
 
  65          (Spring will end up loading SOAP 1.1)
 
  67     <bean id="messageFactory" class="org.springframework.ws.soap.saaj.SaajSoapMessageFactory">
 
  68         <property name="soapVersion">
 
  69             <util:constant static-field="org.springframework.ws.soap.SoapVersion.SOAP_12" />
 
  75         ¿Este validador funciona teniendo inheritance en el xsd? (inheritances es una cosa especial 
 
  76         del JAXB2 que estoy usando para generar las clases desde el xsd)
 
  77         Parece que el unmarshal (que supongo que se hace con el JAXB2 que está en el classpath
 
  78         debido al tipo de Endpoint que estoy usando, que por cierto no sé cual JAXB2 está cogiendo realmente) 
 
  79         funciona, así que supongo el validador tambien :/
 
  80         Lo que realmente tampoco sé es si hay alguna relación entre los validadores y JAXB2 :/
 
  82     <bean id="payloadValidatingInterceptor" 
 
  83         class="org.springframework.ws.client.support.interceptor.PayloadValidatingInterceptor">
 
  84         <property name="schemas">
 
  87                         ALWAYS FIRST THE XSD FILES TO BE IMPORTED!!!!!  O.o
 
  88                         OTHERWISE THE import IN examples.xsd WILL BE SOLVED BY MEANS OF DOWNLOADING THE
 
  89                         EXTERNAL parent.xsd (USING THE URL LINKED BY THE IMPORT STATEMENT IN examples.xsd)
 
  91                                 IF YOU DON'T DO THIS, PayloadValidatingInterceptor WILL TRY TO CONNECT TO THE
 
  92                                 EXTERNAL SERVER WHERE parent.xsd IS LOCATED AND IT WILL FAIL IF BECAUSE SOME
 
  93                                 REASON YOU DON'T HAVE IN THAT VERY MOMENT NETWORK CONNECTION. SO, DON'T MESS WITH THIS
 
  96                  <value>classpath:schemas/parent.xsd</value>
 
  98                  <value>classpath:schemas/examples.xsd</value>
 
 101         <property name="validateRequest" value="true"/>
 
 102         <property name="validateResponse" value="true"/>
 
 106                 Los errores de validacion se devuelven así:
 
 108                 <env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope">
 
 113                             <env:Value>env:Sender</env:Value>
 
 116                             <env:Text xml:lang="en">Validation error</env:Text>
 
 119                             <spring-ws:ValidationError xmlns:spring-ws="http://springframework.org/spring-ws">cvc-maxLength-valid: El valor 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' con la longitud = '91' no es de faceta válida con respecto a maxLength '30' para el tipo 'limitedString'.</spring-ws:ValidationError>
 
 120                             <spring-ws:ValidationError xmlns:spring-ws="http://springframework.org/spring-ws">cvc-type.3.1.3: El valor 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' del elemento 'exam:data' no es válido.</spring-ws:ValidationError>
 
 126                 El manejador de errores de validación es implementado por AbstractValidatingInterceptor (PayloadValidatingInterceptor)
 
 127                 luego si quisiéramos loguear los mensaje de error de validación de algún modo especial tendríamos que crear nuestro propio PayloadValidatingInterceptor :(          
 
 130     <!-- Enables us to log custom Fault remote messages. No loguea mensajes de error de validación :( -->
 
 131     <bean id="customFaultMessageResolver" class="de.spring.webservices.client.CustomFaultMessageResolver">
 
 132                 <property name="unmarshaller" ref="marshaller"/>
 
 136     WebServiceTemplate using these strategies by default (see WebServiceTemplate.properties file)
 
 138     org.springframework.ws.client.core.FaultMessageResolver=org.springframework.ws.soap.client.core.SoapFaultMessageResolver
 
 139         org.springframework.ws.WebServiceMessageFactory=org.springframework.ws.soap.saaj.SaajSoapMessageFactory
 
 140         org.springframework.ws.transport.WebServiceMessageSender=org.springframework.ws.transport.http.HttpUrlConnectionMessageSender
 
 144     <bean id="webServiceTemplate" class="org.springframework.ws.client.core.WebServiceTemplate">
 
 145         <constructor-arg ref="messageFactory"/>
 
 146         <property name="marshaller" ref="marshaller" />
 
 147         <property name="unmarshaller" ref="marshaller" />
 
 149         <!-- For local deployments change to http://localhost:8080/web-services-spring-jaxb2-server/spring-ws/example -->
 
 150         <property name="defaultUri" value="http://gumartinm.name/spring-ws/example"/>
 
 152         <property name="interceptors">
 
 154                 <ref bean="payloadValidatingInterceptor" />
 
 158         <property name="faultMessageResolver" ref="customFaultMessageResolver" />
 
 160         <property name="messageSenders">
 
 162                 <bean class="de.spring.webservices.client.transport.http.CustomHttpRequestMessageSender" />
 
 168     Using @Service and @Autowired
 
 169     We could use just XML configuration, or XML confirguration and @Autowired or as I am doing now @Service and @Autowired.
 
 170     <bean id="exampleClientService" class="de.spring.webservices.client.ExampleClientService">
 
 172         @Autowired works even using XML configuration as long as you use context:component-scan
 
 173         <property name="webServiceTemplate" ref="webServiceTemplate"/>