July 30, 2014
Hot Topics:
RSS RSS feed Download our iPhone app

Simplify Your Web Services Development with JSR 181

  • February 28, 2008
  • By Ayyappan Gandhirajan
  • Send Email »
  • More Articles »

Step 6 — Build file

To reiterate, the Web Service developer needs only to define the Web Service interfaces using JSR 181 annotation but does not need to worry about the remaining deployment process. The corresponding vendor platform, in our case WebLogic, will take care of implementing (or generating) necessary classes and configuration files, which are JSR 921 compliant.

As mentioned earlier, WebLogic application server provides an ant task namely jwsc. The ant task will take a few inputs like name of the annotated Web Service file name and build directory and then create the necessary files in EAR format, which can be deployed into WebLogic application server using a separate ant task (wldeploy) or manual deployment via administration console.

Listing 6 shows a sample ant configuration file with two important tasks:

  1. Build
    1. Clean directories and files generated as part of previous build (if any)
    2. Use jwsc to generate Web Service deployment files in EAR format
  2. Deploy
    1. Use wldeploy ant task to deploy the ear into WebLogic application server

Listing 6: Build file for building and deploying Web Service

<?xml version="1.0" encoding="ISO-8859-1"?>
<project name="ZipCodeFinder" default="all" basedir=".">
  <property name="ws.file" value="ZipCodeFinderService" />
  <property name="ear.dir" value="ZipCodeFinderServiceEAR" />
  
  <taskdef name="jwsc"
    classname="weblogic.wsee.tools.anttasks.JwscTask" />
  <target name="all" depends="build, deploy" />
  <target name="build" depends="clean, server" />
  <target name="clean">
    <delete dir="${ear.dir}"/>
  </target>
  <target name="server">
    <mkdir dir="${ear.dir}"/>
    <jwsc
      srcdir="${basedir}/src/service"
      destdir="${ear.dir}"
      classpath="${java.class.path}"
      fork="true"
      keepGenerated="true"
      deprecation="${deprecation}"
      debug="${debug}"
      verbose="false">
        <jws file="${ws.file}.java" explode="true"/>
    </jwsc>
  </target>
  <target name="deploy">
    <wldeploy action="deploy"
      source="${ear.dir}" user="weblogic"
      password="weblogic" verbose="true"
      adminurl="t3://localhost:7001"
      targets="AdminServer" />
  </target>
</project>

Step 7 — Running build file

In order to run ant build and deploy targets, you will need to do the following steps:

  1. Open command prompt
  2. Call %WL_HOME%\server\bin\setWLSEnv.cmd
    1. This will set up all necessary path and classpath
  3. Now, run "ant build deploy"
    1. The build target will create necessary classes in a proper layout
    2. The deploy target will deploy the ear into application server

Step 8 — Testing

Now all dirty jobs of creating Java class, build files, running ant tasks are over. It is time to test the Web Service that was deployed in the previous steps.

If you strictly followed the steps mentioned above, the Web Service would be deployed with a URL http://localhost:7001/ZipCodeServices/ZipCodeFinderService and its WSDL can be accessed from http://localhost:7001/ZipCodeServices/ZipCodeFinderService?WSDL

This article does not create or attempt to create the Web Service client that can consume the deployed Web Services as nothing has fundamentally changed in the way the Web Service client works. You are encouraged to use whatever implementation you are comfortable to create Web Service clients.

I used Apache Axis 1.4 to create Web Service stubs to consume the deployed Web Service. The following listings (Listing 7 and Listing 8) capture the incoming and outgoing SOAP messages respectively.

Listing 7: Request SOAP message for Zip Code Finder Service

<env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
  <Header xmlns="http://schemas.xmlsoap.org/soap/envelope/" />
    <env:Body>
    <getZipCode xmlns="http://sampleweb.com/services">
      <city>Edison</city>
      <state>NJ</state>
    </getZipCode>
  </env:Body>
  </env:Envelope>

Listing 8: Response SOAP message for Zip Code Finder Service

<env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
  <env:Header />
    <env:Body>
    <m:getZipCodeResponse xmlns:m="http://sampleweb.com/services">
      <m:return>08817</m:return>
    </m:getZipCodeResponse>
  </env:Body>
  </env:Envelope>

Comparison with conventional Web Services

The conventional Web Services development required developers to spend extra time in configuration and deployment whenever the underlying SOAP container was changed. The annotated Java Web services will save developers not to worry too much about deployment but concentrate on the core business areas.

The source level configuration of JSR 181 Web Services will also help the developers achieving uniform configuration and development process where the deployment of Web Service will be taken care by JSR 921 specification.

Conclusion

Web Service technology is one of those areas which evolves rapidly towards maturity. JSR 181 is an attempt to standardize and simplify the Web Service development, which will free you as a developer from the underlying implementation details and you concentrate on core business areas. Apart from standardization, they also help Web Service to achieve robustness, easy maintenance and interoperability.

Reference

About the author

Ayyappan Gandhirajan holds a Master's degree in Software Systems from BITS, Pilani, India and a Bachelor's degree in Electronics & Communication Engineering from MK University, India. He has 10 years of profound software experience in Travel, Telecom/Mobility, and e-commerce domains using technologies such as SOA, ESB, Web Service, Web Service Security, Spring, AOP and J2EE. He is currently working for Perot Systems, Bangalore, India. Before joining Perot Systems, he worked for good five years with Hewlett-Packard ISO, Bangalore, India. He can be reached at G_Ayyapparaj@yahoo.com / ayyappan.gandhirajan@ps.net


Tags: Web services



Page 3 of 3



Comment and Contribute

 


(Maximum characters: 1200). You have characters left.

 

 


Sitemap | Contact Us

Rocket Fuel