Unformatted text preview:

Internet TechnologiesSlide 2Slide 3Slide 4Slide 5Slide 6Slide 7The XML Describing the WeatherServing the weatherSlide 10Slide 11Slide 12Registrations (HTML)Registrations (Servlet)Slide 15Slide 16Slide 17Slide 18Slide 19The SchedulerSlide 21The Watcher ClassSlide 23Slide 24Slide 25Slide 26Slide 27Slide 28Slide 29Slide 30Internet Technologies 1Internet Technologies XML Messaging A PowerWarning application using servlets and SAXThe PowerWarning Application is from “XML and Java” by Maruyama, Tamura, and Uramoto, Addison-Wesley.Internet Technologies 2XML Messaging Part IThe PowerWarning application allows users to registertheir geographical position and their temperature concerns.Users will receive e-mail when the temperature exceeds the userspecified parameters. This example is from“XML and Java” by Maruyama, Tamura, and Uramoto, Addison-Wesley.The web container is called Jigsaw from the W3C.Internet Technologies 3[1] <html>[2] <head>[3] <title>Weather Report</title>[4] </head>[5] <body>[6] <h2>Weather Report -- White Plains, NY </h2>[7] <table border=1>[8] <tr><td>Date/Time</td><td align=center>11 AM EDT Sat Jul 25 1998</td></tr>[9] <tr><td>Current Tem.</td><td align=center>70&#176;</td></tr>[10] <tr><td>Today’s High</td><td align=center>82&#176;</td></tr>[11] <tr><td>Today’s Low</td><td align=center>62&#176;</td><tr>[12] </table>[13] </body>[14] </html>Suppose that we know that the weather information is availablefrom the web at http://www.xweather.com/White_Plains_NY_US.html.Internet Technologies 4•Strategy 1:For the current temperature of White Plains, go to line 9,column 46 of the page and continue until reaching the nextampersand.•Strategy 2:For the current temperature of the White Plains, go to thefirst <table> tag, then go to the second <tr> tag within thetable, and then go to the second <tg> tag within the row.Neither of these seems very appealing…Internet Technologies 5<?xml version=“1.0”?><!DOCTYPE WeatherReport SYSTEM“http>//www.xweather.com/WeatherReport.dtd”><WeatherReport><City>White Plains</City><State>NY</State><Date>Sat Jul 25 1998</Date><Time>11 AM EDT</Time><CurrTemp unit=“Farenheit”>70</CurrTemp><High unit=“Farenheit”>82</High><Low unit=“Farenheit”>62</Low></Weather Report>XML would helpInternet Technologies 6•Strategy 3:For the current temperature of White Plains, N.Y., go to the <CurrTemp> tag.Internet Technologies 7XMLMobile usersPC usersHttp://www.xweather.comWeatherReportapplicationWMLHTMLPowerWarningapplicationApplicationprogramsXMLEmail notificationsRegistrationsXMLXSLTInternet Technologies 8The XML Describing the Weather<?xml version="1.0" encoding="UTF-8"?><WeatherReport> <City>Pittsburgh</City> <State>PA</State> <Date>Wed. April 11, 2001</Date> <Time>3</Time> <CurrTemp Unit = "Farenheit">70</CurrTemp> <High Unit = "Farenheit">82</High> <Low Unit = "Farenheit">62</Low> </WeatherReport>This file is behindJigsaw in the fileWww/weather/weather.xml.Perhaps this is being served upby www.xweather.comfor ½ cents per hit.Internet Technologies 9Serving the weather// This servlet file is stored in Www/Jigsaw/servlet/GetWeather.java// This servlet returns a user selected xml weather file from// the Www/weather directory and returns it to the client.import java.io.*;import java.util.*;import javax.servlet.*;import javax.servlet.http.*;public class GetWeather extends HttpServlet { This data would notnormally be retrievedfrom a file.Internet Technologies 10public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { String theData = ""; /* For simplicity we get the user’s request from the path. */ String extraPath = req.getPathInfo(); extraPath = extraPath.substring(1); // read the file try { // open file and create a DataInputStream FileInputStream theFile = new FileInputStream("c:\\Jigsaw\\Jigsaw\\”+ “Jigsaw\\Www\\weather\\"+extraPath);Internet Technologies 11 InputStreamReader is = new InputStreamReader(theFile); BufferedReader br = new BufferedReader(is); // read the file into the string theData String thisLine; while((thisLine = br.readLine()) != null) { theData += thisLine + "\n"; } } catch(Exception e) { System.err.println("Error " + e); } PrintWriter out = res.getWriter(); out.write(theData); System.out.println("Wrote document to client"); out.close(); }}Internet Technologies 12XMLMobile usersPC usersHttp://www.xweather.comWeatherReportapplicationWMLHTMLPowerWarningapplicationApplicationprogramsXMLEmail notificationsRegistrationsXMLXSLTInternet Technologies 13Registrations (HTML) <!-- PowerWarningForm.html --><html><head><title>PowerWarning</title></head><body> <form method="post" action="/servlet/PowerWarn"> E-Mail <input type="text" name = "User"> <p> State <input type="text" name = "State"> <p> City <input type="text" name = "City"> <p> Temperature <input type="text" name = "Temperature"> <p> Duration <input type="text" name = "Duration"> <p> <input type = "submit"> </form></body></html>Internet Technologies 14Registrations (Servlet)On servlet initialization, we will start up an object whose responsibility it is to periodically wake up and tell the watcherobjects to check the weather.The servlet will create a watcher object for each registered user. The watcher object will be told of each user’s locationand temperature requirements. Each watcher object will runin its own thread and may or may not notify its assigneduser by email.Internet Technologies 15Registrations (Servlet)/* This servlet is called by an HTML form. The form passes the user email, state, city, temperature and duration.*/import java.io.*;import java.util.*;import javax.servlet.*;import javax.servlet.http.*;public class PowerWarn extends HttpServlet {Internet Technologies 16 static Hashtable userTable; /* Holds (email,watcher) pairs */ public void init(ServletConfig conf) throws ServletException { super.init(conf); PowerWarn.userTable = new


View Full Document

CMU ISM 95733 - XML Messaging

Download XML Messaging
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view XML Messaging and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view XML Messaging 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?