Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>in my previous project, I implemented a Webservice client with Spring 2.5.6, maven2, xmlbeans.</p> <ul> <li>xmlbeans is responsible for un/marshal</li> <li>maven2 is for project mgmt/building etc.</li> </ul> <p>I paste some codes here and hope they are helpful.</p> <p>xmlbeans maven plugin conf: (in pom.xml)</p> <pre><code>&lt;build&gt; &lt;finalName&gt;projectname&lt;/finalName&gt; &lt;resources&gt; &lt;resource&gt; &lt;directory&gt;src/main/resources&lt;/directory&gt; &lt;filtering&gt;true&lt;/filtering&gt; &lt;/resource&gt; &lt;resource&gt; &lt;directory&gt;target/generated-classes/xmlbeans &lt;/directory&gt; &lt;/resource&gt; &lt;/resources&gt; &lt;!-- xmlbeans maven plugin for the client side --&gt; &lt;plugin&gt; &lt;groupId&gt;org.codehaus.mojo&lt;/groupId&gt; &lt;artifactId&gt;xmlbeans-maven-plugin&lt;/artifactId&gt; &lt;version&gt;2.3.2&lt;/version&gt; &lt;executions&gt; &lt;execution&gt; &lt;goals&gt; &lt;goal&gt;xmlbeans&lt;/goal&gt; &lt;/goals&gt; &lt;/execution&gt; &lt;/executions&gt; &lt;inherited&gt;true&lt;/inherited&gt; &lt;configuration&gt; &lt;schemaDirectory&gt;src/main/resources/&lt;/schemaDirectory&gt; &lt;/configuration&gt; &lt;/plugin&gt; &lt;plugin&gt; &lt;groupId&gt;org.codehaus.mojo&lt;/groupId&gt; &lt;artifactId&gt;build-helper-maven-plugin &lt;/artifactId&gt; &lt;version&gt;1.1&lt;/version&gt; &lt;executions&gt; &lt;execution&gt; &lt;id&gt;add-source&lt;/id&gt; &lt;phase&gt;generate-sources&lt;/phase&gt; &lt;goals&gt; &lt;goal&gt;add-source&lt;/goal&gt; &lt;/goals&gt; &lt;configuration&gt; &lt;sources&gt; &lt;source&gt; target/generated-sources/xmlbeans&lt;/source&gt; &lt;/sources&gt; &lt;/configuration&gt; &lt;/execution&gt; &lt;/executions&gt; &lt;/plugin&gt; &lt;/plugins&gt; &lt;/build&gt; </code></pre> <p>So from the above conf, you need to put the schema file (either standalone or in your WSDL file, you need to extract them and save as a schema file.) under src/main/resources. when you build the project with maven, the pojos are gonna be generated by xmlbeans. The generated sourcecodes will be under target/generated-sources/xmlbeans.</p> <p>then we come to Spring conf. I just put the WS relevant context here:</p> <pre><code> &lt;bean id="messageFactory" class="org.springframework.ws.soap.axiom.AxiomSoapMessageFactory"&gt; &lt;property name="payloadCaching" value="true"/&gt; &lt;/bean&gt; &lt;bean id="abstractClient" abstract="true"&gt; &lt;constructor-arg ref="messageFactory"/&gt; &lt;/bean&gt; &lt;bean id="marshaller" class="org.springframework.oxm.xmlbeans.XmlBeansMarshaller"/&gt; &lt;bean id="myWebServiceClient" parent="abstractClient" class="class.path.MyWsClient"&gt; &lt;property name="defaultUri" value="http://your.webservice.url"/&gt; &lt;property name="marshaller" ref="marshaller"/&gt; &lt;property name="unmarshaller" ref="marshaller"/&gt; &lt;/bean&gt; </code></pre> <p>finally, take a look the ws-client java class</p> <pre><code>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. } </code></pre> <p>}</p> <p>I hope the example codes are helpful.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload