CORSFilter.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.filter;

  21. import java.io.IOException;

  22. import org.openspcoop2.core.config.rs.server.config.LoggerProperties;
  23. import org.openspcoop2.core.config.rs.server.config.ServerProperties;
  24. import org.openspcoop2.utils.transport.http.AbstractCORSFilter;
  25. import org.openspcoop2.utils.transport.http.CORSFilterConfiguration;
  26. import org.slf4j.Logger;

  27. /**
  28.  * CORSFilter
  29.  *
  30.  * @author $Author$
  31.  * @version $Rev$, $Date$
  32.  *
  33.  */
  34. public class CORSFilter extends AbstractCORSFilter {

  35.     private static CORSFilterConfiguration CORS_FILTER_CONFIGURATION;
  36.     private static synchronized void initCORSFilterConfiguration() throws IOException {
  37.         if(CORS_FILTER_CONFIGURATION==null) {
  38.             try {
  39.                 ServerProperties serverProperties = ServerProperties.getInstance();
  40.                 CORS_FILTER_CONFIGURATION = new CORSFilterConfiguration();
  41.                 CORS_FILTER_CONFIGURATION.init(serverProperties.getProperties());
  42.             }catch(Exception e) {
  43.                 throw new IOException(e.getMessage(),e);
  44.             }
  45.         }
  46.     }
  47.     private static CORSFilterConfiguration getCORSFilterConfiguration() throws IOException {
  48.         if(CORS_FILTER_CONFIGURATION==null) {
  49.             initCORSFilterConfiguration();
  50.         }
  51.         return CORS_FILTER_CONFIGURATION;
  52.     }
  53.    
  54.     @Override
  55.     protected CORSFilterConfiguration getConfig() throws IOException {
  56.         return getCORSFilterConfiguration();
  57.     }

  58.     @Override
  59.     protected Logger getLog() {
  60.         return LoggerProperties.getLoggerCore();
  61.     }

  62. }