Author: kkolinko
Date: Thu Jan 20 17:43:35 2011
New Revision: 1061412

URL: http://svn.apache.org/viewvc?rev=1061412&view=rev
Log:
Fix http://issues.apache.org/bugzilla/show_bug.cgi?id=50606
Improve CGIServlet: Provide support for specifying empty value for the 
executable init-param. Provide support for explicit additional arguments for 
the executable. Those were broken when implementing fix for bug 49657

Modified:
    tomcat/trunk/java/org/apache/catalina/servlets/CGIServlet.java
    tomcat/trunk/webapps/docs/cgi-howto.xml
    tomcat/trunk/webapps/docs/changelog.xml

Modified: tomcat/trunk/java/org/apache/catalina/servlets/CGIServlet.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/servlets/CGIServlet.java?rev=1061412&r1=1061411&r2=1061412&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/servlets/CGIServlet.java (original)
+++ tomcat/trunk/java/org/apache/catalina/servlets/CGIServlet.java Thu Jan 20 
17:43:35 2011
@@ -32,6 +32,7 @@ import java.util.ArrayList;
 import java.util.Date;
 import java.util.Enumeration;
 import java.util.Hashtable;
+import java.util.List;
 import java.util.Locale;
 import java.util.StringTokenizer;
 import java.util.Vector;
@@ -257,7 +258,10 @@ public final class CGIServlet extends Ht
 
     /** the executable to use with the script */
     private String cgiExecutable = "perl";
-    
+
+    /** additional arguments for the executable */
+    private List<String> cgiExecutableArgs = null;
+
     /** the encoding to use for parameters */
     private String parameterEncoding =
         System.getProperty("file.encoding", "UTF-8");
@@ -309,6 +313,19 @@ public final class CGIServlet extends Ht
             cgiExecutable = getServletConfig().getInitParameter("executable");
         }
 
+        if (getServletConfig().getInitParameter("executable-arg-1") != null) {
+            List<String> args = new ArrayList<String>();
+            for (int i = 1;; i++) {
+                String arg = getServletConfig().getInitParameter(
+                        "executable-arg-" + i);
+                if (arg == null) {
+                    break;
+                }
+                args.add(arg);
+            }
+            cgiExecutableArgs = args;
+        }
+
         if (getServletConfig().getInitParameter("parameterEncoding") != null) {
             parameterEncoding = 
getServletConfig().getInitParameter("parameterEncoding");
         }
@@ -1578,20 +1595,21 @@ public final class CGIServlet extends Ht
             Process proc = null;
             int bufRead = -1;
 
-            String[] cmdAndArgs = new String[params.size() + 2];
-            
-            cmdAndArgs[0] = cgiExecutable;
-            
-            cmdAndArgs[1] = command;
-
-            //create query arguments
-            for (int i=0; i < params.size(); i++) {
-                cmdAndArgs[i + 2] = params.get(i);
+            List<String> cmdAndArgs = new ArrayList<String>();
+            if (cgiExecutable.length() != 0) {
+                cmdAndArgs.add(cgiExecutable);
+            }
+            if (cgiExecutableArgs != null) {
+                cmdAndArgs.addAll(cgiExecutableArgs);
             }
+            cmdAndArgs.add(command);
+            cmdAndArgs.addAll(params);
 
             try {
                 rt = Runtime.getRuntime();
-                proc = rt.exec(cmdAndArgs, hashToStringArray(env), wd);
+                proc = rt.exec(
+                        cmdAndArgs.toArray(new String[cmdAndArgs.size()]),
+                        hashToStringArray(env), wd);
     
                 String sContentLength = env.get("CONTENT_LENGTH");
 

Modified: tomcat/trunk/webapps/docs/cgi-howto.xml
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/webapps/docs/cgi-howto.xml?rev=1061412&r1=1061411&r2=1061412&view=diff
==============================================================================
--- tomcat/trunk/webapps/docs/cgi-howto.xml (original)
+++ tomcat/trunk/webapps/docs/cgi-howto.xml Thu Jan 20 17:43:35 2011
@@ -80,9 +80,14 @@ The default cgiPathPrefix is <code>WEB-I
 <li><strong>debug</strong> - Debugging detail level for messages logged
 by this servlet. Default 0.</li>
 <li><strong>executable</strong> - The of the executable to be used to
-run the script. Default is <code>perl</code>.</li>
+run the script. You may explicitly set this parameter to be an empty string
+if your script is itself executable (e.g. an exe file). Default is
+<code>perl</code>.</li>
+<li><strong>executable-arg-1</strong>, <strong>executable-arg-2</strong>,
+and so on - additional arguments for the executable. These precede the
+CGI script name. By default there are no additional arguments.</li>
 <li><strong>parameterEncoding</strong> - Name of the parameter encoding
-to be used with the GCI servlet. Default is
+to be used with the CGI servlet. Default is
 <code>System.getProperty("file.encoding","UTF-8")</code>.</li>
 <li><strong>passShellEnvironment</strong> - Should the shell environment
 variables (if any) be passed to the CGI script? Default is

Modified: tomcat/trunk/webapps/docs/changelog.xml
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/webapps/docs/changelog.xml?rev=1061412&r1=1061411&r2=1061412&view=diff
==============================================================================
--- tomcat/trunk/webapps/docs/changelog.xml (original)
+++ tomcat/trunk/webapps/docs/changelog.xml Thu Jan 20 17:43:35 2011
@@ -148,6 +148,12 @@
       <fix>
         <bug>50601</bug>: Code clean-up. Patch provided by sebb. (markt)
       </fix>
+      <fix>
+        <bug>50606</bug>: Improve CGIServlet: Provide support for specifying
+        empty value for the <code>executable</code> init-param. Provide support
+        for explicit additional arguments for the executable. Those were
+        broken when implementing fix for bug <bug>49657</bug>. (kkolinko)
+      </fix>
     </changelog>
   </subsection>
 </section>



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org

Reply via email to