1 16 17 package org.apache.webapp.admin.resources; 18 19 import java.io.IOException ; 20 import java.net.URLDecoder ; 21 import java.util.Iterator ; 22 import java.util.Locale ; 23 import javax.management.Attribute ; 24 import javax.management.MBeanServer ; 25 import javax.management.MBeanServerFactory ; 26 import javax.management.QueryExp ; 27 import javax.management.Query ; 28 import javax.management.ObjectInstance ; 29 import javax.management.ObjectName ; 30 import javax.management.JMException ; 31 import javax.management.MBeanAttributeInfo ; 32 import javax.management.MBeanOperationInfo ; 33 import javax.management.MBeanInfo ; 34 import javax.servlet.ServletException ; 35 import javax.servlet.http.HttpServletRequest ; 36 import javax.servlet.http.HttpServletResponse ; 37 import javax.servlet.http.HttpSession ; 38 import org.apache.struts.action.Action; 39 import org.apache.struts.action.ActionErrors; 40 import org.apache.struts.action.ActionForm; 41 import org.apache.struts.action.ActionForward; 42 import org.apache.struts.action.ActionMapping; 43 import org.apache.struts.util.MessageResources; 44 import org.apache.webapp.admin.ApplicationServlet; 45 46 47 57 58 public final class SetUpMailSessionAction extends Action { 59 60 62 63 66 private MBeanServer mserver = null; 67 68 69 71 72 87 public ActionForward execute(ActionMapping mapping, 88 ActionForm form, 89 HttpServletRequest request, 90 HttpServletResponse response) 91 throws IOException , ServletException { 92 93 if (mserver == null) { 95 mserver = ((ApplicationServlet) getServlet()).getServer(); 96 } 97 MessageResources resources = getResources(request); 98 HttpSession session = request.getSession(); 99 Locale locale = getLocale(request); 100 101 String objectName = request.getParameter("objectName"); 103 String resourcetype = request.getParameter("resourcetype"); 104 String path = request.getParameter("path"); 105 String host = request.getParameter("host"); 106 String domain = request.getParameter("domain"); 107 108 MailSessionForm mailSessionForm = new MailSessionForm(); 109 mailSessionForm.setResourcetype(resourcetype); 110 mailSessionForm.setPath(path); 111 mailSessionForm.setHost(host); 112 mailSessionForm.setDomain(domain); 113 mailSessionForm.setType(ResourceUtils.MAILSESSION_CLASS); 114 115 if (objectName == null) { 116 mailSessionForm.setNodeLabel 117 (resources.getMessage(locale, "resources.actions.mailsession.create")); 118 mailSessionForm.setObjectName(null); 119 mailSessionForm.setType(ResourceUtils.MAILSESSION_CLASS); 120 121 } else { 122 mailSessionForm.setNodeLabel 123 (resources.getMessage(locale, "resources.actions.mailsession.edit")); 124 mailSessionForm.setObjectName(objectName); 125 126 String attribute = null; 127 try { 128 129 ObjectName oname = new ObjectName (objectName); 130 attribute = "name"; 131 mailSessionForm.setName 132 ((String ) mserver.getAttribute(oname, attribute)); 133 attribute = "mail.smtp.host"; 134 mailSessionForm.setMailhost 135 ((String ) mserver.getAttribute(oname, attribute)); 136 137 } catch (Exception e) { 138 getServlet().log 139 (resources.getMessage(locale, 140 "users.error.attribute.get", attribute), e); 141 response.sendError 142 (HttpServletResponse.SC_INTERNAL_SERVER_ERROR, 143 resources.getMessage 144 (locale, "users.error.attribute.get", attribute)); 145 return (null); 146 } 147 } 148 149 saveToken(request); 151 request.setAttribute("mailSessionForm", mailSessionForm); 152 return (mapping.findForward("MailSession")); 153 154 } 155 } 156 | Popular Tags |