ContextOutInterceptor.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;

  21. import org.apache.cxf.interceptor.Fault;
  22. import org.apache.cxf.message.Message;
  23. import org.apache.cxf.phase.AbstractPhaseInterceptor;
  24. import org.apache.cxf.phase.Phase;
  25. import org.openspcoop2.utils.LoggerWrapperFactory;

  26. /**
  27.  * ContextOutInterceptor
  28.  *
  29.  * @author Lorenzo Nardi (nardi@link.it)
  30.  * @author $Author$
  31.  * @version $Rev$, $Date$
  32.  */
  33. public class ContextOutInterceptor extends AbstractPhaseInterceptor<Message> {

  34.     private ContextConfig contextConfig = null;
  35.    
  36.     public ContextOutInterceptor() {
  37.         super(Phase.SETUP_ENDING);
  38.     }

  39.     public ContextConfig getContextConfig() {
  40.         return this.contextConfig;
  41.     }
  42.     public void setContextConfig(ContextConfig contextConfig) {
  43.         this.contextConfig = contextConfig;
  44.     }
  45.    
  46.     @Override
  47.     public void handleMessage(Message message) throws Fault {
  48.         try {
  49.             IContext context = ContextThreadLocal.get();
  50.             if(this.contextConfig.isEmitTransaction()) {
  51.                 context.getApplicationLogger().log();
  52.             }
  53.             ContextThreadLocal.unset();
  54.         } catch (Throwable e) {
  55.             LoggerWrapperFactory.getLogger(ContextInInterceptor.class).error(e.getMessage(),e);
  56.             throw new Fault(e);
  57.         }
  58.     }

  59. }