Using Axis to generate Java files from WSDLs |
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: http://www.apache.org/dyn/closer.cgi/ws/axis/1_2_1 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.
-
#!/usr/bin/bash
-
version=3 # Yahoo API version number
-
clpath="SET THIS TO AXIS’S CLASSPATH"
-
-
# 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[@]}
-
do
-
echo "Processing "${wsdl}
-
java -classpath ${clpath} org.apache.axis.wsdl.WSDL2Java –NStoPkg http://marketing.ews.yahooapis.com/V${version}=com.yahoo.sm.ws.client \
-
-T 1.3 https://global.marketing.ews.yahooapis.com/services/V${version}/${wsdl}
-
done
-
-
# Compile the files and create javadoc
-
javac -classpath ${clpath} com/yahoo/sm/ws/client/*.java
-
javadoc -quiet -classpath $clpath -d ./doc/ com.yahoo.sm.ws.client
-
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 http://marketing.ews.yahooapis.com/V${version} to the package com.yahoo.sm.ws.client. 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.
References:
Axis Userguide
Yahoo EWS Documentation
Tags: Axis, EWS, Java, SOAP, Yahoo
Related |
|




Mieke
I need to do exactly what is being demonstrated in the axis example but am unable to generate the proper stubs using axis2-1.3. An example of the command I am trying is
./wsdl2java.bat -ns2p http://marketing.ews.yahooapis.com/V4=com.yahoo.sm.ws.client -uri https://sandbox.marketing.ews.yahooapis.com/services/V4/AccountService?wsdl -o c:/workspace/YahooServicesClients/ -t -ss -g
Do you have more information on this example? Is there sample code on how the LocationService is used?
jess
I’m not sure exactly the wsdl2java syntax on windows, but I assume the syntax would be the same as the *nix version. Try something like this:
wsdl2java.bat –NStoPkg http://marketing.ews.yahooapis.com/V4=com.yahoo.sm.ws.client -T 1.3 https://global.marketing.ews.yahooapis.com/services/V4/{wsdl}
where you would replace {wsdl} with the name of the actual WSDL (AccountService?wsdl, AdGroupService?wsdl, etc.)