001: /*
002: * JOnAS: Java(TM) Open Application Server
003: * Copyright (C) 1999 Bull S.A.
004: * Contact: jonas-team@objectweb.org
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2.1 of the License, or any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: * You should have received a copy of the GNU Lesser General Public
017: * License along with this library; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
019: * USA
020: *
021: * --------------------------------------------------------------------------
022: * $Id: ApplySessionMailFactoryAction.java 9680 2006-10-06 12:08:33Z danesa $
023: * --------------------------------------------------------------------------
024: */
025:
026: package org.objectweb.jonas.webapp.jonasadmin.service.mail;
027:
028: import java.io.IOException;
029: import java.util.Properties;
030:
031: import javax.management.ObjectName;
032: import javax.servlet.ServletException;
033: import javax.servlet.http.HttpServletRequest;
034: import javax.servlet.http.HttpServletResponse;
035:
036: import org.apache.struts.action.ActionForm;
037: import org.apache.struts.action.ActionForward;
038: import org.apache.struts.action.ActionMapping;
039: import org.objectweb.jonas.jmx.J2eeObjectName;
040: import org.objectweb.jonas.jmx.JonasManagementRepr;
041: import org.objectweb.jonas.mail.MailServiceImpl;
042: import org.objectweb.jonas.webapp.jonasadmin.JonasBaseAction;
043:
044: /**
045: * @author Adriana Danes
046: */
047:
048: public class ApplySessionMailFactoryAction extends JonasBaseAction {
049:
050: // --------------------------------------------------------- Public Methods
051:
052: public ActionForward executeAction(ActionMapping p_Mapping,
053: ActionForm p_Form, HttpServletRequest p_Request,
054: HttpServletResponse p_Response) throws IOException,
055: ServletException {
056:
057: // Form used
058: MailFactoryForm oForm = (MailFactoryForm) p_Form;
059: try {
060: // process form ....
061: // Mail factory form
062: String mfName = oForm.getMailFactoryName();
063: // Object name used
064: String domainName = m_WhereAreYou.getCurrentDomainName();
065: String serverName = m_WhereAreYou
066: .getCurrentJonasServerName();
067: ObjectName oObjectName = J2eeObjectName.JavaMailResource(
068: domainName, mfName, serverName,
069: MailServiceImpl.SESSION_PROPERTY_TYPE);
070: String jndiName = oForm.getJndiName();
071: String currentJndiName = getStringAttribute(oObjectName,
072: "Name");
073: if (!jndiName.equals(currentJndiName)) {
074: JonasManagementRepr.setAttribute(oObjectName, "Name",
075: jndiName, serverName);
076: }
077:
078: // apply session properties
079: String sSessionProps = oForm.getSessionProps().trim();
080: Properties pSessionProps = getPropsFromString(sSessionProps); // method in JonasBaseAction
081: JonasManagementRepr.setAttribute(oObjectName,
082: "SessionProperties", pSessionProps, serverName);
083:
084: // apply authentication properties if changed
085: String username = oForm.getUsername();
086: String password = oForm.getPassword();
087: Properties authProps = new Properties();
088: authProps.setProperty("mail.authentication.username",
089: username);
090: authProps.setProperty("mail.authentication.password",
091: password);
092: JonasManagementRepr.setAttribute(oObjectName,
093: "AuthenticationProperties", authProps, serverName);
094:
095: if (oForm.getAction().equals("save")) {
096: JonasManagementRepr.invoke(oObjectName, "saveConfig",
097: null, null, serverName);
098: }
099: } catch (Throwable t) {
100: addGlobalError(t);
101: saveErrors(p_Request, m_Errors);
102: return (p_Mapping.findForward("Global Error"));
103: }
104: // Forward to the jsp and add the parameter 'name' with the good value.
105: return new ActionForward(p_Mapping.findForward(
106: "ActionEditSessionMailFactory").getPath()
107: + "?name=" + oForm.getMailFactoryName());
108: }
109:
110: }
|