KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sslexplorer > applications > types > JavaType


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.applications.types;
21
22 import java.util.Map JavaDoc;
23
24 import javax.servlet.http.HttpServletRequest JavaDoc;
25
26 import org.apache.commons.logging.Log;
27 import org.apache.commons.logging.LogFactory;
28 import org.apache.struts.action.ActionForward;
29 import org.apache.struts.action.ActionMapping;
30
31 import com.maverick.multiplex.Request;
32 import com.sslexplorer.agent.AgentTunnel;
33 import com.sslexplorer.agent.DefaultAgentManager;
34 import com.sslexplorer.applications.ApplicationLauncherType;
35 import com.sslexplorer.applications.ApplicationService;
36 import com.sslexplorer.applications.ApplicationShortcut;
37 import com.sslexplorer.extensions.ExtensionDescriptor;
38 import com.sslexplorer.extensions.ExtensionException;
39 import com.sslexplorer.extensions.types.AbstractJavaType;
40 import com.sslexplorer.policyframework.LaunchSession;
41 import com.sslexplorer.security.SessionInfo;
42
43 /**
44  * Implementation of an
45  * {@link com.sslexplorer.applications.ApplicationLauncherType} that allows
46  * execution of Java applications using a running Agent.
47  *
48  * @author Brett Smith <a HREF="mailto: brett@3sp.com">&lt;brett@3sp.com&gt;</a>
49  */

50 public class JavaType extends AbstractJavaType implements ApplicationLauncherType {
51
52
53     static Log log = LogFactory.getLog(JavaType.class);
54     
55     /**
56      * Type name
57      */

58     public final static String JavaDoc TYPE = "java";
59
60     /**
61      * Constructor
62      */

63     public JavaType() {
64         super(TYPE, true);
65     }
66     
67     /* (non-Javadoc)
68      * @see com.sslexplorer.extensions.ExtensionType#isHidden()
69      */

70     public boolean isHidden() {
71         return false;
72     }
73
74     /* (non-Javadoc)
75      * @see com.sslexplorer.extensions.ApplicationLauncherType#isAgentRequired(com.sslexplorer.extensions.ApplicationShortcut, com.sslexplorer.extensions.ExtensionDescriptor)
76      */

77     public boolean isAgentRequired(ApplicationShortcut shortcut, ExtensionDescriptor descriptor) {
78         return true;
79     }
80
81     /* (non-Javadoc)
82      * @see com.sslexplorer.applications.ApplicationLauncherType#launch(java.util.Map, com.sslexplorer.extensions.ExtensionDescriptor, com.sslexplorer.applications.ApplicationShortcut, org.apache.struts.action.ActionMapping, com.sslexplorer.policyframework.LaunchSession, java.lang.String, javax.servlet.http.HttpServletRequest)
83      */

84     public ActionForward launch(Map JavaDoc<String JavaDoc, String JavaDoc> parameters, ExtensionDescriptor descriptor, ApplicationShortcut shortcut, ActionMapping mapping, LaunchSession launchSession, String JavaDoc returnTo, HttpServletRequest JavaDoc request) throws ExtensionException {
85         if (log.isInfoEnabled())
86             log.info("Launching client application " + shortcut.getResourceName());
87
88         SessionInfo session = launchSession.getSession();
89         if (DefaultAgentManager.getInstance().hasActiveAgent(session)) {
90             try {
91                 Request JavaDoc agentRequest = ((ApplicationService) DefaultAgentManager.getInstance().getService(ApplicationService.class)).launchApplication(launchSession);
92                 AgentTunnel agent = DefaultAgentManager.getInstance().getAgentBySession(launchSession.getSession());
93                 if (!agent.sendRequest(agentRequest, true, 60000)) {
94                     throw new ExtensionException(ExtensionException.AGENT_REFUSED_LAUNCH);
95                 }
96             } catch (ExtensionException ee) {
97                 throw ee;
98             } catch (Exception JavaDoc e) {
99                 throw new ExtensionException(ExtensionException.INTERNAL_ERROR, e);
100             }
101         }
102         else {
103             throw new ExtensionException(ExtensionException.NO_AGENT);
104         }
105         return null;
106     }
107
108     /* (non-Javadoc)
109      * @see com.sslexplorer.extensions.ExtensionType#getTypeBundle()
110      */

111     public String JavaDoc getTypeBundle() {
112         return "applications";
113     }
114
115     /* (non-Javadoc)
116      * @see com.sslexplorer.applications.ApplicationLauncherType#isServiceSide()
117      */

118     public boolean isServerSide() {
119         return false;
120     }
121 }
Popular Tags