public String buildServiceOptions(String rule) throws SQLException { List services = NotificationFactory.getInstance().getServiceNames(); Collections.sort( services, new Comparator() { public int compare(Object o1, Object o2) { return ((String) o1).compareToIgnoreCase((String) o2); } }); StringBuffer buffer = new StringBuffer(); for (int i = 0; i < services.size(); i++) { if (rule != null && rule.indexOf((String) services.get(i)) > 0) { buffer.append( "<option selected VALUE='" + services.get(i) + "'>" + services.get(i) + "</option>"); } else { buffer.append("<option VALUE='" + services.get(i) + "'>" + services.get(i) + "</option>"); } } return buffer.toString(); }
public String buildServiceList(String rule) throws SQLException { if (rule == null) { return ""; } List services = NotificationFactory.getInstance().getServiceNames(); Collections.sort( services, new Comparator() { public int compare(Object o1, Object o2) { return ((String) o1).compareToIgnoreCase((String) o2); } }); StringBuffer buffer = new StringBuffer(); for (int i = 0; i < services.size(); i++) { if (rule.indexOf((String) services.get(i)) > 0) { buffer.append(services.get(i)).append("</br>"); } } return buffer.toString(); }
public Writer getErrorReport( Writer to, final HttpServletRequest request, CharTransformer escape) throws IOException { final Writer logMsg = new StringWriter(); final Writer tee = new org.mmbase.util.ChainedWriter(to, logMsg); Writer msg = tee; LinkedList<Throwable> stack = getStack(); String ticket = new Date().toString(); Map<String, String> props; try { props = org.mmbase.util.ApplicationContextReader.getProperties("mmbase_errorpage"); } catch (javax.naming.NamingException ne) { props = Collections.emptyMap(); log.info(ne); } if (request != null) { { msg.append("Headers\n----------\n"); // request properties for (Object name : Collections.list(request.getHeaderNames())) { msg.append( escape.transform( name + ": " + escape.transform(request.getHeader((String) name)) + "\n")); } } { msg.append("\nAttributes\n----------\n"); Pattern p = requestIgnore; if (p == null && props.get("request_ignore") != null) { p = Pattern.compile(props.get("request_ignore")); } for (Object name : Collections.list(request.getAttributeNames())) { if (p == null || !p.matcher((String) name).matches()) { msg.append( escape.transform(name + ": " + request.getAttribute((String) name) + "\n")); } } } if (Boolean.TRUE.equals(showSession) || (showSession == null && !"false".equals(props.get("show_session")))) { HttpSession ses = request.getSession(false); if (ses != null) { msg.append("\nSession\n----------\n"); Pattern p = sessionIgnore; if (p == null && props.get("session_ignore") != null) { p = Pattern.compile(props.get("session_ignore")); } for (Object name : Collections.list(ses.getAttributeNames())) { if (p == null || !p.matcher((String) name).matches()) { msg.append(escape.transform(name + ": " + ses.getAttribute((String) name) + "\n")); } } } } } msg.append("\n"); msg.append("Misc. properties\n----------\n"); if (request != null) { msg.append("method: ").append(escape.transform(request.getMethod())).append("\n"); msg.append("querystring: ").append(escape.transform(request.getQueryString())).append("\n"); msg.append("requesturl: ") .append(escape.transform(request.getRequestURL().toString())) .append("\n"); } if (Boolean.TRUE.equals(showMMBaseVersion) || (showMMBaseVersion == null && !"false".equals(props.get("show_mmbase_version")))) { msg.append("mmbase version: ").append(org.mmbase.Version.get()).append("\n"); } msg.append("status: ").append("").append(String.valueOf(status)).append("\n\n"); if (request != null) { msg.append("Parameters\n----------\n"); // request parameters Enumeration en = request.getParameterNames(); while (en.hasMoreElements()) { String name = (String) en.nextElement(); msg.append(name) .append(": ") .append(escape.transform(request.getParameter(name))) .append("\n"); } } msg.append("\nException ") .append(ticket) .append("\n----------\n\n") .append( exception != null ? (escape.transform(exception.getClass().getName())) : "NO EXCEPTION") .append(": "); int wroteCauses = 0; while (!stack.isEmpty()) { Throwable t = stack.removeFirst(); // add stack stacktraces if (t != null) { if (stack.isEmpty()) { // write last message always msg = tee; } String message = t.getMessage(); if (msg != tee) { to.append("\n=== skipped(see log) : ") .append(escape.transform(t.getClass().getName())) .append(": ") .append(message) .append("\n"); } msg.append("\n\n").append(escape.transform(t.getClass().getName() + ": " + message)); StackTraceElement[] stackTrace = t.getStackTrace(); for (StackTraceElement e : stackTrace) { msg.append("\n at ").append(escape.transform(e.toString())); } if (!stack.isEmpty()) { msg.append("\n-------caused:\n"); } wroteCauses++; if (wroteCauses >= MAX_CAUSES) { msg = logMsg; } } } // write errors to log if (status == 500) { try { if (props.get("to") != null && props.get("to").length() > 0) { javax.naming.Context initCtx = new javax.naming.InitialContext(); javax.naming.Context envCtx = (javax.naming.Context) initCtx.lookup("java:comp/env"); Object mailSession = envCtx.lookup("mail/Session"); Class sessionClass = Class.forName("javax.mail.Session"); Class recipientTypeClass = Class.forName("javax.mail.Message$RecipientType"); Class messageClass = Class.forName("javax.mail.internet.MimeMessage"); Object mail = messageClass.getConstructor(sessionClass).newInstance(mailSession); messageClass .getMethod("addRecipients", recipientTypeClass, String.class) .invoke(mail, recipientTypeClass.getDeclaredField("TO").get(null), props.get("to")); messageClass.getMethod("setSubject", String.class).invoke(mail, ticket); mail.getClass().getMethod("setText", String.class).invoke(mail, logMsg.toString()); Class.forName("javax.mail.Transport") .getMethod("send", Class.forName("javax.mail.Message")) .invoke(null, mail); tee.append("\nmailed to (").append(String.valueOf(props)).append(")"); } } catch (Exception nnfe) { tee.append("\nnot mailed (").append(String.valueOf(nnfe)).append(")"); if (log.isDebugEnabled()) { log.debug(nnfe.getMessage(), nnfe); } } log.error("TICKET " + ticket + ":\n" + logMsg); } return to; }
public void _jspService(HttpServletRequest request, HttpServletResponse response) throws java.io.IOException, ServletException { JspFactory _jspxFactory = null; PageContext pageContext = null; HttpSession session = null; ServletContext application = null; ServletConfig config = null; JspWriter out = null; Object page = this; JspWriter _jspx_out = null; PageContext _jspx_page_context = null; try { _jspxFactory = JspFactory.getDefaultFactory(); response.setContentType("text/html"); pageContext = _jspxFactory.getPageContext(this, request, response, "error.jsp", true, 8192, true); _jspx_page_context = pageContext; application = pageContext.getServletContext(); config = pageContext.getServletConfig(); session = pageContext.getSession(); out = pageContext.getOut(); _jspx_out = out; out.write("\n\n\n\n\n\n\n\n\n"); out.write('\n'); org.jivesoftware.util.WebManager webManager = null; synchronized (_jspx_page_context) { webManager = (org.jivesoftware.util.WebManager) _jspx_page_context.getAttribute("webManager", PageContext.PAGE_SCOPE); if (webManager == null) { webManager = new org.jivesoftware.util.WebManager(); _jspx_page_context.setAttribute("webManager", webManager, PageContext.PAGE_SCOPE); } } out.write('\n'); webManager.init(request, response, session, application, out); out.write('\n'); out.write('\n'); // Get paramters boolean doTest = request.getParameter("test") != null; boolean cancel = request.getParameter("cancel") != null; boolean sent = ParamUtils.getBooleanParameter(request, "sent"); boolean success = ParamUtils.getBooleanParameter(request, "success"); String from = ParamUtils.getParameter(request, "from"); String to = ParamUtils.getParameter(request, "to"); String subject = ParamUtils.getParameter(request, "subject"); String body = ParamUtils.getParameter(request, "body"); // Cancel if requested if (cancel) { response.sendRedirect("system-email.jsp"); return; } // Variable to hold messaging exception, if one occurs Exception mex = null; // Validate input Map<String, String> errors = new HashMap<String, String>(); if (doTest) { if (from == null) { errors.put("from", ""); } if (to == null) { errors.put("to", ""); } if (subject == null) { errors.put("subject", ""); } if (body == null) { errors.put("body", ""); } EmailService service = EmailService.getInstance(); // Validate host - at a minimum, it needs to be set: String host = service.getHost(); if (host == null) { errors.put("host", ""); } // if no errors, continue if (errors.size() == 0) { // Create a message MimeMessage message = service.createMimeMessage(); // Set the date of the message to be the current date SimpleDateFormat format = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss Z", java.util.Locale.US); format.setTimeZone(JiveGlobals.getTimeZone()); message.setHeader("Date", format.format(new Date())); // Set to and from. message.setRecipient(Message.RecipientType.TO, new InternetAddress(to, null)); message.setFrom(new InternetAddress(from, null)); message.setSubject(subject); message.setText(body); // Send the message, wrap in a try/catch: try { service.sendMessagesImmediately(Collections.singletonList(message)); // success, so indicate this: response.sendRedirect("system-emailtest.jsp?sent=true&success=true"); return; } catch (MessagingException me) { me.printStackTrace(); mex = me; } } } // Set var defaults Collection<JID> jids = webManager.getXMPPServer().getAdmins(); User user = null; if (!jids.isEmpty()) { for (JID jid : jids) { if (webManager.getXMPPServer().isLocal(jid)) { user = webManager.getUserManager().getUser(jid.getNode()); if (user.getEmail() != null) { break; } } } } if (from == null) { from = user.getEmail(); } if (to == null) { to = user.getEmail(); } if (subject == null) { subject = "Test email sent via Openfire"; } if (body == null) { body = "This is a test message."; } out.write("\n\n<html>\n <head>\n <title>"); if (_jspx_meth_fmt_message_0(_jspx_page_context)) return; out.write( "</title>\n <meta name=\"pageID\" content=\"system-email\"/>\n </head>\n <body>\n\n<script language=\"JavaScript\" type=\"text/javascript\">\nvar clicked = false;\nfunction checkClick(el) {\n if (!clicked) {\n clicked = true;\n return true;\n }\n return false;\n}\n</script>\n\n<p>\n"); if (_jspx_meth_fmt_message_1(_jspx_page_context)) return; out.write("\n</p>\n\n"); if (JiveGlobals.getProperty("mail.smtp.host") == null) { out.write( "\n\n <div class=\"jive-error\">\n <table cellpadding=\"0\" cellspacing=\"0\" border=\"0\">\n <tbody>\n <tr>\n \t<td class=\"jive-icon\"><img src=\"images/error-16x16.gif\" width=\"16\" height=\"16\" border=\"0\" alt=\"\"></td>\n\t <td class=\"jive-icon-label\">\n\t\t "); if (_jspx_meth_fmt_message_2(_jspx_page_context)) return; out.write("\n\t </td>\n </tr>\n </tbody>\n </table>\n </div>\n\n"); } out.write('\n'); out.write('\n'); if (doTest || sent) { out.write("\n\n "); if (success) { out.write( "\n\n <div class=\"jive-success\">\n <table cellpadding=\"0\" cellspacing=\"0\" border=\"0\">\n <tbody>\n <tr>\n \t<td class=\"jive-icon\"><img src=\"images/success-16x16.gif\" width=\"16\" height=\"16\" border=\"0\" alt=\"\"></td>\n \t<td class=\"jive-icon-label\">"); if (_jspx_meth_fmt_message_3(_jspx_page_context)) return; out.write( "</td>\n </tr>\n </tbody>\n </table>\n </div>\n\n "); } else { out.write( "\n\n <div class=\"jive-error\">\n <table cellpadding=\"0\" cellspacing=\"0\" border=\"0\">\n <tbody>\n <tr><td class=\"jive-icon\"><img src=\"images/error-16x16.gif\" width=\"16\" height=\"16\" border=\"0\" alt=\"\"></td>\n <td class=\"jive-icon-label\">\n "); if (_jspx_meth_fmt_message_4(_jspx_page_context)) return; out.write("\n "); if (mex != null) { out.write("\n "); if (mex instanceof AuthenticationFailedException) { out.write("\n \t"); if (_jspx_meth_fmt_message_5(_jspx_page_context)) return; out.write(" \n "); } else { out.write("\n (Message: "); out.print(mex.getMessage()); out.write(")\n "); } out.write("\n "); } out.write( "\n </td></tr>\n </tbody>\n </table>\n </div>\n\n "); } out.write("\n\n <br>\n\n"); } out.write( "\n\n<form action=\"system-emailtest.jsp\" method=\"post\" name=\"f\" onsubmit=\"return checkClick(this);\">\n\n<table cellpadding=\"3\" cellspacing=\"0\" border=\"0\">\n<tbody>\n <tr>\n <td>\n "); if (_jspx_meth_fmt_message_6(_jspx_page_context)) return; out.write(":\n </td>\n <td>\n "); String host = JiveGlobals.getProperty("mail.smtp.host"); if (host == null) { out.write("\n <i>"); if (_jspx_meth_fmt_message_7(_jspx_page_context)) return; out.write("</i>\n "); } else { out.write("\n "); out.print(host); out.write(':'); out.print(JiveGlobals.getIntProperty("mail.smtp.port", 25)); out.write("\n\n "); if (JiveGlobals.getBooleanProperty("mail.smtp.ssl", false)) { out.write("\n\n ("); if (_jspx_meth_fmt_message_8(_jspx_page_context)) return; out.write(")\n\n "); } out.write("\n "); } out.write("\n </td>\n </tr>\n <tr>\n <td>\n "); if (_jspx_meth_fmt_message_9(_jspx_page_context)) return; out.write( ":\n </td>\n <td>\n <input type=\"hidden\" name=\"from\" value=\""); out.print(from); out.write("\">\n "); out.print(StringUtils.escapeHTMLTags(from)); out.write( "\n <span class=\"jive-description\">\n (<a href=\"user-edit-form.jsp?username="******"\">Update Address</a>)\n </span>\n </td>\n </tr>\n <tr>\n <td>\n "); if (_jspx_meth_fmt_message_10(_jspx_page_context)) return; out.write( ":\n </td>\n <td>\n <input type=\"text\" name=\"to\" value=\""); out.print(((to != null) ? to : "")); out.write( "\"\n size=\"40\" maxlength=\"100\">\n </td>\n </tr>\n <tr>\n <td>\n "); if (_jspx_meth_fmt_message_11(_jspx_page_context)) return; out.write( ":\n </td>\n <td>\n <input type=\"text\" name=\"subject\" value=\""); out.print(((subject != null) ? subject : "")); out.write( "\"\n size=\"40\" maxlength=\"100\">\n </td>\n </tr>\n <tr valign=\"top\">\n <td>\n "); if (_jspx_meth_fmt_message_12(_jspx_page_context)) return; out.write( ":\n </td>\n <td>\n <textarea name=\"body\" cols=\"45\" rows=\"5\" wrap=\"virtual\">"); out.print(body); out.write( "</textarea>\n </td>\n </tr>\n <tr>\n <td colspan=\"2\">\n <br>\n <input type=\"submit\" name=\"test\" value=\""); if (_jspx_meth_fmt_message_13(_jspx_page_context)) return; out.write("\">\n <input type=\"submit\" name=\"cancel\" value=\""); if (_jspx_meth_fmt_message_14(_jspx_page_context)) return; out.write( "\">\n </td>\n </tr>\n</tbody>\n</table>\n\n</form>\n\n </body>\n</html>"); } catch (Throwable t) { if (!(t instanceof SkipPageException)) { out = _jspx_out; if (out != null && out.getBufferSize() != 0) out.clearBuffer(); if (_jspx_page_context != null) _jspx_page_context.handlePageException(t); } } finally { if (_jspxFactory != null) _jspxFactory.releasePageContext(_jspx_page_context); } }