ConfigurazioneNodiRuntime.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.config;

  21. import java.io.File;
  22. import java.io.FileInputStream;
  23. import java.io.InputStream;
  24. import java.util.ArrayList;
  25. import java.util.Enumeration;
  26. import java.util.HashMap;
  27. import java.util.List;
  28. import java.util.Map;
  29. import java.util.Properties;

  30. import org.apache.commons.lang.StringUtils;
  31. import org.openspcoop2.core.config.constants.CostantiConfigurazione;
  32. import org.openspcoop2.pdd.core.CostantiPdD;
  33. import org.openspcoop2.utils.BooleanNullable;
  34. import org.openspcoop2.utils.UtilsException;
  35. import org.openspcoop2.utils.certificate.byok.BYOKCostanti;
  36. import org.openspcoop2.utils.properties.PropertiesReader;
  37. import org.openspcoop2.utils.transport.TransportUtils;
  38. import org.slf4j.Logger;

  39. /**
  40.  * ConfigurazioneNodiRuntime
  41.  *
  42.  * @author Poli Andrea (apoli@link.it)
  43.  * @author $Author$
  44.  * @version $Rev$, $Date$
  45.  */
  46. public class ConfigurazioneNodiRuntime {

  47.     public static final String RESOURCE_NAME = "govway.nodirun.properties";
  48.    
  49.     public static final String RESOURCE_TIPOLOGIA_ACCESSO_JMX = "jmx";
  50.     public static final String RESOURCE_TIPOLOGIA_ACCESSO_OPENSPCOOP = "openspcoop";
  51.     public static final String RESOURCE_TIPOLOGIA_ACCESSO_GOVWAY = "govway";
  52.    
  53.     public static final String ALIAS_DEFAULT = "pdd";
  54.    
  55.     private static Map<String, ConfigurazioneNodiRuntime> staticInstanceMap = new HashMap<>();
  56.     private static final String PREFIX_DEFAULT = "";
  57.     public static void initialize(String path, ConfigurazioneNodiRuntimeProperties ... backwardCompatibilitiesProperties) throws UtilsException {
  58.         initialize(path, true, backwardCompatibilitiesProperties);
  59.     }
  60.     public static void initialize(String path, boolean configFileRequired, ConfigurazioneNodiRuntimeProperties ... backwardCompatibilitiesProperties) throws UtilsException {
  61.        
  62.         ConfigurazioneNodiRuntimeProperties cpClasspath = null;
  63.         try(InputStream is = ConfigurazioneNodiRuntime.class.getResourceAsStream("/"+RESOURCE_NAME);){
  64.             if(is!=null) {
  65.                 Properties p = new Properties();
  66.                 p.load(is);
  67.                 cpClasspath = new ConfigurazioneNodiRuntimeProperties(PREFIX_DEFAULT, p);
  68.             }
  69.         }catch(Exception e) {
  70.             throw new UtilsException(e.getMessage(),e);
  71.         }
  72.        
  73.         ConfigurazioneNodiRuntimeProperties cpFile = null;
  74.         if(path!=null && StringUtils.isNotEmpty(path)) {
  75.             File f = new File(path);
  76.             boolean read = false;
  77.             if(cpClasspath!=null || (backwardCompatibilitiesProperties!=null && backwardCompatibilitiesProperties.length>0)) {
  78.                 // la configurazione di default e' opzionale, se siamo in backwardCompatibilities mode
  79.                 if(f.exists() && f.canRead()) {
  80.                     read = true;
  81.                 }
  82.             }
  83.             else {
  84.                 if(!f.exists()) {
  85.                     if(configFileRequired) {
  86.                         throw new UtilsException("Configuration file '"+f.getAbsolutePath()+"' not exists");
  87.                     }
  88.                 }
  89.                 else if(!f.canRead()) {
  90.                     if(configFileRequired) {
  91.                         throw new UtilsException("Configuration file '"+f.getAbsolutePath()+"' cannot read");
  92.                     }
  93.                 }
  94.                 else {
  95.                     read = true;
  96.                 }
  97.             }
  98.             if(read) {
  99.                 try(FileInputStream fin = new FileInputStream(f)){
  100.                     Properties p = new Properties();
  101.                     p.load(fin);
  102.                     cpFile = new ConfigurazioneNodiRuntimeProperties(PREFIX_DEFAULT, p);
  103.                 }catch(Exception e) {
  104.                     throw new UtilsException(e.getMessage(),e);
  105.                 }
  106.             }
  107.         }
  108.        
  109.         if(cpClasspath!=null || cpFile!=null) {
  110.             ConfigurazioneNodiRuntime newInstance = new ConfigurazioneNodiRuntime(cpFile, cpClasspath);
  111.             staticInstanceMap.put(PREFIX_DEFAULT, newInstance);
  112.         }
  113.        
  114.         if(backwardCompatibilitiesProperties!=null && backwardCompatibilitiesProperties.length>0) {
  115.             for (ConfigurazioneNodiRuntimeProperties bc : backwardCompatibilitiesProperties) {
  116.                 ConfigurazioneNodiRuntime newInstance = new ConfigurazioneNodiRuntime(bc, null);
  117.                 staticInstanceMap.put(bc.getPrefix(), newInstance);
  118.             }
  119.         }
  120.            
  121.     }
  122.     public static ConfigurazioneNodiRuntime getConfigurazioneNodiRuntime() {
  123.         return getConfigurazioneNodiRuntime(PREFIX_DEFAULT);
  124.     }
  125.     public static ConfigurazioneNodiRuntime getConfigurazioneNodiRuntime(String prefix) {
  126.         if(staticInstanceMap!=null) {
  127.             return staticInstanceMap.get(prefix);
  128.         }
  129.         return null;
  130.     }
  131.     public static List<String> getPrefixes(){
  132.         List<String> l = null;
  133.         if(staticInstanceMap!=null && !staticInstanceMap.isEmpty()) {
  134.             l = new ArrayList<>();
  135.             l.addAll(staticInstanceMap.keySet());
  136.             return l;
  137.         }
  138.         return l;
  139.     }
  140.    
  141.     private PropertiesReader reader;
  142.     private PropertiesReader readerClasspath;
  143.     private String prefix = PREFIX_DEFAULT;
  144.    
  145.     private boolean clusterDinamico = false;
  146.    
  147.     private List<String> aliases;
  148.    
  149.     private Map<String,List<String>> gruppiAliases;
  150.    
  151.     private Map<String, String> descrizione;
  152.    
  153.     private Map<String, String> tipoAccesso;
  154.    
  155.     private Map<String, String> username;
  156.     private Map<String, String> password;
  157.    
  158.     private Map<String, Boolean> https;
  159.     private Map<String, Boolean> httpsVerificaHostName;
  160.     private Map<String, Boolean> httpsAutenticazioneServer;
  161.     private Map<String, String> httpsAutenticazioneServerTruststorePath;
  162.     private Map<String, String> httpsAutenticazioneServerTruststoreType;
  163.     private Map<String, String> httpsAutenticazioneServerTruststorePassword;
  164.    
  165.     private Map<String, String> connectionTimeout;
  166.     private Map<String, String> readConnectionTimeout;
  167.     private Map<String, String> readConnectionTimeoutSlowOperation;
  168.    
  169.     private Map<String, String> as;
  170.     private Map<String, String> factory;
  171.    
  172.     private Map<String, String> resourceUrl; // check con parametri o proxy in modalità dinamica
  173.     private Map<String, String> forceResourceUrl = new HashMap<>();
  174.     private Map<String, String> checkStatusUrl; // check senza parametri
  175.    
  176.     private Map<String, String> dominio;
  177.    
  178.     private ConfigurazioneNodiRuntime(ConfigurazioneNodiRuntimeProperties config, ConfigurazioneNodiRuntimeProperties configClasspath) throws UtilsException {
  179.         if(config!=null) {
  180.             this.reader = new PropertiesReader(config.getProperties(), false);
  181.             this.prefix = config.getPrefix();
  182.         }
  183.         if(configClasspath!=null) {
  184.             this.readerClasspath = new PropertiesReader(configClasspath.getProperties(), false);
  185.             this.prefix = configClasspath.getPrefix();
  186.         }
  187.         if(this.reader==null && this.readerClasspath==null) {
  188.             throw new UtilsException("Nessuna configurazione fornita");
  189.         }
  190.        
  191.         this.initAliases();
  192.         this.initGruppiAliases();
  193.         this.initConfigAliases();
  194.        
  195.     }
  196.    
  197.     public boolean containsNode(String alias) {
  198.         return this.aliases.contains(alias);
  199.     }
  200.    
  201.     public void initClusterDinamico() throws UtilsException {
  202.         String tipo = this.readProperty(false, "clusterDinamico");
  203.         if(tipo!=null) {
  204.             this.clusterDinamico = "true".equalsIgnoreCase(tipo);
  205.         }
  206.         else {
  207.             // backward compatibility
  208.             if(!PREFIX_DEFAULT.equals(this.prefix)){
  209.                 tipo = this.readProperty(false, "cluster_dinamico.enabled");
  210.                 if(tipo!=null) {
  211.                     this.clusterDinamico = "true".equalsIgnoreCase(tipo);
  212.                 }
  213.             }
  214.         }
  215.     }
  216.     public boolean isClusterDinamico() {
  217.         return this.clusterDinamico;
  218.     }
  219.    
  220.     public void initAliases() throws UtilsException {
  221.         List<String> list = new ArrayList<>();
  222.         String tipo = this.readProperty(false, "aliases");
  223.         if(tipo!=null && !"".equals(tipo)){
  224.             String [] tmp = tipo.split(",");
  225.             for (int i = 0; i < tmp.length; i++) {
  226.                 list.add(tmp[i].trim());
  227.             }
  228.         }
  229.         if(PREFIX_DEFAULT.equals(this.prefix) && list.isEmpty()) {
  230.             list.add(ALIAS_DEFAULT);
  231.         }
  232.         this.aliases = list;
  233.     }
  234.     public List<String> getAliases() {
  235.         return this.aliases;
  236.     }
  237.    
  238.     private void initGruppiAliases() throws UtilsException {
  239.         Map<String,List<String>> map = new HashMap<>();
  240.         String nomeP = "aliases.";
  241.         Properties p = null;
  242.         if(this.readerClasspath!=null) {
  243.             p = this.readerClasspath.readProperties(nomeP);
  244.         }
  245.         if(this.reader!=null) {
  246.             if(p==null || p.isEmpty()) {
  247.                 p = this.reader.readProperties(nomeP);
  248.             }
  249.             else {
  250.                 Properties pConfig = this.reader.readProperties(nomeP);
  251.                 if(pConfig!=null && !pConfig.isEmpty()) {
  252.                     p.putAll(pConfig); // sovrascrivo
  253.                 }
  254.             }
  255.         }
  256.         if(p!=null && !p.isEmpty()) {
  257.            
  258.             List<String> aliasesRegistrati = getAliases();
  259.            
  260.             Enumeration<?> en = p.keys();
  261.             while (en.hasMoreElements()) {
  262.                 Object object = en.nextElement();
  263.                 if(object instanceof String) {
  264.                     String gruppo = (String) object;
  265.                     if(map.containsKey(gruppo)) {
  266.                         throw new UtilsException("Gruppo '"+gruppo+"' definito più di una volta nella proprietà '"+this.prefix+nomeP+"*'");
  267.                     }
  268.                     String aliasesGruppo = p.getProperty(gruppo);
  269.                     if(aliasesGruppo!=null && !"".equals(aliasesGruppo)){
  270.                         String [] tmp = aliasesGruppo.split(",");
  271.                         if(tmp!=null && tmp.length>0) {
  272.                             List<String> list = new ArrayList<>();
  273.                             for (int i = 0; i < tmp.length; i++) {
  274.                                 String alias = tmp[i].trim();
  275.                                 if(!aliasesRegistrati.contains(alias)) {
  276.                                     throw new UtilsException("Alias '"+alias+"' indicato nella proprietà '"+nomeP+""+gruppo+"' non è uno degli alias censiti in '"+this.prefix+"aliases'");
  277.                                 }
  278.                                 list.add(alias);
  279.                             }
  280.                             if(!list.isEmpty()) {
  281.                                 map.put(gruppo, list);
  282.                             }
  283.                         }
  284.                     }
  285.                 }
  286.             }
  287.         }
  288.         this.gruppiAliases = map;
  289.     }
  290.     public Map<String, List<String>> getGruppi_aliases() {
  291.         return this.gruppiAliases;
  292.     }
  293.    
  294.     public void initConfigAliases() throws UtilsException {
  295.        
  296.         this.descrizione = new HashMap<>();
  297.        
  298.         this.tipoAccesso = new HashMap<>();
  299.        
  300.         this.username = new HashMap<>();
  301.         this.password = new HashMap<>();
  302.        
  303.         this.https = new HashMap<>();
  304.         this.httpsVerificaHostName = new HashMap<>();
  305.         this.httpsAutenticazioneServer = new HashMap<>();
  306.         this.httpsAutenticazioneServerTruststorePath = new HashMap<>();
  307.         this.httpsAutenticazioneServerTruststoreType = new HashMap<>();
  308.         this.httpsAutenticazioneServerTruststorePassword = new HashMap<>();
  309.        
  310.         this.connectionTimeout = new HashMap<>();
  311.         this.readConnectionTimeout = new HashMap<>();
  312.         this.readConnectionTimeoutSlowOperation = new HashMap<>();
  313.        
  314.         this.as = new HashMap<>();
  315.         this.factory = new HashMap<>();
  316.        
  317.         this.resourceUrl = new HashMap<>();
  318.         this.checkStatusUrl = new HashMap<>();
  319.        
  320.         this.dominio = new HashMap<>();
  321.        
  322.         if(this.aliases!=null && !this.aliases.isEmpty()) {
  323.             for (String alias : this.aliases) {
  324.                
  325.                 String descr = this.readProperty(false, alias+".descrizione");
  326.                 if(descr!=null) {
  327.                     this.descrizione.put(alias, descr);
  328.                 }
  329.                
  330.                 boolean tipoAccessoRequired = PREFIX_DEFAULT.equals(this.prefix) ? false : true;
  331.                 String tipoAccessoCfg = getValueEngine(tipoAccessoRequired, alias, "tipoAccesso");
  332.                 if(tipoAccessoCfg==null) {
  333.                     tipoAccessoCfg = RESOURCE_TIPOLOGIA_ACCESSO_JMX;
  334.                 }
  335.                 if(RESOURCE_TIPOLOGIA_ACCESSO_GOVWAY.equals(tipoAccessoCfg)) {
  336.                     tipoAccessoCfg = RESOURCE_TIPOLOGIA_ACCESSO_OPENSPCOOP;
  337.                 }
  338.                 else {
  339.                     if(!RESOURCE_TIPOLOGIA_ACCESSO_JMX.equals(tipoAccessoCfg) && !RESOURCE_TIPOLOGIA_ACCESSO_OPENSPCOOP.equals(tipoAccessoCfg)){
  340.                         throw new UtilsException("Tipo di accesso ["+tipoAccessoCfg+"] non supportato per la proprietà '"+this.prefix+"tipoAccesso'");
  341.                     }
  342.                 }
  343.                 this.tipoAccesso.put(alias, tipoAccessoCfg);
  344.                
  345.                 String user =getValueEngine(false, alias, "remoteAccess.username");
  346.                 if(user!=null) {
  347.                     this.username.put(alias, user);
  348.                 }
  349.                 String pwd =getValueEngine(false, alias, "remoteAccess.password");
  350.                 if(pwd!=null) {
  351.                     this.password.put(alias, pwd);
  352.                 }
  353.                
  354.                 String v = getValueEngine(false, alias, "remoteAccess.https");
  355.                 boolean httpsEnabled = v!=null ? Boolean.valueOf(v.trim()) : false; // default false
  356.                 this.https.put(alias, httpsEnabled);
  357.                
  358.                 v = getValueEngine(false, alias, "remoteAccess.https.verificaHostName");
  359.                 boolean httpsVerificaHostNameEnabled = v!=null ? Boolean.valueOf(v.trim()) : true; // default true
  360.                 this.httpsVerificaHostName.put(alias, httpsVerificaHostNameEnabled);

  361.                 v =  getValueEngine(false, alias, "remoteAccess.https.autenticazioneServer");
  362.                 boolean httpsAutenticazioneServerEnabled = v!=null ? Boolean.valueOf(v.trim()) : true; // default true
  363.                 this.httpsAutenticazioneServer.put(alias, httpsAutenticazioneServerEnabled);
  364.                
  365.                 v = getValueEngine(false, alias, "remoteAccess.https.autenticazioneServer.truststorePath");
  366.                 if(v!=null) {
  367.                     this.httpsAutenticazioneServerTruststorePath.put(alias, v);
  368.                 }
  369.                
  370.                 v = getValueEngine(false, alias, "remoteAccess.https.autenticazioneServer.truststoreType");
  371.                 if(v!=null) {
  372.                     this.httpsAutenticazioneServerTruststoreType.put(alias, v);
  373.                 }
  374.                
  375.                 v = getValueEngine(false, alias, "remoteAccess.https.autenticazioneServer.truststorePassword");
  376.                 if(v!=null) {
  377.                     this.httpsAutenticazioneServerTruststorePassword.put(alias, v);
  378.                 }
  379.                
  380.                
  381.                 v = getValueEngine(false, alias, "remoteAccess.connectionTimeout");
  382.                 if(v!=null) {
  383.                     this.connectionTimeout.put(alias, v);
  384.                 }
  385.                
  386.                 v = getValueEngine(false, alias, "remoteAccess.readConnectionTimeout");
  387.                 if(v!=null) {
  388.                     this.readConnectionTimeout.put(alias, v);
  389.                 }
  390.                
  391.                 v = getValueEngine(false, alias, "remoteAccess.readConnectionTimeout.slowOperation");
  392.                 if(v!=null) {
  393.                     this.readConnectionTimeoutSlowOperation.put(alias, v);
  394.                 }
  395.                
  396.                 v = getValueEngine(false, alias, "remoteAccess.as");
  397.                 if(v!=null) {
  398.                     this.as.put(alias, v);
  399.                 }
  400.                
  401.                 v = getValueEngine(false, alias, "remoteAccess.factory");
  402.                 if(v!=null) {
  403.                     this.factory.put(alias, v);
  404.                 }
  405.                
  406.                 v = getValueEngine(false, alias, "remoteAccess.url");
  407.                 if(v!=null) {
  408.                     this.resourceUrl.put(alias, v);
  409.                 }
  410.                
  411.                 v = getValueEngine(false, alias, "remoteAccess.checkStatus.url");
  412.                 if(v!=null) {
  413.                     this.checkStatusUrl.put(alias, v);
  414.                 }
  415.                
  416.                 v = getValueEngine(!PREFIX_DEFAULT.equals(this.prefix), alias, "dominio");
  417.                 if(v!=null) {
  418.                     this.dominio.put(alias, v);
  419.                 }
  420.                 else {
  421.                     this.dominio.put(alias, org.openspcoop2.utils.jmx.CostantiJMX.JMX_DOMINIO);
  422.                 }
  423.             }
  424.         }
  425.     }
  426.    
  427.     public String getDescrizione(String alias) {
  428.         return this.descrizione.get(alias);
  429.     }
  430.    
  431.     public String getTipoAccesso(String alias)  {
  432.         return this.tipoAccesso.get(alias);
  433.     }
  434.    
  435.     public String getUsername(String alias) {
  436.         return this.username.get(alias);
  437.     }
  438.     public String getPassword(String alias) {
  439.         return this.password.get(alias);
  440.     }
  441.    
  442.     public boolean isHttps(String alias) {
  443.         return this.https.get(alias);
  444.     }
  445.     public boolean isHttps_verificaHostName(String alias) {
  446.         return this.httpsVerificaHostName.get(alias);
  447.     }
  448.     public boolean isHttps_autenticazioneServer(String alias) {
  449.         return this.httpsAutenticazioneServer.get(alias);
  450.     }
  451.     public String getHttps_autenticazioneServer_truststorePath(String alias) {
  452.         return this.httpsAutenticazioneServerTruststorePath.get(alias);
  453.     }
  454.     public String getHttps_autenticazioneServer_truststoreType(String alias) {
  455.         return this.httpsAutenticazioneServerTruststoreType.get(alias);
  456.     }
  457.     public String getHttps_autenticazioneServer_truststorePassword(String alias) {
  458.         return this.httpsAutenticazioneServerTruststorePassword.get(alias);
  459.     }
  460.    
  461.     public String getConnectionTimeout(String alias) {
  462.         return this.connectionTimeout.get(alias);
  463.     }
  464.     public String getReadConnectionTimeout(String alias) {
  465.         return this.readConnectionTimeout.get(alias);
  466.     }
  467.     public String getReadConnectionTimeout_slowOperation(String alias) {
  468.         return this.readConnectionTimeoutSlowOperation.get(alias);
  469.     }
  470.    
  471.     public String getAs(String alias) {
  472.         return this.as.get(alias);
  473.     }
  474.    
  475.     public String getFactory(String alias) {
  476.         return this.factory.get(alias);
  477.     }
  478.    
  479.     public void addForceResourceUrl(String alias, String url) {
  480.         this.forceResourceUrl.put(alias, url);
  481.     }
  482.     public String getResourceUrl(String alias) {
  483.         if(!this.forceResourceUrl.isEmpty() && this.forceResourceUrl.containsKey(alias)) {
  484.             return this.forceResourceUrl.get(alias);
  485.         }
  486.         return this.resourceUrl.get(alias);
  487.     }
  488.    
  489.     public String getCheckStatusUrl(String alias) {
  490.         return this.checkStatusUrl.get(alias);
  491.     }
  492.    
  493.     public String getDominio(String alias) {
  494.         return this.dominio.get(alias);
  495.     }
  496.    
  497.    
  498.     private String getValueEngine(boolean required, String alias, String prop) throws UtilsException{
  499.         String tmp = this.readProperty(false, alias+"."+prop);
  500.         if(tmp==null || "".equals(tmp)){
  501.             tmp = this.readProperty(required, prop);
  502.         }
  503.         return tmp;
  504.     }
  505.     private String readProperty(boolean required,String property) throws UtilsException{
  506.         String tmp = null;
  507.         if(this.reader!=null) {
  508.             tmp = this.reader.getValue_convertEnvProperties(property);
  509.         }
  510.         if(tmp==null &&
  511.             this.readerClasspath!=null) {
  512.             tmp = this.readerClasspath.getValue_convertEnvProperties(property);
  513.         }
  514.         if(tmp==null){
  515.             if(required){
  516.                 throw new UtilsException("Property ["+this.prefix+property+"] not found");
  517.             }
  518.             else{
  519.                 return null;
  520.             }
  521.         }else{
  522.             return tmp.trim();
  523.         }
  524.     }
  525.     @SuppressWarnings("unused")
  526.     private BooleanNullable readBooleanProperty(boolean required,String property) throws UtilsException{
  527.         String tmp = this.readProperty(required, property);
  528.         if(tmp==null && !required) {
  529.             return BooleanNullable.NULL(); // se e' required viene sollevata una eccezione dal metodo readProperty
  530.         }
  531.         if(!"true".equalsIgnoreCase(tmp) && !"false".equalsIgnoreCase(tmp)){
  532.             throw new UtilsException("Property ["+this.prefix+property+"] with uncorrect value ["+tmp+"] (true/value expected)");
  533.         }
  534.         return Boolean.parseBoolean(tmp) ? BooleanNullable.TRUE() : BooleanNullable.FALSE();
  535.     }
  536.     @SuppressWarnings("unused")
  537.     private Integer readIntegerProperty(boolean required,String property) throws UtilsException{
  538.         String tmp = this.readProperty(required, property);
  539.         if(tmp==null && !required) {
  540.             return null; // se e' required viene sollevata una eccezione dal metodo readProperty
  541.         }
  542.         try{
  543.             return Integer.parseInt(tmp);
  544.         }catch(Exception e){
  545.             throw new UtilsException("Property ["+this.prefix+property+"] with uncorrect value ["+tmp+"] (int value expected)");
  546.         }
  547.     }
  548.     @SuppressWarnings("unused")
  549.     private Long readLongProperty(boolean required,String property) throws UtilsException{
  550.         String tmp = this.readProperty(required, property);
  551.         if(tmp==null && !required) {
  552.             return null; // se e' required viene sollevata una eccezione dal metodo readProperty
  553.         }
  554.         try{
  555.             return Long.parseLong(tmp);
  556.         }catch(Exception e){
  557.             throw new UtilsException("Property ["+this.prefix+property+"] with uncorrect value ["+tmp+"] (long value expected)");
  558.         }
  559.     }
  560.    
  561.    
  562.     public void initBYOKDynamicMapRemoteGovWayNode(Logger log, Map<String, Object> dynamicMap, boolean wrap, boolean unwrap, ConfigurazioneNodiRuntimeBYOKRemoteConfig remoteConfig) {
  563.         if(this.aliases!=null && !this.aliases.isEmpty()){
  564.             // prendo il primo nodo funzionante
  565.             for (String alias : this.aliases) {
  566.                 if(isActiveNode(log, alias, remoteConfig) &&
  567.                     this.getResourceUrl(alias)!=null && !"".equals(this.getResourceUrl(alias))
  568.                     && !InvokerNodiRuntime.RESOURCE_URL_LOCALE.equals(this.getResourceUrl(alias))
  569.                         ){
  570.                     initBYOKDynamicMapRemoteGovWayNode(dynamicMap, wrap, unwrap, alias, remoteConfig);
  571.                     break;
  572.                 }
  573.             }
  574.         }
  575.     }
  576.     public boolean isAtLeastOneActiveNode(Logger log, ConfigurazioneNodiRuntimeBYOKRemoteConfig remoteConfig) {
  577.         if(this.aliases!=null && !this.aliases.isEmpty()){
  578.             // prendo il primo nodo funzionante
  579.             for (String alias : this.aliases) {
  580.                 if(isActiveNode(log, alias, remoteConfig)){
  581.                     return true;
  582.                 }
  583.             }
  584.         }
  585.         return false;
  586.     }
  587.     public boolean isActiveNode(Logger log, String alias, ConfigurazioneNodiRuntimeBYOKRemoteConfig remoteConfig) {
  588.         try {
  589.             InvokerNodiRuntime invoker = new InvokerNodiRuntime(null,this); // passo volutamente null per non registrare l'errore
  590.             String value = invoker.readJMXAttribute(alias, remoteConfig.getType(),
  591.                     remoteConfig.getResourceStatoServiziPdd(),
  592.                     remoteConfig.getAttributeComponentePD());
  593.             return value!=null && !"".equals(value) && !value.startsWith(InvokerNodiRuntime.PREFIX_HTTP_CODE) &&
  594.                     (CostantiConfigurazione.ABILITATO.getValue().equals(value) || CostantiConfigurazione.DISABILITATO.getValue().equals(value));
  595.         }catch(Exception e) {
  596.             log.debug("Nodo '"+alias+"' non non attivo?: "+e.getMessage(),e);
  597.             return false;
  598.         }
  599.     }

  600.     private void initBYOKDynamicMapRemoteGovWayNode(Map<String, Object> dynamicMap, boolean wrap, boolean unwrap, String alias, ConfigurazioneNodiRuntimeBYOKRemoteConfig remoteConfig)  {
  601.         String remoteUrl = this.getResourceUrl(alias);
  602.        
  603.         Map<String, String> govwayContext = new HashMap<>();
  604.         dynamicMap.put(BYOKCostanti.GOVWAY_RUNTIME_CONTEXT, govwayContext);
  605.        
  606.         Map<String, List<String>> p = new HashMap<>();
  607.         TransportUtils.setParameter(p,CostantiPdD.CHECK_STATO_PDD_RESOURCE_NAME, remoteConfig.getResourceConfigurazioneSistema());
  608.         if(wrap) {
  609.             TransportUtils.setParameter(p,CostantiPdD.CHECK_STATO_PDD_METHOD_NAME, remoteConfig.getMethodWrap());
  610.             String urlWrap = TransportUtils.buildUrlWithParameters(p, remoteUrl);
  611.             govwayContext.put(BYOKCostanti.GOVWAY_RUNTIME_ENDPOINT_WRAP, urlWrap);
  612.         }
  613.         if(unwrap) {
  614.             TransportUtils.setParameter(p,CostantiPdD.CHECK_STATO_PDD_METHOD_NAME, remoteConfig.getMethodUnwrap());
  615.             String urlUnwrap = TransportUtils.buildUrlWithParameters(p, remoteUrl);
  616.             govwayContext.put(BYOKCostanti.GOVWAY_RUNTIME_ENDPOINT_UNWRAP, urlUnwrap);
  617.         }

  618.         String user = this.getUsername(alias);
  619.         if(user!=null) {
  620.             govwayContext.put(BYOKCostanti.GOVWAY_RUNTIME_USERNAME, user);
  621.         }
  622.         String pwd = this.getPassword(alias);
  623.         if(pwd!=null) {
  624.             govwayContext.put(BYOKCostanti.GOVWAY_RUNTIME_PASSWORD, pwd);
  625.         }
  626.     }
  627. }