ServerInfoInInterceptor.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.utils.service.context.server;

  21. import java.util.HashSet;
  22. import java.util.Set;

  23. import org.apache.cxf.common.injection.NoJSR250Annotations;
  24. import org.apache.cxf.ext.logging.event.DefaultLogEventMapper;
  25. import org.apache.cxf.ext.logging.event.LogEvent;
  26. import org.apache.cxf.interceptor.Fault;
  27. import org.apache.cxf.message.Message;
  28. import org.openspcoop2.utils.LoggerWrapperFactory;
  29. import org.openspcoop2.utils.transport.http.HttpRequestMethod;


  30. /**
  31.  * ServerInfoInInterceptor
  32.  *
  33.  * @author Lorenzo Nardi (nardi@link.it)
  34.  * @author $Author$
  35.  * @version $Rev$, $Date$
  36.  */
  37. @NoJSR250Annotations
  38. public class ServerInfoInInterceptor extends org.apache.cxf.ext.logging.LoggingInInterceptor {

  39.     private ServerConfig serverConfig;
  40.     private ServerInfoUtilities utilities;
  41.    
  42.     public ServerInfoInInterceptor() {
  43.         super();
  44.     }

  45.     public ServerConfig getServerConfig() {
  46.         return this.serverConfig;
  47.     }

  48.     public void setServerConfig(ServerConfig serverConfig) {
  49.         this.serverConfig = serverConfig;
  50.         this.utilities = new ServerInfoUtilities(this.serverConfig);
  51.     }
  52.    
  53.     @Override
  54.     public void handleMessage(Message message) throws Fault {
  55.        
  56.         try {

  57.             ServerInfoRequest request = new ServerInfoRequest();
  58.            
  59.             Set<String> sensitiveProtocolHeaders = new HashSet<String>();
  60.             final LogEvent event = new DefaultLogEventMapper().map(message, sensitiveProtocolHeaders);
  61.            
  62.             request.setAddress(event.getAddress());
  63.             request.setHttpRequestMethod(HttpRequestMethod.valueOf(event.getHttpMethod().toUpperCase()));
  64.            
  65.             this.utilities.processBeforeSend(request);
  66.            
  67.         } catch (Throwable e) {
  68.             LoggerWrapperFactory.getLogger(ServerInfoInInterceptor.class).error(e.getMessage(),e);
  69.             throw new Fault(e);
  70.         }
  71.     }

  72. }