1 package com.sslexplorer.agent.client.applications; 2 3 import java.io.IOException ; 4 import java.util.Enumeration ; 5 import java.util.Hashtable ; 6 import java.util.Vector ; 7 8 import com.maverick.multiplex.MultiplexedConnection; 9 import com.maverick.multiplex.Request; 10 import com.maverick.multiplex.RequestHandler; 11 import com.maverick.util.ByteArrayReader; 12 import com.maverick.util.ByteArrayWriter; 13 import com.sslexplorer.agent.client.AbstractResourceManager; 14 import com.sslexplorer.agent.client.Agent; 15 import com.sslexplorer.agent.client.util.TunnelConfiguration; 16 17 public class ApplicationManager extends AbstractResourceManager implements RequestHandler { 18 19 public static final String LAUNCH_APPLICATION_REQUEST = "launchApplication@3sp.com"; 20 21 org.apache.commons.logging.Log log = org.apache.commons.logging.LogFactory.getLog(ApplicationManager.class); 23 25 28 public final static int APPLICATION_SHORTCUT_RESOURCE_TYPE_ID = 3; 29 30 Hashtable applicationResources = new Hashtable (); 31 32 static ApplicationManager instance; 33 34 public ApplicationManager(Agent agent) { 35 super(agent); 36 agent.getConnection().registerRequestHandler(LAUNCH_APPLICATION_REQUEST, this); 37 } 38 39 public void getApplicationResources() { 40 super.getResources(APPLICATION_SHORTCUT_RESOURCE_TYPE_ID, "Applications"); 41 } 42 43 public void launchResource(int resourceId) { 44 try { 45 ByteArrayWriter baw = new ByteArrayWriter(); 46 baw.writeInt(resourceId); 47 Request request = new Request("setupAndLaunchApplication@3sp.com", baw.toByteArray()); 48 if (agent.getConnection().sendRequest(request, true)) { 49 log.debug("Application launch setup"); 51 processLaunchRequest(request); 53 } else { 54 log.error("Failed to setup and launch application launch"); 56 } 58 } catch (IOException e) { 59 log.error("Failed to setup and launch application launch", e); 61 } 63 } 64 65 public boolean processRequest(Request request, MultiplexedConnection con) { 66 67 if (request.getRequestName().equals(LAUNCH_APPLICATION_REQUEST)) { 68 69 try { 70 return processLaunchRequest(request); 71 } catch (IOException e) { 72 log.error("Failed to process launch application request", e); return false; 76 } 77 } else 78 return false; 79 } 80 81 public void postReply(MultiplexedConnection connection) { 82 } 83 84 boolean processLaunchRequest(Request request) throws IOException { 85 86 if(request.getRequestData()==null) 87 return true; 88 89 ByteArrayReader msg = new ByteArrayReader(request.getRequestData()); 90 91 boolean serverSide = msg.readBoolean(); 93 if(serverSide) { 94 log.info("Server side launch. No further processing required."); 96 return false; 98 } 99 100 String name = msg.readString(); 102 msg.readInt(); String launchId = msg.readString(); 104 String descriptor = msg.readString(); 105 Hashtable parameters = new Hashtable (); 106 parameters.put("launchId", launchId); 107 parameters.put("ticket", launchId); 108 109 Application app = launchApplication(name, descriptor, parameters); 110 app.start(); 111 Vector tunnels = ((AgentApplicationLauncher)app.getLauncher()).getTunnels(); 112 ByteArrayWriter baw = new ByteArrayWriter(); 113 for(Enumeration e = tunnels.elements(); e.hasMoreElements(); ) { 114 TunnelConfiguration listeningSocketConfiguration = (TunnelConfiguration) e.nextElement(); 115 baw.writeString(listeningSocketConfiguration.getName()); 116 baw.writeString(listeningSocketConfiguration.getSourceInterface()); 117 baw.writeInt(listeningSocketConfiguration.getSourcePort()); 118 } 119 request.setRequestData(baw.toByteArray()); 120 121 return true; 122 } 123 124 public Application launchApplication(String name, String descriptor, Hashtable parameters) throws IOException { 125 if (agent.getConfiguration().isDisplayInformationPopups()) { 126 agent.getGUI().popup(null, "Launching " + name, "SSL-Explorer Agent", "popup-application", -1); } 128 Application app = new Application(agent, parameters, name, descriptor); 129 return app; 130 } 131 } 132 | Popular Tags |