in meinem vorherigen Projekt, umgesetzt ich ein Webservice-Client mit Feder 2.5.6, maven2, XMLBeans.
- XMLBeans ist verantwortlich für un/Marschall
- maven2 für Projekt mgmt ist/Gebäude usw.
ich einige Codes hier einfügen und hoffen, dass sie nützlich sind.
XMLBeans Maven Plugin conf: (in 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>
So aus der obigen conf, müssen Sie die Schemadatei setzen (entweder eigenständig oder in Ihrer WSDL-Datei, müssen Sie sie extrahieren und Speichern Sie als Schemadatei.) unter src/main/resources. Wenn du das Projekt mit Maven erstellst, werden die Pojos von xmlbeans generiert. Die generierten Quellcodes liegen unter target/generated-sources/xmlbeans.
dann kommen wir zu Spring conf. Ich habe nur den WS relevanten Kontext hier:
<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>
schließlich nimmt eine der Java-Klasse ws-Client sucht
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.
}
}
ich die Beispiel-Codes sind hilfreich hoffen.
Eine gute Probe konnte bei http://stackoverflow.com/questions/18641928/consume-webservice-service-in- finden Frühling-ws-using-wsdl –