1 25 26 package org.objectweb.jonas.webapp.jonasadmin.service.mail; 27 28 import java.io.IOException ; 29 import java.util.Properties ; 30 31 import javax.management.ObjectName ; 32 import javax.servlet.ServletException ; 33 import javax.servlet.http.HttpServletRequest ; 34 import javax.servlet.http.HttpServletResponse ; 35 36 import org.apache.struts.action.ActionForm; 37 import org.apache.struts.action.ActionForward; 38 import org.apache.struts.action.ActionMapping; 39 import org.objectweb.jonas.jmx.J2eeObjectName; 40 import org.objectweb.jonas.jmx.JonasManagementRepr; 41 import org.objectweb.jonas.mail.MailServiceImpl; 42 import org.objectweb.jonas.webapp.jonasadmin.JonasBaseAction; 43 44 45 48 49 public class ApplySessionMailFactoryAction extends JonasBaseAction { 50 51 53 public ActionForward executeAction(ActionMapping p_Mapping, ActionForm p_Form 54 , HttpServletRequest p_Request, HttpServletResponse p_Response) 55 throws IOException , ServletException { 56 57 MailFactoryForm oForm = (MailFactoryForm) p_Form; 59 try { 60 String mfName = oForm.getMailFactoryName(); 63 String domainName = m_WhereAreYou.getCurrentDomainName(); 65 String serverName = m_WhereAreYou.getCurrentJonasServerName(); 66 ObjectName oObjectName = J2eeObjectName.JavaMailResource(domainName, mfName, serverName, 67 MailServiceImpl.SESSION_PROPERTY_TYPE); 68 String jndiName = oForm.getJndiName(); 69 String currentJndiName = getStringAttribute(oObjectName, "Name"); 70 if (!jndiName.equals(currentJndiName)) { 71 JonasManagementRepr.setAttribute(oObjectName, "Name", jndiName); 72 } 73 74 String sSessionProps = oForm.getSessionProps().trim(); 76 Properties pSessionProps = getPropsFromString(sSessionProps); JonasManagementRepr.setAttribute(oObjectName, "SessionProperties", pSessionProps); 78 79 String username = oForm.getUsername(); 81 String password = oForm.getPassword(); 82 Properties authProps = new Properties (); 83 authProps.setProperty("mail.authentication.username", username); 84 authProps.setProperty("mail.authentication.password", password); 85 JonasManagementRepr.setAttribute(oObjectName, "AuthenticationProperties", authProps); 86 87 if (oForm.getAction().equals("save") == true) { 88 JonasManagementRepr.invoke(oObjectName, "saveConfig", null, null); 89 } 90 } 91 catch (Throwable t) { 92 addGlobalError(t); 93 saveErrors(p_Request, m_Errors); 94 return (p_Mapping.findForward("Global Error")); 95 } 96 return new ActionForward(p_Mapping.findForward("ActionEditSessionMailFactory").getPath() + "?name=" 98 + oForm.getMailFactoryName()); 99 } 100 101 } 102 | Popular Tags |