ContextFeature.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.Bus;
  22. import org.apache.cxf.annotations.Provider;
  23. import org.apache.cxf.annotations.Provider.Type;
  24. import org.apache.cxf.common.injection.NoJSR250Annotations;
  25. import org.apache.cxf.feature.AbstractFeature;
  26. import org.apache.cxf.interceptor.InterceptorProvider;
  27. import org.openspcoop2.utils.logger.beans.context.core.Role;
  28. import org.openspcoop2.utils.service.context.dump.DumpConfig;
  29. import org.openspcoop2.utils.service.context.dump.DumpFeature;

  30. /**
  31.  * ContextFeature
  32.  *
  33.  * @author Lorenzo Nardi (nardi@link.it)
  34.  * @author $Author$
  35.  * @version $Rev$, $Date$
  36.  */
  37. @NoJSR250Annotations
  38. @Provider(value = Type.Feature)
  39. public class ContextFeature extends AbstractFeature {
  40.    
  41.     private ContextInInterceptor in;
  42.     private ContextOutInterceptor out;
  43.     private ContextConfig contextConfig;

  44.     public ContextFeature() {
  45.         this.in = new ContextInInterceptor();
  46.         this.out = new ContextOutInterceptor();
  47.     }

  48.     public IContextFactory getContextFactory() {
  49.         return this.in.getContextFactory();
  50.     }
  51.     public void setContextFactory(IContextFactory contextFactory) {
  52.         this.in.setContextFactory(contextFactory);
  53.     }
  54.    
  55.     public ContextConfig getContextConfig() {
  56.         return this.contextConfig;
  57.     }
  58.     public void setContextConfig(ContextConfig contextConfig) {
  59.         this.contextConfig = contextConfig;
  60.         this.in.setContextConfig(contextConfig);
  61.         this.out.setContextConfig(contextConfig);
  62.     }
  63.    
  64.     @Override
  65.     protected void initializeProvider(InterceptorProvider provider, Bus bus) {
  66.        
  67.         if(this.contextConfig==null) {
  68.             this.contextConfig = new ContextConfig();
  69.             this.in.setContextConfig(this.contextConfig);
  70.             this.out.setContextConfig(this.contextConfig);
  71.         }
  72.        
  73.         provider.getInInterceptors().add(this.in);
  74.         provider.getInFaultInterceptors().add(this.in);
  75.                
  76.         if(this.contextConfig.isFillServiceInfo()) {
  77.             ServiceInfoInInterceptor infoIn = new ServiceInfoInInterceptor();
  78.             provider.getInInterceptors().add(infoIn);
  79.             provider.getInFaultInterceptors().add(infoIn);
  80.         }
  81.        
  82.         provider.getOutInterceptors().add(this.out);
  83.         provider.getOutFaultInterceptors().add(this.out);
  84.        
  85.         if(this.contextConfig.isFillServiceInfo()) {
  86.             ServiceInfoOutInterceptor infoOut = new ServiceInfoOutInterceptor();
  87.             provider.getOutInterceptors().add(infoOut);
  88.             provider.getOutFaultInterceptors().add(infoOut);
  89.         }
  90.        
  91.         if(this.contextConfig.isDump()) {
  92.             DumpFeature dumpFeature = new DumpFeature();
  93.             DumpConfig dumpConfig = this.contextConfig.getDumpConfig();
  94.             if(dumpConfig==null) {
  95.                 dumpConfig = new DumpConfig();
  96.             }
  97.             dumpConfig.setRole(Role.SERVER);
  98.             dumpFeature.setDumpConfig(dumpConfig);
  99.             dumpFeature.doInitializeProvider(provider,bus);
  100.         }

  101.     }
  102. }