Java Doc for CGIServlet.java in  » Sevlet-Container » apache-tomcat-6.0.14 » org » apache » catalina » servlets » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Sevlet Container » apache tomcat 6.0.14 » org.apache.catalina.servlets 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


javax.servlet.http.HttpServlet
   org.apache.catalina.servlets.CGIServlet

CGIServlet
final public class CGIServlet extends HttpServlet (Code)
CGI-invoking servlet for web applications, used to execute scripts which comply to the Common Gateway Interface (CGI) specification and are named in the path-info used to invoke this servlet.

Note: This code compiles and even works for simple CGI cases. Exhaustive testing has not been done. Please consider it beta quality. Feedback is appreciated to the author (see below).

Example:
If an instance of this servlet was mapped (using <web-app>/WEB-INF/web.xml) to:

<web-app>/cgi-bin/*

then the following request:

http://localhost:8080/<web-app>/cgi-bin/dir1/script/pathinfo1

would result in the execution of the script

<web-app-root>/WEB-INF/cgi/dir1/script

with the script's PATH_INFO set to /pathinfo1.

Recommendation: House all your CGI scripts under <webapp>/WEB-INF/cgi. This will ensure that you do not accidentally expose your cgi scripts' code to the outside world and that your cgis will be cleanly ensconced underneath the WEB-INF (i.e., non-content) area.

The default CGI location is mentioned above. You have the flexibility to put CGIs wherever you want, however:

The CGI search path will start at webAppRootDir + File.separator + cgiPathPrefix (or webAppRootDir alone if cgiPathPrefix is null).

cgiPathPrefix is defined by setting this servlet's cgiPathPrefix init parameter

CGI Specification:
derived from http://cgi-spec.golux.com. A work-in-progress & expired Internet Draft. Note no actual RFC describing the CGI specification exists. Where the behavior of this servlet differs from the specification cited above, it is either documented here, a bug, or an instance where the specification cited differs from Best Community Practice (BCP). Such instances should be well-documented here. Please email the Jakarta Tomcat group [tomcat-dev@jakarta.apache.org] with amendments.

Canonical metavariables:
The CGI specification defines the following canonical metavariables:
[excerpt from CGI specification]

 AUTH_TYPE
 CONTENT_LENGTH
 CONTENT_TYPE
 GATEWAY_INTERFACE
 PATH_INFO
 PATH_TRANSLATED
 QUERY_STRING
 REMOTE_ADDR
 REMOTE_HOST
 REMOTE_IDENT
 REMOTE_USER
 REQUEST_METHOD
 SCRIPT_NAME
 SERVER_NAME
 SERVER_PORT
 SERVER_PROTOCOL
 SERVER_SOFTWARE
 

Metavariables with names beginning with the protocol name (e.g., "HTTP_ACCEPT") are also canonical in their description of request header fields. The number and meaning of these fields may change independently of this specification. (See also section 6.1.5 [of the CGI specification].)

[end excerpt]

Implementation notes

standard input handling: If your script accepts standard input, then the client must start sending input within a certain timeout period, otherwise the servlet will assume no input is coming and carry on running the script. The script's the standard input will be closed and handling of any further input from the client is undefined. Most likely it will be ignored. If this behavior becomes undesirable, then this servlet needs to be enhanced to handle threading of the spawned process' stdin, stdout, and stderr (which should not be too hard).
If you find your cgi scripts are timing out receiving input, you can set the init parameter of your webapps' cgi-handling servlet to be

Metavariable Values: According to the CGI specificion, implementations may choose to represent both null or missing values in an implementation-specific manner, but must define that manner. This implementation chooses to always define all required metavariables, but set the value to "" for all metavariables whose value is either null or undefined. PATH_TRANSLATED is the sole exception to this rule, as per the CGI Specification.

NPH -- Non-parsed-header implementation: This implementation does not support the CGI NPH concept, whereby server ensures that the data supplied to the script are preceisely as supplied by the client and unaltered by the server.

The function of a servlet container (including Tomcat) is specifically designed to parse and possible alter CGI-specific variables, and as such makes NPH functionality difficult to support.

The CGI specification states that compliant servers MAY support NPH output. It does not state servers MUST support NPH output to be unconditionally compliant. Thus, this implementation maintains unconditional compliance with the specification though NPH support is not present.

The CGI specification is located at http://cgi-spec.golux.com.

TODO:

  • Support for setting headers (for example, Location headers don't work)
  • Support for collapsing multiple header lines (per RFC 2616)
  • Ensure handling of POST method does not interfere with 2.3 Filters
  • Refactor some debug code out of core
  • Ensure header handling preserves encoding
  • Possibly rewrite CGIRunner.run()?
  • Possibly refactor CGIRunner and CGIEnvironment as non-inner classes?
  • Document handling of cgi stdin when there is no stdin
  • Revisit IOException handling in CGIRunner.run()
  • Better documentation
  • Confirm use of ServletInputStream.available() in CGIRunner.run() is not needed
  • Make checking for "." and ".." in servlet & cgi PATH_INFO less draconian
  • [add more to this TODO list]


author:
   Martin T Dengler [root@martindengler.com]
author:
   Amy Roh
version:
   $Revision: 543681 $, $Date: 2007-06-02 02:42:59 +0200 (sam., 02 juin 2007) $
since:
   Tomcat 4.0

Inner Class :protected class CGIEnvironment
Inner Class :protected class CGIRunner
Inner Class :protected class HTTPHeaderInputStream extends InputStream

Field Summary
static  ObjectexpandFileLock
    
static  Hashtable<String, String>shellEnv
    


Method Summary
protected  voiddoGet(HttpServletRequest req, HttpServletResponse res)
    
protected  voiddoPost(HttpServletRequest req, HttpServletResponse res)
    
public  voidinit(ServletConfig config)
     Sets instance variables.

Modified from Craig R.

public static  voidmain(String[] args)
    
protected  voidprintServletEnvironment(ServletOutputStream out, HttpServletRequest req, HttpServletResponse res)
     Prints out important Servlet API and container information

Copied from SnoopAllServlet by Craig R.


Field Detail
expandFileLock
static Object expandFileLock(Code)
object used to ensure multiple threads don't try to expand same file



shellEnv
static Hashtable<String, String> shellEnv(Code)
the shell environment variables to be passed to the CGI script





Method Detail
doGet
protected void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException(Code)
Provides CGI Gateway service
Parameters:
  req - HttpServletRequest passed in by servlet container
Parameters:
  res - HttpServletResponse passed in by servlet container
exception:
  ServletException - if a servlet-specific exception occurs
exception:
  IOException - if a read/write exception occurs
See Also:   javax.servlet.http.HttpServlet



doPost
protected void doPost(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException(Code)
Provides CGI Gateway service -- delegates to doGet
Parameters:
  req - HttpServletRequest passed in by servlet container
Parameters:
  res - HttpServletResponse passed in by servlet container
exception:
  ServletException - if a servlet-specific exception occurs
exception:
  IOException - if a read/write exception occurs
See Also:   javax.servlet.http.HttpServlet



init
public void init(ServletConfig config) throws ServletException(Code)
Sets instance variables.

Modified from Craig R. McClanahan's InvokerServlet


Parameters:
  config - a ServletConfig objectcontaining the servlet'sconfiguration and initializationparameters
exception:
  ServletException - if an exception has occurred thatinterferes with the servlet's normaloperation



main
public static void main(String[] args)(Code)
For future testing use only; does nothing right now



printServletEnvironment
protected void printServletEnvironment(ServletOutputStream out, HttpServletRequest req, HttpServletResponse res) throws IOException(Code)
Prints out important Servlet API and container information

Copied from SnoopAllServlet by Craig R. McClanahan


Parameters:
  out - ServletOutputStream as target of the information
Parameters:
  req - HttpServletRequest object used as source of information
Parameters:
  res - HttpServletResponse object currently not used but couldprovide future information
exception:
  IOException - if a write operation exception occurs



Methods inherited from javax.servlet.http.HttpServlet
protected void doDelete(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException(Code)(Java Doc)
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException(Code)(Java Doc)
protected void doHead(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException(Code)(Java Doc)
protected void doOptions(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException(Code)(Java Doc)
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException(Code)(Java Doc)
protected void doPut(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException(Code)(Java Doc)
protected void doTrace(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException(Code)(Java Doc)
protected long getLastModified(HttpServletRequest req)(Code)(Java Doc)
protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException(Code)(Java Doc)
public void service(ServletRequest req, ServletResponse res) throws ServletException, IOException(Code)(Java Doc)

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.