1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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 }