1 package org.openecomp.sdc.webseal.simulator;
4 import javax.servlet.http.HttpServletRequest;
5 import javax.servlet.http.HttpServletRequestWrapper;
8 public final class MutableHttpServletRequest extends HttpServletRequestWrapper {
9 // holds custom header and value mapping
10 private final Map<String, String> customHeaders;
12 public MutableHttpServletRequest(HttpServletRequest request){
14 this.customHeaders = new HashMap<>();
17 public void putHeader(String name, String value){
18 this.customHeaders.put(name, value);
21 public String getHeader(String name) {
22 // check the custom headers first
23 String headerValue = customHeaders.get(name);
25 if (headerValue != null){
28 // else return from into the original wrapped object
29 return ((HttpServletRequest) getRequest()).getHeader(name);
32 public Enumeration<String> getHeaderNames() {
33 // create a set of the custom header names
34 Set<String> set = new HashSet<>(customHeaders.keySet());
36 // now add the headers from the wrapped request object
37 @SuppressWarnings("unchecked")
38 Enumeration<String> e = ((HttpServletRequest) getRequest()).getHeaderNames();
39 while (e.hasMoreElements()) {
40 // add the names of the request headers into the list
41 String n = e.nextElement();
45 // create an enumeration from the set and return
46 return Collections.enumeration(set);