1 package org.openecomp.sdc.webseal.simulator;
4 import java.util.Collections;
5 import java.util.Enumeration;
6 import java.util.HashMap;
7 import java.util.HashSet;
11 import javax.servlet.http.HttpServletRequest;
12 import javax.servlet.http.HttpServletRequestWrapper;
14 public final class MutableHttpServletRequest extends HttpServletRequestWrapper {
15 // holds custom header and value mapping
16 private final Map<String, String> customHeaders;
18 public MutableHttpServletRequest(HttpServletRequest request){
20 this.customHeaders = new HashMap<String, String>();
23 public void putHeader(String name, String value){
24 this.customHeaders.put(name, value);
27 public String getHeader(String name) {
28 // check the custom headers first
29 String headerValue = customHeaders.get(name);
31 if (headerValue != null){
34 // else return from into the original wrapped object
35 return ((HttpServletRequest) getRequest()).getHeader(name);
38 public Enumeration<String> getHeaderNames() {
39 // create a set of the custom header names
40 Set<String> set = new HashSet<String>(customHeaders.keySet());
42 // now add the headers from the wrapped request object
43 @SuppressWarnings("unchecked")
44 Enumeration<String> e = ((HttpServletRequest) getRequest()).getHeaderNames();
45 while (e.hasMoreElements()) {
46 // add the names of the request headers into the list
47 String n = e.nextElement();
51 // create an enumeration from the set and return
52 return Collections.enumeration(set);