NodeSenderJMS.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.node;

  21. import java.io.Serializable;

  22. import org.openspcoop2.core.id.IDSoggetto;
  23. import org.openspcoop2.pdd.core.AbstractCore;
  24. import org.openspcoop2.pdd.core.GestoreMessaggi;
  25. import org.openspcoop2.pdd.core.JMSSender;
  26. import org.openspcoop2.pdd.core.PdDContext;
  27. import org.openspcoop2.pdd.logger.MsgDiagnostico;
  28. import org.openspcoop2.pdd.logger.OpenSPCoop2Logger;
  29. import org.openspcoop2.pdd.mdb.GenericMessage;
  30. import org.openspcoop2.protocol.sdk.state.RequestInfo;
  31. import org.openspcoop2.protocol.sdk.state.RequestInfoConfigUtilities;

  32. /**
  33.  * Classe utilizzata per la spedizione di messaggi contenuti nell'architettura di OpenSPCoop (versione JMS).
  34.  *
  35.  * @author Poli Andrea (apoli@link.it)
  36.  * @author $Author$
  37.  * @version $Rev$, $Date$
  38.  */

  39. public class NodeSenderJMS extends AbstractCore implements INodeSender{

  40.     /**
  41.      * Spedizione di un messaggio  
  42.      *
  43.      * @param msg Messaggio
  44.      * @param destinazione Modulo di destinazione del msg
  45.      * @param codicePorta Codice Porta per cui effettuare la receive
  46.      * @param idModulo Nodo destinatario per cui effettuare la ricezione.
  47.      * @param idMessaggio Identificativo del messaggio
  48.      *
  49.      */
  50.     @Override
  51.     public void send(Serializable msg, String destinazione, MsgDiagnostico msgDiag,
  52.             IDSoggetto codicePorta, String idModulo, String idMessaggio, GestoreMessaggi gm)
  53.             throws NodeException {
  54.        
  55.         // Elimino dalla RequestInfo i dati "cached"
  56.         RequestInfo requestInfoBackup = null;
  57.         PdDContext pddContext = null;
  58.         java.util.Map<String,Object> dynamicContext = null;
  59.         if(msg instanceof GenericMessage) {
  60.             GenericMessage mm = (GenericMessage) msg;
  61.             pddContext = mm.getPddContext();
  62.             if(pddContext!=null) {
  63.                 requestInfoBackup = RequestInfoConfigUtilities.normalizeRequestInfoBeforeSerialization(pddContext);
  64.                 dynamicContext = org.openspcoop2.core.constants.Costanti.removeDynamicMap(pddContext);
  65.             }
  66.         }      
  67.         try{
  68.            
  69.             JMSSender senderJMS = new JMSSender(codicePorta,idModulo,OpenSPCoop2Logger.getLoggerOpenSPCoopCore(), PdDContext.getValue(org.openspcoop2.core.constants.Costanti.ID_TRANSAZIONE, this.getPddContext()));
  70.             if(!senderJMS.send(destinazione,
  71.                     msg,idMessaggio)){
  72.                 if(senderJMS.getException()!=null)
  73.                     throw new NodeException("Spedizione jms con errore: "+ senderJMS.getErrore(),senderJMS.getException());
  74.                 else
  75.                     throw new NodeException("Spedizione jms con errore: "+ senderJMS.getErrore());
  76.             }else{
  77.                 msgDiag.highDebug("ObjectMessage send via JMS.");
  78.             }
  79.         } catch (Exception e) {
  80.             throw new NodeException(e.getMessage(),e);
  81.            
  82.         }finally {
  83.             if(requestInfoBackup!=null) {
  84.                 RequestInfoConfigUtilities.restoreRequestInfoAfterSerialization(pddContext, requestInfoBackup);
  85.             }
  86.             if(dynamicContext!=null) {
  87.                 pddContext.put(org.openspcoop2.core.constants.Costanti.DYNAMIC_MAP_CONTEXT, dynamicContext);
  88.             }
  89.         }
  90.     }

  91. }