28.07.2010

Creating Spring WebServices part 2

In this post you will find how to create spring web services. The different part from part 1 is this type of web services uses application servers' listener. What i’m trying to say is in part 1 with configuration of creates a new listener.

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





In this part you’ll find how to publish web services from an application servers’ listener.

1.Define your web service bean in your applicationContext.xml




<bean id="clientWebService" class="com.montoya.ClientServiceEndpoint" />








2. Add these lines into your web.xml




<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/Spring-servlet.xml</param-value>
</context-param>
<servlet>
<servlet-name>jaxws-servlet</servlet-name>
<servlet-class>com.sun.xml.ws.transport.http.servlet.WSSpringServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>jaxws-servlet</servlet-name>
<url-pattern>/ClientService</url-pattern>
</servlet-mapping>




3. Bind the url which is ClientService in our sample, with a bean.


<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:ws="http://jax-ws.dev.java.net/spring/core"
xmlns:wss="http://jax-ws.dev.java.net/spring/servlet"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://jax-ws.dev.java.net/spring/core
http://jax-ws.dev.java.net/spring/core.xsd
http://jax-ws.dev.java.net/spring/servlet
http://jax-ws.dev.java.net/spring/servlet.xsd"
>

<import resource="applicationContext.xml"/>

<wss:binding url="/ClientService">
<wss:service>
<ws:service bean="#clientWebService" />
</wss:service>
</wss:binding>
</beans>



Hiç yorum yok: