| 1 19 20 package com.sslexplorer.agent.client.applications; 21 22 import java.io.File ; 23 import java.io.FileNotFoundException ; 24 import java.io.FileOutputStream ; 25 import java.io.IOException ; 26 import java.text.MessageFormat ; 27 import java.util.Hashtable ; 28 29 import com.sslexplorer.agent.client.Agent; 30 import com.sslexplorer.agent.client.Messages; 31 import com.sslexplorer.agent.client.util.AbstractApplicationLauncher; 32 import com.sslexplorer.agent.client.util.ProcessMonitor; 33 34 41 public class Application extends Thread { 42 43 private Agent client; 45 String name; 46 Hashtable parameters; 47 private AbstractApplicationLauncher launcher; 48 private ApplicationEventListener events; 49 private String descriptor; 50 51 static org.apache.commons.logging.Log log = org.apache.commons.logging.LogFactory.getLog(Application.class); 53 54 56 64 public Application(Agent client, Hashtable parameters, String name, String descriptor) throws IOException { 65 super(MessageFormat.format(Messages.getString("Application.threadName"), new Object [] { name })); this.client = client; 67 this.name = name; 68 this.descriptor = descriptor; 69 this.parameters = parameters; 70 events = new ApplicationEventListener(this.client); 71 events.startingLaunch(name); 72 launcher = new AgentApplicationLauncher(this.client, name, parameters, descriptor, events); 73 launcher.prepare(); 74 75 } 76 77 82 public AbstractApplicationLauncher getLauncher() { 83 return launcher; 84 } 85 86 91 public String getRedirectParameters() { 92 return launcher.getApplicationType().getRedirectParameters(); 93 } 94 95 100 public void run() { 101 102 103 FileOutputStream out = null; 104 boolean hasErrored = false;; 105 106 try { 107 launcher.start(); 108 109 } catch (Throwable t) { 110 hasErrored = true; 111 112 log.error("Failed to launch application " + name, t); 116 client.getGUI().popup(null, 117 MessageFormat.format(Messages.getString("Application.error.message"), new Object [] { launcher.getName(), t.getMessage()}), 118 Messages.getString("Application.error.title"), "popup-error", 0); 119 120 } finally { 121 122 events.finishedLaunch(); 123 124 if(!hasErrored) { 125 try { 126 out = new FileOutputStream (new File (launcher.getInstallDir(), launcher.getName() + ".out")); ProcessMonitor monitor = launcher.getApplicationType().getProcessMonitor(); 128 if (monitor != null) { 129 monitor.watch(out, out); 130 } 131 } catch (Throwable e) { 132 } finally { 133 if (out != null) { 134 try { 135 out.close(); 136 } catch (IOException ioe) { 137 138 } 139 } 140 } 141 } 142 143 144 } 145 } 146 } | Popular Tags |