The road less taken

Main | On configuring Glass... »
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.


Comments:

[Trackback] Manveen works on XML Web Services and Security and is now blogging. Welcome to the blogosphere! She has already posted three entries this week: XWSS on Maven On configuring Glassfish keystores Converting an existing webservice to one using the JSR109...

Posted by Arun Gupta's Blog on March 29, 2007 at 05:10 PM PDT #

Hi, i think i'm of the topic with my question, sorry. There goes the question: how can i publish a webMethod when a method is obtained by Inheritance: Ex: Class A{ Method1(); } @Webservice() Class B extends A{ } I want Method1() to be published in B. I'm in netbeans 5.5.1 Thanxs PS: sorry for my english!

Posted by Salaboy on April 10, 2007 at 08:03 AM PDT #

I am just getting started with web services and want to put my wsdl under WEB-INF/wsdl but how does my servlet get access to the wsdl file as a resource? I have tried /WEB-INF/wsdl, WEB-INF/wsdl and /wsdl but no luck!

Posted by Mike Miller on August 02, 2007 at 02:04 PM PDT #

Post a Comment:
  • HTML Syntax: NOT allowed