1 16 package org.directwebremoting.util; 17 18 import java.io.IOException ; 19 import java.io.PrintWriter ; 20 import java.io.Writer ; 21 import java.util.Locale ; 22 23 import javax.servlet.ServletOutputStream ; 24 import javax.servlet.http.Cookie ; 25 import javax.servlet.http.HttpServletResponse ; 26 import javax.servlet.http.HttpServletResponseWrapper ; 27 28 35 public final class SwallowingHttpServletResponse extends HttpServletResponseWrapper implements HttpServletResponse 36 { 37 43 public SwallowingHttpServletResponse(HttpServletResponse response, Writer sout, String characterEncoding) 44 { 45 super(response); 46 47 pout = new PrintWriter (sout); 48 outputStream = new WriterOutputStream(sout, characterEncoding); 49 50 this.characterEncoding = characterEncoding; 51 } 52 53 56 public void addCookie(Cookie cookie) 57 { 58 } 59 60 63 public void addDateHeader(String name, long value) 64 { 65 } 66 67 70 public void addHeader(String name, String value) 71 { 72 } 73 74 77 public void addIntHeader(String name, int value) 78 { 79 } 80 81 84 public boolean containsHeader(String name) 85 { 86 return false; 87 } 88 89 92 public String encodeRedirectUrl(String url) 93 { 94 return url; 95 } 96 97 100 public String encodeRedirectURL(String url) 101 { 102 return url; 103 } 104 105 108 public String encodeUrl(String url) 109 { 110 return url; 111 } 112 113 116 public String encodeURL(String url) 117 { 118 return url; 119 } 120 121 124 public void flushBuffer() throws IOException 125 { 126 pout.flush(); 127 } 128 129 132 public int getBufferSize() 133 { 134 return bufferSize; 135 } 136 137 140 public String getCharacterEncoding() 141 { 142 return characterEncoding; 143 } 144 145 149 public String getContentType() 150 { 151 return contentType; 152 } 153 154 159 public String getErrorMessage() 160 { 161 return errorMessage; 162 } 163 164 167 public Locale getLocale() 168 { 169 return locale; 170 } 171 172 175 public ServletOutputStream getOutputStream() 176 { 177 return outputStream; 178 } 179 180 184 public String getRedirectedUrl() 185 { 186 return redirectedUrl; 187 } 188 189 193 public int getStatus() 194 { 195 return status; 196 } 197 198 201 public PrintWriter getWriter() 202 { 203 return pout; 204 } 205 206 209 public boolean isCommitted() 210 { 211 return false; 212 } 213 214 217 public void reset() 218 { 219 } 220 221 224 public void resetBuffer() 225 { 226 } 227 228 231 public void sendError(int newStatus) 232 { 233 if (committed) 234 { 235 throw new IllegalStateException ("Cannot set error status - response is already committed"); 236 } 237 238 log.warn("Ignoring call to sendError(" + newStatus + ')'); 239 240 status = newStatus; 241 committed = true; 242 } 243 244 247 public void sendError(int newStatus, String newErrorMessage) 248 { 249 if (committed) 250 { 251 throw new IllegalStateException ("Cannot set error status - response is already committed"); 252 } 253 254 log.warn("Ignoring call to sendError(" + newStatus + ", " + newErrorMessage + ')'); 255 256 status = newStatus; 257 errorMessage = newErrorMessage; 258 committed = true; 259 } 260 261 264 public void sendRedirect(String location) 265 { 266 if (committed) 267 { 268 throw new IllegalStateException ("Cannot send redirect - response is already committed"); 269 } 270 271 log.warn("Ignoring call to sendRedirect(" + location + ')'); 272 273 redirectedUrl = location; 274 committed = true; 275 } 276 277 280 public void setBufferSize(int bufferSize) 281 { 282 this.bufferSize = bufferSize; 283 } 284 285 289 public void setCharacterEncoding(String characterEncoding) 290 { 291 this.characterEncoding = characterEncoding; 292 } 293 294 297 public void setContentLength(int i) 298 { 299 } 302 303 306 public void setContentType(String contentType) 307 { 308 this.contentType = contentType; 309 } 310 311 314 public void setDateHeader(String name, long value) 315 { 316 } 317 318 321 public void setHeader(String name, String value) 322 { 323 } 324 325 328 public void setIntHeader(String name, int value) 329 { 330 } 331 332 335 public void setLocale(Locale locale) 336 { 337 this.locale = locale; 338 } 339 340 343 public void setStatus(int status) 344 { 345 this.status = status; 346 log.warn("Ignoring call to setStatus(" + status + ')'); 347 } 348 349 353 public void setStatus(int newStatus, String newErrorMessage) 354 { 355 status = newStatus; 356 errorMessage = newErrorMessage; 357 log.warn("Ignoring call to setStatus(" + newStatus + ", " + newErrorMessage + ')'); 358 } 359 360 363 private int bufferSize = 0; 364 365 368 private String characterEncoding; 369 370 373 private boolean committed = false; 374 375 378 private String contentType; 379 380 383 private String errorMessage; 384 385 388 private Locale locale = Locale.getDefault(); 389 390 393 private final ServletOutputStream outputStream; 394 395 398 private final PrintWriter pout; 399 400 403 private String redirectedUrl; 404 405 408 private int status = HttpServletResponse.SC_OK; 409 410 413 private static final Logger log = Logger.getLogger(SwallowingHttpServletResponse.class); 414 } 415 | Popular Tags |