1 19 20 package com.sslexplorer.applications.server; 21 22 import java.io.BufferedReader ; 23 import java.io.File ; 24 import java.io.FileInputStream ; 25 import java.io.FileOutputStream ; 26 import java.io.IOException ; 27 import java.io.InputStreamReader ; 28 import java.util.Map ; 29 30 import org.apache.commons.logging.Log; 31 import org.apache.commons.logging.LogFactory; 32 33 import com.sslexplorer.applications.ApplicationShortcut; 34 import com.sslexplorer.boot.Util; 35 import com.sslexplorer.extensions.store.ExtensionStore; 36 import com.sslexplorer.security.SessionInfo; 37 38 39 44 public class ServerApplicationLauncher extends Thread { 45 46 47 final static Log log = LogFactory.getLog(ServerApplicationLauncher.class); 48 49 Map <String , String > parameters; 50 boolean running = false; 51 String name; 52 ServerLauncher launcher; 53 String exitMessage = null; 54 55 64 public ServerApplicationLauncher(Map <String , String > parameters, String id, SessionInfo session, ApplicationShortcut shortcut) throws IOException { 65 super(id + " launcher"); 66 this.name = id; 67 this.parameters = parameters; 68 running = true; 69 try { 70 launcher = new ServerLauncher(ExtensionStore.getInstance().getExtensionDescriptor(id), session, shortcut, parameters); 71 launcher.prepare(); 72 launcher.start(); 73 exitMessage = launcher.exitMessage.equals("") ? "OK" : launcher.exitMessage; 74 } catch (Throwable t) { 75 if (t instanceof IOException ) { 76 throw (IOException ) t; 77 } else { 78 log.error("Failed to launch. ", t); 79 throw new IOException ("Failed to launch. " + t.getMessage()); 80 } 81 } 82 } 83 84 public void run() { 85 FileOutputStream out = null; 86 FileInputStream in = null; 87 File tmp = null; 88 try { 89 tmp = File.createTempFile("montitor", ".out"); 90 out = new FileOutputStream (tmp); 91 ProcessMonitor monitor = launcher.getApplicationType().getProcessMonitor(); 92 if (monitor != null) { 93 monitor.watch(out, out); 94 } 95 96 97 if(log.isInfoEnabled()) { 98 String line; 99 BufferedReader reader = new BufferedReader (new InputStreamReader (in = new FileInputStream (tmp))); 100 while((line = reader.readLine())!=null) { 101 log.info(line); 102 } 103 } 104 } catch (Throwable ex) { 105 log.error("Exception during process monitoring.", ex); 106 } finally { 107 108 Util.closeStream(out); 109 Util.closeStream(in); 110 Util.delTree(tmp); 111 Util.delTree(launcher.getInstallDir()); 112 } 113 running = false; 114 115 } 116 } | Popular Tags |