How do I run a Perl CGI script in JBoss ?
Environment
- JBoss Enterprise Application Platform (EAP)
- 4.x
- 5.x
- 6.x
- Perl
Issue
- We need to be able to run a perl script on jboss. Can you please provide instruction how to install it .
Resolution
JBoss Web already contains the necessary CGIServlet class to enable this behaviour out of the box. The most basic Hello World example in Perl on JBoss goes like this:
-
Create an exploded war directory called
cgiexample.war/under$JBOSS_HOME/server/$PROFILE/deploy/in EAP 4.x/EAP 5.x or under$JBOSS_HOME/standalone/deployments/in EAP 6.x -
Create a
WEB-INFdirectory and aweb.xmlin theWEB-INFand ensure that the executable param points to the location of perl on your os:<?xml version="1.0" encoding="UTF-8"?> <web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" > <description>cgitest</description> <display-name>cgitest</display-name> <servlet> <servlet-name>cgi</servlet-name> <servlet-class>org.apache.catalina.servlets.CGIServlet</servlet-class> <init-param> <param-name>executable</param-name> <param-value>/usr/bin/perl</param-value> </init-param> <init-param> <param-name>passShellEnvironment</param-name> <param-value>true</param-value> </init-param> <init-param> <param-name>debug</param-name> <param-value>6</param-value> </init-param> <init-param> <param-name>cgiPathPrefix</param-name> <!--param-value>WEB-INF/cgi</param-value--> <param-value></param-value> </init-param> <load-on-startup>5</load-on-startup> </servlet> <servlet-mapping> <servlet-name>cgi</servlet-name> <url-pattern>*.cgi</url-pattern> </servlet-mapping> </web-app> -
create a
helloWorld.cgifile undercgiexample.war/#!/usr/bin/perl<br> print "Content-type: text/html\n\n";<br> print "<H1>Hello World</H1>\n"; -
Start JBoss and open in your browser
http://localhost:8080/cgiexample/helloWorld.cgi
Also see the attached cgiexample.war.zip for a deployable version of the above code.
Note:
-
As noted in Content from docs.jboss.org is not included.API doc, it clearly states this CGIServlet compiles and even works for simple CGI cases. Exhaustive testing has not been done. Please consider it beta quality. In addistion, as noted in Content from docs.jboss.org is not included.documentation, it says "Typically this is done during development when you don't want to run a web server like Apache httpd". So this feature should not be considered as enterprise quality in production system but should be used only for testing purpose in development system.
-
It was seen on Solaris 10 where the heap was set to 5 gigs that the cgi would not execute and throw the following error
java.io.IOException: error=12, Not enough space
at java.lang.UNIXProcess.forkAndExec(Native Method)
at java.lang.UNIXProcess.(UNIXProcess.java:53)
at java.lang.ProcessImpl.start(ProcessImpl.java:65)
This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.