The purpose of this tutorial is to demonstrate how to access ArcWeb Services with Apache Axis 1.4. Apache Axis is an open source toolkit for creating and consuming Web Services with Java.
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 a validation token prior to accessing any 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 1.0 instead of Authentication Web Service with ArcWeb Services.
This tutorial assumes you have the following:
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 Services user. Use this token to access Address Finder Web Service.
In the second request, you call Address Finder Web Service 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 correspond to the input argument.
NOTE TO UNIX USERS: You need to change the directory paths from "\" to "/".
* <Axis Installation Directory>\axis-1_4\lib\axis.jar
* <Axis Installation Directory>\axis-1_4\lib\commons-discovery-0.2.jar
* <Axis Installation Directory>\axis-1_4\lib\commons-logging-1.0.4.jar
* <Axis Installation Directory>\axis-1_4\lib\jaxrpc.jar
* <Axis Installation Directory>\axis-1_4\lib\saaj.jar
* <Axis Installation Directory>\axis-1_4\lib\wsdl4j-1.5.1.jar
C:\>cd awaxissamples
C:\awaxissamples>java org.apache.axis.wsdl.WSDL2Java https://www.arcwebservices.com/services/v2006_1/Authentication?WSDL
-p esri.aws.v2006_1 -v
NOTE: -p is an option to override the default package. Once you run the WSDL2Java tool, a directory appears called esri/aws/v2006_1. This directory contains all the stubs.
You should now have the following four files in the esri/aws/v2006_1 directory:
C:\awaxissamples>java org.apache.axis.wsdl.WSDL2Java http://www.arcwebservices.com/services/v2006_1/AddressFinder?WSDL -p esri.aws.v2006_1 -v
You should now have the following files in the esri/aws/v2006_1 directory:
import esri.aws.v2006_1.* ;/** * This is an ESRI ArcWeb Services sample. * This class gives the address location information for the given valid token and address. */
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" ;
// --------------Call to Authentication Web Services and get the token---------String token = authentication.getCustomExpirationToken(username,password,expiration);
// --------------Locate AddressFinder Web Services -----------AddressFinderLocator afLocate = new AddressFinderLocator(); IAddressFinder addressFinder = afLocate.getAddressFinderHttpPort();
// --------------Call AddressFinder Web Service -----------GeocodeInfo geocodeInfo = addressFinder.findLocationByAddress(address,addressFinderOptions,token); //Get the candidatesGeocodeCandidate[] candidates = geocodeInfo.getCandidates();
//candidates include 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()); } } }
NOTE: Your account must be activated for ArcWeb Services.
C:\awaxissamples\esri\aws\v2006_1>javac
*.java
C:\awaxissamples\esri\aws\v2006_1>cd ..\..\..\
C:\awaxissamples>javac *.java -classpath %classpath%;.
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.