HttpRequestWrapper.java

  1. /*
  2.  * GovWay - A customizable API Gateway
  3.  * https://govway.org
  4.  *
  5.  * Copyright (c) 2005-2025 Link.it srl (https://link.it).
  6.  *
  7.  * This program is free software: you can redistribute it and/or modify
  8.  * it under the terms of the GNU General Public License version 3, as published by
  9.  * the Free Software Foundation.
  10.  *
  11.  * This program is distributed in the hope that it will be useful,
  12.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.  * GNU General Public License for more details.
  15.  *
  16.  * You should have received a copy of the GNU General Public License
  17.  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  18.  *
  19.  */
  20. package org.openspcoop2.core.config.rs.server.api.impl;

  21. import java.util.HashMap;

  22. import javax.servlet.http.HttpServletRequest;

  23. import org.openspcoop2.utils.transport.http.WrappedHttpServletRequest;

  24. /**
  25.  * HttpRequestWrapper
  26.  *
  27.  * @author $Author$
  28.  * @version $Rev$, $Date$
  29.  *
  30.  */
  31. public class HttpRequestWrapper extends WrappedHttpServletRequest  {

  32.     private HashMap<String,String> overrides = new HashMap<>();
  33.     private HashMap<String,String[]> overridesValues = new HashMap<>();
  34.    
  35.     @Override
  36.     public String getParameter(String key) {
  37.         if (this.overrides.get(key) != null) {
  38.             return this.overrides.get(key);
  39.         }
  40.        
  41.         return super.getParameter(key);
  42.     }
  43.    
  44.     public void overrideParameter(String key, Object value) {
  45.         if (value == null)
  46.             this.overrides.put(key, null);
  47.         else
  48.             this.overrides.put(key, value.toString());
  49.     }
  50.    
  51.     public void overrideParameterValues(String key, String[] values) {
  52.         this.overridesValues.put(key, values);
  53.     }
  54.    
  55.     @Override
  56.     public String[] getParameterValues(String arg0) {
  57.         if ( this.overridesValues.get(arg0) != null)
  58.             return this.overridesValues.get(arg0);
  59.        
  60.         return super.getParameterValues(arg0);
  61.     }

  62.     public HttpRequestWrapper(HttpServletRequest httpServletRequest) {
  63.         super(httpServletRequest);
  64.     }

  65. }