1 29 30 package com.caucho.server.webapp; 31 32 import com.caucho.server.connection.AbstractHttpResponse; 33 import com.caucho.server.connection.AbstractResponseStream; 34 import com.caucho.server.connection.CauchoResponse; 35 import com.caucho.server.connection.IncludeResponseStream; 36 import com.caucho.util.FreeList; 37 import com.caucho.vfs.WriteStream; 38 39 import javax.servlet.ServletResponse ; 40 import javax.servlet.ServletResponseWrapper ; 41 import javax.servlet.http.HttpServletResponse ; 42 import java.io.IOException ; 43 44 47 class DispatchResponse extends AbstractHttpResponse { 48 private static final FreeList<DispatchResponse> _freeList = 49 new FreeList<DispatchResponse>(32); 50 51 private IncludeResponseStream _stream; 52 53 private HttpServletResponse _next; 54 55 protected DispatchResponse() 56 { 57 } 58 59 62 public static DispatchResponse createDispatch() 63 { 64 DispatchResponse res = _freeList.allocate(); 65 if (res == null) 66 res = new DispatchResponse(); 67 68 return res; 69 } 70 71 74 protected AbstractResponseStream createResponseStream() 75 { 76 _stream = new IncludeResponseStream(this); 77 78 return _stream; 79 } 80 81 84 public void setNextResponse(HttpServletResponse next) 85 { 86 _next = next; 87 88 _stream.init(next); 89 } 90 91 94 public ServletResponse getResponse() 95 { 96 return _next; 97 } 98 99 102 public void start() 103 throws IOException 104 { 105 super.start(); 106 107 setResponseStream(_stream); 108 109 _stream.start(); 110 } 111 112 115 public void setContentType(String type) 116 { 117 } 118 119 122 public String encodeURL(String url) 123 { 124 return _next.encodeURL(url); 125 } 126 127 130 public String encodeRedirectURL(String url) 131 { 132 return _next.encodeRedirectURL(url); 133 } 134 135 138 protected boolean writeHeadersInt(WriteStream os, int length) 139 throws IOException 140 { 141 return false; 142 } 143 144 147 public boolean isTop() 148 { 149 return false; 150 } 151 152 @Override 153 public boolean isCommitted() 154 { 155 return _next.isCommitted(); 157 } 158 159 162 public boolean isCauchoResponse() 163 { 164 return _next instanceof CauchoResponse; 165 } 166 167 170 public void setCauchoResponseStream(boolean isCaucho) 171 { 172 _stream.setCauchoResponseStream(isCaucho); 173 } 174 175 178 public void killCache() 179 { 180 super.killCache(); 181 182 ServletResponse next = _next; 183 while (next != null && next != this) { 184 if (next instanceof CauchoResponse) { 185 ((CauchoResponse) next).killCache(); 186 break; 187 } 188 189 if (next instanceof ServletResponseWrapper ) 190 next = ((ServletResponseWrapper ) next).getResponse(); 191 else if (next instanceof DispatchResponse) 192 next = ((DispatchResponse) next).getResponse(); 193 else 194 break; 195 } 196 } 197 198 201 public void free() 202 { 203 super.free(); 204 205 _next = null; 206 } 207 208 211 public static void free(DispatchResponse res) 212 { 213 res.free(); 214 215 _freeList.free(res); 216 } 217 } 218 | Popular Tags |