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 47 48 public class ApplyMimePartMailFactoryAction extends JonasBaseAction { 49 50 52 public ActionForward executeAction(ActionMapping p_Mapping, ActionForm p_Form 53 , HttpServletRequest p_Request, HttpServletResponse p_Response) 54 throws IOException , ServletException { 55 56 MailFactoryForm oForm = (MailFactoryForm) p_Form; 58 try { 59 String mfName = oForm.getMailFactoryName(); 62 String domainName = m_WhereAreYou.getCurrentDomainName(); 64 String serverName = m_WhereAreYou.getCurrentJonasServerName(); 65 ObjectName oObjectName = J2eeObjectName.JavaMailResource(domainName, mfName, serverName, 66 MailServiceImpl.MIMEPART_PROPERTY_TYPE); 67 68 String jndiName = oForm.getJndiName(); 69 String currentJndiName = getStringAttribute(oObjectName, "Name"); 70 if (!jndiName.equals(currentJndiName)) { 71 JonasManagementRepr.setAttribute(oObjectName, "Name", jndiName); 73 } 74 75 String sSessionProps = oForm.getSessionProps(); 77 Properties pSessionProps = getPropsFromString(sSessionProps); 78 String aName = null; 79 String aValue = null; 80 JonasManagementRepr.setAttribute(oObjectName, "SessionProperties", pSessionProps); 81 82 String username = oForm.getUsername(); 84 String password = oForm.getPassword(); 85 Properties authProps = new Properties (); 86 authProps.setProperty("mail.authentication.username", username); 87 authProps.setProperty("mail.authentication.password", password); 88 JonasManagementRepr.setAttribute(oObjectName, "AuthenticationProperties", authProps); 89 90 String to = oForm.getTo(); 92 String subject = oForm.getSubject(); 93 String cc = oForm.getCc(); 94 String bcc = oForm.getBcc(); 95 Properties mimeProps = new Properties (); 96 mimeProps.setProperty("mail.to", to); 97 mimeProps.setProperty("mail.subject", subject); 98 mimeProps.setProperty("mail.cc", cc); 99 mimeProps.setProperty("mail.bcc", bcc); 100 JonasManagementRepr.setAttribute(oObjectName, "MimeMessageProperties", mimeProps); 101 102 if (oForm.getAction().equals("save") == true) { 103 JonasManagementRepr.invoke(oObjectName, "saveConfig", null, null); 104 } 105 } 106 catch (Throwable t) { 107 addGlobalError(t); 108 saveErrors(p_Request, m_Errors); 109 return (p_Mapping.findForward("Global Error")); 110 } 111 return new ActionForward(p_Mapping.findForward("ActionEditMimePartMailFactory").getPath() 113 + "?name=" + oForm.getMailFactoryName()); 114 } 115 116 } 117 | Popular Tags |