ServerInfoOutInterceptor.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. /**
  30.  * ServerInfoOutInterceptor
  31.  *
  32.  * @author Lorenzo Nardi (nardi@link.it)
  33.  * @author $Author$
  34.  * @version $Rev$, $Date$
  35.  */
  36. @NoJSR250Annotations
  37. public class ServerInfoOutInterceptor extends org.apache.cxf.ext.logging.LoggingOutInterceptor {

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

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

  47.     public void setServerConfig(ServerConfig serverConfig) {
  48.         this.serverConfig = serverConfig;
  49.         this.utilities = new ServerInfoUtilities(this.serverConfig);
  50.     }
  51.    
  52.     @Override
  53.     public void handleMessage(Message message) throws Fault {
  54.        
  55.         try {
  56.        
  57.             ServerInfoResponse response = new ServerInfoResponse();
  58.            
  59.             Set<String> sensitiveProtocolHeaders = new HashSet<String>();
  60.             final LogEvent event = new DefaultLogEventMapper().map(message, sensitiveProtocolHeaders);
  61.                
  62.             try {
  63.                 if(event.getResponseCode()!=null) {
  64.                     response.setResponseCode(Integer.parseInt(event.getResponseCode()));
  65.                 }
  66.             }catch(Throwable t) {
  67.             }
  68.            
  69.             this.utilities.processAfterSend(response);
  70.            
  71.         } catch (Throwable e) {
  72.             LoggerWrapperFactory.getLogger(ServerInfoInInterceptor.class).error(e.getMessage(),e);
  73.             throw new Fault(e);
  74.         }
  75.     }
  76. }