Search in sources :

Example 1 with MailUtil

use of edu.uiuc.ncsa.security.util.mail.MailUtil in project OA4MP by ncsa.

the class OA4MPServletInitializer method setupNotifiers.

public void setupNotifiers() throws IOException {
    // do this once or you will have a message sent for each listener!
    if (notifiersSet)
        return;
    MyProxyDelegationServlet mps = (MyProxyDelegationServlet) getServlet();
    ServiceEnvironmentImpl env = (ServiceEnvironmentImpl) getEnvironment();
    MyLoggingFacade logger = env.getMyLogger();
    // debugging this...
    NewClientNotifier newClientNotifier = createNewClientNotifier(env.getMailUtil(), logger);
    MyProxyDelegationServlet.addNotificationListener(newClientNotifier);
    MailUtil x = new MailUtil(env.getMailUtil().getMailEnvironment());
    String fName = mps.getServletContext().getInitParameter(ERROR_NOTIFICATION_SUBJECT_KEY);
    if (fName == null) {
        logger.info("No error notification subject set. Skipping...");
        notifiersSet = true;
        return;
    } else {
        logger.info("Set error notification subject to " + fName);
    }
    x.setSubjectTemplate(getTemplate(new File(fName)));
    fName = mps.getServletContext().getInitParameter(ERROR_NOTIFICATION_BODY_KEY);
    if (fName == null) {
        logger.info("No error notification message body set. Skipping...");
        notifiersSet = true;
        return;
    } else {
        logger.info("Set error notification message body to " + fName);
    }
    x.setMessageTemplate(getTemplate(new File(fName)));
    ExceptionEventNotifier exceptionNotifier = new ExceptionEventNotifier(x, logger);
    MyProxyDelegationServlet.addNotificationListener(exceptionNotifier);
    notifiersSet = true;
}
Also used : MyLoggingFacade(edu.uiuc.ncsa.security.core.util.MyLoggingFacade) NewClientNotifier(edu.uiuc.ncsa.myproxy.oa4mp.server.util.NewClientNotifier) ExceptionEventNotifier(edu.uiuc.ncsa.myproxy.oa4mp.server.util.ExceptionEventNotifier) ServiceEnvironmentImpl(edu.uiuc.ncsa.myproxy.oa4mp.server.ServiceEnvironmentImpl) MailUtil(edu.uiuc.ncsa.security.util.mail.MailUtil) File(java.io.File)

Example 2 with MailUtil

use of edu.uiuc.ncsa.security.util.mail.MailUtil in project OA4MP by ncsa.

the class Monitor method sendNotification.

public void sendNotification(Throwable t) {
    if (!mailNotificationsOn())
        return;
    try {
        HashMap<String, String> replacements = new HashMap<String, String>();
        replacements.put("name", getClientEnvironment().getInitializeUri().toString());
        replacements.put("message", t.getMessage());
        replacements.put("host", InetAddress.getLocalHost().getCanonicalHostName());
        String st = null;
        if (t instanceof ServerRedirectException) {
            st = ((ServerRedirectException) t).getWebpage();
        } else {
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            PrintWriter pw = new PrintWriter(baos);
            t.printStackTrace(pw);
            pw.flush();
            st = new String(baos.toByteArray());
            pw.close();
        }
        replacements.put("stacktrace", st);
        MailUtil mailUtil = mup.get();
        // log it all to the right place.
        mailUtil.setMyLogger(getMyLogger());
        mailUtil.sendMessage(replacements);
    } catch (Throwable throwable) {
        info("Could not send notification: " + t.getMessage());
        if (isVerbose()) {
            throwable.printStackTrace();
        }
    }
}
Also used : HashMap(java.util.HashMap) MailUtil(edu.uiuc.ncsa.security.util.mail.MailUtil) ServerRedirectException(edu.uiuc.ncsa.security.core.exceptions.ServerRedirectException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) PrintWriter(java.io.PrintWriter)

Aggregations

MailUtil (edu.uiuc.ncsa.security.util.mail.MailUtil)2 ServiceEnvironmentImpl (edu.uiuc.ncsa.myproxy.oa4mp.server.ServiceEnvironmentImpl)1 ExceptionEventNotifier (edu.uiuc.ncsa.myproxy.oa4mp.server.util.ExceptionEventNotifier)1 NewClientNotifier (edu.uiuc.ncsa.myproxy.oa4mp.server.util.NewClientNotifier)1 ServerRedirectException (edu.uiuc.ncsa.security.core.exceptions.ServerRedirectException)1 MyLoggingFacade (edu.uiuc.ncsa.security.core.util.MyLoggingFacade)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 File (java.io.File)1 PrintWriter (java.io.PrintWriter)1 HashMap (java.util.HashMap)1