2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.openecomp.sdc.webseal.simulator;
24 import javax.servlet.http.HttpServletRequest;
25 import javax.servlet.http.HttpServletRequestWrapper;
28 public final class MutableHttpServletRequest extends HttpServletRequestWrapper {
29 // holds custom header and value mapping
30 private final Map<String, String> customHeaders;
32 public MutableHttpServletRequest(HttpServletRequest request){
34 this.customHeaders = new HashMap<>();
37 public void putHeader(String name, String value){
38 this.customHeaders.put(name, value);
41 public String getHeader(String name) {
42 // check the custom headers first
43 String headerValue = customHeaders.get(name);
45 if (headerValue != null){
48 // else return from into the original wrapped object
49 return ((HttpServletRequest) getRequest()).getHeader(name);
52 public Enumeration<String> getHeaderNames() {
53 // create a set of the custom header names
54 Set<String> set = new HashSet<>(customHeaders.keySet());
56 // now add the headers from the wrapped request object
57 @SuppressWarnings("unchecked")
58 Enumeration<String> e = ((HttpServletRequest) getRequest()).getHeaderNames();
59 while (e.hasMoreElements()) {
60 // add the names of the request headers into the list
61 String n = e.nextElement();
65 // create an enumeration from the set and return
66 return Collections.enumeration(set);