cs571_10sp-final-papa v2

Cs571_10sp-final-pap - Computer Science 571 2nd Exam Prof Papa Thursday 5:30pm 6:45pm Name 1 This is a closed book exam 2 Please answer all

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
1 Computer Science 571 2 nd Exam Prof. Papa Thursday, April 29, 2010, 5:30pm – 6:45pm Name: Student ID Number: 1. This is a closed book exam. 2. Please answer all questions on the test Assignment #9 Questions – Java [30 pts] Below is the Java source which implements a portion of the proxy back-end of Homework #9, but some of the code is missing, replaced by XXXXXXXs. Fill in the missing code in the space provided. import java.io.*; import javax. XXXXXXXX1; import javax. XXXXXXXX2; import java.net.HttpURLConnection; import java.net.ProtocolException; import java.net.URL; import java.net.URLConnection; import java.net.URLEncoder; import org.jdom.Document; import org.jdom.Element; import org.jdom.JDOMException; import org.jdom.input.SAXBuilder; import org.jdom.output.XMLOutputter; import java.util.*; import org.json.JSONObject; import org.json.JSONArray; public class ajax_flickr extends HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String title = "AJAX Veoh"; String flickr_api_key = "63a3fce8919dfd73a09e7ab56ed5f7cd"; String query = request. XXXXXXXX3 ("query"); if ( XXXXXXXX4 ) { response.setContentType(" XXXXXXXX5 ");
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
2 response.setHeader("Cache-Control", "no-cache"); JSONObject failResp = new JSONObject(); failResp.put("type","error"); failResp.put("code", "400"); failResp.put("message", "Bad request"); response.getWriter().write(failResp.toString()); return; } String hw6Res = sendhw6GetRequest("http://volga.usc.edu/cgi- bin/searchVeoh.pl?input=" + XXXXXXXX6 ); if ( XXXXXXXX7 ) { response.setContentType(" XXXXXXXX8 "); response.setHeader("Cache-Control", "no-cache"); JSONObject failResp = new JSONObject(); failResp.put("type","error"); failResp.put("code", "502"); failResp.put("message", "Bad gateway"); response.getWriter().write(failResp.toString()); return; } response.setContentType(" XXXXXXXX9 "); response.setHeader("Cache-Control", "no-cache"); response.getWriter().write( XXXXXXXX10 ); } private String sendhw6GetRequest(String urlStr) { String result = null; try { // Construct data StringBuffer data = new XXXXXXXX11;
Background image of page 2
3 // Send data urlStr = urlStr.replace(' ', '+'); URL url = new URL(urlStr); URLConnection conn = XXXXXXXX12; // Get the response BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream())); StringBuffer sb = new StringBuffer(); String line; while ((line = rd. XXXXXXXX13 ()) != null) sb.append(line); rd.close(); result = sb.toString(); Document xmlDoc = XXXXXXXX14 (result); if ((xmlDoc == null) || (result.indexOf("error") != -1)) return null; JSONObject json = new JSONObject(); JSONObject innerJson = new JSONObject(); json.put("videos", innerJson); JSONArray arrayObj = new JSONArray(); // recursively walk and modify document ListElements(xmlDoc.getRootElement(), arrayObj); innerJson.put("video",arrayObj); result = json.toString(); } catch (Exception e)
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 05/12/2011 for the course CSCI 571 taught by Professor Papa during the Fall '07 term at USC.

Page1 / 13

Cs571_10sp-final-pap - Computer Science 571 2nd Exam Prof Papa Thursday 5:30pm 6:45pm Name 1 This is a closed book exam 2 Please answer all

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online