1
2
3
4
5
6
7
8
9
10 package org.mule.transport.http.servlet;
11
12 import org.mule.api.MuleEvent;
13 import org.mule.api.MuleMessage;
14 import org.mule.api.transport.PropertyScope;
15 import org.mule.transport.http.HttpConnector;
16 import org.mule.transport.http.HttpConstants;
17
18 import java.io.IOException;
19 import java.io.PrintWriter;
20 import java.util.ArrayList;
21 import java.util.Arrays;
22 import java.util.List;
23 import java.util.Locale;
24
25 import javax.servlet.ServletOutputStream;
26 import javax.servlet.http.Cookie;
27 import javax.servlet.http.HttpServletResponse;
28
29
30
31
32 public class MuleHttpServletResponse implements HttpServletResponse
33 {
34
35
36
37
38
39 private MuleEvent event;
40 private MuleMessage message;
41
42 public MuleHttpServletResponse(MuleEvent event)
43 {
44 super();
45 this.event = event;
46 this.message = event.getMessage();
47 }
48
49 public String getCharacterEncoding()
50 {
51 return event.getEncoding();
52 }
53
54 public String getContentType()
55 {
56 return message.getInboundProperty(HttpConstants.HEADER_CONTENT_TYPE);
57 }
58
59 public ServletOutputStream getOutputStream() throws IOException
60 {
61 throw new UnsupportedOperationException();
62 }
63
64 public PrintWriter getWriter() throws IOException
65 {
66 throw new UnsupportedOperationException();
67 }
68
69 public void setCharacterEncoding(String charset)
70 {
71 message.setEncoding(charset);
72 }
73
74 public void setContentLength(int len)
75 {
76 throw new UnsupportedOperationException();
77 }
78
79 public void setContentType(String type)
80 {
81 message.setProperty(HttpConstants.HEADER_CONTENT_TYPE, type, PropertyScope.OUTBOUND);
82 }
83
84 public void setBufferSize(int size)
85 {
86 }
87
88 public int getBufferSize()
89 {
90 return 0;
91 }
92
93 public void flushBuffer() throws IOException
94 {
95 }
96
97 public void resetBuffer()
98 {
99 }
100
101 public boolean isCommitted()
102 {
103 return false;
104 }
105
106 public void reset()
107 {
108 }
109
110 public void setLocale(Locale loc)
111 {
112 }
113
114 public Locale getLocale()
115 {
116 return null;
117 }
118
119 public void addCookie(Cookie cookie)
120 {
121 org.apache.commons.httpclient.Cookie internal = toHttpClientCookie(cookie);
122
123 org.apache.commons.httpclient.Cookie[] internalCookies = message.getOutboundProperty(HttpConnector.HTTP_COOKIES_PROPERTY);
124 if (internalCookies == null)
125 {
126 internalCookies = new org.apache.commons.httpclient.Cookie[] { internal };
127 }
128 else
129 {
130 List<org.apache.commons.httpclient.Cookie> list = new ArrayList<org.apache.commons.httpclient.Cookie>(Arrays.asList(internalCookies));
131 list.add(internal);
132 internalCookies = list.toArray(new org.apache.commons.httpclient.Cookie[list.size()]);
133 }
134 message.setInvocationProperty(HttpConnector.HTTP_COOKIES_PROPERTY, internalCookies);
135 }
136
137 private org.apache.commons.httpclient.Cookie toHttpClientCookie(Cookie cookie)
138 {
139 org.apache.commons.httpclient.Cookie internal = new org.apache.commons.httpclient.Cookie();
140
141 internal.setName(cookie.getName());
142 internal.setValue(cookie.getValue());
143 internal.setComment(cookie.getComment());
144 internal.setDomain(cookie.getDomain());
145
146 internal.setPath(cookie.getPath());
147 internal.setVersion(cookie.getVersion());
148
149 return internal;
150 }
151
152 public boolean containsHeader(String name)
153 {
154 return false;
155 }
156
157 public String encodeURL(String url)
158 {
159 return null;
160 }
161
162 public String encodeRedirectURL(String url)
163 {
164 return null;
165 }
166
167 public String encodeUrl(String url)
168 {
169 return null;
170 }
171
172 public String encodeRedirectUrl(String url)
173 {
174 return null;
175 }
176
177 public void sendError(int sc, String msg) throws IOException
178 {
179 }
180
181 public void sendError(int sc) throws IOException
182 {
183 }
184
185 public void sendRedirect(String location) throws IOException
186 {
187 }
188
189 public void setDateHeader(String name, long date)
190 {
191
192 }
193
194 public void addDateHeader(String name, long date)
195 {
196 setDateHeader(name, date);
197 }
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251 public void setHeader(String name, String value)
252 {
253 message.setOutboundProperty(name, value);
254 }
255
256 public void addHeader(String name, String value)
257 {
258 message.setOutboundProperty(name, value);
259 }
260
261 public void setIntHeader(String name, int value)
262 {
263 message.setOutboundProperty(HttpConnector.HTTP_STATUS_PROPERTY, value);
264 }
265
266 public void addIntHeader(String name, int value)
267 {
268 message.setOutboundProperty(HttpConnector.HTTP_STATUS_PROPERTY, value);
269 }
270
271 public void setStatus(int sc)
272 {
273 message.setOutboundProperty(HttpConnector.HTTP_STATUS_PROPERTY, sc);
274 }
275
276 public void setStatus(int sc, String sm)
277 {
278 }
279
280 }