Tuesday Mar 27, 2007

Converting an existing webservice to one using the JSR109 deployment model

This is my first blog, and in this, I am going to talk about how to develop a Web service and a client using JSR 109 programming model.

Let's consider a scenario. You have an existing web based application running on glassfish, WSIT based web service (secure or non-secure).

Now you want to see if you can convert what you have to (servlet based) JSR 109 based programming model. You obviously want to do this with a minimal effort (taking the path of least resistance). You wish there were simple steps that could help you do this. Well, you're in luck! Voila! Here are they:

    Step 1.

    Update your existing WebserviceImpl class (POJO) in the @WebService annotation section. The default SOAP binding is SOAP 1.1. So you might want to add an annotation (@javax.xml.ws.BindingType) to change the binding to SOAP 1.2 HTTP.

    Here's what the final result will look like-
    @javax.jws.WebService(endpointInterface="simple.server.IPingService", targetNamespace="http://InteropBaseAddress/interop", portName="A_IPingService", serviceName="PingService11", wsdlLocation="WEB-INF/wsdl/PingService.wsdl") @javax.xml.ws.BindingType( value=javax.xml.ws.soap.SOAPBinding.SOAP12HTTP_BINDING)
    public class PingImpl implements IPingService { ... }
    Step 2.

    You can safely remove sun-jaxws.xml from your .war package. If you want to use the defaults, you can remove web.xml as well. You need to package your war to be compliant with what JSR109 expects from you, which is- the wsdl and xsd's go under WEB-INF/wsdl, and all the classes go under WEB-INF/classes.

Here's a sample ant target that shows that I'm talking about....

Target to bundle the war


<target name="create-war-jsr109">
	<property name="war.file" value="${build.war.home}/${wsdlcontext.name}.war"/>
	<delete file="${war.file}"/>
	<mkdir dir="${build.war.home}/temp"/>	
	<mkdir dir="${build.war.home}/temp/WEB-INF"/>
	<mkdir dir="${build.war.home}/temp/WEB-INF/classes"/>
	<mkdir dir="${build.war.home}/temp/WEB-INF/wsdl"/>
	<copy todir="${build.war.home}/temp/WEB-INF/classes">
		<fileset dir="${build.classes.home}">	
			<include name="\*\*/\*.class"/>
		</fileset>
	</copy>
	<copy todir="${build.war.home}/temp/WEB-INF/wsdl">
		<fileset dir="${current.dir}/../../etc">
			<include name="\*.wsdl"/>
			<include name="\*.xsd"/>
		</fileset>
	</copy>
	<echo message="Creating war file ${war.file}"/>
	<jar jarfile="${war.file}" basedir="${build.war.home}/temp"
		update="true" includes ="\*\*/\*">
	</jar>
	<echo message="created war file ${war.file} at ${build.war.home}/temp"/>
</target>

    Step 3.

    If you're not overriding the defaults with web.xml, then your service is deployed at /${yourServiceName in your wsdl}. Check where your service is actually deployed.

    Then change all your client wsdl and schema bindings to make sure you use the right ServiceName in all relevant places.

    You're all set!

Was that easy? Is there a way you can make this even easier? Share your thoughts as comments to this blog. Thanks for reading.


About

manveen

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today