The Source for Java Technology Collaboration
User: Password:



Jean-Francois Arcand

Jean-Francois Arcand's Blog

Enabling CGI support in GlassFish

Posted by jfarcand on April 06, 2006 at 02:10 PM | Comments (6)

Wants to execute CGI in GlassFish? The GlassFish CGI support is disabled by default, and it is based on the Tomcat implementation. Two ways to enable it: only inside your web application or for all web applications deployed in GlassFish. I strongly recommend you enable it inside your application only for security reason, but if you control the applications deployed in GlassFish, then enabling it to all web applications might be simpler. For your web application, you will add the information in your WEB-INF/web.xml. To enable it globally, you will add it in $glassfish.home/domains/domain1/config/default-web.xml.

First, define the CGI Servlet:

  <!-- Common Gateway Includes (CGI) processing servlet, which supports     -->
  <!-- execution of external applications that conform to the CGI spec      -->
  <!-- requirements.  Typically, this servlet is mapped to the URL pattern  -->
  <!-- "/cgi-bin/*", which means that any CGI applications that are         -->
  <!-- executed must be present within the web application.  This servlet   -->
  <!-- supports the following initialization parameters (default values     -->
  <!-- are in square brackets):                                             -->
  <!--                                                                      -->
  <!--   cgiPathPrefix        The CGI search path will start at             -->
  <!--                        webAppRootDir + File.separator + this prefix. -->
  <!--                        [WEB-INF/cgi]                                 -->
  <!--                                                                      -->
  <!--   debug                Debugging detail level for messages logged    -->
  <!--                        by this servlet.  [0]                         -->
  <!--                                                                      -->
  <!--   executable           Name of the exectuable used to run the        -->
  <!--                        script. [perl]                                -->
  <!--                                                                      -->
  <!--   parameterEncoding    Name of parameter encoding to be used with    -->
  <!--                        CGI servlet.                                  -->
  <!--                        [System.getProperty("file.encoding","UTF-8")] -->
  <!--                                                                      -->
  <!--   passShellEnvironment Should the shell environment variables (if    -->
  <!--                        any) be passed to the CGI script? [false]     -->
  <!--                                                                      -->
 
    <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>
Then define the servlet mapping:
<servlet-mapping>
   <servlet-name>cgi</servlet-name>
   <url-pattern>/cgi-bin/*</url-pattern>
</servlet-mapping>

If you added this info in default-web.xml, you gonna need to restart GlassFish. Then in you web application, creates a folder under


WEB-INF/cgi/

and drop you CGI under than folder, then deploy your application. You will be able to execute your CGI by doing:


http://host:port/yoor-app/cgi-bin/your_script

Voila!
technorati:


Bookmark blog post: del.icio.us del.icio.us Digg Digg DZone DZone Furl Furl Reddit Reddit
Comments
Comments are listed in date ascending order (oldest first) | Post Comment

  • thanks for the info. CGI still lives... :D

    leouser

    Posted by: leouser on April 06, 2006 at 03:32 PM

  • The server loads without errors a blank page with the name of the script but it does not excecute it. Do I have to configure something in perl or the server ?

    Posted by: htrejos on September 21, 2007 at 12:23 PM

  • Hum, can you give me more info? How have you defined your web.xml? Thanks

    Posted by: jfarcand on September 21, 2007 at 02:33 PM

  • I am working on a Mac. I just copied what is in this page and pasted it below the I am testing with a simple Perl script to print 'Hello'

    Posted by: htrejos on September 24, 2007 at 07:15 AM

  • I am sorry, part of the message didn't print. Pasted below the Faces Servlet mapping, working with Netbeans

    Posted by: htrejos on September 24, 2007 at 07:21 AM

  • Thank you for your interest. I solved the problem. I was using a wrong #!perl path.

    Posted by: htrejos on September 25, 2007 at 08:27 AM



Only logged in users may post comments. Login Here.


Powered by
Movable Type 3.01D
 Feed java.net RSS Feeds