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

T U T O R I A L

Using Axis (Java) with ArcWeb Services v2006.1

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.

Requirements

This tutorial assumes you have the following:

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 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  "/".

How to use Axis (Java)

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

* <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  

  1. Add a 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.

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:

  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_1/AddressFinder?WSDL -p esri.aws.v2006_1 -v

You should now have the following files in the esri/aws/v2006_1 directory:

  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_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());  }  } }
  1. Replace USERNAME and PASSWORD in the AddressFinderClient.java code with your ESRI Global Account user name and password.
  2. NOTE: Your account must be activated for ArcWeb Services.

  3. Compile all the .java files in the esri/aws/v2006_1 directory and the AddressFinderClient.java file in the awaxissamples directory.  

C:\awaxissamples\esri\aws\v2006_1>javac *.java
C:\awaxissamples\esri\aws\v2006_1>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