1 package ch.qos.logback.access.dummy; 2 3 import java.io.BufferedReader; 4 import java.io.IOException; 5 import java.io.UnsupportedEncodingException; 6 import java.security.Principal; 7 import java.util.Enumeration; 8 import java.util.Hashtable; 9 import java.util.Locale; 10 import java.util.Map; 11 12 import javax.servlet.RequestDispatcher; 13 import javax.servlet.ServletInputStream; 14 import javax.servlet.http.Cookie; 15 import javax.servlet.http.HttpServletRequest; 16 import javax.servlet.http.HttpSession; 17 18 import ch.qos.logback.access.AccessConstants; 19 20 public class DummyRequest implements HttpServletRequest { 21 22 public final static String DUMMY_CONTENT_STRING = "request contents"; 23 public final static byte[] DUMMY_CONTENT_BYTES = DUMMY_CONTENT_STRING.getBytes(); 24 25 26 public static final String DUMMY_RESPONSE_CONTENT_STRING = "response contents"; 27 public static final byte[] DUMMY_RESPONSE_CONTENT_BYTES =DUMMY_RESPONSE_CONTENT_STRING.getBytes(); 28 29 Hashtable<String, String> headerNames; 30 String uri; 31 32 public DummyRequest() { 33 headerNames = new Hashtable<String, String>(); 34 headerNames.put("headerName1", "headerValue1"); 35 headerNames.put("headerName2", "headerValue2"); 36 } 37 38 public String getAuthType() { 39 return null; 40 } 41 42 public String getContextPath() { 43 return null; 44 } 45 46 public Cookie[] getCookies() { 47 Cookie cookie = new Cookie("testName", "testCookie"); 48 return new Cookie[] { cookie }; 49 } 50 51 public long getDateHeader(String arg0) { 52 return 0; 53 } 54 55 public String getHeader(String key) { 56 return headerNames.get(key); 57 } 58 59 public Enumeration getHeaderNames() { 60 return headerNames.keys(); 61 } 62 63 public Enumeration getHeaders(String arg0) { 64 return null; 65 } 66 67 public int getIntHeader(String arg0) { 68 return 0; 69 } 70 71 public String getMethod() { 72 return "testMethod"; 73 } 74 75 public String getPathInfo() { 76 return null; 77 } 78 79 public String getPathTranslated() { 80 return null; 81 } 82 83 public String getQueryString() { 84 return null; 85 } 86 87 public String getRemoteUser() { 88 return "testUser"; 89 } 90 91 public String getRequestURI() { 92 return uri; 93 } 94 95 public StringBuffer getRequestURL() { 96 return new StringBuffer(uri); 97 } 98 99 public String getRequestedSessionId() { 100 return null; 101 } 102 103 public String getServletPath() { 104 return null; 105 } 106 107 public HttpSession getSession() { 108 return null; 109 } 110 111 public HttpSession getSession(boolean arg0) { 112 return null; 113 } 114 115 public Principal getUserPrincipal() { 116 return null; 117 } 118 119 public boolean isRequestedSessionIdFromCookie() { 120 return false; 121 } 122 123 public boolean isRequestedSessionIdFromURL() { 124 return false; 125 } 126 127 public boolean isRequestedSessionIdFromUrl() { 128 return false; 129 } 130 131 public boolean isRequestedSessionIdValid() { 132 return false; 133 } 134 135 public boolean isUserInRole(String arg0) { 136 return false; 137 } 138 139 public Object getAttribute(String key) { 140 if (key.equals("testKey")) { 141 return "testKey"; 142 } else if (AccessConstants.LB_INPUT_BUFFER.equals(key)) { 143 return DUMMY_CONTENT_BYTES; 144 } else if (AccessConstants.LB_OUTPUT_BUFFER.equals(key)) { 145 return DUMMY_RESPONSE_CONTENT_BYTES; 146 } else { 147 return null; 148 } 149 } 150 151 public Enumeration getAttributeNames() { 152 return null; 153 } 154 155 public String getCharacterEncoding() { 156 return null; 157 } 158 159 public int getContentLength() { 160 return 0; 161 } 162 163 public String getContentType() { 164 return null; 165 } 166 167 public ServletInputStream getInputStream() throws IOException { 168 return null; 169 } 170 171 public String getLocalAddr() { 172 return null; 173 } 174 175 public String getLocalName() { 176 return null; 177 } 178 179 public int getLocalPort() { 180 return 11; 181 } 182 183 public Locale getLocale() { 184 return null; 185 } 186 187 public Enumeration getLocales() { 188 return null; 189 } 190 191 public String getParameter(String arg0) { 192 return null; 193 } 194 195 public Map getParameterMap() { 196 return null; 197 } 198 199 public Enumeration getParameterNames() { 200 return null; 201 } 202 203 public String[] getParameterValues(String arg0) { 204 return null; 205 } 206 207 public String getProtocol() { 208 return "testProtocol"; 209 } 210 211 public BufferedReader getReader() throws IOException { 212 return null; 213 } 214 215 public String getRealPath(String arg0) { 216 return null; 217 } 218 219 public String getRemoteAddr() { 220 return "testRemoteAddress"; 221 } 222 223 public String getRemoteHost() { 224 return "testHost"; 225 } 226 227 public int getRemotePort() { 228 return 0; 229 } 230 231 public RequestDispatcher getRequestDispatcher(String arg0) { 232 return null; 233 } 234 235 public String getScheme() { 236 return null; 237 } 238 239 public String getServerName() { 240 return "testServerName"; 241 } 242 243 public int getServerPort() { 244 return 0; 245 } 246 247 public boolean isSecure() { 248 return false; 249 } 250 251 public void removeAttribute(String arg0) { 252 } 253 254 public void setAttribute(String arg0, Object arg1) { 255 } 256 257 public void setCharacterEncoding(String arg0) 258 throws UnsupportedEncodingException { 259 } 260 261 public void setRequestUri(String uri) { 262 this.uri = uri; 263 } 264 }