Presentation is loading. Please wait.

Presentation is loading. Please wait.

Creating File Access Services Presented by Ashraf Memon Presented by Ashraf Memon.

Similar presentations


Presentation on theme: "Creating File Access Services Presented by Ashraf Memon Presented by Ashraf Memon."— Presentation transcript:

1 Creating File Access Services Presented by Ashraf Memon Presented by Ashraf Memon

2 2 Overview Writing file access service classes in Java Generating service Deploying services with Apache Axis Generating client files and testing them

3 3 Writing file access service classes in Java A spatial ASCII file will be used as an example for this service. ASCII file format is not standard. Sample ASCII file looks like Longitude Latitude Magnitude 143.002 37.2850 2.25000E-02 -106.081 -4.33800 2.50000E-02 151.750 45.3590 3.75000E-02 139.720 -3.22000 2.87500E-02

4 4 Writing file access service classes in Java (contd) First line of the file contains labels i.e. coordinates and attributes Each following line contains values Each value is seaparated by space Each record is separated by a new line.

5 5 Writing file access service classes in Java (contd) Sample File Access Class contains 1 function which reads lat/lon values and attributes from quakes1.dat file and return XML for those values Function signature is public String parse(String content, int criteria) Complete class code follows on next slide.

6 6 Writing file access service classes in Java (contd) import java.io.BufferedReader; import java.io.IOException; import java.util.StringTokenizer; import java.io.StringReader; import java.io.RandomAccessFile; import java.io.File; public class AsciiAccess { public AsciiAccess() { }

7 7 Writing file access service classes in Java (contd) public String parse(String ascii, int magnitudeCriteria) throws IOException{ String xml = " \r\n\t"; BufferedReader reader = new BufferedReader(new StringReader(ascii)); String line = reader.readLine(); line = reader.readLine(); while(line!=null){ StringTokenizer tokenizer = new StringTokenizer(line, " ");

8 8 Writing file access service classes in Java (contd) String[] tempArr = new String[tokenizer.countTokens()]; for(int i=0;tokenizer.hasMoreTokens();i++){ tempArr[i]=tokenizer.nextToken(); } if(Double.parseDouble(tempArr[tempArr.length- 1])>magnitudeCriteria){ xml+=" \r\n\t\t"; xml+=" "+tempArr[0]+" \r\n\t\t"; xml+=" "+tempArr[1]+" \r\n\t\t";

9 9 Writing file access service classes in Java (contd) xml+=" "+tempArr[2]+" \r\n\t"; xml+=" \r\n\t"; } line = reader.readLine(); } xml+="\r\n"; xml+=" "; return xml; }

10 10 Generating Service Download AsciiAccessService directory from ftp://dotnet.sdsc.edu/CSIG-WS/ ftp://dotnet.sdsc.edu/CSIG-WS/ Save directory to C:\training\user\code Copy quakes1.dat to C:\training\user\ Compile AsciiAccess.java file by typing following at command prompt javac AsciiAccess.java

11 11 Generating Service (contd) Run program by typing following at command prompt java AsciiAccess Output should be 143.002 37.2850 2.25000E-02

12 12 Deploying services with Apache Axis Copy generated class file to C:\training\tools\tomcat\webapps\axis\WEB -INF\classes\ Open deployAsciiAccess.wsdd in Textpad (Explanation by instructor) Close file.

13 13 Deploying services with Apache Axis(contd) Set classpath by typing classpath at command prompt Execute deployment descriptor by typing deploy deployAsciiAccess.wsdd at command prompt. This deploys webservice on Axis SOAP Server.

14 14 Generating client files and testing them(contd) Compile AsciiAccessServiceClient.java by typing following at command prompt –javac AsciiAccessServiceClient.java Execute Client by typing following at command prompt –java AsciiAccessServiceClient Output should be similar to the result of executing AsciiAccess


Download ppt "Creating File Access Services Presented by Ashraf Memon Presented by Ashraf Memon."

Similar presentations


Ads by Google