public void doGet(HttpServletRequest req, HttpServletResponse res) { res.setContentType("application/download-xml-file"); String messageId = req.getParameter("message"); OMElement report = null; try { Message m = new Message(messageId); m.readMessage(); report = buildReport(m); } catch (LoggerException e) { report = omFactory.createOMElement(new QName("NoReportAvailable")); report.setText(e.getMessage().replaceAll("<", "<")); } catch (ServletException e) { report = omFactory.createOMElement(new QName("NoReportAvailable")); report.setText(e.getMessage().replaceAll("<", "<")); } try { res.getWriter().write(report.toString()); } catch (IOException e) { } }
OMElement buildReport(Message m) throws ServletException { if (!verifyTables(m)) { throw new ServletException("Missing Table"); } System.out.println(index(m)); HashMap<String, HashMap<String, Object>> mm = m.toHashMap(); OMElement report = omFactory.createOMElement(new QName("XdsEvsResult")); addParm(report, mm, "Test", "other", "Service"); addParm(report, mm, "Date", "main", "Timestamp"); addParm(report, mm, "Source", "http", "IP_address_From"); OMElement ele = omFactory.createOMElement(new QName("Target")); ele.setText(localIPAddress()); report.addChild(ele); addParm(report, mm, "Endpoint", "http", "URI_To"); addParm(report, mm, "Result", "main", "Pass"); addParm(report, mm, "LogEvent", "main", "MessageId"); addParm(report, mm, "Error", "error", "Error"); // System.out.println("errors are:\n" + mm.get("error")); return report; }
String index(Message m) { HashMap<String, HashMap<String, Object>> mm = m.toHashMap(); StringBuffer buf = new StringBuffer(); for (String key : mm.keySet()) { buf.append("\n" + key + "\n" + mm.get(key).keySet()); } return buf.toString(); }
boolean verifyTables(Message m) { HashSet<String> tableList = m.getTableList(); boolean hasMain = tableList.contains("main"); boolean hasOther = tableList.contains("other"); boolean hasHttp = tableList.contains("http"); boolean hasSoap = tableList.contains("soap"); boolean hasError = tableList.contains("error"); return hasMain && hasOther && hasHttp && hasSoap && hasError; }