Source Code Cross Referenced for CGIServlet.java in  » J2EE » Enhydra-Application-Framework » org » enhydra » servlet » 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 » J2EE » Enhydra Application Framework » org.enhydra.servlet.servlets 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Enhydra Java Application Server Project
003:         * 
004:         * The contents of this file are subject to the Enhydra Public License
005:         * Version 1.1 (the "License"); you may not use this file except in
006:         * compliance with the License. You may obtain a copy of the License on
007:         * the Enhydra web site ( http://www.enhydra.org/ ).
008:         * 
009:         * Software distributed under the License is distributed on an "AS IS"
010:         * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See 
011:         * the License for the specific terms governing rights and limitations
012:         * under the License.
013:         * 
014:         * The Initial Developer of the Enhydra Application Server is Lutris
015:         * Technologies, Inc. The Enhydra Application Server and portions created
016:         * by Lutris Technologies, Inc. are Copyright Lutris Technologies, Inc.
017:         * All Rights Reserved.
018:         * 
019:         * Contributor(s):
020:         * 
021:         * $Id: CGIServlet.java,v 1.2 2006-06-15 14:07:00 sinisa Exp $
022:         */
023:
024:        package org.enhydra.servlet.servlets;
025:
026:        import java.io.File;
027:        import java.io.IOException;
028:
029:        import javax.servlet.ServletContext;
030:        import javax.servlet.ServletException;
031:        import javax.servlet.http.HttpServlet;
032:        import javax.servlet.http.HttpServletRequest;
033:        import javax.servlet.http.HttpServletResponse;
034:
035:        /**
036:         * This Servlet is for the purpose of executing a CGI program that resides on
037:         *  the system.  In order to use this servlet in the server please
038:         *  remember to specify the fully qualified classname 
039:         *   org.enhydra.servlet.servlets.CGIServlet in the Classname field and specify
040:         *  the directory of the CGI to run in the DocRoot field.
041:         *
042:         * @version $Revision: 1.2 $
043:         * @author  Kent Henneuse
044:         * @author  Paul Morgan
045:         */
046:        public class CGIServlet extends HttpServlet {
047:
048:            /**
049:             * Overide the service method of HttpServelet.  This method executes a CGI
050:             *  program that is specified on the URL line of a browser.
051:             *
052:             * @param request the request that is sent by a browser
053:             * @param response the response that is sent back to the browser after 
054:             *    processing the CGI
055:             */
056:            public void service(HttpServletRequest request,
057:                    HttpServletResponse response) throws ServletException,
058:                    IOException {
059:
060:                // Get the full path of the CGI program to execute, the simple
061:                // script name and the path info...
062:                String strBuffer, progName, scriptPath, scriptName, pathInfo;
063:                int pathLength, sp, sp2;
064:                String servletPath = request.getServletPath();
065:
066:                if (servletPath.equals("")) {
067:                    // handles url mappings to directories
068:                    progName = request.getPathTranslated();
069:                    pathLength = servletPath.length();
070:                    strBuffer = request.getRequestURI().substring(pathLength);
071:                    sp = progName.indexOf(strBuffer);
072:                    int nextSlash = 0;
073:                    while (sp == -1 && nextSlash != -1) {
074:
075:                        nextSlash = strBuffer.indexOf(File.separator, 1);
076:                        if (nextSlash != -1) {
077:                            strBuffer = strBuffer.substring(nextSlash);
078:                            sp = progName.indexOf(strBuffer);
079:                        }
080:                    }
081:
082:                    scriptPath = progName;
083:                    sp2 = 0;
084:                    while (sp2 < progName.length()) {
085:                        sp2 = progName.indexOf(File.separator, sp);
086:                        scriptPath = progName.substring(0, sp2 == -1 ? progName
087:                                .length() : sp2);
088:                        if (!scriptPath.equals("")) {
089:                            File file = new File(scriptPath);
090:                            if (!file.isDirectory()) {
091:                                break;
092:                            }
093:                        }
094:                        sp = sp2 + 1;
095:                    }
096:
097:                    pathInfo = progName.substring(scriptPath.length());
098:                    scriptName = scriptPath.substring(scriptPath
099:                            .lastIndexOf(File.separator) + 1);
100:                } else {
101:                    // handles url mappings to suffixes
102:                    ServletContext context = getServletContext();
103:                    String realPath = context.getRealPath("");
104:                    if (!realPath.endsWith(File.separator)) {
105:                        realPath = realPath + File.separator;
106:                    }
107:                    if (servletPath.startsWith(File.separator)) {
108:                        servletPath = servletPath.substring(1);
109:                    }
110:                    scriptPath = realPath + servletPath;
111:                    scriptName = scriptPath.substring(scriptPath
112:                            .lastIndexOf(File.separator) + 1);
113:                    pathInfo = request.getPathInfo();
114:                }
115:
116:                // Check that the script pathname is valid i.e. no ".."
117:                if (!isAuthorized(scriptPath)) {
118:                    response.sendError(response.SC_NOT_FOUND);
119:                    return;
120:                }
121:
122:                CgiProcessor cgi = new CgiProcessor();
123:                try {
124:                    cgi.processCgiRequest(request, response, scriptPath,
125:                            pathInfo, scriptName);
126:                } catch (IOException e) {
127:                    cgi.cgiError(response);
128:                    System.err.println("ERROR: CGI: " + e);
129:                }
130:            }
131:
132:            /**
133:             *  Test if a path is authorized. Currently the only limitations
134:             *  are that the pathname must not contain "..".
135:             *
136:             * @param path requested path
137:             * @return true if the path is authorized
138:             */
139:            private boolean isAuthorized(String path) {
140:                if ((path != null) && (path.indexOf("..") != -1))
141:                    return false;
142:                return true;
143:            }
144:
145:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.