Grails and CGI
            by jja
            on 
          
          Topics: 
      Here's how to get CGI working in a Grails app.
Install a copy of web.xml:
grails install-templates
then edit it:
src/templates/war/web.xml
adding these elements in their appropriate sections. Some other instructions
and the Tomcat encourage you to edit the main Tomcat web.xml, but that won't
help you in development mode with grails run-app and also adds CGIs to all
other webapps (if they're privileged).
First the servlet (there are other configurable parameters available):
    <!-- Common Gateway Interface (CGI) processing servlet -->
    <servlet>
        <servlet-name>cgi</servlet-name>
        <servlet-class>org.apache.catalina.servlets.CGIServlet</servlet-class>
        <init-param>
          <param-name>debug</param-name>
          <param-value>0</param-value>
        </init-param>
        <init-param>
          <param-name>cgiPathPrefix</param-name>
          <param-value>WEB-INF/cgi</param-value>
        </init-param>
        <load-on-startup>5</load-on-startup>
    </servlet>
and the servlet-mapping:
    <!-- The mapping for the CGI Gateway servlet -->
    <servlet-mapping>
        <servlet-name>cgi</servlet-name>
        <url-pattern>/cgi-bin/*</url-pattern>
    </servlet-mapping>
Here's the secret part. Edit scripts/Events.groovy to make your webapp
privileged:
eventConfigureTomcat = { tomcat ->
    def ctx=tomcat.host.findChild(serverContextPath)
    ctx.privileged = true
}
Then put your CGI script in web-app/WEB-INF/cgi/