1 / 12

Creating File Access Services

Creating File Access Services. Presented by Ashraf Memon Hands-on Ashraf Memon, Ghulam Memon. Overview. Writing file access service classes in Java Generating service Deploying services with Apache Axis Generating client files and testing them. Writing file access service classes in Java.

mingan
Download Presentation

Creating File Access Services

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Creating File Access Services Presented by Ashraf Memon Hands-on Ashraf Memon, Ghulam 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 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. 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. 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 ispublic 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. Writing file access service classes in Java (contd) • public String getData(double magnitude) throws IOException{ • String xml = "<table>\r\n\t"; • RandomAccessFile reader = new RandomAccessFile("C:\\data\\csig05\\ws\\solutions\\ascii\\data\\quakes.dat", "r"); • String line = reader.readLine(); • line = reader.readLine(); • while(line!=null){ • StringTokenizer tokenizer = new StringTokenizer(line, " "); • String[] tempArr = new String[tokenizer.countTokens()]; • for(int i=0;tokenizer.hasMoreTokens();i++){ • tempArr[i]=tokenizer.nextToken(); • } • if(Double.parseDouble(tempArr[0])>magnitude){ • xml+="<record>\r\n\t\t"; • xml+="<lon>"+tempArr[4]+"</lon>\r\n\t\t"; • xml+="<lat>"+tempArr[3]+"</lat>\r\n\t\t"; • xml+="<magnitude>"+tempArr[0]+"</magnitude>\r\n\t"; • xml+="</record>\r\n\t"; • } • line = reader.readLine(); • } • xml+="\r\n"; • xml+="</table>"; • return xml; • }

  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. Testing the code (contd) <table> <record> <lon>121.265W</lon> <lat>36.650N</lat> <magnitude>3.0</magnitude> </record> <record> <lon>115.771W</lon> <lat>32.042N</lat> <magnitude>2.6</magnitude> </record> <record> <lon>115.754W</lon> <lat>32.003N</lat> <magnitude>3.3</magnitude> </record> <record> <lon>120.530W</lon> <lat>35.974N</lat> <magnitude>2.8</magnitude> </record> <record> <lon>121.685W</lon> <lat>37.316N</lat> <magnitude>2.9</magnitude> </record> </table> • Type exit on the command prompt to quit

  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. 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 AsciiAccessService

  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.javaby typing following at command prompt • javac AsciiAccessServiceClient.java • Execute Client by typing following at command prompt • java AsciiAccessServiceClient • Output should be similar to previous one

  12. Next Chapter • Creating Web Service to Access Database

More Related