Source Code Cross Referenced for HttpReplyHdr.java in  » Testing » jakarta-jmeter » org » apache » jmeter » protocol » http » proxy » 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 » Testing » jakarta jmeter » org.apache.jmeter.protocol.http.proxy 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Licensed to the Apache Software Foundation (ASF) under one or more
003:         * contributor license agreements.  See the NOTICE file distributed with
004:         * this work for additional information regarding copyright ownership.
005:         * The ASF licenses this file to You under the Apache License, Version 2.0
006:         * (the "License"); you may not use this file except in compliance with
007:         * the License.  You may obtain a copy of the License at
008:         *
009:         *   http://www.apache.org/licenses/LICENSE-2.0
010:         *
011:         * Unless required by applicable law or agreed to in writing, software
012:         * distributed under the License is distributed on an "AS IS" BASIS,
013:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         * See the License for the specific language governing permissions and
015:         * limitations under the License.
016:         * 
017:         */
018:
019:        package org.apache.jmeter.protocol.http.proxy;
020:
021:        /**
022:         * Utility class to generate HTTP responses of various types.
023:         * 
024:         * @version $Revision: 595875 $
025:         */
026:        public final class HttpReplyHdr {
027:            /** String representing a carriage-return/line-feed pair. */
028:            private static final String CR = "\r\n";
029:
030:            /** A HTTP protocol version string. */
031:            private static final String HTTP_PROTOCOL = "HTTP/1.0";
032:
033:            /** The HTTP server name. */
034:            private static final String HTTP_SERVER = "Java Proxy Server";
035:
036:            /**
037:             * Don't allow instantiation of this utility class.
038:             */
039:            private HttpReplyHdr() {
040:            }
041:
042:            /**
043:             * Forms a http ok reply header
044:             * 
045:             * @param contentType
046:             *            the mime-type of the content
047:             * @param contentLength
048:             *            the length of the content
049:             * @return a string with the header in it
050:             */
051:            public static String formOk(String contentType, long contentLength) {
052:                StringBuffer out = new StringBuffer();
053:
054:                out.append(HTTP_PROTOCOL).append(" 200 Ok").append(CR);
055:                out.append("Server: ").append(HTTP_SERVER).append(CR);
056:                out.append("MIME-version: 1.0").append(CR);
057:
058:                if (0 < contentType.length()) {
059:                    out.append("Content-Type: ").append(contentType).append(CR);
060:                } else {
061:                    out.append("Content-Type: text/html").append(CR);
062:                }
063:
064:                if (0 != contentLength) {
065:                    out.append("Content-Length: ").append(contentLength)
066:                            .append(CR);
067:                }
068:
069:                out.append(CR);
070:
071:                return out.toString();
072:            }
073:
074:            /**
075:             * private! builds an http document describing a headers reason.
076:             * 
077:             * @param error
078:             *            Error name.
079:             * @param description
080:             *            Errors description.
081:             * @return A string with the HTML description body
082:             */
083:            private static String formErrorBody(String error, String description) {
084:                StringBuffer out = new StringBuffer();
085:                // Generate Error Body
086:                out.append("<HTML><HEAD><TITLE>");
087:                out.append(error);
088:                out.append("</TITLE></HEAD>");
089:                out.append("<BODY><H2>").append(error).append("</H2>\n");
090:                out.append("</P></H3>");
091:                out.append(description);
092:                out.append("</BODY></HTML>");
093:                return out.toString();
094:            }
095:
096:            /**
097:             * builds an http document describing an error.
098:             * 
099:             * @param error
100:             *            Error name.
101:             * @param description
102:             *            Errors description.
103:             * @return A string with the HTML description body
104:             */
105:            private static String formError(String error, String description) {
106:                /*
107:                 * A HTTP RESPONSE HEADER LOOKS ALOT LIKE:
108:                 * 
109:                 * HTTP/1.0 200 OK Date: Wednesday, 02-Feb-94 23:04:12 GMT Server:
110:                 * NCSA/1.1 MIME-version: 1.0 Last-modified: Monday, 15-Nov-93 23:33:16
111:                 * GMT Content-Type: text/html Content-Length: 2345 \r\n
112:                 */
113:
114:                String body = formErrorBody(error, description);
115:                StringBuffer header = new StringBuffer();
116:
117:                header.append(HTTP_PROTOCOL).append(" ").append(error).append(
118:                        CR);
119:                header.append("Server: ").append(HTTP_SERVER).append(CR);
120:                header.append("MIME-version: 1.0").append(CR);
121:                header.append("Content-Type: text/html").append(CR);
122:
123:                header.append("Content-Length: ").append(body.length()).append(
124:                        CR);
125:
126:                header.append(CR);
127:                header.append(body);
128:
129:                return header.toString();
130:            }
131:
132:            /**
133:             * Indicates a new file was created.
134:             * 
135:             * @return The header in a string;
136:             */
137:            public static String formCreated() {
138:                return formError("201 Created", "Object was created");
139:            }
140:
141:            /**
142:             * Indicates the document was accepted.
143:             * 
144:             * @return The header in a string;
145:             */
146:            public static String formAccepted() {
147:                return formError("202 Accepted", "Object checked in");
148:            }
149:
150:            /**
151:             * Indicates only a partial responce was sent.
152:             * 
153:             * @return The header in a string;
154:             */
155:            public static String formPartial() {
156:                return formError("203 Partial",
157:                        "Only partail document available");
158:            }
159:
160:            /**
161:             * Indicates a requested URL has moved to a new address or name.
162:             * 
163:             * @return The header in a string;
164:             */
165:            public static String formMoved() {
166:                // 300 codes tell client to do actions
167:                return formError("301 Moved", "File has moved");
168:            }
169:
170:            /**
171:             * Never seen this used.
172:             * 
173:             * @return The header in a string;
174:             */
175:            public static String formFound() {
176:                return formError("302 Found", "Object was found");
177:            }
178:
179:            /**
180:             * The requested method is not implemented by the server.
181:             * 
182:             * @return The header in a string;
183:             */
184:            public static String formMethod() {
185:                return formError("303 Method unseported", "Method unseported");
186:            }
187:
188:            /**
189:             * Indicates remote copy of the requested object is current.
190:             * 
191:             * @return The header in a string;
192:             */
193:            public static String formNotModified() {
194:                return formError("304 Not modified", "Use local copy");
195:            }
196:
197:            /**
198:             * Client not otherized for the request.
199:             * 
200:             * @return The header in a string;
201:             */
202:            public static String formUnautorized() {
203:                return formError("401 Unathorized",
204:                        "Unathorized use of this service");
205:            }
206:
207:            /**
208:             * Payment is required for service.
209:             * 
210:             * @return The header in a string;
211:             */
212:            public static String formPaymentNeeded() {
213:                return formError("402 Payment required", "Payment is required");
214:            }
215:
216:            /**
217:             * Client if forbidden to get the request service.
218:             * 
219:             * @return The header in a string;
220:             */
221:            public static String formForbidden() {
222:                return formError("403 Forbidden",
223:                        "You need permission for this service");
224:            }
225:
226:            /**
227:             * The requested object was not found.
228:             * 
229:             * @return The header in a string;
230:             */
231:            public static String formNotFound() {
232:                return formError("404 Not_found",
233:                        "Requested object was not found");
234:            }
235:
236:            /**
237:             * The server had a problem and could not fulfill the request.
238:             * 
239:             * @return The header in a string;
240:             */
241:            public static String formInternalError() {
242:                return formError("500 Internal server error", "Server broke");
243:            }
244:
245:            /**
246:             * Server does not do the requested feature.
247:             * 
248:             * @return The header in a string;
249:             */
250:            public static String formNotImplemented() {
251:                return formError("501 Method not implemented",
252:                        "Service not implemented");
253:            }
254:
255:            /**
256:             * Server is overloaded, client should try again latter.
257:             * 
258:             * @return The header in a string;
259:             */
260:            public static String formOverloaded() {
261:                return formError("502 Server overloaded", "Try again latter");
262:            }
263:
264:            /**
265:             * Indicates the request took to long.
266:             * 
267:             * @return The header in a string;
268:             */
269:            public static String formTimeout() {
270:                return formError("503 Gateway timeout",
271:                        "The connection timed out");
272:            }
273:
274:            /**
275:             * Indicates the client's proxies could not locate a server.
276:             * 
277:             * @return The header in a string;
278:             */
279:            public static String formServerNotFound() {
280:                return formError("503 Gateway timeout",
281:                        "The requested server was not found");
282:            }
283:
284:            /**
285:             * Indicates the client is not allowed to access the object.
286:             * 
287:             * @return The header in a string;
288:             */
289:            public static String formNotAllowed() {
290:                return formError("403 Access Denied", "Access is not allowed");
291:            }
292:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.