Creating File Access Services Presented by Ashraf Memon Presented by Ashraf Memon.
-
Upload
winifred-cameron -
Category
Documents
-
view
214 -
download
0
Transcript of Creating File Access Services Presented by Ashraf Memon Presented by Ashraf Memon.
Creating File Access Services
Creating File Access Services
Presented by
Ashraf Memon
Presented by
Ashraf Memon
2
Overview
• Writing file access service classes in Java
• Generating service
• Deploying services with Apache Axis
• Generating client files and testing them
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 likeLongitude 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
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
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 ispublic String parse(String content, int criteria)
• Complete class code follows on next slide.
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
Writing file access service classes in Java (contd)
public String parse(String ascii, int magnitudeCriteria) throws IOException{
String xml = "<table>\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
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+="<record>\r\n\t\t";
xml+="<lon>"+tempArr[0]+"</lon>\r\n\t\t";
xml+="<lat>"+tempArr[1]+"</lat>\r\n\t\t";
9
Writing file access service classes in Java (contd)
xml+="<magnitude>"+tempArr[2]+"</magnitude>\r\n\t";
xml+="</record>\r\n\t";
}
line = reader.readLine();
}
xml+="\r\n";
xml+="</table>";
return xml;
}
10
Generating Service
• Download AsciiAccessService directory from 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
Generating Service (contd)• Run program by typing following at command prompt
java AsciiAccess
• Output should be<table>
<record>
<lon>143.002</lon>
<lat>37.2850</lat>
<magnitude>2.25000E-02</magnitude>
</record>
</table>
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
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
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