1   /*
2    * $Header: /home/cvs/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/server/SimpleResponse.java,v 1.1 2004/02/27 19:04:32 olegk Exp $
3    * $Revision: 1.1 $
4    * $Date: 2004/02/27 19:04:32 $
5    *
6    * ====================================================================
7    *
8    *  Copyright 1999-2004 The Apache Software Foundation
9    *
10   *  Licensed under the Apache License, Version 2.0 (the "License");
11   *  you may not use this file except in compliance with the License.
12   *  You may obtain a copy of the License at
13   *
14   *      http://www.apache.org/licenses/LICENSE-2.0
15   *
16   *  Unless required by applicable law or agreed to in writing, software
17   *  distributed under the License is distributed on an "AS IS" BASIS,
18   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19   *  See the License for the specific language governing permissions and
20   *  limitations under the License.
21   * ====================================================================
22   *
23   * This software consists of voluntary contributions made by many
24   * individuals on behalf of the Apache Software Foundation.  For more
25   * information on the Apache Software Foundation, please see
26   * <http://www.apache.org/>.
27   *
28   * [Additional notices, if required by prior licensing conditions]
29   *
30   */
31  
32  package org.apache.commons.httpclient.server;
33  
34  import java.util.Iterator;
35  
36  import org.apache.commons.httpclient.Header;
37  import org.apache.commons.httpclient.HeaderGroup;
38  
39  /***
40   * A generic HTTP response.
41   * 
42   * @author Christian Kohlschuetter
43   * @author Oleg Kalnichevski
44   */
45  public class SimpleResponse {
46      
47      private String statusLine = "HTTP/1.0 200 OK";
48      private String contentType = "text/plain";
49      private String bodyString = null;
50      private HeaderGroup headers = new HeaderGroup();
51  
52      public SimpleResponse() {
53          super();
54      }
55  
56      public SimpleResponse(final String statusLine) {
57          super();
58          this.statusLine = statusLine;
59      }
60  
61      public String getContentType() {
62          return this.contentType;
63      }
64      
65      public void setContentType(String string) {
66          this.contentType = string;
67      }
68  
69      public void setBodyString(String string) {
70          this.bodyString = string;
71      }
72      
73      public String getBodyString() {
74          return this.bodyString;
75      }
76  
77      public String getStatusLine() {
78          return this.statusLine;
79      }
80  
81      public void setStatusLine(String string) {
82          this.statusLine = string;
83      }
84  
85      public boolean containsHeader(final String name) {
86          return this.headers.containsHeader(name);
87      }
88  
89      public Header[] getHeaders() {
90          return this.headers.getAllHeaders();
91      }
92  
93      public void setHeader(final Header header) {
94          if (header == null) {
95              return;
96          }
97          Header[] headers = this.headers.getHeaders(header.getName());
98          for (int i = 0; i < headers.length; i++) {
99              this.headers.removeHeader(headers[i]);
100         }
101         this.headers.addHeader(header);
102     }
103 
104     public void addHeader(final Header header) {
105         if (header == null) {
106             return;
107         }
108         this.headers.addHeader(header);
109     }
110 
111     public void setHeaders(final Header[] headers) {
112         if (headers == null) {
113             return;
114         }
115         this.headers.setHeaders(headers);
116     }
117 
118     public Iterator getHeaderIterator() {
119         return this.headers.getIterator();
120     }
121 }