NotifierPreInRequestHandler.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.pdd.core.handlers.notifier;

  21. import java.util.List;

  22. import org.openspcoop2.pdd.config.ClassNameProperties;
  23. import org.openspcoop2.pdd.config.OpenSPCoop2Properties;
  24. import org.openspcoop2.pdd.core.handlers.HandlerException;
  25. import org.openspcoop2.pdd.core.handlers.PreInRequestContext;
  26. import org.openspcoop2.pdd.core.handlers.PreInRequestHandler;
  27. import org.openspcoop2.utils.resources.Loader;
  28. import org.openspcoop2.utils.io.notifier.NotifierInputStreamParams;
  29. import org.openspcoop2.utils.io.notifier.StreamingHandler;

  30. /**
  31.  * NotifierPreInRequestHandler
  32.  *
  33.  * @author Poli Andrea (apoli@link.it)
  34.  * @author $Author$
  35.  * @version $Rev$, $Date$
  36.  */
  37. public class NotifierPreInRequestHandler implements PreInRequestHandler {

  38.     @Override
  39.     public void invoke(PreInRequestContext context) throws HandlerException {
  40.        
  41.         try{
  42.        
  43.             OpenSPCoop2Properties properties = OpenSPCoop2Properties.getInstance();
  44.             ClassNameProperties classNameProperties = ClassNameProperties.getInstance();
  45.             if(properties.isNotifierInputStreamEnabled()) {
  46.                 String notifierInputStreamCallback = properties.getNotifierInputStreamCallback();
  47.                 INotifierCallback notifierCallback = (INotifierCallback) Loader.getInstance().newInstance(classNameProperties.getNotifierCallback(notifierInputStreamCallback));
  48.                 if(notifierCallback.enableNotifierInputStream(NotifierType.PRE_IN_REQUEST, context)){
  49.                    
  50.                     NotifierInputStreamParams notifierInputStreamParams = new NotifierInputStreamParams();
  51.                    
  52.                     // Notify
  53.                     NotifierResult notifierResult = notifierCallback.notify(NotifierType.PRE_IN_REQUEST, context);
  54.                    
  55.                     notifierInputStreamParams.setBufferEnabled(NotifierBufferState.ENABLE.equals(notifierResult.getBufferState()));
  56.                    
  57.                     List<StreamingHandler> streamingHandlers = notifierResult.getStreamingHandlers();
  58.                     if(streamingHandlers!=null && streamingHandlers.size()>0){
  59.                         for (StreamingHandler streamingHandler : streamingHandlers) {
  60.                             notifierInputStreamParams.addStreamingHandler(streamingHandler);
  61.                         }
  62.                     }
  63.                    
  64.                     notifierInputStreamParams.setThrowStreamingHandlerException(notifierCallback.throwStreamingHandlerException(NotifierType.PRE_IN_REQUEST, context));
  65.                
  66.                     notifierInputStreamParams.setLog(context.getLogCore());
  67.                    
  68.                     context.setNotifierInputStreamParams(notifierInputStreamParams);
  69.                 }
  70.             }
  71.            
  72.         }catch(Exception e){
  73.             throw new HandlerException(e.getMessage(),e);
  74.         }
  75.     }

  76. }