--- /dev/null
+package com.pentila.basic;
+/**
+ * Copyright 2009 Jee Vang
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0 Unless required
+ * by applicable law or agreed to in writing, software distributed
+ * under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
+ * or implied. See the License for the specific language governing
+ * permissions and limitations under the License.
+ */
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Enumeration;
+import java.util.List;
+
+import javax.servlet.http.Cookie;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletRequestWrapper;
+
+/**
+ * Fake headers request object. Adds a request header
+ * with the name "username". The value of this request header
+ * will be taken from a cookie (also with the name, "username").
+ *
+ * @author Jee Vang
+ *
+ */
+public class FakeHeadersRequest extends HttpServletRequestWrapper {
+
+ String attribute = null;
+ String value = null;
+ /**
+ * Constructor.
+ *
+ * @param request HttpServletRequest.
+ */
+ public FakeHeadersRequest(HttpServletRequest request, String attribute, String value) {
+ super(request);
+ this.attribute = attribute;
+ this.value = value;
+
+ }
+
+ public String getHeader(String name) {
+ //get the request object and cast it
+ HttpServletRequest request = (HttpServletRequest)getRequest();
+
+ //if we are looking for the "username" request header
+ if(attribute.equals(name)) {
+ return this.value;
+ }
+
+ //otherwise fall through to wrapped request object
+ return request.getHeader(name);
+ }
+
+ public Enumeration getHeaderNames() {
+ //create an enumeration of the request headers
+ //additionally, add the "username" request header
+
+ //create a list
+ List list = new ArrayList();
+
+ //loop over request headers from wrapped request object
+ HttpServletRequest request = (HttpServletRequest)getRequest();
+ Enumeration e = request.getHeaderNames();
+ while(e.hasMoreElements()) {
+ //add the names of the request headers into the list
+ String n = (String)e.nextElement();
+ list.add(n);
+ }
+
+ //additionally, add the "username" to the list of request header names
+ list.add(attribute);
+
+ //create an enumeration from the list and return
+ Enumeration en = Collections.enumeration(list);
+ return en;
+ }
+
+}