KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sslexplorer > extensions > actions > GetExtensionDescriptorAction


1 /*
2  * SSL-Explorer
3  *
4  * Copyright (C) 2003-2006 3SP LTD. All Rights Reserved
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2 of
9  * the License, or (at your option) any later version.
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public
16  * License along with this program; if not, write to the Free Software
17  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18  */

19             
20 package com.sslexplorer.extensions.actions;
21
22 import java.io.IOException JavaDoc;
23 import java.util.Enumeration JavaDoc;
24 import java.util.Properties JavaDoc;
25
26 import javax.servlet.http.HttpServletRequest JavaDoc;
27 import javax.servlet.http.HttpServletResponse JavaDoc;
28
29 import org.apache.commons.logging.Log;
30 import org.apache.commons.logging.LogFactory;
31 import org.apache.struts.action.ActionForm;
32 import org.apache.struts.action.ActionForward;
33 import org.apache.struts.action.ActionMapping;
34 import org.jdom.JDOMException;
35
36 import com.sslexplorer.core.CoreException;
37 import com.sslexplorer.core.actions.XMLOutputAction;
38 import com.sslexplorer.extensions.ExtensionDescriptor;
39 import com.sslexplorer.extensions.ExtensionException;
40 import com.sslexplorer.extensions.ExtensionParser;
41 import com.sslexplorer.extensions.store.ExtensionStore;
42 import com.sslexplorer.security.Constants;
43 import com.sslexplorer.security.LogonControllerFactory;
44 import com.sslexplorer.security.SessionInfo;
45
46 /**
47  * Retrieve an application extensions descriptor.
48  *
49  * @author Brett Smith <a HREF="mailto: brett@3sp.com">&lt;brett@3sp.com&gt;</a>
50  * @author Lee David Painter <a HREF="mailto: lee@3sp.com">&lt;lee@3sp.com&gt;</a>
51  */

52 public class GetExtensionDescriptorAction extends XMLOutputAction {
53
54     final static Log log = LogFactory.getLog(GetExtensionDescriptorAction.class);
55
56     /*
57      * (non-Javadoc)
58      *
59      * @see org.apache.struts.action.Action#execute(org.apache.struts.action.ActionMapping,
60      * org.apache.struts.action.ActionForm,
61      * javax.servlet.http.HttpServletRequest,
62      * javax.servlet.http.HttpServletResponse)
63      */

64     public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response)
65                     throws Exception JavaDoc {
66
67         request.setAttribute(Constants.REQ_ATTR_COMPRESS, Boolean.FALSE);
68         String JavaDoc ticket = request.getParameter("ticket");
69         String JavaDoc id = request.getParameter("id");
70         if(id == null) {
71             throw new Exception JavaDoc("No id");
72         }
73         ExtensionDescriptor app = ExtensionStore.getInstance().getExtensionDescriptor(id);
74         if(app == null) {
75             throw new Exception JavaDoc("No extension with id of " + id);
76         }
77         Properties JavaDoc properties = new Properties JavaDoc();
78         for (Enumeration JavaDoc e = request.getParameterNames(); e.hasMoreElements();) {
79             String JavaDoc name = (String JavaDoc) e.nextElement();
80             String JavaDoc val = request.getParameter(name);
81             if (name.equals("ticket") || name.equals("id") || name.equals("name")) {
82                 continue;
83             } else {
84                 properties.put(name, val);
85             }
86         }
87         processApplicationRequest(app, ticket, request, response, properties);
88         return null;
89     }
90
91     protected void processApplicationRequest(ExtensionDescriptor app, String JavaDoc ticket, HttpServletRequest JavaDoc request,
92                                                 HttpServletResponse JavaDoc response, Properties JavaDoc properties)
93                     throws JDOMException, Exception JavaDoc {
94         try {
95             SessionInfo session = LogonControllerFactory.getInstance().getSessionInfo(request);
96             if(session == null) {
97                 throw new ExtensionException(ExtensionException.INTERNAL_ERROR, "No session.");
98             }
99             sendApplicationDescriptor(app, request, response, session, properties);
100
101         } catch (CoreException coreException) {
102             String JavaDoc message = coreException.getLocalizedMessage(request.getSession());
103             log.error(message, coreException);
104             sendError(message, response);
105         } catch (Throwable JavaDoc t) {
106             log.error("Failed to process request for application.", t);
107             sendError(t.getLocalizedMessage() == null ? "<null>" : t.getLocalizedMessage(), response);
108         }
109     }
110
111     private void sendApplicationDescriptor(ExtensionDescriptor app, HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response,
112                                             SessionInfo session, Properties JavaDoc properties)
113                     throws JDOMException, IOException JavaDoc, UndefinedParameterException, CoreException {
114         response.setHeader("Content-type", "text/xml");
115         byte[] xml = ExtensionParser.processAgentParameters(app, request, session, properties).getBytes();
116 // response.setContentLength(xml.length);
117
response.getOutputStream().write(xml);
118         response.getOutputStream().close();
119     }
120
121 }
122
Popular Tags