Using Axis to Generate Java Files From WSDLs

by in Tips & Tutorials
0 Flares 0 Flares ×

Apache Axis is an implementation of the SOAP protocol. It is a framework for constructing SOAP clients and servers. A Java client application is able to use a Web Service by calling Java stub classes created from WSDL files. These WSDL files are made availible by the SOAP server application. As an example, we will go through the process of creating a jar file from WSDLs using the Yahoo’s Enterprise Web Services (EWS). The EWS platform makes Yahoo’s Search Marketing API available.

EWS allows access to Yahoo search marketing data. To use EWS, you must have a Yahoo pay per click advertising account, and then sign up for a license key. EWS provides tools to do keyword research, create ads and keywords, generate reports on the performance of your pay per click ads, and more. We want to create a jar file of the services EWS provides so that we can use it in a client application.

First, download and Apache Axis 1.2. A list of mirrors can be found here: Since we are developing a SOAP client, there is no need to integrate Axis into our application. Just get the Axis source and compile it. Be sure the classpath includes the jar files in the axis-1_2/lib/ directory.

The Axis WSDL2Java command will generate the Java files from the EWS WSDLs. Here is a simple shell script that shows how to do it.

version=3   # Yahoo API version number

# List of wsdls to include in the jar
wsdls=(AccountService?wsdl AdGroupService?wsdl AdService?wsdl BasicReportService?wsdl BidInformationService?wsdl \
BudgetingService?wsdl CampaignService?wsdl CompanyService?wsdl ExcludedWordsService?wsdl ForecastService?wsdl \
KeywordResearchService?wsdl KeywordService?wsdl LocationService?wsdl MasterAccountService?wsdl \
UpgradeService?wsdl UserManagementService?wsdl VaultService?wsdl)
for wsdl in ${wsdls[@]}
    echo "Processing "${wsdl}
    java -classpath ${clpath} org.apache.axis.wsdl.WSDL2Java --NStoPkg${version} \
-T 1.3${version}/${wsdl}

# Compile the files and create javadoc
javac -classpath ${clpath} com/yahoo/sm/ws/client/*.java
javadoc -quiet -classpath $clpath -d ./doc/
jar -cf yahoo-api.jar com/yahoo/sm/ws/client/*.class

The first thing we do is create a list of all the WSDLs in EWS. Then we use the Axis’s WSDL2Java tools to generate a java file for each of the WSDLs. The –NStoPkg flag maps the namespace${version} to the package The -T flag specifies the SOAP type mapping version. 1.3 is the value recommended by Yahoo, so we stick with that.

Now that we have the java stub files, we compile them, generate the javadocs, and jar up the class files for use in our application. If you would rather just download the jar file than go through the process yourself, you can get it here yahoo-api.jar.

Axis Userguide
Yahoo EWS Documentation

0 Flares Twitter 0 Google+ 0 Facebook 0 0 Flares ×
# December 29, 2007 2 Comments