You are here: Using SOAP > v2006 services > Tutorials and samples > Using Axis (Java) with ArcWeb Services v2006

T U T O R I A L

Using Axis (Java) with ArcWeb Services v2006

The purpose of this tutorial is to demonstrate how to access ArcWeb Services with Apache Axis 1.3. Apache Axis is an open source toolkit for creating and consuming Web Services with Java. This tutorial assumes you have Apache Axis 1.3 and JDK 1.4.x. or greater running on your machine and an activated ArcWeb account. It also assumes you have a program to unzip the sample code. You can download and install Apache Axis from the Apache Axis Web site. You can download and install JDK from the Sun Developers Web site.

The sample uses Authentication Web Service and Address Finder Web Service as examples of how to use Axis to call ArcWeb services. ArcWeb Authentication Web Service requires that you send it a request for an validation token prior to accessing an ArcWeb service. You then use this returned token to send your geocoding request to Address Finder Web Service. In this sample, a user enters a series of addresses to be geocoded until the authentication token expires, at which point, the client requests a new token from the Authentication Web Service.

See Using WS-Security with Axis (Java) for a tutorial about using WS-Security instead of Authentication Web Service with ArcWeb Services.

Overview

Download the sample code.

The following steps guide you through sending two requests to ArcWeb Services.

In the first request, you call Authentication Web Service with the following method:

getCustomExpirationToken(username:string, password:string, expiration:integer):string

Included in your request is your user name (username), password (password) and the minutes until the token should expire (expiration). Authentication Web Service returns a token (string) that validates you as an authorized ArcWeb user. Use this token to access Address Finder Web Service.

In the second request, you call Address Web Finder with the following method:

findLocationByAddress(address:Address, addressFinderOptions:AddressFinderOptions, token:string):GeocodeInfo

Included in your request are two objects (Address and AddressFinderOptions) and the token from the Authentication Web Service. Address Finder Web Service returns a list of geocoded matches for the address that match the input argument.

Note to UNIX users: You need to change the directory paths from "\" to  "/".

How to use

  1. Add the following .jar files to your classpath so that Java can find Axis.

* <Axis Installation Directory>\axis-1_3\lib\axis.jar

* <Axis Installation Directory>\axis-1_3\lib\commons-discovery-0.2.jar

* <Axis Installation Directory>\axis-1_3\lib\commons-logging-1.0.4.jar

* <Axis Installation Directory>\axis-1_3\lib\jaxrpc.jar

* <Axis Installation Directory>\axis-1_3\lib\saaj.jar

* <Axis Installation Directory>\axis-1_3\lib\wsdl4j-1.5.1.jar  

  1. Add JAXP-1.1 compliant XML parser such as Crimson (included with JDK 1.4) or Xerces (recommended by Apache) to your classpath. JAXP parser allows you to translate XML into Java. If you want to use Crimson you can skip this step.
  2. Create a directory named "awaxissamples".
  3. In a command path run WSDL2Java against the Authentication Web Service HTTPS WSDL URL. This creates a stub from the Authentication.WSDL file. WSDL2Java is an Axis Utility class provided by Axis. The stub you create is Java code that connects to the Web service and enables you to call the methods as if they were local methods.

C:\>cd  awaxissamples
C:\awaxissamples>java org.apache.axis.wsdl.WSDL2Java https://www.arcwebservices.com/services/v2006/Authentication.WSDL -p esri.aws.v2006 -v

NOTE: -p is an option to override default package. Once you run the WSDL2Java tool, a directory appears called esri/aws/v2006. This directory has all the stubs.

You should now have the following four files in the esri/aws/v2006 directory:
IAuthentication_PortType.java, IAuthentication_BindingStub.java, Authentication.java, AuthenticationLocator.java

  1. In a command path run WSDL2Java against the Address Finder Web Service HTTP WSDL URL. This creates a stub from the AddressFinder.WSDL file.

C:\awaxissamples>java org.apache.axis.wsdl.WSDL2Java http://www.arcwebservices.com/services/v2006/AddressFinder.WSDL -p esri.aws.v2006 -v

You should now have the following files in the esri/aws/v2006 directory:
Envelope.java, ResultSetRange.java, Address.java, Point.java, GeocodeInfo.java, AddressFinderOptions.java, KeyValue.java, CoordSys.java, GeocodeCandidate.java, AddressFinderInfo.java, AddressFinder.java, AddressFinderLocator.java, IAddressFinder_PortType.java, IAddressFinder_BindingStub.java

  1. Create a new AddressFinderClient.java file by copying the following client code or downloading AddressFinderClient.java to the awaxissamples directory.
import esri.aws.v2006.* ;/**
 * This is an ESRI ArcWeb Services sample.
 * This class gives the address location information for the given valid token and address.
 */
class AddressFinderClient {
/**     * returns address location for the specified address.     */public static void main(String args[]) {       try {           //Replace the [USERNAME] and [PASSWORD] with a valid username/password.String username = "[USERNAME]" ;           String password = "[PASSWORD]" ;           int expiration = 60; // in seconds
String housenumber = "380";           String street = "New York st" ;           String city = "Redlands" ;           String state = "CA" ;           String postalCode = "92373" ;           String country_code= "US" ;
String dataSource = "ArcWeb:TA.Streets.US" ;
 // --------------Locate Authentication Web services -----------AuthenticationLocator locate = new AuthenticationLocator();           IAuthentication_PortType authentication = locate.getIAuthentication() ;
// --------------Call to Authentication Web Services and get the token---------String token = authentication.getCustomExpirationToken(username,password,expiration);
 
           // --------------Locate to AddressFinder Web services -----------AddressFinderLocator afLocate = new AddressFinderLocator();           IAddressFinder_PortType addressFinder = afLocate.getIAddressFinder();
// Populate the address object with user input.Address address = new Address();                address.setHouseNumber(housenumber) ;                address.setStreet(street) ;                address.setCity(city) ;                address.setStateProvince(state) ;                address.setPostalCode(postalCode) ;                address.setCountry(country_code) ;
// set AddressFinderOptionsAddressFinderOptions addressFinderOptions = new AddressFinderOptions();                addressFinderOptions.setDataSource(dataSource) ;
// --------------Call to AddressFinder Web Service -----------GeocodeInfo geocodeInfo = addressFinder.findLocationByAddress(address,addressFinderOptions,token);           //Get the  candidatesGeocodeCandidate[] candidates = geocodeInfo.getCandidates();
//candidates includes x,y coordinates and the complete address description           // Print first candidateSystem.out.print(candidates[0].getDesc1());           System.out.print(" (" + candidates[0].getPoint().getX() + "," + candidates[0].getPoint().getY() + ")");        } catch (Exception e) {            System.out.println("Error : " + e.getMessage());        }    } }
  1. Replace [username] and [password] in the AddressFinderClient.java code with your ESRI Global Account user name and password. NOTE: Your account must be activated for ArcWeb Services.
  2. Compile all the .java files in the esri/aws/v2006 directory and the AddressFinderClient.java file in the awaxissamples directory.   

C:\awaxissamples\esri\aws\v2006>javac *.java
C:\awaxissamples\esri\aws\v2006>cd ..\..\..\
C:\awaxissamples>javac *.java -classpath %classpath%;.

  1. Run the client. For example:

C:\awaxissamples>java -cp %classpath%;. AddressFinderClient

380 New York St,Redlands,CA 92373 (-117.195533,34.057058)


Visit the Feedback page to give comments or suggestions about the ArcWeb Developer's Guide.

ArcWeb site | ArcWeb support | support.esri.com

Copyright © ESRI