en mi proyecto anterior, que implementan un cliente de servicio web con Spring 2.5.6, maven2, xmlbeans.
- xmlbeans es responsable de un/Mariscal
- maven2 es para Gestión de proyectos/edificio, etc.
pego algunos códigos aquí y espero que sean útiles.
xmlbeans experto plug-in conf: (en pom.xml)
<build>
<finalName>projectname</finalName>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
<resource>
<directory>target/generated-classes/xmlbeans
</directory>
</resource>
</resources>
<!-- xmlbeans maven plugin for the client side -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>xmlbeans-maven-plugin</artifactId>
<version>2.3.2</version>
<executions>
<execution>
<goals>
<goal>xmlbeans</goal>
</goals>
</execution>
</executions>
<inherited>true</inherited>
<configuration>
<schemaDirectory>src/main/resources/</schemaDirectory>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin
</artifactId>
<version>1.1</version>
<executions>
<execution>
<id>add-source</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source> target/generated-sources/xmlbeans</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
Así que desde el conf anterior, es necesario poner el archivo de esquema (ya sea independiente o en su archivo WSDL, es necesario extraerlos y guardar como un archivo de esquema.) en src/main/resources. cuando construyas el proyecto con maven, los pojos serán generados por xmlbeans. Los códigos fuente generados estarán bajo target/generated-sources/xmlbeans.
luego llegamos a Spring conf. Acabo de poner el contexto relevante WS aquí:
<bean id="messageFactory" class="org.springframework.ws.soap.axiom.AxiomSoapMessageFactory">
<property name="payloadCaching" value="true"/>
</bean>
<bean id="abstractClient" abstract="true">
<constructor-arg ref="messageFactory"/>
</bean>
<bean id="marshaller" class="org.springframework.oxm.xmlbeans.XmlBeansMarshaller"/>
<bean id="myWebServiceClient" parent="abstractClient" class="class.path.MyWsClient">
<property name="defaultUri" value="http://your.webservice.url"/>
<property name="marshaller" ref="marshaller"/>
<property name="unmarshaller" ref="marshaller"/>
</bean>
finalmente, echar un vistazo a la clase de Java WS-cliente
public class MyWsClient extends WebServiceGatewaySupport {
//if you need some Dao, Services, just @Autowired here.
public MyWsClient(WebServiceMessageFactory messageFactory) {
super(messageFactory);
}
// here is the operation defined in your wsdl
public Object someOperation(Object parameter){
//instantiate the xmlbeans generated class, infact, the instance would be the document (marshaled) you are gonna send to the WS
SomePojo requestDoc = SomePojo.Factory.newInstance(); // the factory and other methods are prepared by xmlbeans
ResponsePojo responseDoc = (ResponsePojo)getWebServiceTemplate().marshalSendAndReceive(requestDoc); // here invoking the WS
//then you can get the returned object from the responseDoc.
}
}
espero que los códigos de ejemplo son útiles.
Un buen ejemplo podría encontrar en http://stackoverflow.com/questions/18641928/consume-webservice-service-in- spring-ws-using-wsdl –