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.monitor.rs.server.api.impl.utils;

  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.containsKey(key)) {
  38.             return this.overrides.get(key);
  39.         }
  40.        
  41.         return null; // senno vengono presi i parametri della query url originale e potrebbero essere stati usati nomi simili
  42.         //return super.getParameter(key);
  43.     }
  44.    
  45.     public void overrideParameter(String key, Object value) {
  46.         if (value == null)
  47.             this.overrides.put(key, null);
  48.         else
  49.             this.overrides.put(key, value.toString());
  50.     }
  51.    
  52.     public void overrideParameterValues(String key, String[] values) {
  53.         this.overridesValues.put(key, values);
  54.     }
  55.    
  56.     @Override
  57.     public String[] getParameterValues(String arg0) {
  58.         if ( this.overridesValues.get(arg0) != null)
  59.             return this.overridesValues.get(arg0);
  60.        
  61.         return null; // senno vengono presi i parametri della query url originale e potrebbero essere stati usati nomi simili
  62.         //return super.getParameterValues(arg0);
  63.     }

  64.     public HttpRequestWrapper(HttpServletRequest httpServletRequest) {
  65.         super(httpServletRequest);
  66.     }

  67. }