ConnettoreJmsApiHelper.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.core.config.rs.server.api.impl.erogazioni;

  21. import static org.openspcoop2.utils.service.beans.utils.BaseHelper.evalnull;

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

  24. import org.openspcoop2.core.config.rs.server.model.ConnettoreEnum;
  25. import org.openspcoop2.core.config.rs.server.model.ConnettoreJms;
  26. import org.openspcoop2.core.config.rs.server.model.ConnettoreJmsSendAsEnum;
  27. import org.openspcoop2.core.config.rs.server.model.ConnettoreJmsTipoEnum;
  28. import org.openspcoop2.core.config.rs.server.model.OneOfApplicativoServerConnettore;
  29. import org.openspcoop2.core.config.rs.server.model.OneOfConnettoreErogazioneConnettore;
  30. import org.openspcoop2.core.config.rs.server.model.OneOfConnettoreFruizioneConnettore;
  31. import org.openspcoop2.core.constants.CostantiConnettori;
  32. import org.openspcoop2.core.constants.CostantiDB;
  33. import org.openspcoop2.core.constants.TipiConnettore;
  34. import org.openspcoop2.core.registry.Connettore;
  35. import org.openspcoop2.web.ctrlstat.costanti.ConnettoreServletType;
  36. import org.openspcoop2.web.ctrlstat.plugins.ExtendedConnettore;
  37. import org.openspcoop2.web.ctrlstat.plugins.servlet.ServletExtendedConnettoreUtils;
  38. import org.openspcoop2.web.ctrlstat.servlet.connettori.ConnettoriCostanti;
  39. import org.openspcoop2.web.lib.mvc.ServletUtils;

  40. /**
  41.  * ConnettoreJmsApiHelper
  42.  *
  43.  * @author $Author$
  44.  * @version $Rev$, $Date$
  45.  *
  46.  */
  47. public class ConnettoreJmsApiHelper extends AbstractConnettoreApiHelper<ConnettoreJms> {

  48.     @Override
  49.     protected ConnettoreJms getConnettore(OneOfConnettoreErogazioneConnettore conn) throws Exception {
  50.         return (ConnettoreJms) conn;
  51.     }

  52.     @Override
  53.     protected ConnettoreJms getConnettore(OneOfConnettoreFruizioneConnettore conn) throws Exception {
  54.         return (ConnettoreJms) conn;
  55.     }

  56.     @Override
  57.     protected ConnettoreJms getConnettore(OneOfApplicativoServerConnettore conn) throws Exception {
  58.         return (ConnettoreJms) conn;
  59.     }

  60.     @Override
  61.     public boolean connettoreCheckData(ConnettoreJms conn, ErogazioniEnv env, boolean erogazione) throws Exception {


  62.         final String endpointtype = TipiConnettore.JMS.getNome();
  63.        
  64.         org.openspcoop2.core.registry.Connettore conTmp = null;
  65.         List<ExtendedConnettore> listExtendedConnettore =
  66.                 ServletExtendedConnettoreUtils.getExtendedConnettore(conTmp, ConnettoreServletType.ACCORDO_SERVIZIO_PARTE_SPECIFICA_ADD, env.apsHelper,
  67.                         null, false, endpointtype);

  68.         String sendAs = conn.getSendAs().equals(ConnettoreJmsSendAsEnum.BYTES) ? CostantiConnettori.CONNETTORE_JMS_SEND_AS_BYTES_MESSAGE : CostantiConnettori.CONNETTORE_JMS_SEND_AS_TEXT_MESSAGE;
  69.         return env.saHelper.endPointCheckData(
  70.                 null,
  71.                 env.tipo_protocollo,
  72.                 erogazione,
  73.                 endpointtype,
  74.                 null,
  75.                 conn.getNome(), // this.nome,
  76.                 conn.getTipoCoda().toString(),  // this.tipo,
  77.                 conn.getUtente(),
  78.                 conn.getPassword(),
  79.                 conn.getJndiInitialContext(),   // this.initcont,
  80.                 conn.getJndiUrlPgkPrefixes(),   // this.urlpgk,
  81.                 conn.getJndiProviderUrl(),   // this.url,
  82.                 conn.getConnectionFactory(),    // this.connfact,
  83.                 sendAs, // this.sendas
  84.                 null,                                                   // this.httpsurl,
  85.                 null,   // httpsConf.getTipologia().toString(),
  86.                 false,      // this.httpshostverify,
  87.                 ConnettoriCostanti.DEFAULT_CONNETTORE_HTTPS_TRUST_VERIFY_CERTS, // httpsTrustVerifyCert
  88.                 null,   // this.httpspath
  89.                 null,   // this.httpstipo,
  90.                 null,   // this.httpspwd,
  91.                 null,   // this.httpsalgoritmo
  92.                 false,
  93.                 null,
  94.                 "",                                                                     // httpspwdprivatekeytrust,
  95.                 null,   // pathkey
  96.                 null,   // this.httpstipokey
  97.                 null,   // this.httpspwdkey
  98.                 null,   // this.httpspwdprivatekey,  
  99.                 null,   // this.httpsalgoritmokey,
  100.                 null,   // httpsKeyAlias
  101.                 null,   // httpsTrustStoreCRLs
  102.                 null,   // httpsTrustStoreOCSPPolicy
  103.                 null,   // httpsKeyStoreBYOKPolicy
  104.                 null,                                                               //  tipoconn (personalizzato)
  105.                 ServletUtils.boolToCheckBoxStatus(false),                                           //autenticazioneHttp,
  106.                 ServletUtils.boolToCheckBoxStatus(false),  
  107.                 null,   // evalnull( () -> proxy.getHostname() ),
  108.                 null,   // evalnull( () -> proxy.getPorta().toString() ),
  109.                 null,   // evalnull( () -> proxy.getUsername() ),
  110.                 null,   // evalnull( () -> proxy.getPassword() ),
  111.                 ServletUtils.boolToCheckBoxStatus(false), //ServletUtils.boolToCheckBoxStatus( tempiRisposta_enabled ),
  112.                 null,   // evalnull( () -> timeoutConf.getConnectionTimeout().toString()),  // this.tempiRisposta_connectionTimeout,
  113.                 null,   // evalnull( () -> timeoutConf.getConnectionReadTimeout().toString()), //null,  // this.tempiRisposta_readTimeout,
  114.                 null,   // evalnull( () -> timeoutConf.getTempoMedioRisposta().toString()), // this.tempiRisposta_tempoMedioRisposta,
  115.                 "no",   // this.opzioniAvanzate,
  116.                 "",     // this.transfer_mode,
  117.                 "",     // this.transfer_mode_chunk_size,
  118.                 "",     // this.redirect_mode,
  119.                 "",     // this.redirect_max_hop,
  120.                 null,   // requestOutputFileName,
  121.                 null,   // this.requestOutputFileName_permissions
  122.                 null,   // this.requestOutputFileNameHeaders,
  123.                 null,   // this.requestOutputFileNameHeaders_permissions
  124.                 null,   // requestOutputParentDirCreateIfNotExists,
  125.                 null,   // requestOutputOverwriteIfExists,
  126.                 null,   // responseInputMode,
  127.                 null,   // responseInputFileName,
  128.                 null,   // responseInputFileNameHeaders,
  129.                 null,   // responseInputDeleteAfterRead,
  130.                 null,   // responseInputWaitTime,
  131.                 false, // autenticazioneToken
  132.                 null, // tokenPolicy
  133.                 null, // autenticazioneApiKey
  134.                 false, // useOAS3Names
  135.                 false, // useAppId
  136.                 null, // apiKeyHeader
  137.                 null, // apiKey,
  138.                 null, // appIdHeader,
  139.                 null, // appId,
  140.                 listExtendedConnettore, // listExtendedConnettore
  141.                 false, // erogazioneServizioApplicativoServerEnabled,
  142.                 null // erogazioneServizioApplicativoServer
  143.             );
  144.     }

  145.     @Override
  146.     public Connettore fillConnettoreRegistro(org.openspcoop2.core.registry.Connettore regConnettore,
  147.             ErogazioniEnv env,
  148.             ConnettoreJms conn,
  149.             String oldConnT) throws Exception {
  150.         final String endpointtype = TipiConnettore.JMS.getNome();
  151.        
  152.         org.openspcoop2.core.registry.Connettore conTmp = null;
  153.         List<ExtendedConnettore> listExtendedConnettore =
  154.                 ServletExtendedConnettoreUtils.getExtendedConnettore(conTmp, ConnettoreServletType.ACCORDO_SERVIZIO_PARTE_SPECIFICA_ADD, env.apsHelper,
  155.                         null, false, endpointtype);


  156.         String sendAs = conn.getSendAs().equals(ConnettoreJmsSendAsEnum.BYTES) ? CostantiConnettori.CONNETTORE_JMS_SEND_AS_BYTES_MESSAGE : CostantiConnettori.CONNETTORE_JMS_SEND_AS_TEXT_MESSAGE;

  157.         env.apsHelper.fillConnettore(
  158.                 regConnettore,
  159.                 conn.isDebug() != null && conn.isDebug() ? "true" : "false",                // this.connettoreDebug,
  160.                 endpointtype,           // endpointtype
  161.                 oldConnT,           // oldConnT
  162.                 "",                     // tipoConn Personalizzato
  163.                 null, // this.url,
  164.                 conn.getNome(), // this.nome,
  165.                 conn.getTipoCoda().toString(),  // this.tipo,
  166.                 conn.getUtente(),
  167.                 conn.getPassword(),
  168.                 conn.getJndiInitialContext(),   // this.initcont,
  169.                 conn.getJndiUrlPgkPrefixes(),   // this.urlpgk,
  170.                 conn.getJndiProviderUrl(),   // this.url,
  171.                 conn.getConnectionFactory(),    // this.connfact,
  172.                 sendAs, // this.sendas
  173.                 null,                                               // this.httpsurl,
  174.                 null,  //this.httpstipologia
  175.                 false,  // this.httpshostverify,
  176.                 ConnettoriCostanti.DEFAULT_CONNETTORE_HTTPS_TRUST_VERIFY_CERTS, // httpsTrustVerifyCert
  177.                 null,  // this.httpspath
  178.                 null,  //this.httpstipo,
  179.                 null,  //this.httpspwd,
  180.                 null,  // this.httpsalgoritmo
  181.                 false,
  182.                 null, // this.httpskeystore,
  183.                 "",                                                                 //  this.httpspwdprivatekeytrust
  184.                 null,  //pathkey
  185.                 null,  //this.httpstipokey
  186.                 null,  //this.httpspwdkey
  187.                 null,  //this.httpspwdprivatekey,  
  188.                 null,  //this.httpsalgoritmokey,
  189.                 null,  //httpsKeyAlias
  190.                 null,  //httpsTrustStoreCRLs
  191.                 null,  //httpsTrustStoreOCSPPolicy
  192.                 null,  //httpsKeyStoreBYOKPolicy
  193.            
  194.                 ServletUtils.boolToCheckBoxStatus( false ),
  195.                 null,
  196.                 null,
  197.                 null,
  198.                 null,
  199.                 ServletUtils.boolToCheckBoxStatus( false ),
  200.                 null,
  201.                 null,
  202.                 null,
  203.                 "no",   // this.opzioniAvanzate,
  204.                 "",     // this.transfer_mode,
  205.                 "",     // this.transfer_mode_chunk_size,
  206.                 "",     // this.redirect_mode,
  207.                 "",     // this.redirect_max_hop,
  208.                 null,   // this.requestOutputFileName,
  209.                 null,   // this.requestOutputFileName_permissions
  210.                 null,   // this.requestOutputFileNameHeaders,
  211.                 null,   // this.requestOutputFileNameHeaders_permissions
  212.                 null,   // this.requestOutputParentDirCreateIfNotExists,
  213.                 null,   // this.requestOutputOverwriteIfExists,
  214.                 null,   // this.responseInputMode,
  215.                 null,   // this.responseInputFileName,
  216.                 null,   // this.responseInputFileNameHeaders,
  217.                 null,   // this.responseInputDeleteAfterRead,
  218.                 null,   // this.responseInputWaitTime,
  219.                 null,   // tokenPolicy
  220.                 null, null, // apiKeyHeader,  apiKeyValue
  221.                 null, null, // appIdHeader, appIdValue
  222.                
  223.                 null, // connettoreStatusParams
  224.                 listExtendedConnettore);                
  225.         return regConnettore;
  226.     }

  227.     @Override
  228.     public org.openspcoop2.core.config.Connettore buildConnettoreConfigurazione(
  229.             org.openspcoop2.core.config.Connettore regConnettore, ErogazioniEnv env, ConnettoreJms conn,
  230.             String oldConnType) throws Exception {

  231.         final String endpointtype = TipiConnettore.JMS.getNome();
  232.        
  233.         org.openspcoop2.core.registry.Connettore conTmp = null;
  234.         List<ExtendedConnettore> listExtendedConnettore =
  235.                 ServletExtendedConnettoreUtils.getExtendedConnettore(conTmp, ConnettoreServletType.ACCORDO_SERVIZIO_PARTE_SPECIFICA_ADD, env.apsHelper,
  236.                         null, false, endpointtype);


  237.         String sendAs = conn.getSendAs().equals(ConnettoreJmsSendAsEnum.BYTES) ? CostantiConnettori.CONNETTORE_JMS_SEND_AS_BYTES_MESSAGE : CostantiConnettori.CONNETTORE_JMS_SEND_AS_TEXT_MESSAGE;

  238.         env.apsHelper.fillConnettore(
  239.                 regConnettore,
  240.                 conn.isDebug() != null && conn.isDebug() ? "true" : "false",                // this.connettoreDebug,
  241.                 endpointtype,           // endpointtype
  242.                 oldConnType,            // oldConnT
  243.                 "",                     // tipoConn Personalizzato
  244.                 null, // this.url,
  245.                 conn.getNome(), // this.nome,
  246.                 conn.getTipoCoda().toString(),  // this.tipo,
  247.                 conn.getUtente(),
  248.                 conn.getPassword(),
  249.                 conn.getJndiInitialContext(),   // this.initcont,
  250.                 conn.getJndiUrlPgkPrefixes(),   // this.urlpgk,
  251.                 conn.getJndiProviderUrl(),   // this.url,
  252.                 conn.getConnectionFactory(),    // this.connfact,
  253.                 sendAs, // this.sendas
  254.                 null,                                               // this.httpsurl,
  255.                 null,  //this.httpstipologia
  256.                 false,  // this.httpshostverify,
  257.                 ConnettoriCostanti.DEFAULT_CONNETTORE_HTTPS_TRUST_VERIFY_CERTS, // httpsTrustVerifyCert
  258.                 null,  // this.httpspath
  259.                 null,  //this.httpstipo,
  260.                 null,  //this.httpspwd,
  261.                 null,  // this.httpsalgoritmo
  262.                 false,
  263.                 null, // this.httpskeystore,
  264.                 "",                                                                 //  this.httpspwdprivatekeytrust
  265.                 null,  //pathkey
  266.                 null,  //this.httpstipokey
  267.                 null,  //this.httpspwdkey
  268.                 null,  //this.httpspwdprivatekey,  
  269.                 null,  //this.httpsalgoritmokey,
  270.                 null,  //httpsKeyAlias
  271.                 null,  //httpsTrustStoreCRLs
  272.                 null,  //httpsTrustStoreOCSPPolicy
  273.                 null,  //httpsKeyStoreBYOKPolicy
  274.            
  275.                 ServletUtils.boolToCheckBoxStatus( false ),
  276.                 null,
  277.                 null,
  278.                 null,
  279.                 null,
  280.                 ServletUtils.boolToCheckBoxStatus( false ),
  281.                 null,
  282.                 null,
  283.                 null,
  284.                 "no",   // this.opzioniAvanzate,
  285.                 "",     // this.transfer_mode,
  286.                 "",     // this.transfer_mode_chunk_size,
  287.                 "",     // this.redirect_mode,
  288.                 "",     // this.redirect_max_hop,
  289.                 null,   // this.requestOutputFileName,
  290.                 null,   // this.requestOutputFileName_permissions
  291.                 null,   // this.requestOutputFileNameHeaders,
  292.                 null,   // this.requestOutputFileNameHeaders_permissions
  293.                 null,   // this.requestOutputParentDirCreateIfNotExists,
  294.                 null,   // this.requestOutputOverwriteIfExists,
  295.                 null,   // this.responseInputMode,
  296.                 null,   // this.responseInputFileName,
  297.                 null,   // this.responseInputFileNameHeaders,
  298.                 null,   // this.responseInputDeleteAfterRead,
  299.                 null,   // this.responseInputWaitTime,
  300.                 null,   // tokenPolicy
  301.                 null, null, // apiKeyHeader,  apiKeyValue
  302.                 null, null, // appIdHeader, appIdValue
  303.                
  304.                 null, // connettoreStatusParams
  305.                 listExtendedConnettore);        
  306.         return regConnettore;
  307.     }

  308.     @Override
  309.     public ConnettoreJms buildConnettore(Map<String, String> props, String tipo) {
  310.         ConnettoreJms c = new ConnettoreJms();
  311.        
  312.         c.setTipo(ConnettoreEnum.JMS);
  313.         c.setDebug(Boolean.parseBoolean(props.get(CostantiDB.CONNETTORE_DEBUG)));
  314.        
  315.         c.setNome(props.get(CostantiDB.CONNETTORE_HTTP_LOCATION));
  316.         c.setTipoCoda(ConnettoreJmsTipoEnum.fromValue(props.get(CostantiDB.CONNETTORE_JMS_TIPO)));
  317.         String jmsSendAs = props.get(CostantiDB.CONNETTORE_JMS_SEND_AS);
  318.         if(jmsSendAs.equals(CostantiConnettori.CONNETTORE_JMS_SEND_AS_BYTES_MESSAGE)) {
  319.             c.setSendAs(ConnettoreJmsSendAsEnum.BYTES);
  320.         } else if(jmsSendAs.equals(CostantiConnettori.CONNETTORE_JMS_SEND_AS_TEXT_MESSAGE)) {
  321.             c.setSendAs(ConnettoreJmsSendAsEnum.TEXT);
  322.         }
  323.         c.setConnectionFactory(props.get(CostantiDB.CONNETTORE_JMS_CONNECTION_FACTORY));
  324.        
  325.         c.setUtente(evalnull( () -> props.get(CostantiDB.CONNETTORE_USER)));
  326.         c.setPassword(evalnull( () -> props.get(CostantiDB.CONNETTORE_PWD)));

  327.         c.setJndiInitialContext(props.get(CostantiDB.CONNETTORE_JMS_CONTEXT_JAVA_NAMING_FACTORY_INITIAL));
  328.         c.setJndiUrlPgkPrefixes(props.get(CostantiDB.CONNETTORE_JMS_CONTEXT_JAVA_NAMING_FACTORY_URL_PKG));
  329.         c.setJndiProviderUrl(props.get(CostantiDB.CONNETTORE_JMS_CONTEXT_JAVA_NAMING_PROVIDER_URL));
  330.        
  331.         return c;
  332.     }

  333.     @Override
  334.     public String getUrlConnettore(Map<String, String> properties, String tipoConnettore) throws Exception {
  335.         return "[jms] " + properties.get(CostantiDB.CONNETTORE_HTTP_LOCATION);
  336.     }

  337. }