Download presentation
Presentation is loading. Please wait.
Published byKathleen Greene Modified over 9 years ago
1
Hints for HW#8
2
HW#6 Architecture Result of Query GOOG Browser with web page PHP Script client Apache web server finance.yahoo.com Send query with arguments Retrieve resulting web page (html) Parse the web page using regular expressions and for each music type build an html page 1 2 3 4 5 Use To invoke server-side script
3
HW#8 Architecture Overview Browser with web page Java Servlet invokes PHP script; Java Servlet transforms XML into JSON client Tomcat web Server running on SCF Finance.yahoo.com Resulting screen Posting to Facebook (done programmatically) Uses Xmlhttprequest to invoke Java Servlet PHP script sends query with arguments Xmlhttprequest Object retrieves JSON User clicks on Facebook As part of the exercise use yahoo’s autocomplete widget to predict the stock symbol PHP script send query with arguments Retrieve web page and convert to XML AWS
4
HW8 Sample Result
5
Facebook Output
6
Outline for the Initial Page (1 of 3) A set of includes define the autocomplete YUI element which uses this URL to get the autocomplete options http://d.yimg.com/autoc.finance.yahoo.com/autoc http://d.yimg.com/autoc.finance.yahoo.com/autoc Define the Facebook interface, e.g. function postToFeed(result) { Define method:, name:, caption:, description:, link:, picture: function (response) //the post was published, or not Call your servlet using Ajax and a URL of the form http://cs-server.usc.edu:YOURPORT/examples/servlet/SearchServlet
7
Outline for the Initial Page (2 of 3) Process the result Handle +/- Handle stock chart, e.g. Handle Facebook icon Build a table containing: Previous close, today’s high, Year high, bid, ask, etc Build a table with the latest News items Render both using the YUI tabview YUI().use('tabview', function(Y) { var tabview = new Y.TabView({srcNode:'#tabs'}); tabview.render(); });
8
Outline for the Initial Page (3 of 3) Here is where the begins Initialize Facebook FB.init({ appId : xxxxxxxxxxxxxxxx', // App ID from the App Dashboard channelUrl : 'http://cs-server.usc.edu:yourport/examples/servlets/producer/channel.html', status : true, // check the login status upon init? cookie : true, // set sessions cookies to allow your server to access the session? xfbml : true // parse XFBML tags on this page? }); // Load the SDK's source Asynchronously Company: Search
9
Posting to Facebook function postToFeed(result) { result = JSON.parse(unescape(result)); FB.ui( { method: 'feed', name: (result.result.Name ? result.result.Name : "NA"), caption: "Stock Information of "+(result.result.Name ? result.result.Name : "NA") + " "+(result.result.Symbol ? "("+result.result.Symbol+")" : ""), description: "Last Trade Price: "+ (result.result.Quote.LastTradePriceOnly ? result.result.Quote.LastTradePriceOnly : "NA") +", Change: "+ (result.result.Quote.ChangeType ? result.result.Quote.ChangeType : "") +""+ (result.result.Quote.Change ? result.result.Quote.Change : "NA") +"("+ (result.result.Quote.ChangeInPercent ? result.result.Quote.ChangeInPercent : "NA") +")", link: (result.result.Symbol ? "http://finance.yahoo.com/q?s="+result.result.Symbol : "http://finance.yahoo.com"), picture: (result.result.StockChartImageURL ? result.result.StockChartImageURL : "") }, function(response) { if (response && response.post_id) { alert('Post was published.'); } else { alert('Post was not published.'); } } ); }
10
Java Servlet running on Tomcat (1 of 2) import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.net.URL; import java.net.URLEncoder; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.json.JSONObject; import org.json.XML;
11
Outline for Your Java Servlet Running on Tomcat (2 of 2) Public class SearchServlet extends HttpServlet { Protected void doGet (request, response) throws... { Response.setContentType(“application/json; charset=utf-8”); Retrieve company name; check if it is null; Try { URL url = new URL(“http://... elasticbeanstalk.com/?companyname=“, encode company name); bufferedReader = new buggeredReader(new INputStreamReader(url.openStream(),... ); While ((line = bufferedReader.readLine()) !- null) { xmlContent += line; } JSONObject jsonObject = XML.toJSONObject(xmlContent); Out.print(jsonObject); Notes: modify the web.xml file Include servlet.jar and json.jar (converts XML to json)
12
Outline for Your Php Program <?php Header(“Content-type: text/xml”); retrieve stock info and output as XML $symbol_url = "http://autoc.finance.yahoo.com/autoc?query=".$name."&callback=YAHOO.Finance.SymbolSuggest.ssCallback"; $url = "http://query.yahooapis.com/v1/public/yql?q=Select%20Name%2C%20Symbol%2C%20LastTradePriceOnly%2C%20Change..."; $output.= " ".htmlspecialchars($name, ENT_QUOTES)." "; $output.= " ".htmlspecialchars($symbol, ENT_QUOTES)." "; $output.= " "; $changeType = substr($change,0, 1); $output.= " ".$changeType." "; $output.= " ".substr($change, 1)." "; $output.= " ".substr($changeinPercent, 1)." "; $output.= " ".number_format((double) $lastTradePriceOnly, 2)." "; Also,,,,,,,,,,,, "; displayHeadlines($symbol); /* a separate routine that goes to http://feeds.finance.yahoo.com/rss/2.0/headline?s=SYMBOL, ETC*/http://feeds.finance.yahoo.com/rss/2.0/headline?s=SYMBOL $output.= " http://chart.finance.yahoo.com/t?s=".$symbol."&lang=en- US&width=300&height=180 ";
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.