Creating Web Services

Download Report

Transcript Creating Web Services

1
Creating Web Services from a
existing tool
Presented by
Ashraf Memon
Hands-on
Ghulam Memon, Longjiang Ding
2
Overview
• Using an existing command line
tool in this case Global Mapper
• Wrapping the tool in Java
• Generating service from the tool
• Deploying services with Apache
Axis
• Generating client files and testing
them
3
Global Mapper
• Global Mapper is a tool for editing, viewing
and converting raster and vector data formats
• In this example this tool takes a raster image
in esri ascii grid format as a input and
produces a map
• Command for executing this would look like
c:\path\to\globalmapper\global_mapper6.exe
script.gms
– script.gms is the file that defines the script that will
be used convert the grd file to tiff image
4
Script file
GLOBAL_MAPPER_SCRIPT VERSION=“1.00"
UNLOAD_ALL
DEFINE_PROJ PROJ_NAME="somename"
Projection
GEOGRAPHIC
Datum
WGS84
Zunits
METER
Units
DD
Xshift
0.000000
Yshift
0.000000
Parameters
END_DEFINE_PROJ
IMPORT FILENAME="path\to\asciiFile" TYPE=ARCASCIIGRID
PROJ_NAME="somename"
EXPORT_RASTER FILENAME="path\to\outputFile" TYPE=JPEG QUALITY=100
5
Writing service classes in Java
1. private String getImage(String localFilePath){
2.
try {
3.
String localFileName = Util.getNameFromFilename(Util.
getNameFromPath(localFilePath));
4.
String outputFileName = "C:\\data\\Arcims\\Output\\" + localFileName + ".jpg";
5.
String scriptFile = createGMScriptFile(localFilePath, outputFileName);
6.
String gmExecuteable = "C:\\tools\\GlobalMapper6\\global_mapper6.exe";
7.
Process process = Runtime.getRuntime().exec(gmExecuteable + " " +
scriptFile);
8.
String outputUrl = "http://" + Util.getLocalURL() + "/output/";
9.
String output = outputUrl + localFileName + ".jpg";
10. return output;
11. }
12. catch (Exception e) {
13.
System.out.println(e.getMessage());
14. }
15. return null;
16. }
6
Full source code
• For full source code please browse to
c:\data\csig05\ws\solutions\tool\ folder and
open the GridAsciiToImage.java file
• Feel free to ask questions
7
Testing the code
• Navigate to solutions directory c:\data\csig05\ws\solutions
• Open command prompt by right clicking on the tool directory
and selecting “Command Prompt Here”
• Change to tool directory by typing following at the command
prompt
cd tool
• Compile GridAsciiToImage.java file by typing following at
command prompt
javac GridAsciiToImage.java
• Run program by typing following at command prompt
java GridAsciiToImage
• Notice the output, it should return the URL to the newly
created map
• Copy the URL and check the result in browser
• Type exit on the command prompt to quit
8
Deploying your code as a web
services with Apache Axis
• Copy generated class file to
C:\tools\tomcat4.1\webapps\axis\WEB-INF\classes\
• Open using any text editor deployTool.wsdd from
C:\tools\tomcat4.1\webapps\axis\WEB-INF\classes\
• Verify the content so that it matches the current service
and its corresponding class
9
Deploying services with Apache Axis
• Navigate to C:\tools\tomcat4.1\webapps\axis\WEB-INF\
• Open command prompt by right clicking on the classes
directory and selecting “Command Prompt Here”
• Change to classes directory by typing following at the
command prompt
cd classes
• Set classpath by typing classpath.bat on the command
prompt
• Execute deployment descriptor by typing deploy.bat
deployTool.wsdd at command prompt
• This will deploy tool webservice on Axis SOAP Server
• Test it by going to http://localhost/axis/ and navigating
to GlobalMapper Service
10
Generating client files and testing them
• Change directory to c:\data\csig05\ws\solutions\tool
by typing “cd c:\data\csig05\ws\solutions\tool” on the
command prompt
• Compile GlobalMapperServiceClient.java by typing
following at command prompt
javac GlobalMapperServiceClient.java
• Execute Client by typing following at command prompt
java GlobalMapperServiceClient
• Notice the output, it should return the URL to the newly
created map
• Copy the URL and check the result in browser
11
Next Chapter
Consuming Existing Web Services from
WSDL