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.
 
  52         <bean id="marshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshaller">
 
  53                 <property name="packagesToScan" value="de.spring.webservices.auto"/>
 
  56         NO PUEDO USAR ESTA CONFIGURACION PORQUE SE PRODUCE ESTE ERROR:
 
  58         Caused by: org.springframework.oxm.UncategorizedMappingException: Unknown JAXB exception;
 
  59         nested exception is com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationsException: 1 counts of IllegalAnnotationExceptions
 
  60                 de.spring.webservices.auto.Examples es una interfaz y JAXB no puede manejar interfaces.
 
  61                         this problem is related to the following location: at de.spring.webservices.auto.Examples
 
  63                         at org.springframework.oxm.jaxb.Jaxb2Marshaller.convertJaxbException(Jaxb2Marshaller.java:888)
 
  65                 ESTE ERROR SE PRODUCE PORQUE cxf-codegen-plugin GENERA Examples QUE ES UN inteface @WebService
 
  66                 maven-jaxb2-plugin NO GENERA ESTOS OBJETOS pero maven-jaxb2-plugin NO ES BUENO PARA GENERAR CLASES
 
  67                 DESDE WSDLs POR LAS RAZONES EXPLICADAS EN EL pom.xml DEL PROYECTO web-services-spring-jaxb2-client.
 
  69      <bean id="marshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshaller">
 
  71                 contextPath because of Examples autogenerated class, which is an @Weberservice interface.
 
  73         <property name="contextPath" value="de.spring.webservices.client.auto:name.gumartinm.spring_ws.parent"/>
 
  78     <!-- Required in order to use SOAP 1.2
 
  79          id="messageFactory" is not a random choice, if you use another name it will not work
 
  80          (Spring will end up loading SOAP 1.1)
 
  82     <bean id="messageFactory" class="org.springframework.ws.soap.saaj.SaajSoapMessageFactory">
 
  83         <property name="soapVersion">
 
  84             <util:constant static-field="org.springframework.ws.soap.SoapVersion.SOAP_12" />
 
  90         ¿Este validador funciona teniendo inheritance en el xsd? (inheritances es una cosa especial 
 
  91         del JAXB2 que estoy usando para generar las clases desde el xsd)
 
  92         Parece que el unmarshal (que supongo que se hace con el JAXB2 que está en el classpath
 
  93         debido al tipo de Endpoint que estoy usando, que por cierto no sé cual JAXB2 está cogiendo realmente) 
 
  94         funciona, así que supongo el validador tambien :/
 
  95         Lo que realmente tampoco sé es si hay alguna relación entre los validadores y JAXB2 :/
 
  97     <bean id="payloadValidatingInterceptor" 
 
  98         class="org.springframework.ws.client.support.interceptor.PayloadValidatingInterceptor">
 
  99         <property name="schemas">
 
 102                         ALWAYS FIRST THE XSD FILES TO BE IMPORTED!!!!!  O.o
 
 103                         OTHERWISE THE import IN examples.xsd WILL BE SOLVED BY MEANS OF DOWNLOADING THE
 
 104                         EXTERNAL parent.xsd (USING THE URL LINKED BY THE IMPORT STATEMENT IN examples.xsd)
 
 106                                 IF YOU DON'T DO THIS, PayloadValidatingInterceptor WILL TRY TO CONNECT TO THE
 
 107                                 EXTERNAL SERVER WHERE parent.xsd IS LOCATED AND IT WILL FAIL IF BECAUSE SOME
 
 108                                 REASON YOU DON'T HAVE IN THAT VERY MOMENT NETWORK CONNECTION. SO, DON'T MESS WITH THIS
 
 111                  <value>classpath:parent.xsd</value>
 
 113                  <value>classpath:examples.xsd</value>
 
 116         <property name="validateRequest" value="true"/>
 
 117         <property name="validateResponse" value="true"/>
 
 122     WebServiceTemplate using these strategies by default (see WebServiceTemplate.properties file)
 
 124     org.springframework.ws.client.core.FaultMessageResolver=org.springframework.ws.soap.client.core.SoapFaultMessageResolver
 
 125         org.springframework.ws.WebServiceMessageFactory=org.springframework.ws.soap.saaj.SaajSoapMessageFactory
 
 126         org.springframework.ws.transport.WebServiceMessageSender=org.springframework.ws.transport.http.HttpUrlConnectionMessageSender
 
 130     <bean id="webServiceTemplate" class="org.springframework.ws.client.core.WebServiceTemplate">
 
 131         <constructor-arg ref="messageFactory"/>
 
 132         <property name="marshaller" ref="marshaller" />
 
 133         <property name="unmarshaller" ref="marshaller" />
 
 135         <!-- For local deployments change to http://localhost:8080/web-services-spring-cxf-server/spring-ws/example -->
 
 136         <property name="defaultUri" value="http://gumartinm.name/spring-ws/example"/>
 
 138         <property name="interceptors">
 
 140                 <ref bean="payloadValidatingInterceptor" />
 
 146     Using @Service and @Autowired
 
 147     We could use just XML configuration, or XML confirguration and @Autowired or as I am doing now @Service and @Autowired.
 
 148     <bean id="exampleClientService" class="de.spring.webservices.client.ExampleClientService">
 
 150         @Autowired works even using XML configuration as long as you use context:component-scan
 
 151         <property name="webServiceTemplate" ref="webServiceTemplate"/>