NotifierUtilities.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.engine;

  21. import org.slf4j.Logger;
  22. import org.openspcoop2.core.constants.Costanti;
  23. import org.openspcoop2.core.constants.TipoPdD;
  24. import org.openspcoop2.message.OpenSPCoop2Message;
  25. import org.openspcoop2.pdd.core.PdDContext;
  26. import org.openspcoop2.pdd.core.handlers.BaseContext;
  27. import org.openspcoop2.pdd.core.handlers.PreInRequestContext;
  28. import org.openspcoop2.pdd.core.handlers.notifier.NotifierType;

  29. /**    
  30.  * NotifierUtilities
  31.  *
  32.  * @author Poli Andrea (poli@link.it)
  33.  * @author $Author$
  34.  * @version $Rev$, $Date$
  35.  */
  36. public class NotifierUtilities {

  37.     public static String getIdTransazione(NotifierType notifierType, Object context){
  38.         PdDContext pddContext = getPddContext(notifierType, context);
  39.         if(pddContext!=null) {
  40.             return (String) pddContext.getObject(Costanti.ID_TRANSAZIONE);
  41.         }
  42.         return null;
  43.     }
  44.    
  45.     public static PdDContext getPddContext(NotifierType notifierType, Object context){
  46.         switch (notifierType) {
  47.         case PRE_IN_REQUEST:
  48.             PreInRequestContext preInRequestContext = (PreInRequestContext) context;
  49.             return preInRequestContext.getPddContext();
  50.         case IN_REQUEST:
  51.         case IN_REQUEST_PROTOCOL_INFO:
  52.         case OUT_REQUEST:
  53.         case POST_OUT_REQUEST:
  54.         case PRE_IN_RESPONSE:
  55.         case IN_RESPONSE:
  56.         case OUT_RESPONSE:
  57.         case POST_OUT_RESPONSE:
  58.             BaseContext baseContext = (BaseContext) context;
  59.             return baseContext.getPddContext();

  60.         default:
  61.             return null;
  62.         }
  63.     }
  64.    
  65.     public static TipoPdD getTipoPorta(NotifierType notifierType, Object context){
  66.         switch (notifierType) {
  67.         case PRE_IN_REQUEST:
  68.             PreInRequestContext preInRequestContext = (PreInRequestContext) context;
  69.             return preInRequestContext.getTipoPorta();
  70.         case IN_REQUEST:
  71.         case IN_REQUEST_PROTOCOL_INFO:
  72.         case OUT_REQUEST:
  73.         case POST_OUT_REQUEST:
  74.         case PRE_IN_RESPONSE:
  75.         case IN_RESPONSE:
  76.         case OUT_RESPONSE:
  77.         case POST_OUT_RESPONSE:
  78.             BaseContext baseContext = (BaseContext) context;
  79.             return baseContext.getTipoPorta();

  80.         default:
  81.             return null;
  82.         }
  83.     }
  84.    
  85.     public static Logger getLogger(NotifierType notifierType, Object context){
  86.         switch (notifierType) {
  87.         case PRE_IN_REQUEST:
  88.             PreInRequestContext preInRequestContext = (PreInRequestContext) context;
  89.             return preInRequestContext.getLogCore();
  90.         case IN_REQUEST:
  91.         case IN_REQUEST_PROTOCOL_INFO:
  92.         case OUT_REQUEST:
  93.         case POST_OUT_REQUEST:
  94.         case PRE_IN_RESPONSE:
  95.         case IN_RESPONSE:
  96.         case OUT_RESPONSE:
  97.         case POST_OUT_RESPONSE:
  98.             BaseContext baseContext = (BaseContext) context;
  99.             return baseContext.getLogCore();

  100.         default:
  101.             return null;
  102.         }
  103.     }
  104.    
  105.     public static OpenSPCoop2Message getOpenSPCoopMessage(NotifierType notifierType, Object context){
  106.         switch (notifierType) {
  107.         case PRE_IN_REQUEST:
  108.             return null;
  109.         case IN_REQUEST:
  110.         case IN_REQUEST_PROTOCOL_INFO:
  111.         case OUT_REQUEST:
  112.         case POST_OUT_REQUEST:
  113.         case PRE_IN_RESPONSE:
  114.         case IN_RESPONSE:
  115.         case OUT_RESPONSE:
  116.         case POST_OUT_RESPONSE:
  117.             BaseContext baseContext = (BaseContext) context;
  118.             return baseContext.getMessaggio();

  119.         default:
  120.             return null;
  121.         }
  122.     }
  123.    
  124. }