FormUrlEncodedFilter.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.pdd.services.connector;

  21. import java.io.IOException;

  22. import javax.servlet.Filter;
  23. import javax.servlet.FilterChain;
  24. import javax.servlet.FilterConfig;
  25. import javax.servlet.ServletException;
  26. import javax.servlet.ServletRequest;
  27. import javax.servlet.ServletResponse;
  28. import javax.servlet.http.HttpServletRequest;

  29. import org.openspcoop2.pdd.config.OpenSPCoop2Properties;


  30. /**
  31.  * FormUrlEncodedFilter
  32.  *
  33.  * @author Poli Andrea (apoli@link.it)
  34.  * @author $Author$
  35.  * @version $Rev$, $Date$
  36.  */
  37. public class FormUrlEncodedFilter implements Filter {

  38.     /*
  39.      * NOTA: da Wilfdly 8.1 questo filtro deve essere abilitato nella configurazione:
  40.      * In the standalone/configuration/standalone.xml file change the servlet-container XML element so that it has the attribute allow-non-standard-wrappers="true".
  41.      *
  42.      *  <servlet-container name="default" allow-non-standard-wrappers="true">
  43.      *           ...
  44.      *  </servlet-container>
  45.      **/
  46.    
  47.     @Override
  48.     public void destroy() {
  49.     }

  50.     @Override
  51.     public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain)
  52.             throws IOException, ServletException {
  53.        
  54.         boolean doFilter = false;
  55.         try {
  56.             OpenSPCoop2Properties op2PropertieS = OpenSPCoop2Properties.getInstance();
  57.             doFilter = op2PropertieS.isFormUrlEncodedFilterEnabled();
  58.         }catch(Throwable t) {}
  59.        
  60.        
  61.         if(doFilter && req instanceof HttpServletRequest) {
  62.             HttpServletRequest httpServletRequest = (HttpServletRequest) req;
  63.             if(FormUrlEncodedHttpServletRequest.isFormUrlEncodedRequest(httpServletRequest)) {
  64.                 req = FormUrlEncodedHttpServletRequest.convert(httpServletRequest);
  65.             }
  66.         }
  67.        
  68.         chain.doFilter(req, res);
  69.     }

  70.     @Override
  71.     public void init(FilterConfig config) throws ServletException {
  72.     }

  73. }