27.07.2010

Integrating Spring WebServices with Maven

As you know in java world we can implement webservices in different ways. This post is step by step telling you how you have to implement spring webservices with maven.
Creating WebServices
1.add this plugin tag into your pom.xml which you are going to deploy.

<plugin>
<groupId>ch.elca.el4j.maven.plugins</groupId>
<artifactId>maven-jaxws-plugin</artifactId>
<version>1.6</version>
<executions>
<execution>
<goals>
<goal>wsgen</goal>
</goals>
</execution>
</executions>
</plugin>


2. Create a class into your maven project.



  • Annotate class as

    @WebService(serviceName= "ClientService")



  • Annotate method as @WebMethod

    @WebService(serviceName = "ClientService")
    public class ClientServiceEndpoint implements InitializingBean, IClientService {
    private IClientService clientService;

    @Override
    public void afterPropertiesSet() throws MandatoryPropertyException {
    if (clientService == null) {
    throw new MandatoryPropertyException(ClientServiceEndpoint.class, "clientService");
    }
    }

    @Override
    @WebMethod
    public Client findByClientNumber(Integer clientNumber) throws ClientNotFoundException {
    return clientService.findByClientNumber(clientNumber);
    }







3. put the lines into your pom.xml




<bean class="org.springframework.remoting.jaxws.SimpleJaxWsServiceExporter">
<property name="baseAddress" value="http://localhost:9080/" />
</bean>



<bean class="com.ykb.ferp.cdm.ws.ClientServiceEndpoint">
<property name="clientService" ref="cdm.service.client" />
</bean>





4. Deploy into your application server.

Consuming Spring Web Services

1. put this plugin code into your client pom.xml





<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxws-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>wsimport</goal>
</goals>
<configuration>
<wsdlUrls>
<wsdlUrl>http://localhost:9080/ClientService?wsdl</wsdlUrl>
</wsdlUrls>
<packageName>com.ykb.ferp.client</packageName>
</configuration>
</execution>
</executions>
</plugin>





2. Right click your project from eclipse and execute update maven configuration project

image 
This will generate web services proxy, interface stub code into your project.


3. put this tag into your application configuration xml depending on your automatic generated code.





<bean id="clientWebService"
class="org.springframework.remoting.jaxws.JaxWsPortProxyFactoryBean">
<property name="serviceInterface"
value="com.ykb.ferp.client.ClientServiceEndpoint" />
<property name="wsdlDocumentUrl"
value="file:${ferp.configuration.base}/ferp-cdm-ws/ClientService.wsdl" />
<property name="namespaceUri" value="http://ws.cdm.ferp.ykb.com/" />
<property name="serviceName" value="ClientService" />
<property name="portName" value="ClientServiceEndpointPort" />
<property name="endpointAddress" value="http://localhost:9080/ClientService"></property>
</bean>



Hiç yorum yok: