Source Code Cross Referenced for Response.java in  » Wiki-Engine » fitnesse » fitnesse » http » 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 » Wiki Engine » fitnesse » fitnesse.http 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        // Copyright (C) 2003,2004,2005 by Object Mentor, Inc. All rights reserved.
002:        // Released under the terms of the GNU General Public License version 2 or later.
003:        package fitnesse.http;
004:
005:        import java.util.*;
006:        import java.text.*;
007:
008:        public abstract class Response {
009:            public static final String DEFAULT_CONTENT_TYPE = "text/html; charset=utf-8";
010:
011:            protected static final String CRLF = "\r\n";
012:
013:            public static SimpleDateFormat makeStandardHttpDateFormat() {
014:                //SimpleDateFormat is not thread safe, so we need to create each instance independently.
015:                SimpleDateFormat df = new SimpleDateFormat(
016:                        "EEE, dd MMM yyyy HH:mm:ss z");
017:                df.setTimeZone(TimeZone.getTimeZone("GMT"));
018:                return df;
019:            }
020:
021:            private int status = 200;
022:            private HashMap headers = new HashMap(17);
023:            private String contentType = DEFAULT_CONTENT_TYPE;
024:
025:            public Response() {
026:            }
027:
028:            public Response(int status) {
029:                this .status = status;
030:            }
031:
032:            public abstract void readyToSend(ResponseSender sender)
033:                    throws Exception;
034:
035:            protected abstract void addSpecificHeaders();
036:
037:            public abstract int getContentSize();
038:
039:            public int getStatus() {
040:                return status;
041:            }
042:
043:            public void setStatus(int s) {
044:                status = s;
045:            }
046:
047:            public String makeHttpHeaders() {
048:                StringBuffer text = new StringBuffer();
049:                text.append("HTTP/1.1 ").append(status).append(" ").append(
050:                        getReasonPhrase()).append(CRLF);
051:                makeHeaders(text);
052:                text.append(CRLF);
053:                return text.toString();
054:            }
055:
056:            public String getContentType() {
057:                return contentType;
058:            }
059:
060:            public void setContentType(String type) {
061:                contentType = type;
062:            }
063:
064:            public void redirect(String location) {
065:                status = 303;
066:                addHeader("Location", location);
067:            }
068:
069:            public void setMaxAge(int age) {
070:                addHeader("Cache-Control", "max-age=" + age);
071:            }
072:
073:            public void setLastModifiedHeader(String date) {
074:                addHeader("Last-Modified", date);
075:            }
076:
077:            public void setExpiresHeader(String date) {
078:                addHeader("Expires", date);
079:            }
080:
081:            public void addHeader(String key, String value) {
082:                headers.put(key, value);
083:            }
084:
085:            public String getHeader(String key) {
086:                return (String) headers.get(key);
087:            }
088:
089:            public byte[] getEncodedBytes(String value) throws Exception {
090:                return value.getBytes("UTF-8");
091:            }
092:
093:            private void makeHeaders(StringBuffer text) {
094:                for (Iterator iterator = headers.keySet().iterator(); iterator
095:                        .hasNext();) {
096:                    String key = (String) iterator.next();
097:                    String value = (String) headers.get(key);
098:                    text.append(key).append(": ").append(value).append(CRLF);
099:                }
100:            }
101:
102:            protected void addStandardHeaders() {
103:                addHeader("Content-Type", getContentType());
104:                addSpecificHeaders();
105:            }
106:
107:            protected String getReasonPhrase() {
108:                return getReasonPhrase(status);
109:            }
110:
111:            public static String getReasonPhrase(int status) {
112:                switch (status) {
113:                case 100:
114:                    return "Continue";
115:                case 101:
116:                    return "Switching Protocols";
117:                case 200:
118:                    return "OK";
119:                case 201:
120:                    return "Created";
121:                case 202:
122:                    return "Accepted";
123:                case 203:
124:                    return "Non-Authoritative Information";
125:                case 204:
126:                    return "No Content";
127:                case 205:
128:                    return "Reset Content";
129:                case 300:
130:                    return "Multiple Choices";
131:                case 301:
132:                    return "Moved Permanently";
133:                case 302:
134:                    return "Found";
135:                case 303:
136:                    return "See Other";
137:                case 304:
138:                    return "Not Modified";
139:                case 305:
140:                    return "Use Proxy";
141:                case 307:
142:                    return "Temporary Redirect";
143:                case 400:
144:                    return "Bad Request";
145:                case 401:
146:                    return "Unauthorized";
147:                case 402:
148:                    return "Payment Required";
149:                case 403:
150:                    return "Forbidden";
151:                case 404:
152:                    return "Not Found";
153:                case 405:
154:                    return "Method Not Allowed";
155:                case 406:
156:                    return "Not Acceptable";
157:                case 407:
158:                    return "Proxy Authentication Required";
159:                case 408:
160:                    return "Request Time-out";
161:                case 409:
162:                    return "Conflict";
163:                case 410:
164:                    return "Gone";
165:                case 411:
166:                    return "Length Required";
167:                case 412:
168:                    return "Precondition Failed";
169:                case 413:
170:                    return "Request Entity Too Large";
171:                case 414:
172:                    return "Request-URI Too Large";
173:                case 415:
174:                    return "Unsupported Media Type";
175:                case 416:
176:                    return "Requested range not satisfiable";
177:                case 417:
178:                    return "Expectation Failed";
179:                case 500:
180:                    return "Internal Server Error";
181:                case 501:
182:                    return "Not Implemented";
183:                case 502:
184:                    return "Bad Gateway";
185:                case 503:
186:                    return "Service Unavailable";
187:                case 504:
188:                    return "Gateway Time-out";
189:                case 505:
190:                    return "HTTP Version not supported";
191:                default:
192:                    return "Unknown Status";
193:                }
194:            }
195:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.