ServerInfoContextFeature.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 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.  * ServerInfoContextFeature
  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 ServerInfoContextFeature extends AbstractFeature {
  40.    
  41.     private ServerInfoInInterceptor in;
  42.     private ServerInfoOutInterceptor out;
  43.     private ServerConfig serverConfig;

  44.     public ServerInfoContextFeature() {
  45.         this.in = new ServerInfoInInterceptor();
  46.         this.out = new ServerInfoOutInterceptor();
  47.     }


  48.     public ServerConfig getServerConfig() {
  49.         return this.serverConfig;
  50.     }

  51.     public void setServerConfig(ServerConfig serverConfig) {
  52.         this.serverConfig = serverConfig;
  53.         ServerInfoUtilities.checkOperationId(this.serverConfig);
  54.         this.in.setServerConfig(this.serverConfig);
  55.         this.out.setServerConfig(this.serverConfig);
  56.     }
  57.    
  58.     @Override
  59.     protected void initializeProvider(InterceptorProvider provider, Bus bus) {
  60.        
  61.         if(this.serverConfig==null) {
  62.             this.serverConfig = new ServerConfig();
  63.             ServerInfoUtilities.checkOperationId(this.serverConfig); // add id
  64.             this.in.setServerConfig(this.serverConfig);
  65.             this.out.setServerConfig(this.serverConfig);
  66.         }
  67.        
  68.         provider.getInInterceptors().add(this.in);
  69.         provider.getInFaultInterceptors().add(this.in);
  70.        
  71.         provider.getOutInterceptors().add(this.out);
  72.         provider.getOutFaultInterceptors().add(this.out);
  73.        
  74.         if(this.serverConfig.isDump()) {
  75.            
  76.             DumpFeature dumpFeature = new DumpFeature();
  77.             DumpConfig dumpConfig = this.serverConfig.getDumpConfig();
  78.             if(dumpConfig==null) {
  79.                 dumpConfig = new DumpConfig();
  80.             }
  81.             dumpConfig.setRole(Role.CLIENT);
  82.             dumpFeature.setDumpConfig(dumpConfig);
  83.             dumpFeature.setServerConfig(this.serverConfig);
  84.             dumpFeature.doInitializeProvider(provider,bus);
  85.            
  86.         }
  87.        
  88.     }
  89. }