2010-03-06 2 views
6

мне нужно, чтобы перейти в проект Spring Web Service, в котором я должен реализовать клиент весной веб-сервиса только ..Spring Web Service Client Учебник или Пример Требуемый

Итак, я уже прошел через с Spring's Client Reference Document.

Итак, у меня возникла идея необходимых классов для реализации Клиента.

Но моя проблема в том, что я сделал некоторый поиск в Google, но не получил подходящего примера как клиента, так и сервера, из которых я могу реализовать один образец для моего клиента.

Итак, если кто-нибудь даст мне ссылку или учебник для правильного примера из этого, я могу узнать о моей реализации на стороне клиента.

Заранее спасибо ...

+0

Хороший образец можно найти на http://stackoverflow.com/questions/18641928/consume-webservice-service-in- весна-WS-используя-WSDL –

ответ

7

в моем предыдущем проекте, я реализовал клиент WebService с Spring 2.5.6, maven2, XMLBeans.

  • XMLBeans отвечает за ООН/маршалу
  • Maven2 для проекта Упр/строительство и т.д.

я вставляю некоторые коды здесь и надеюсь, что они полезны.

XMLBeans Maven плагин конф: (в 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> 

Так из приведенного выше конф, вам необходимо поместить файл схемы (либо автономный или в файле WSDL, необходимо извлечь их и сохранить как файл схемы.) в разделе src/main/resources. когда вы создаете проект с maven, pojos собираются сгенерировать xmlbeans. Сгенерированные исходные коды будут находиться в пределах целевых/сгенерированных источников/xmlbeans.

затем мы приходим к весне conf. Я просто поставить соответствующий контекст WS здесь:

<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> 

наконец, гляньте WS-клиентский класс Java

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. 

    } 

}

Я надеюсь, что примеры кодов полезны.

Смежные вопросы