ControlStationJMSCore.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.web.ctrlstat.core;

  21. import java.util.List;
  22. import java.util.Map;
  23. import java.util.Properties;

  24. import javax.jms.ObjectMessage;
  25. import javax.jms.Queue;
  26. import javax.jms.QueueConnection;
  27. import javax.jms.QueueConnectionFactory;
  28. import javax.jms.QueueSender;
  29. import javax.jms.QueueSession;
  30. import javax.jms.Session;
  31. import javax.naming.InitialContext;

  32. import org.openspcoop2.web.ctrlstat.costanti.OperationsParameter;
  33. import org.openspcoop2.web.ctrlstat.costanti.TipoOggettoDaSmistare;
  34. import org.openspcoop2.web.lib.queue.costanti.Operazione;

  35. /**
  36.  * ControlStationJMSCore
  37.  *
  38.  * @author Andrea Poli (apoli@link.it)
  39.  * @author $Author$
  40.  * @version $Rev$, $Date$
  41.  *
  42.  */
  43. public class ControlStationJMSCore {

  44.     /**
  45.      * Inoltra l'operazione nella coda dello smistatore in caso di errori lancia
  46.      * un'eccezione che verra' gestita dal chiamante
  47.      *
  48.      * @param operazioneDaSmistare
  49.      * @throws Exception
  50.      */
  51.     public static void setDati(OperazioneDaSmistare operazioneDaSmistare,String smistatoreQueue,String cfName,Properties cfProp) throws Exception {

  52.         QueueConnection qc = null;
  53.         QueueSession qs = null;
  54.         QueueSender sender = null;
  55.         try{

  56.             // Estraggo i dati dall'Operazione da smistare, che tanto mi servono
  57.             // per settare la StringProperty
  58.             long idTable = operazioneDaSmistare.getIDTable();
  59.             Operazione operazione = operazioneDaSmistare.getOperazione();
  60.             String pdd = operazioneDaSmistare.getPdd();
  61.             TipoOggettoDaSmistare oggettoDaSmistare = operazioneDaSmistare.getOggetto();
  62.    
  63.             ControlStationCore.log.debug("[ControlStationCore::setDati] id[" + idTable + "] operazione[" + operazione.name() +
  64.                     "] pdd[" + pdd + "] oggetto[" + oggettoDaSmistare.name() + "]");
  65.    
  66.             InitialContext ctx = new InitialContext(cfProp);
  67.             Queue queue = (Queue) ctx.lookup(smistatoreQueue);
  68.             QueueConnectionFactory qcf = (QueueConnectionFactory) ctx.lookup(cfName);
  69.             qc = qcf.createQueueConnection();
  70.             qs = qc.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
  71.             sender = qs.createSender(queue);
  72.             ctx.close();
  73.    
  74.             // Create a message
  75.             ObjectMessage message = qs.createObjectMessage(operazioneDaSmistare);
  76.    
  77.             // Preparo la StringProperty, che serve per il filtro
  78.             StringBuilder idOperazione = new StringBuilder();
  79.             idOperazione.append("[" + operazione.name() + "]");
  80.             idOperazione.append("[" + oggettoDaSmistare.name() + "]");
  81.    
  82.             Map<OperationsParameter, List<String>> params = operazioneDaSmistare.getParameters();
  83.             if(params!=null && !params.isEmpty()) {
  84.                 // aggiungo informazioni il filtro
  85.                 for (OperationsParameter key : params.keySet()) {
  86.                     List<String> values = params.get(key);
  87.                     for (String value : values) {
  88.                         idOperazione.append("[" + value + "]");
  89.                     }
  90.        
  91.                 }
  92.             }
  93.    
  94.             ControlStationCore.log.debug("[ControlStationCore::setDati] id=[" + idOperazione.toString() + "]");
  95.             message.setStringProperty("ID", idOperazione.toString());
  96.    
  97.             // send a message
  98.             sender.send(message);

  99.         }finally {
  100.             try {
  101.                 if(sender!=null) {
  102.                     sender.close();
  103.                 }
  104.             }catch(Throwable t) {
  105.                 // ignore
  106.             }
  107.             try {
  108.                 if(qs!=null) {
  109.                     qs.close();
  110.                 }
  111.             }catch(Throwable t) {
  112.                 // ignore
  113.             }
  114.             try {
  115.                 if(qc!=null) {
  116.                     qc.close();
  117.                 }
  118.             }catch(Throwable t) {
  119.                 // ignore
  120.             }
  121.         }

  122.     }
  123.    
  124. }