1 4 package weblogic.servlet.internal; 5 6 import com.terracotta.session.TerracottaRequest; 7 import com.terracotta.session.TerracottaResponse; 8 9 import java.io.IOException ; 10 import java.io.PrintWriter ; 11 import java.lang.reflect.Method ; 12 import java.lang.reflect.Modifier ; 13 import java.util.ArrayList ; 14 import java.util.HashSet ; 15 import java.util.Iterator ; 16 import java.util.List ; 17 import java.util.Locale ; 18 import java.util.Set ; 19 20 import javax.servlet.ServletOutputStream ; 21 import javax.servlet.http.Cookie ; 22 23 30 public final class TerracottaServletResponseImpl extends ServletResponseImpl implements TerracottaResponse { 31 private final TerracottaRequest req; 32 private final ServletResponseImpl nativeResponse; 33 34 public TerracottaServletResponseImpl(TerracottaRequest req, ServletResponseImpl response) { 35 this.req = req; 36 this.nativeResponse = response; 37 } 38 39 public String encodeRedirectUrl(String url) { 40 return encodeRedirectURL(url); 41 } 42 43 public String encodeUrl(String url) { 44 return encodeURL(url); 45 } 46 47 public String encodeRedirectURL(final String url) { 48 return req.encodeRedirectURL(url); 49 } 50 51 public String encodeURL(final String url) { 52 return req.encodeURL(url); 53 } 54 55 public void addCookie(Cookie arg0) { 56 nativeResponse.addCookie(arg0); 57 } 58 59 public void addDateHeader(String arg0, long arg1) { 60 nativeResponse.addDateHeader(arg0, arg1); 61 } 62 63 public void addHeader(String arg0, String arg1) { 64 nativeResponse.addHeader(arg0, arg1); 65 } 66 67 public void addIntHeader(String arg0, int arg1) { 68 nativeResponse.addIntHeader(arg0, arg1); 69 } 70 71 public boolean containsHeader(String arg0) { 72 return nativeResponse.containsHeader(arg0); 73 } 74 75 public void flushBuffer() throws IOException { 76 nativeResponse.flushBuffer(); 77 } 78 79 public int getBufferSize() { 80 return nativeResponse.getBufferSize(); 81 } 82 83 public String getCharacterEncoding() { 84 return nativeResponse.getCharacterEncoding(); 85 } 86 87 public String getContentType() { 88 return nativeResponse.getContentType(); 89 } 90 91 public Locale getLocale() { 92 return nativeResponse.getLocale(); 93 } 94 95 public ServletOutputStream getOutputStream() throws IOException { 96 return nativeResponse.getOutputStream(); 97 } 98 99 public PrintWriter getWriter() throws IOException { 100 return nativeResponse.getWriter(); 101 } 102 103 public boolean isCommitted() { 104 return nativeResponse.isCommitted(); 105 } 106 107 public void reset() { 108 nativeResponse.reset(); 109 } 110 111 public void resetBuffer() { 112 nativeResponse.resetBuffer(); 113 } 114 115 public void sendError(int arg0, String arg1) throws IOException { 116 nativeResponse.sendError(arg0, arg1); 117 } 118 119 public void sendError(int arg0) throws IOException { 120 nativeResponse.sendError(arg0); 121 } 122 123 public void sendRedirect(String arg0) throws IOException { 124 nativeResponse.sendRedirect(arg0); 125 } 126 127 public void setBufferSize(int arg0) { 128 nativeResponse.setBufferSize(arg0); 129 } 130 131 public void setCharacterEncoding(String arg0) { 132 nativeResponse.setCharacterEncoding(arg0); 133 } 134 135 public void setContentLength(int arg0) { 136 nativeResponse.setContentLength(arg0); 137 } 138 139 public void setContentType(String arg0) { 140 nativeResponse.setContentType(arg0); 141 } 142 143 public void setDateHeader(String arg0, long arg1) { 144 nativeResponse.setDateHeader(arg0, arg1); 145 } 146 147 public void setHeader(String arg0, String arg1) { 148 nativeResponse.setHeader(arg0, arg1); 149 } 150 151 public void setIntHeader(String arg0, int arg1) { 152 nativeResponse.setIntHeader(arg0, arg1); 153 } 154 155 public void setLocale(Locale arg0) { 156 nativeResponse.setLocale(arg0); 157 } 158 159 public void setStatus(int arg0, String arg1) { 160 nativeResponse.setStatus(arg0, arg1); 161 } 162 163 public void setStatus(int arg0) { 164 nativeResponse.setStatus(arg0); 165 } 166 167 static { 168 Set superMethods = methodsFor(ServletResponseImpl.class); 169 Set thisMethods = methodsFor(TerracottaServletResponseImpl.class); 170 171 List missing = new ArrayList (); 172 173 for (Iterator i = superMethods.iterator(); i.hasNext();) { 174 String method = (String ) i.next(); 175 176 if (!thisMethods.contains(method)) { 177 missing.add(method); 179 } 180 } 181 182 if (!missing.isEmpty()) { throw new RuntimeException ("Missing overrides:\n" + missing); } 183 } 184 185 private static Set methodsFor(Class c) { 186 Method [] methods = c.getDeclaredMethods(); 187 188 Set set = new HashSet (); 189 for (int i = 0; i < methods.length; i++) { 190 Method m = methods[i]; 191 192 int access = m.getModifiers(); 193 194 if (Modifier.isAbstract(access) || Modifier.isStatic(access) || Modifier.isPrivate(access)) { 195 continue; 196 } 197 198 StringBuffer sig = new StringBuffer (); 199 sig.append(m.getName()).append('('); 200 201 Class [] parameterTypes = m.getParameterTypes(); 202 for (int j = 0; j < parameterTypes.length; j++) { 203 sig.append(parameterTypes[j].getName()); 204 if (j < (parameterTypes.length - 1)) { 205 sig.append(','); 206 } 207 } 208 sig.append(')'); 209 210 set.add(sig.toString()); 211 } 212 return set; 213 } 214 215 } 216 | Popular Tags |