1 11 package org.apache.catalina.ssi; 12 13 14 import java.io.BufferedReader ; 15 import java.io.IOException ; 16 import java.io.InputStreamReader ; 17 import java.io.PrintWriter ; 18 import org.apache.catalina.util.IOTools; 19 29 public class SSIExec implements SSICommand { 30 protected SSIInclude ssiInclude = new SSIInclude(); 31 protected final static int BUFFER_SIZE = 1024; 32 33 34 37 public long process(SSIMediator ssiMediator, String commandName, 38 String [] paramNames, String [] paramValues, PrintWriter writer) { 39 long lastModified = 0; 40 String configErrMsg = ssiMediator.getConfigErrMsg(); 41 String paramName = paramNames[0]; 42 String paramValue = paramValues[0]; 43 String substitutedValue = ssiMediator.substituteVariables(paramValue); 44 if (paramName.equalsIgnoreCase("cgi")) { 45 lastModified = ssiInclude.process(ssiMediator, "include", 46 new String []{"virtual"}, new String []{substitutedValue}, 47 writer); 48 } else if (paramName.equalsIgnoreCase("cmd")) { 49 boolean foundProgram = false; 50 try { 51 Runtime rt = Runtime.getRuntime(); 52 Process proc = rt.exec(substitutedValue); 53 foundProgram = true; 54 BufferedReader stdOutReader = new BufferedReader ( 55 new InputStreamReader (proc.getInputStream())); 56 BufferedReader stdErrReader = new BufferedReader ( 57 new InputStreamReader (proc.getErrorStream())); 58 char[] buf = new char[BUFFER_SIZE]; 59 IOTools.flow(stdErrReader, writer, buf); 60 IOTools.flow(stdOutReader, writer, buf); 61 proc.waitFor(); 62 lastModified = System.currentTimeMillis(); 63 } catch (InterruptedException e) { 64 ssiMediator.log("Couldn't exec file: " + substitutedValue, e); 65 writer.write(configErrMsg); 66 } catch (IOException e) { 67 if (!foundProgram) { 68 } 71 ssiMediator.log("Couldn't exec file: " + substitutedValue, e); 72 } 73 } 74 return lastModified; 75 } 76 } | Popular Tags |