Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 Creating File Access Services Presented by Ashraf Memon Hands-on Ashraf Memon, Ghulam Memon.

Similar presentations


Presentation on theme: "1 Creating File Access Services Presented by Ashraf Memon Hands-on Ashraf Memon, Ghulam Memon."— Presentation transcript:

1 1 Creating File Access Services Presented by Ashraf Memon Hands-on Ashraf Memon, Ghulam 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 Magnitude Date Time Latitude Longitude Depth 1.4 2005/07/07 11:15:57 37.534N 118.839W 4.1 1.9 2005/07/07 11:11:26 35.663N 121.073W 6.0 2.0 2005/07/07 10:58:00 36.102N 115.591W 0.0 1.9 2005/07/07 10:55:57 34.408N 119.386W 12.2

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 separated 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 quakes.dat file and return XML for those values Function signature is public String getData(double magnitude) Explanatory source code follows on next slide. For complete source code check c:\data\csig05\ws\solutions\ascii\AsciiAccess.java

6 6 Writing file access service classes in Java (contd) 1. public String getData(double magnitude) throws IOException{ 2. String xml = " \r\n\t"; 3.RandomAccessFile reader = new RandomAccessFile("C:\\data\\csig05\\ws\\solutions\\ascii\\data\\quakes.dat", "r"); 4. String line = reader.readLine(); 5. line = reader.readLine(); 6. while(line!=null){ 7. StringTokenizer tokenizer = new StringTokenizer(line, " "); 8. String[] tempArr = new String[tokenizer.countTokens()]; 9. for(int i=0;tokenizer.hasMoreTokens();i++){ 10. tempArr[i]=tokenizer.nextToken(); 11. } 12. if(Double.parseDouble(tempArr[0])>magnitude){ 13. xml+=" \r\n\t\t"; 14. xml+=" "+tempArr[4]+" \r\n\t\t"; 15. xml+=" "+tempArr[3]+" \r\n\t\t"; 16. xml+=" "+tempArr[0]+" \r\n\t"; 17. xml+=" \r\n\t"; 18. } 19. line = reader.readLine(); 20. } 21. xml+="\r\n"; 22. xml+=" "; 23. return xml; 24. }

7 7 Testing the code Navigate to solutions directory c:\data\csig05\ws\solutions Open command prompt by right clicking on the ascii directory and selecting “Command Prompt Here” Change to ascii directory by typing following at the command prompt cd ascii Compile AsciiAccess.java file by typing following at command prompt javac AsciiAccess.java Run program by typing following at command prompt java AsciiAccess Output should be of the form: continued on the next page

8 8 Testing the code (contd) 121.265W 36.650N 3.0 115.771W 32.042N 2.6 115.754W 32.003N 3.3 120.530W 35.974N 2.8 121.685W 37.316N 2.9 Type exit on the command prompt to quit

9 9 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 deployAsciiAccess.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

10 10 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 deployAsciiAccess.wsdd at command prompt This will deploy database webservice on Axis SOAP Server Test it by going to http://localhost/axis/ and navigating to AsciiAccessServicehttp://localhost/axis/

11 11 Generating client files and testing them Change directory to c:\data\csig05\ws\solutions\ascii by typing “cd c:\data\csig05\ws\solutions\ascii” on the command prompt Compile AsciiAccessServiceClient.java by typing following at command prompt –javac AsciiAccess ServiceClient.java Execute Client by typing following at command prompt –java AsciiAccess ServiceClient Output should be similar to previous one

12 12 Creating Web Service to Access DatabaseCreating Web Service to Access Database Next Chapter


Download ppt "1 Creating File Access Services Presented by Ashraf Memon Hands-on Ashraf Memon, Ghulam Memon."

Similar presentations


Ads by Google