Source Code Cross Referenced for BasicHttpResponse.java in  » Net » httpcomponents-core-4.0-beta1 » org » apache » http » message » 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 » Net » httpcomponents core 4.0 beta1 » org.apache.http.message 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * $HeadURL: https://svn.apache.org/repos/asf/httpcomponents/httpcore/tags/4.0-beta1/module-main/src/main/java/org/apache/http/message/BasicHttpResponse.java $
003:         * $Revision: 573864 $
004:         * $Date: 2007-09-08 17:53:25 +0200 (Sat, 08 Sep 2007) $
005:         *
006:         * ====================================================================
007:         * Licensed to the Apache Software Foundation (ASF) under one
008:         * or more contributor license agreements.  See the NOTICE file
009:         * distributed with this work for additional information
010:         * regarding copyright ownership.  The ASF licenses this file
011:         * to you under the Apache License, Version 2.0 (the
012:         * "License"); you may not use this file except in compliance
013:         * with the License.  You may obtain a copy of the License at
014:         *
015:         *   http://www.apache.org/licenses/LICENSE-2.0
016:         *
017:         * Unless required by applicable law or agreed to in writing,
018:         * software distributed under the License is distributed on an
019:         * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
020:         * KIND, either express or implied.  See the License for the
021:         * specific language governing permissions and limitations
022:         * under the License.
023:         * ====================================================================
024:         *
025:         * This software consists of voluntary contributions made by many
026:         * individuals on behalf of the Apache Software Foundation.  For more
027:         * information on the Apache Software Foundation, please see
028:         * <http://www.apache.org/>.
029:         *
030:         */
031:
032:        package org.apache.http.message;
033:
034:        import java.util.Locale;
035:
036:        import org.apache.http.HttpEntity;
037:        import org.apache.http.HttpResponse;
038:        import org.apache.http.ProtocolVersion;
039:        import org.apache.http.StatusLine;
040:        import org.apache.http.ReasonPhraseCatalog;
041:
042:        /**
043:         * Basic implementation of an HTTP response that can be modified.
044:         * This implementation makes sure that there always is a status line.
045:         *
046:         * @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a>
047:         *
048:         * @version $Revision: 573864 $
049:         * 
050:         * @since 4.0
051:         */
052:        public class BasicHttpResponse extends AbstractHttpMessage implements 
053:                HttpResponse {
054:
055:            private StatusLine statusline;
056:            private HttpEntity entity;
057:            private ReasonPhraseCatalog reasonCatalog;
058:            private Locale locale;
059:
060:            /**
061:             * Creates a new response.
062:             * This is the constructor to which all others map.
063:             *
064:             * @param statusline        the status line
065:             * @param catalog           the reason phrase catalog, or
066:             *                          <code>null</code> to disable automatic
067:             *                          reason phrase lookup
068:             * @param locale            the locale for looking up reason phrases, or
069:             *                          <code>null</code> for the system locale
070:             */
071:            public BasicHttpResponse(final StatusLine statusline,
072:                    final ReasonPhraseCatalog catalog, final Locale locale) {
073:                super ();
074:                if (statusline == null) {
075:                    throw new IllegalArgumentException(
076:                            "Status line may not be null.");
077:                }
078:                this .statusline = statusline;
079:                this .reasonCatalog = catalog;
080:                this .locale = (locale != null) ? locale : Locale.getDefault();
081:            }
082:
083:            /**
084:             * Creates a response from a status line.
085:             * The response will not have a reason phrase catalog and
086:             * use the system default locale.
087:             *
088:             * @param statusline        the status line
089:             */
090:            public BasicHttpResponse(final StatusLine statusline) {
091:                this (statusline, null, null);
092:            }
093:
094:            /**
095:             * Creates a response from elements of a status line.
096:             * The response will not have a reason phrase catalog and
097:             * use the system default locale.
098:             *
099:             * @param ver       the protocol version of the response
100:             * @param code      the status code of the response
101:             * @param reason    the reason phrase to the status code, or
102:             *                  <code>null</code>
103:             */
104:            public BasicHttpResponse(final ProtocolVersion ver, final int code,
105:                    final String reason) {
106:                this (new BasicStatusLine(ver, code, reason), null, null);
107:            }
108:
109:            // non-javadoc, see interface HttpMessage
110:            public ProtocolVersion getProtocolVersion() {
111:                return this .statusline.getProtocolVersion();
112:            }
113:
114:            // non-javadoc, see interface HttpResponse
115:            public StatusLine getStatusLine() {
116:                return this .statusline;
117:            }
118:
119:            // non-javadoc, see interface HttpResponse
120:            public HttpEntity getEntity() {
121:                return this .entity;
122:            }
123:
124:            // non-javadoc, see interface HttpResponse
125:            public Locale getLocale() {
126:                return this .locale;
127:            }
128:
129:            // non-javadoc, see interface HttpResponse
130:            public void setStatusLine(final StatusLine statusline) {
131:                if (statusline == null) {
132:                    throw new IllegalArgumentException(
133:                            "Status line may not be null");
134:                }
135:                this .statusline = statusline;
136:            }
137:
138:            // non-javadoc, see interface HttpResponse
139:            public void setStatusLine(final ProtocolVersion ver, final int code) {
140:                // arguments checked in BasicStatusLine constructor
141:                this .statusline = new BasicStatusLine(ver, code,
142:                        getReason(code));
143:            }
144:
145:            // non-javadoc, see interface HttpResponse
146:            public void setStatusLine(final ProtocolVersion ver,
147:                    final int code, final String reason) {
148:                // arguments checked in BasicStatusLine constructor
149:                this .statusline = new BasicStatusLine(ver, code, reason);
150:            }
151:
152:            // non-javadoc, see interface HttpResponse
153:            public void setStatusCode(int code) {
154:                // argument checked in BasicStatusLine constructor
155:                ProtocolVersion ver = this .statusline.getProtocolVersion();
156:                this .statusline = new BasicStatusLine(ver, code,
157:                        getReason(code));
158:            }
159:
160:            // non-javadoc, see interface HttpResponse
161:            public void setReasonPhrase(String reason) {
162:
163:                if ((reason != null)
164:                        && ((reason.indexOf('\n') >= 0) || (reason
165:                                .indexOf('\r') >= 0))) {
166:                    throw new IllegalArgumentException(
167:                            "Line break in reason phrase.");
168:                }
169:                this .statusline = new BasicStatusLine(this .statusline
170:                        .getProtocolVersion(), this .statusline.getStatusCode(),
171:                        reason);
172:            }
173:
174:            // non-javadoc, see interface HttpResponse
175:            public void setEntity(final HttpEntity entity) {
176:                this .entity = entity;
177:            }
178:
179:            // non-javadoc, see interface HttpResponse
180:            public void setLocale(Locale loc) {
181:                if (loc == null) {
182:                    throw new IllegalArgumentException(
183:                            "Locale may not be null.");
184:                }
185:                this .locale = loc;
186:                final int code = this .statusline.getStatusCode();
187:                this .statusline = new BasicStatusLine(this .statusline
188:                        .getProtocolVersion(), code, getReason(code));
189:            }
190:
191:            /**
192:             * Looks up a reason phrase.
193:             * This method evaluates the currently set catalog and locale.
194:             * It also handles a missing catalog.
195:             *
196:             * @param code      the status code for which to look up the reason
197:             *
198:             * @return  the reason phrase, or <code>null</code> if there is none
199:             */
200:            protected String getReason(int code) {
201:                return (this.reasonCatalog == null) ? null : this.reasonCatalog
202:                        .getReason(code, this.locale);
203:            }
204:
205:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.