001/** 002 * Logback: the reliable, generic, fast and flexible logging framework. 003 * Copyright (C) 1999-2015, QOS.ch. All rights reserved. 004 * 005 * This program and the accompanying materials are dual-licensed under 006 * either the terms of the Eclipse Public License v1.0 as published by 007 * the Eclipse Foundation 008 * 009 * or (per the licensee's choosing) 010 * 011 * under the terms of the GNU Lesser General Public License version 2.1 012 * as published by the Free Software Foundation. 013 */ 014package ch.qos.logback.access.dummy; 015 016import ch.qos.logback.access.AccessConstants; 017 018import javax.servlet.*; 019import javax.servlet.http.*; 020import java.io.BufferedReader; 021import java.io.IOException; 022import java.io.UnsupportedEncodingException; 023import java.security.Principal; 024import java.util.*; 025 026public class DummyRequest implements HttpServletRequest { 027 028 public final static String DUMMY_CONTENT_STRING = "request contents"; 029 public final static byte[] DUMMY_CONTENT_BYTES = DUMMY_CONTENT_STRING.getBytes(); 030 031 public static final Map<String, Object> DUMMY_DEFAULT_ATTR_MAP = new HashMap<String, Object>(); 032 033 public static final String DUMMY_RESPONSE_CONTENT_STRING = "response contents"; 034 public static final byte[] DUMMY_RESPONSE_CONTENT_BYTES = DUMMY_RESPONSE_CONTENT_STRING.getBytes(); 035 036 Hashtable<String, String> headerMap; 037 Hashtable<String, String[]> parameterMap; 038 039 String uri; 040 Map<String, Object> attributes; 041 042 static { 043 DUMMY_DEFAULT_ATTR_MAP.put("testKey", "testKey"); 044 DUMMY_DEFAULT_ATTR_MAP.put(AccessConstants.LB_INPUT_BUFFER, DUMMY_CONTENT_BYTES); 045 DUMMY_DEFAULT_ATTR_MAP.put(AccessConstants.LB_OUTPUT_BUFFER, DUMMY_RESPONSE_CONTENT_BYTES); 046 } 047 048 public DummyRequest() { 049 headerMap = new Hashtable<String, String>(); 050 headerMap.put("headerName1", "headerValue1"); 051 headerMap.put("headerName2", "headerValue2"); 052 053 parameterMap = new Hashtable<String, String[]>(); 054 parameterMap.put("param1", new String[] {"value1"}); 055 056 attributes = new HashMap<String, Object>(DUMMY_DEFAULT_ATTR_MAP); 057 } 058 059 public String getAuthType() { 060 return null; 061 } 062 063 public String getContextPath() { 064 return null; 065 } 066 067 public Cookie[] getCookies() { 068 Cookie cookie = new Cookie("testName", "testCookie"); 069 return new Cookie[] { cookie }; 070 } 071 072 public long getDateHeader(String arg0) { 073 return 0; 074 } 075 076 public String getHeader(String key) { 077 return headerMap.get(key); 078 } 079 080 081 @Override 082 public Enumeration<String> getHeaderNames() { 083 return headerMap.keys(); 084 } 085 086 @Override 087 public Enumeration<String> getHeaders(String arg) { 088 return null; 089 } 090 091 public Map<String, String> getHeaders() { 092 return headerMap; 093 } 094 095 096 public int getIntHeader(String arg0) { 097 return 0; 098 } 099 100 public String getMethod() { 101 return "testMethod"; 102 } 103 104 public String getPathInfo() { 105 return null; 106 } 107 108 public String getPathTranslated() { 109 return null; 110 } 111 112 public String getQueryString() { 113 return null; 114 } 115 116 public String getRemoteUser() { 117 return "testUser"; 118 } 119 120 public String getRequestURI() { 121 return uri; 122 } 123 124 public StringBuffer getRequestURL() { 125 return new StringBuffer(uri); 126 } 127 128 public String getRequestedSessionId() { 129 return null; 130 } 131 132 public String getServletPath() { 133 return null; 134 } 135 136 public HttpSession getSession() { 137 return null; 138 } 139 140 public HttpSession getSession(boolean arg0) { 141 return null; 142 } 143 144 public Principal getUserPrincipal() { 145 return null; 146 } 147 148 public boolean isRequestedSessionIdFromCookie() { 149 return false; 150 } 151 152 public boolean isRequestedSessionIdFromURL() { 153 return false; 154 } 155 156 public boolean isRequestedSessionIdFromUrl() { 157 return false; 158 } 159 160 public boolean authenticate(HttpServletResponse response) throws IOException, ServletException { 161 return false; // To change body of implemented methods use File | Settings | File Templates. 162 } 163 164 public void login(String username, String password) throws ServletException { 165 // To change body of implemented methods use File | Settings | File Templates. 166 } 167 168 public void logout() throws ServletException { 169 // To change body of implemented methods use File | Settings | File Templates. 170 } 171 172 public Collection<Part> getParts() throws IOException, IllegalStateException, ServletException { 173 return null; // To change body of implemented methods use File | Settings | File Templates. 174 } 175 176 public Part getPart(String name) throws IOException, IllegalStateException, ServletException { 177 return null; // To change body of implemented methods use File | Settings | File Templates. 178 } 179 180 public boolean isRequestedSessionIdValid() { 181 return false; 182 } 183 184 public boolean isUserInRole(String arg0) { 185 return false; 186 } 187 188 public Object getAttribute(String key) { 189 return attributes.get(key); 190 } 191 192 public Enumeration<String> getAttributeNames() { 193 return Collections.enumeration(attributes.keySet()); 194 } 195 196 public String getCharacterEncoding() { 197 return null; 198 } 199 200 public int getContentLength() { 201 return 0; 202 } 203 204 public String getContentType() { 205 return null; 206 } 207 208 public ServletInputStream getInputStream() throws IOException { 209 return null; 210 } 211 212 public String getLocalAddr() { 213 return null; 214 } 215 216 public String getLocalName() { 217 return null; 218 } 219 220 public int getLocalPort() { 221 return 11; 222 } 223 224 public ServletContext getServletContext() { 225 return null; // To change body of implemented methods use File | Settings | File Templates. 226 } 227 228 public AsyncContext startAsync() { 229 return null; // To change body of implemented methods use File | Settings | File Templates. 230 } 231 232 public AsyncContext startAsync(ServletRequest servletRequest, ServletResponse servletResponse) { 233 return null; // To change body of implemented methods use File | Settings | File Templates. 234 } 235 236 public boolean isAsyncStarted() { 237 return false; // To change body of implemented methods use File | Settings | File Templates. 238 } 239 240 public boolean isAsyncSupported() { 241 return false; // To change body of implemented methods use File | Settings | File Templates. 242 } 243 244 public AsyncContext getAsyncContext() { 245 return null; // To change body of implemented methods use File | Settings | File Templates. 246 } 247 248 public DispatcherType getDispatcherType() { 249 return null; // To change body of implemented methods use File | Settings | File Templates. 250 } 251 252 public Locale getLocale() { 253 return null; 254 } 255 256 @Override 257 public Enumeration<Locale> getLocales() { 258 return null; 259 } 260 261 public String getParameter(String arg) { 262 String[] stringArray = parameterMap.get(arg); 263 if(stringArray == null || stringArray.length == 0) 264 return null; 265 else 266 return stringArray[0]; 267 } 268 269 @Override 270 public Map<String, String[]> getParameterMap() { 271 return parameterMap; 272 } 273 274 public Enumeration<String> getParameterNames() { 275 return parameterMap.keys(); 276 //eturn Collections.enumeration(parameterMap.keySet()); 277 } 278 279 public String[] getParameterValues(String arg) { 280 return parameterMap.get(arg); 281 } 282 283 public String getProtocol() { 284 return "testProtocol"; 285 } 286 287 public BufferedReader getReader() throws IOException { 288 return null; 289 } 290 291 public String getRealPath(String arg0) { 292 return null; 293 } 294 295 public String getRemoteAddr() { 296 return "testRemoteAddress"; 297 } 298 299 public String getRemoteHost() { 300 return "testHost"; 301 } 302 303 public int getRemotePort() { 304 return 0; 305 } 306 307 public RequestDispatcher getRequestDispatcher(String arg0) { 308 return null; 309 } 310 311 public String getScheme() { 312 return null; 313 } 314 315 public String getServerName() { 316 return "testServerName"; 317 } 318 319 public int getServerPort() { 320 return 0; 321 } 322 323 public boolean isSecure() { 324 return false; 325 } 326 327 public void removeAttribute(String arg0) { 328 } 329 330 public void setAttribute(String name, Object value) { 331 attributes.put(name, value); 332 } 333 334 public void setCharacterEncoding(String arg0) throws UnsupportedEncodingException { 335 } 336 337 public void setRequestUri(String uri) { 338 this.uri = uri; 339 } 340 341 @Override 342 public long getContentLengthLong() { 343 // TODO Auto-generated method stub 344 return 0; 345 } 346 347 @Override 348 public String changeSessionId() { 349 return null; 350 } 351 352 @Override 353 public <T extends HttpUpgradeHandler> T upgrade(Class<T> httpUpgradeHandlerClass) throws IOException, ServletException { 354 return null; 355 } 356}