implement cgi api improvements

This commit is contained in:
Sebastian Sdorra
2011-05-05 13:51:10 +02:00
parent 6ae090ae2e
commit 6fd04b19d3
2 changed files with 72 additions and 29 deletions

View File

@@ -199,13 +199,13 @@ public abstract class AbstractCGIExecutor implements CGIExecutor
protected EnvList environment;
/** Field description */
protected boolean ignoreExitCode;
protected boolean ignoreExitCode = false;
/** Field description */
protected String interpreter;
/** Field description */
protected boolean passShellEnvironment;
protected boolean passShellEnvironment = false;
/** Field description */
protected File workDirectory;

View File

@@ -42,6 +42,7 @@ import sonia.scm.SCMContext;
import sonia.scm.config.ScmConfiguration;
import sonia.scm.util.HttpUtil;
import sonia.scm.util.IOUtil;
import sonia.scm.util.SystemUtil;
import sonia.scm.util.Util;
//~--- JDK imports ------------------------------------------------------------
@@ -54,6 +55,7 @@ import java.io.InputStreamReader;
import java.io.OutputStream;
import java.util.Enumeration;
import java.util.Map;
import javax.servlet.ServletContext;
import javax.servlet.ServletInputStream;
@@ -74,6 +76,9 @@ public class DefaultCGIExecutor extends AbstractCGIExecutor
/** Field description */
public static final int DEFAULT_BUFFER_SIZE = 16264;
/** Field description */
public static final String SYSTEM_ROOT_WINDOWS = "C:\\WINDOWS";
/** Field description */
private static final String SERVER_SOFTWARE_PREFIX = "scm-manager/";
@@ -167,7 +172,6 @@ public class DefaultCGIExecutor extends AbstractCGIExecutor
{
p = Runtime.getRuntime().exec(execCmd, environment.getEnvArray(),
workDirectory);
execute(p);
}
finally
@@ -179,6 +183,25 @@ public class DefaultCGIExecutor extends AbstractCGIExecutor
}
}
/**
* Method description
*
*
* @param env
*/
private void apendOsEnvironment(EnvList env)
{
Map<String, String> osEnv = System.getenv();
if (Util.isNotEmpty(osEnv))
{
for (Map.Entry<String, String> e : osEnv.entrySet())
{
env.set(e.getKey(), e.getValue());
}
}
}
/**
* Method description
*
@@ -194,8 +217,13 @@ public class DefaultCGIExecutor extends AbstractCGIExecutor
String scriptPath = context.getRealPath(scriptName);
String pathTranslated = request.getPathTranslated();
int len = request.getContentLength();
EnvList env = new EnvList();
if (passShellEnvironment)
{
apendOsEnvironment(env);
}
env.set(ENV_AUTH_TYPE, request.getAuthType());
/**
@@ -204,8 +232,7 @@ public class DefaultCGIExecutor extends AbstractCGIExecutor
* Servlet API spec.
*
* see org.apache.catalina.servlets.CGIServlet
**/
*/
if (len <= 0)
{
env.set(ENV_CONTENT_LENGTH, "");
@@ -255,6 +282,11 @@ public class DefaultCGIExecutor extends AbstractCGIExecutor
? ENV_HTTPS_VALUE_ON
: ENV_HTTPS_VALUE_OFF));
if (SystemUtil.isWindows())
{
env.set(ENV_SYSTEM_ROOT, SYSTEM_ROOT_WINDOWS);
}
return env;
}
@@ -287,20 +319,6 @@ public class DefaultCGIExecutor extends AbstractCGIExecutor
}
}
private void processErrorStreamAsync( final InputStream errorStream )
{
new Thread(new Runnable() {
@Override
public void run() {
try {
processErrorStream(errorStream);
} catch (IOException ex) {
logger.error( "could not read errorstream", ex );
}
}
}).start();
}
/**
* Method description
*
@@ -413,6 +431,31 @@ public class DefaultCGIExecutor extends AbstractCGIExecutor
}
}
/**
* Method description
*
*
* @param errorStream
*/
private void processErrorStreamAsync(final InputStream errorStream)
{
new Thread(new Runnable()
{
@Override
public void run()
{
try
{
processErrorStream(errorStream);
}
catch (IOException ex)
{
logger.error("could not read errorstream", ex);
}
}
}).start();
}
/**
* Method description
*
@@ -481,7 +524,7 @@ public class DefaultCGIExecutor extends AbstractCGIExecutor
{
int exitCode = process.waitFor();
if (exitCode != 0)
if ((exitCode != 0) &&!ignoreExitCode)
{
logger.warn("process ends with exit code {}", exitCode);
}