Source Code Cross Referenced for HttpRequest.java in  » Database-JDBC-Connection-Pool » Primrose » uk » org » primrose » console » 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 » Database JDBC Connection Pool » Primrose » uk.org.primrose.console 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         *	Library name : Primrose - A Java Database Connection Pool.
003:         *	Published by Ben Keeping, http://primrose.org.uk .
004:         *	Copyright (C) 2004 Ben Keeping, primrose.org.uk
005:         *	Email: Use "Contact Us Form" on website
006:         *
007:         *	This library is free software; you can redistribute it and/or
008:         *	modify it under the terms of the GNU Lesser General Public
009:         *	License as published by the Free Software Foundation; either
010:         *	version 2.1 of the License, or (at your option) any later version.
011:         *
012:         *	This library is distributed in the hope that it will be useful,
013:         *	but WITHOUT ANY WARRANTY; without even the implied warranty of
014:         *	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
015:         *	Lesser General Public License for more details.
016:         *
017:         *	You should have received a copy of the GNU Lesser General Public
018:         *	License along with this library; if not, write to the Free Software
019:         *	Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
020:         */package uk.org.primrose.console;
021:
022:        import uk.org.primrose.Logger;
023:        import java.net.*;
024:        import java.util.*;
025:
026:        public class HttpRequest {
027:
028:            protected String szMethod;
029:            protected String szResource;
030:            protected String szResponseMimeType;
031:            protected String szVersion;
032:            HashMap<String, String> headers = new HashMap<String, String>();
033:            HashMap<String, String> parameters = new HashMap<String, String>();
034:            Logger logger = null;
035:
036:            public HttpRequest(Logger logger) {
037:                this .logger = logger;
038:            }
039:
040:            /**
041:             *	Get the 'szMethod '
042:             */
043:            public String getMethod() {
044:                return szMethod;
045:            }
046:
047:            /**
048:             *	Set the 'szMethod '
049:             */
050:            public void setMethod(String szMethod) {
051:                this .szMethod = szMethod;
052:            }
053:
054:            /**
055:             *	Get the 'szResource '
056:             */
057:            public String getResource() {
058:                return szResource;
059:            }
060:
061:            /**
062:             *	Set the 'szResource '
063:             */
064:            public void setResource(String szResource) {
065:                this .szResource = szResource;
066:            }
067:
068:            /**
069:             *	Get the 'szResponseMimeType '
070:             */
071:            public String getResponseMimeType() {
072:                return szResponseMimeType;
073:            }
074:
075:            /**
076:             *	Set the 'szResponseMimeType '
077:             */
078:            public void setResponseMimeType(String szResponseMimeType) {
079:                this .szResponseMimeType = szResponseMimeType;
080:            }
081:
082:            /**
083:             *	Get the 'szVersion '
084:             */
085:            public String getVersion() {
086:                return szVersion;
087:            }
088:
089:            /**
090:             *	Set the 'szVersion '
091:             */
092:            public void setVersion(String szVersion) {
093:                this .szVersion = szVersion;
094:            }
095:
096:            /**
097:             *	Get the 'headers '
098:             */
099:            public HashMap<String, String> getHeaders() {
100:                return headers;
101:            }
102:
103:            /**
104:             *	Get the 'parameters '
105:             */
106:            public HashMap<String, String> getParameters() {
107:                return parameters;
108:            }
109:
110:            public void printDetails() {
111:                logger.info("szMethod=" + szMethod);
112:                logger.info("szResource=" + szResource);
113:                logger.info("szResponseMimeType=" + szResponseMimeType);
114:                logger.info("szVersion=" + szVersion);
115:
116:                logger.info("\n\nHeaders : ");
117:                Iterator<String> headersIter = headers.keySet().iterator();
118:                while (headersIter.hasNext()) {
119:                    String key = headersIter.next();
120:                    logger.info(key + "=" + headers.get(key));
121:                }
122:
123:                logger.info("\n\nParameters : ");
124:                Iterator<String> parametersIter = parameters.keySet()
125:                        .iterator();
126:                while (parametersIter.hasNext()) {
127:                    String key = parametersIter.next();
128:                    logger.info(key + "=" + parameters.get(key));
129:                }
130:            }
131:
132:            @SuppressWarnings("deprecation")
133:            boolean parseRequest(String szRequestData) {
134:                if (szRequestData != null && szRequestData.length() == 0)
135:                    return false;
136:                // Create a tokenizer from the request
137:                String[] t = szRequestData.split("\n");
138:                String szTok;
139:                boolean bFirstLine = true;
140:
141:                // Loop the request, extacting the necessary data
142:                for (int i = 0; i < t.length; i++) {
143:                    szTok = t[i];
144:                    //CReportError::Info("LINE : %s", szTok);
145:                    // first line :
146:                    // extract the method, resource and http version data
147:                    if (bFirstLine) {
148:                        bFirstLine = false;
149:                        int j = 0;
150:                        String[] t2 = szTok.split(" ");
151:
152:                        // populate the HTTP method
153:                        String szTok2 = t2[j++];
154:                        if (szTok2 != null) {
155:                            szMethod = szTok2;
156:                        }
157:
158:                        // populate the resource requested
159:                        szTok2 = t2[j++];
160:                        if (szTok2 != null) {
161:                            szResource = szTok2;
162:
163:                            // set the MIME type too
164:                            if (szResource.indexOf(".htm") != -1) {
165:                                szResponseMimeType = ("text/html");
166:                            } else if (szResource.indexOf(".svg") != -1) {
167:                                szResponseMimeType = ("image/svg+xml");
168:                            } else if (szResource.indexOf(".png") != -1) {
169:                                szResponseMimeType = ("image/png");
170:                            } else if (szResource.indexOf(".gif") != -1) {
171:                                szResponseMimeType = ("image/gif");
172:                            } else if ((szResource.indexOf(".jpeg") != -1)
173:                                    || (szResource.indexOf(".jpg") != -1)) {
174:                                szResponseMimeType = ("image/jpeg");
175:                            } else if (szResource.indexOf(".txt") != -1) {
176:                                szResponseMimeType = ("text/plain");
177:                            } else if (szResource.indexOf(".log") != -1) {
178:                                szResponseMimeType = ("text/plain");
179:                            } else {
180:                                szResponseMimeType = ("text/html");
181:                            }
182:
183:                            // populate the request attributes for a GET
184:                            if (szMethod.indexOf("GET") != -1) {
185:                                String[] t3 = szResource.split("\\?");
186:                                if (t3.length > 1) {
187:                                    String szToken = t3[1];
188:                                    String[] t4 = szToken.split("&");
189:
190:                                    // breaking each pair up
191:                                    String szToken2;
192:                                    for (int l = 0; l < t4.length; l++) {
193:                                        szToken2 = t4[l];
194:                                        // and finally breaking the pairs into their
195:                                        // names and values
196:                                        String[] t5 = szToken2.split("=");
197:                                        if (t5.length == 2) {
198:                                            parameters.put(URLDecoder
199:                                                    .decode(t5[0].trim()),
200:                                                    URLDecoder.decode(t5[1]
201:                                                            .trim()));
202:                                        }
203:
204:                                    }
205:
206:                                }
207:                            }
208:                        }
209:
210:                        // populate the HTTP version
211:                        szTok2 = t2[j++];
212:                        if (szTok2 != null) {
213:                            szVersion = szTok2;
214:                        }
215:                        continue;
216:                    }
217:
218:                    // non-first line :
219:                    // extract the header details
220:                    String[] t2 = szTok.split(":");
221:                    String szHeaderName = t2[0];
222:                    String szHeaderValue = t2[1];
223:                    if (szHeaderName == null || szHeaderValue == null) {
224:                        continue;
225:                    }
226:
227:                    headers.put(szHeaderName.trim(), szHeaderValue.trim());
228:
229:                }
230:
231:                return true;
232:            }
233:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.