ApplySessionMailFactoryAction.java

00001 /*
00002  * JOnAS: Java(TM) Open Application Server
00003  * Copyright (C) 1999 Bull S.A.
00004  * Contact: jonas-team@objectweb.org
00005  *
00006  * This library is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU Lesser General Public
00008  * License as published by the Free Software Foundation; either
00009  * version 2.1 of the License, or any later version.
00010  *
00011  * This library is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  * Lesser General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU Lesser General Public
00017  * License along with this library; if not, write to the Free Software
00018  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
00019  * USA
00020  *
00021  * --------------------------------------------------------------------------
00022  * $Id: ApplySessionMailFactoryAction.java,v 1.5 2004/03/19 14:31:49 sauthieg Exp $
00023 * --------------------------------------------------------------------------
00024  */
00025 
00026 package org.objectweb.jonas.webapp.jonasadmin.service.mail;
00027 
00028 import java.io.IOException;
00029 import java.util.Properties;
00030 
00031 import javax.management.ObjectName;
00032 import javax.servlet.ServletException;
00033 import javax.servlet.http.HttpServletRequest;
00034 import javax.servlet.http.HttpServletResponse;
00035 
00036 import org.apache.struts.action.ActionForm;
00037 import org.apache.struts.action.ActionForward;
00038 import org.apache.struts.action.ActionMapping;
00039 import org.objectweb.jonas.jmx.J2eeObjectName;
00040 import org.objectweb.jonas.jmx.JonasManagementRepr;
00041 import org.objectweb.jonas.mail.MailServiceImpl;
00042 import org.objectweb.jonas.webapp.jonasadmin.JonasBaseAction;
00043 
00044 
00049 public class ApplySessionMailFactoryAction extends JonasBaseAction {
00050 
00051 // --------------------------------------------------------- Public Methods
00052 
00053     public ActionForward executeAction(ActionMapping p_Mapping, ActionForm p_Form
00054         , HttpServletRequest p_Request, HttpServletResponse p_Response)
00055         throws IOException, ServletException {
00056 
00057         // Form used
00058         MailFactoryForm oForm = (MailFactoryForm) p_Form;
00059         try {
00060             // process form ....
00061             // Mail factory form
00062             String mfName = oForm.getMailFactoryName();
00063             // Object name used          
00064             String domainName = m_WhereAreYou.getCurrentDomainName();
00065             String serverName = m_WhereAreYou.getCurrentJonasServerName();
00066             ObjectName oObjectName = J2eeObjectName.JavaMailResource(domainName, mfName, serverName, 
00067                                                                      MailServiceImpl.SESSION_PROPERTY_TYPE);
00068             String jndiName = oForm.getJndiName();
00069             String currentJndiName = getStringAttribute(oObjectName, "Name");
00070             if (!jndiName.equals(currentJndiName)) {
00071                 JonasManagementRepr.setAttribute(oObjectName, "Name",  jndiName);
00072             }
00073 
00074             // apply session properties
00075             String sSessionProps = oForm.getSessionProps().trim();
00076             Properties pSessionProps = getPropsFromString(sSessionProps); // method in JonasBaseAction
00077             JonasManagementRepr.setAttribute(oObjectName, "SessionProperties", pSessionProps);
00078 
00079             // apply authentication properties if changed
00080             String username = oForm.getUsername();
00081             String password = oForm.getPassword();
00082             Properties authProps = new Properties();
00083             authProps.setProperty("mail.authentication.username", username);
00084             authProps.setProperty("mail.authentication.password", password);
00085             JonasManagementRepr.setAttribute(oObjectName, "AuthenticationProperties", authProps);
00086 
00087             if (oForm.getAction().equals("save") == true) {
00088                 JonasManagementRepr.invoke(oObjectName, "saveConfig", null, null);
00089             }
00090         }
00091         catch (Throwable t) {
00092             addGlobalError(t);
00093             saveErrors(p_Request, m_Errors);
00094             return (p_Mapping.findForward("Global Error"));
00095         }
00096         // Forward to the jsp and add the parameter 'name' with the good value.
00097         return new ActionForward(p_Mapping.findForward("ActionEditSessionMailFactory").getPath() + "?name="
00098             + oForm.getMailFactoryName());
00099     }
00100 
00101 }

Generated on Tue Feb 15 15:05:33 2005 for JOnAS by  doxygen 1.3.9.1