MonitorUtilities.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.servlet.monitor;

  21. import java.math.BigInteger;
  22. import java.util.List;

  23. import javax.xml.ws.BindingProvider;

  24. import org.openspcoop2.pdd.monitor.Messaggio;
  25. import org.openspcoop2.pdd.monitor.StatoPdd;
  26. import org.openspcoop2.pdd.monitor.driver.FilterSearch;
  27. import org.openspcoop2.pdd.monitor.driver.FiltroStatoConsegnaAsincrona;
  28. import org.openspcoop2.pdd.monitor.driver.StatoConsegneAsincrone;
  29. import org.openspcoop2.web.ctrlstat.core.ControlStationLogger;
  30. import org.openspcoop2.web.ctrlstat.dao.PdDControlStation;

  31. /**
  32. *
  33. * MonitorUtilities
  34. *
  35. * @author Andrea Poli (apoli@link.it)
  36. * @author $Author$
  37. * @version $Rev$, $Date$
  38. *
  39. */
  40. public class MonitorUtilities {

  41.     public static long countListaRichiestePendenti(FilterSearch filter,String pddName, String sorgenteDati) throws Exception{
  42.         if(Monitor.singlePdD){
  43.             return Monitor.driverMonitoraggioLocale.get(sorgenteDati).countListaRichiestePendenti(filter);
  44.         }
  45.         else{
  46.             return getMessaggioWS(pddName).count(convertToSearchFilterMessaggio(filter));
  47.         }
  48.     }
  49.    
  50.     public static List<Messaggio> getListaRichiestePendenti(FilterSearch filter,String pddName, String sorgenteDati) throws Exception{
  51.         if(Monitor.singlePdD){
  52.             return Monitor.driverMonitoraggioLocale.get(sorgenteDati).getListaRichiestePendenti(filter);
  53.         }
  54.         else{
  55.             return getMessaggioWS(pddName).findAll(convertToSearchFilterMessaggio(filter));
  56.         }
  57.     }
  58.    
  59.     public static long deleteRichiestePendenti(FilterSearch filter,String pddName, String sorgenteDati) throws Exception{
  60.         if(Monitor.singlePdD){
  61.             return Monitor.driverMonitoraggioLocale.get(sorgenteDati).deleteRichiestePendenti(filter);
  62.         }
  63.         else{
  64.             return getMessaggioWS(pddName).deleteAllByFilter(convertToSearchFilterMessaggio(filter));
  65.         }
  66.     }
  67.    
  68.     public static long aggiornaDataRispedizioneRichiestePendenti(FilterSearch filter,String pddName, String sorgenteDati) throws Exception{
  69.         if(Monitor.singlePdD){
  70.             return Monitor.driverMonitoraggioLocale.get(sorgenteDati).aggiornaDataRispedizioneRichiestePendenti(filter);
  71.         }
  72.         else{
  73.             throw new Exception("Not Implemented");
  74.         }
  75.     }
  76.    
  77.     public static StatoPdd getStatoRichiestePendenti(FilterSearch filter,String pddName, String sorgenteDati) throws Exception{
  78.         if(Monitor.singlePdD){
  79.             return Monitor.driverMonitoraggioLocale.get(sorgenteDati).getStatoRichiestePendenti(filter);
  80.         }
  81.         else{
  82.             return getStatoPddWS(pddName).find(convertToSearchFilterStatoPdd(filter));
  83.         }
  84.     }
  85.    
  86.     public static StatoConsegneAsincrone getStatoConsegneAsincrone(FiltroStatoConsegnaAsincrona filtro, String sorgenteDati) throws Exception{
  87.         if(Monitor.singlePdD){
  88.             return Monitor.driverMonitoraggioLocale.get(sorgenteDati).getStatoConsegneAsincrone(filtro);
  89.         }
  90.         else{
  91.             throw new Exception("Non supportato");
  92.         }
  93.     }
  94.    
  95.     private static String getWSUrl(String pddName, boolean statoPdD) throws Exception{
  96.         String ipPdd = null;
  97.         String protocollo = null;
  98.         int porta = 80;
  99.         try {
  100.             // ipPdd = backEndConnector.getIPPdd(queueName);
  101.             PdDControlStation pdd = Monitor.pddCore.getPdDControlStation(pddName);
  102.             ipPdd = pdd.getIpGestione();
  103.             protocollo = pdd.getProtocolloGestione();
  104.             porta = pdd.getPortaGestione();

  105.             if (ipPdd == null || protocollo == null || porta <= 0)
  106.                 throw new Exception("Parametri Porta di Dominio non validi.");

  107.         } catch (Exception e) {
  108.             ControlStationLogger.getPddConsoleCoreLogger().error("Riscontrato errore durante la get dell'ip del pdd(" + pddName + "): " + e.toString(), e);
  109.             throw new Exception("Riscontrato errore durante la get dell'ip del pdd(" + pddName + "): " + e.toString(), e);
  110.         }
  111.         String prefixUrl = protocollo + "://" + ipPdd + ":" + porta + "/";
  112.         if(statoPdD){
  113.             return prefixUrl + Monitor.consoleProperties.getGestioneCentralizzataWSMonitorEndpointSuffixStatoPdd();
  114.         }
  115.         else{
  116.             return prefixUrl + Monitor.consoleProperties.getGestioneCentralizzataWSMonitorEndpointSuffixMessaggio();
  117.         }
  118.     }
  119.    
  120.     private static org.openspcoop2.pdd.monitor.ws.client.messaggio.all.Messaggio getMessaggioWS(String pddName) throws Exception{
  121.         org.openspcoop2.pdd.monitor.ws.client.messaggio.all.MessaggioSoap11Service messaggioService =
  122.                 new org.openspcoop2.pdd.monitor.ws.client.messaggio.all.MessaggioSoap11Service();
  123.         org.openspcoop2.pdd.monitor.ws.client.messaggio.all.Messaggio messaggioPort = messaggioService.getMessaggioPortSoap11();
  124.         ((BindingProvider)messaggioPort).getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY,
  125.                 getWSUrl(pddName, false));
  126.         ((BindingProvider)messaggioPort).getRequestContext().put("schema-validation-enabled", true);
  127.         String username = Monitor.consoleProperties.getGestioneCentralizzataWSMonitorCredenzialiBasicUsername();
  128.         String password = Monitor.consoleProperties.getGestioneCentralizzataWSMonitorCredenzialiBasicPassword();
  129.         if(username !=null && password!=null){
  130.             // to use Basic HTTP Authentication:
  131.             ((BindingProvider)messaggioPort).getRequestContext().put(BindingProvider.USERNAME_PROPERTY, username);
  132.             ((BindingProvider)messaggioPort).getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, password);
  133.         }
  134.         return messaggioPort;
  135.     }
  136.    
  137.     private static org.openspcoop2.pdd.monitor.ws.client.statopdd.all.StatoPdd getStatoPddWS(String pddName) throws Exception{
  138.         org.openspcoop2.pdd.monitor.ws.client.statopdd.all.StatoPddSoap11Service statoPddService =
  139.                 new org.openspcoop2.pdd.monitor.ws.client.statopdd.all.StatoPddSoap11Service();
  140.         org.openspcoop2.pdd.monitor.ws.client.statopdd.all.StatoPdd statoPddPort = statoPddService.getStatoPddPortSoap11();
  141.         ((BindingProvider)statoPddPort).getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY,
  142.                 getWSUrl(pddName, true));
  143.         ((BindingProvider)statoPddPort).getRequestContext().put("schema-validation-enabled", true);
  144.         String username = Monitor.consoleProperties.getGestioneCentralizzataWSMonitorCredenzialiBasicUsername();
  145.         String password = Monitor.consoleProperties.getGestioneCentralizzataWSMonitorCredenzialiBasicPassword();
  146.         if(username !=null && password!=null){
  147.             // to use Basic HTTP Authentication:
  148.             ((BindingProvider)statoPddPort).getRequestContext().put(BindingProvider.USERNAME_PROPERTY, username);
  149.             ((BindingProvider)statoPddPort).getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, password);
  150.         }
  151.         return statoPddPort;
  152.     }
  153.    
  154.     private static org.openspcoop2.pdd.monitor.ws.client.messaggio.all.SearchFilterMessaggio convertToSearchFilterMessaggio(FilterSearch filter){
  155.         org.openspcoop2.pdd.monitor.ws.client.messaggio.all.SearchFilterMessaggio filterWS = new org.openspcoop2.pdd.monitor.ws.client.messaggio.all.SearchFilterMessaggio();
  156.        
  157.         if(filter.getLimit()>0){
  158.             filterWS.setLimit(new BigInteger(filter.getLimit()+""));
  159.         }
  160.         if(filter.getOffset()>=0){
  161.             filterWS.setOffset(new BigInteger(filter.getOffset()+""));
  162.         }
  163.        
  164.         org.openspcoop2.pdd.monitor.ws.client.messaggio.all.Filtro filtroInternoWS = new org.openspcoop2.pdd.monitor.ws.client.messaggio.all.Filtro();
  165.         filtroInternoWS.setTipo(filter.getTipo());
  166.         filtroInternoWS.setStato(filter.getStato());
  167.         if(filter.getSoglia()>0)
  168.             filtroInternoWS.setSoglia(filter.getSoglia());
  169.         filtroInternoWS.setMessagePattern(filter.getMessagePattern());
  170.         filtroInternoWS.setIdMessaggio(filter.getIdMessaggio());
  171.         filtroInternoWS.setCorrelazioneApplicativa(filter.getCorrelazioneApplicativa());
  172.         org.openspcoop2.pdd.monitor.ws.client.messaggio.all.Busta busta = null;
  173.         if(filter.getBusta()!=null){
  174.             busta = new org.openspcoop2.pdd.monitor.ws.client.messaggio.all.Busta();
  175.            
  176.             busta.setAttesaRiscontro(filter.getBusta().getAttesaRiscontro());
  177.             busta.setAzione(filter.getBusta().getAzione());
  178.             busta.setCollaborazione(filter.getBusta().getCollaborazione());
  179.            
  180.             org.openspcoop2.pdd.monitor.ws.client.messaggio.all.BustaSoggetto bustaDestinatario = null;
  181.             if(filter.getBusta().getDestinatario()!=null){
  182.                 bustaDestinatario = new org.openspcoop2.pdd.monitor.ws.client.messaggio.all.BustaSoggetto();
  183.                 bustaDestinatario.setNome(filter.getBusta().getDestinatario().getNome());
  184.                 bustaDestinatario.setTipo(filter.getBusta().getDestinatario().getTipo());
  185.             }
  186.             busta.setDestinatario(bustaDestinatario);
  187.            
  188.             org.openspcoop2.pdd.monitor.ws.client.messaggio.all.BustaSoggetto bustaMittente = null;
  189.             if(filter.getBusta().getMittente()!=null){
  190.                 bustaMittente = new org.openspcoop2.pdd.monitor.ws.client.messaggio.all.BustaSoggetto();
  191.                 bustaMittente.setNome(filter.getBusta().getMittente().getNome());
  192.                 bustaMittente.setTipo(filter.getBusta().getMittente().getTipo());
  193.             }
  194.             busta.setMittente(bustaMittente);
  195.            
  196.             org.openspcoop2.pdd.monitor.ws.client.messaggio.all.BustaServizio bustaServizio = null;
  197.             if(filter.getBusta().getServizio()!=null){
  198.                 bustaServizio = new org.openspcoop2.pdd.monitor.ws.client.messaggio.all.BustaServizio();
  199.                 bustaServizio.setNome(filter.getBusta().getServizio().getNome());
  200.                 bustaServizio.setTipo(filter.getBusta().getServizio().getTipo());
  201.                 //bustaServizio.setVersione(filter.getBusta().getServizio().getVersione());
  202.             }
  203.             busta.setServizio(bustaServizio);
  204.            
  205.             busta.setProfiloCollaborazione(filter.getBusta().getProfiloCollaborazione());
  206.             busta.setRiferimentoMessaggio(filter.getBusta().getRiferimentoMessaggio());
  207.         }
  208.         filtroInternoWS.setBusta(busta);
  209.         filterWS.setFiltro(filtroInternoWS);
  210.        
  211.         return filterWS;
  212.     }
  213.    
  214.     private static org.openspcoop2.pdd.monitor.ws.client.statopdd.all.SearchFilterStatoPdd convertToSearchFilterStatoPdd(FilterSearch filter){
  215.         org.openspcoop2.pdd.monitor.ws.client.statopdd.all.SearchFilterStatoPdd filterWS = new org.openspcoop2.pdd.monitor.ws.client.statopdd.all.SearchFilterStatoPdd();
  216.        
  217.         if(filter.getLimit()>0){
  218.             filterWS.setLimit(new BigInteger(filter.getLimit()+""));
  219.         }
  220.         if(filter.getOffset()>=0){
  221.             filterWS.setOffset(new BigInteger(filter.getOffset()+""));
  222.         }
  223.        
  224.         org.openspcoop2.pdd.monitor.ws.client.statopdd.all.Filtro filtroInternoWS = new org.openspcoop2.pdd.monitor.ws.client.statopdd.all.Filtro();
  225.         filtroInternoWS.setTipo(filter.getTipo());
  226.         filtroInternoWS.setStato(filter.getStato());
  227.         if(filter.getSoglia()>0)
  228.             filtroInternoWS.setSoglia(filter.getSoglia());
  229.         filtroInternoWS.setMessagePattern(filter.getMessagePattern());
  230.         filtroInternoWS.setIdMessaggio(filter.getIdMessaggio());
  231.         filtroInternoWS.setCorrelazioneApplicativa(filter.getCorrelazioneApplicativa());
  232.         org.openspcoop2.pdd.monitor.ws.client.statopdd.all.Busta busta = null;
  233.         if(filter.getBusta()!=null){
  234.             busta = new org.openspcoop2.pdd.monitor.ws.client.statopdd.all.Busta();
  235.            
  236.             busta.setAttesaRiscontro(filter.getBusta().getAttesaRiscontro());
  237.             busta.setAzione(filter.getBusta().getAzione());
  238.             busta.setCollaborazione(filter.getBusta().getCollaborazione());
  239.            
  240.             org.openspcoop2.pdd.monitor.ws.client.statopdd.all.BustaSoggetto bustaDestinatario = null;
  241.             if(filter.getBusta().getDestinatario()!=null){
  242.                 bustaDestinatario = new org.openspcoop2.pdd.monitor.ws.client.statopdd.all.BustaSoggetto();
  243.                 bustaDestinatario.setNome(filter.getBusta().getDestinatario().getNome());
  244.                 bustaDestinatario.setTipo(filter.getBusta().getDestinatario().getTipo());
  245.             }
  246.             busta.setDestinatario(bustaDestinatario);
  247.            
  248.             org.openspcoop2.pdd.monitor.ws.client.statopdd.all.BustaSoggetto bustaMittente = null;
  249.             if(filter.getBusta().getMittente()!=null){
  250.                 bustaMittente = new org.openspcoop2.pdd.monitor.ws.client.statopdd.all.BustaSoggetto();
  251.                 bustaMittente.setNome(filter.getBusta().getMittente().getNome());
  252.                 bustaMittente.setTipo(filter.getBusta().getMittente().getTipo());
  253.             }
  254.             busta.setMittente(bustaMittente);
  255.            
  256.             org.openspcoop2.pdd.monitor.ws.client.statopdd.all.BustaServizio bustaServizio = null;
  257.             if(filter.getBusta().getServizio()!=null){
  258.                 bustaServizio = new org.openspcoop2.pdd.monitor.ws.client.statopdd.all.BustaServizio();
  259.                 bustaServizio.setNome(filter.getBusta().getServizio().getNome());
  260.                 bustaServizio.setTipo(filter.getBusta().getServizio().getTipo());
  261.                 //bustaServizio.setVersione(filter.getBusta().getServizio().getVersione());
  262.             }
  263.             busta.setServizio(bustaServizio);
  264.            
  265.             busta.setProfiloCollaborazione(filter.getBusta().getProfiloCollaborazione());
  266.             busta.setRiferimentoMessaggio(filter.getBusta().getRiferimentoMessaggio());
  267.         }
  268.         filtroInternoWS.setBusta(busta);
  269.         filterWS.setFiltro(filtroInternoWS);
  270.        
  271.         return filterWS;
  272.     }
  273.    

  274.    
  275. }