April 16, 2014
Hot Topics:
RSS RSS feed Download our iPhone app

Accelerate Your Java Web Service Development with XFire, Page 2

  • July 5, 2007
  • By Dominic Da Silva
  • Send Email »
  • More Articles »

Filling in the Ant build.xml File

You are going to use Ant to build your XFire test, so you need to create your build.xml file. The build file contains three targets: one to clean the build, called 'clean'; one to generate our SOAP client Java classes from the web service WSDL definition, called 'wsgen'; and one to compile the project, called 'compile'. Here is the build.xml file with the 'clean' and 'compile' targets filled in:

<?xml version="1.0" encoding="UTF-8"?>
<project default="compile" name="xfireclient">

   <property environment="env"/>

   <!-- Clean class files -->
   <target name="clean">
      <delete>
         <fileset dir="bin" includes="**/*.class"/>
      </delete>
   </target>

   <!-- Compiles source files -->
   <target name="compile" depends="clean">
      <javac srcdir="src" destdir="bin" debug="on" verbose="off">
         <classpath>
            <fileset dir="lib"/>
         </classpath>
      </javac>
   </target>


</project>

You will compile your Java source files from the 'src' directory, creating Java classes in the 'bin' directory.

XMethods Stock Quote Web Service

You are going to create a SOAP client for the XMethods Stock Quote web service. This simple SOAP web service takes a String parameter representing a stock company symbol and returns the stock quote for this symbol. This web service has a WSDL located at the URL http://www.webservicex.net/stockquote.asmx. You will use XFire to generate SOAP client Java classes that you can use to access this web service.

Generating SOAP Client Java Classes from a WSDL Using XFire

XFire provides an Ant task that allows a user to generate the Java classes for the SOAP client of a web service. It does this by inspecting a WSDL definition for that web service. You are going to point XFire to the XMethods Stock Quote WSDL URL and have it generate your SOAP client Java classes for you. To do this, you need to set up your 'wsgen' Ant task in our build.xml file. Add the following to the 'build.xml' file:

<?xml version="1.0" encoding="UTF-8"?>
<project default="compile" name="xfireclient">

   <property environment="env"/>

   <property name="wsdlurl"
      value="http://www.webservicex.net/stockquote.asmx?WSDL" />

   <path id="compile.classpath">
      <fileset dir="${basedir}/lib" includes="**/*.jar" />
   </path>

   <taskdef name="wsgen" classname="org.codehaus.xfire.gen.WsGenTask"
            classpathref="compile.classpath"/>

   <target name="wsgen">
      <wsgen outputDirectory="${basedir}/src"
             wsdl="${wsdlurl}"
             package="net.xmethods.services.stockquote"
             overwrite="true" />
   </target>

   <!-- Clean class files -->
   <target name="clean">
      <delete>
         <fileset dir="bin" includes="**/*.class"/>
      </delete>
   </target>

   <!-- Compiles source files -->
   <target name="compile" depends="clean, wsgen">
      <javac srcdir="src" destdir="bin" debug="on" verbose="off">
         <classpath>
            <fileset dir="lib" />
         </classpath>
      </javac>
   </target>
</project>

You define a 'wsdlurl' property that contains your StockQuote web service WSDL URL. You also specify your Java compilation classpath by using a path variable 'compile.classpath'. You define the XFire built-in 'wsgen' Ant task definition. You then specify your 'wsgen' ant target that uses the XFire 'wsgen' taskdef, pointing to the 'wsdlurl', to generate your StockQuote web service SOAP client Java classes in the 'net.xmethods.services.stockquote' package. When you run this task, you will see the following new Java classes in your project:

Figure 2:StockQuote SOAP web service client Java classes generated by XFire





Page 2 of 3



Comment and Contribute

 


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

 

 


Sitemap | Contact Us

Rocket Fuel