Весенний веб-сервис Урок клиента или пример требуется

StackOverflow https://stackoverflow.com/questions/2391428

Вопрос

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

Итак, я уже прошел с Справочный документ Спринского клиента.

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

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

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

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

Это было полезно?

Решение

В моем предыдущем проекте я реализовал Webservice Client с Spring 2.5.6, Maven2, Xmlbeans.

  • xmlbeans отвечает за ООН / маршал
  • Maven2 предназначен для проекта MGMT / здания и т. Д.

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

XMLBeans Maven Plugin Conf: (в 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. Сгенерированные SourceCodes будут в целевых / сгенерированных источниках / XMLBeans.

Затем мы приходим к весенне конф. Я просто положил соответствующий контекст 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.

   }

}

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

Другие советы

Шаг за шагом Учебное пособие на - Клиент веб-сервиса с Spring-WS @http://justcompiled.blogspot.com/2010/11/web-service-client-with-spring-ws.html.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top