PorteApplicativeConnettoriMultipliChange.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.pa;

  21. import java.util.ArrayList;
  22. import java.util.Arrays;
  23. import java.util.List;
  24. import java.util.Map;
  25. import java.util.Properties;

  26. import javax.net.ssl.KeyManagerFactory;
  27. import javax.net.ssl.TrustManagerFactory;
  28. import javax.servlet.http.HttpServletRequest;
  29. import javax.servlet.http.HttpServletResponse;
  30. import javax.servlet.http.HttpSession;

  31. import org.apache.commons.lang.StringUtils;
  32. import org.apache.struts.action.Action;
  33. import org.apache.struts.action.ActionForm;
  34. import org.apache.struts.action.ActionForward;
  35. import org.apache.struts.action.ActionMapping;
  36. import org.openspcoop2.core.commons.Liste;
  37. import org.openspcoop2.core.config.Connettore;
  38. import org.openspcoop2.core.config.Credenziali;
  39. import org.openspcoop2.core.config.InvocazioneCredenziali;
  40. import org.openspcoop2.core.config.InvocazionePorta;
  41. import org.openspcoop2.core.config.InvocazioneServizio;
  42. import org.openspcoop2.core.config.PortaApplicativa;
  43. import org.openspcoop2.core.config.PortaApplicativaServizioApplicativo;
  44. import org.openspcoop2.core.config.PortaApplicativaServizioApplicativoConnettore;
  45. import org.openspcoop2.core.config.Property;
  46. import org.openspcoop2.core.config.ProprietaOggetto;
  47. import org.openspcoop2.core.config.RispostaAsincrona;
  48. import org.openspcoop2.core.config.ServizioApplicativo;
  49. import org.openspcoop2.core.config.constants.TipoBehaviour;
  50. import org.openspcoop2.core.config.constants.CostantiConfigurazione;
  51. import org.openspcoop2.core.config.constants.CredenzialeTipo;
  52. import org.openspcoop2.core.config.constants.InvocazioneServizioTipoAutenticazione;
  53. import org.openspcoop2.core.config.constants.StatoFunzionalita;
  54. import org.openspcoop2.core.config.constants.TipologiaErogazione;
  55. import org.openspcoop2.core.config.constants.TipologiaFruizione;
  56. import org.openspcoop2.core.config.driver.db.IDServizioApplicativoDB;
  57. import org.openspcoop2.core.constants.CostantiConnettori;
  58. import org.openspcoop2.core.constants.CostantiDB;
  59. import org.openspcoop2.core.constants.TipiConnettore;
  60. import org.openspcoop2.core.constants.TransferLengthModes;
  61. import org.openspcoop2.core.controllo_traffico.ConfigurazioneGenerale;
  62. import org.openspcoop2.core.id.IDServizioApplicativo;
  63. import org.openspcoop2.core.id.IDSoggetto;
  64. import org.openspcoop2.core.mapping.MappingErogazionePortaApplicativa;
  65. import org.openspcoop2.core.registry.AccordoServizioParteSpecifica;
  66. import org.openspcoop2.core.registry.beans.AccordoServizioParteComuneSintetico;
  67. import org.openspcoop2.message.constants.ServiceBinding;
  68. import org.openspcoop2.pdd.core.behaviour.built_in.multi_deliver.ConfigurazioneMultiDeliver;
  69. import org.openspcoop2.pdd.core.behaviour.built_in.multi_deliver.MultiDeliverUtils;
  70. import org.openspcoop2.pdd.core.behaviour.conditional.ConditionalUtils;
  71. import org.openspcoop2.pdd.core.behaviour.conditional.ConfigurazioneSelettoreCondizioneRegola;
  72. import org.openspcoop2.utils.date.DateManager;
  73. import org.openspcoop2.web.ctrlstat.core.ControlStationCore;
  74. import org.openspcoop2.web.ctrlstat.core.ControlStationCoreException;
  75. import org.openspcoop2.web.ctrlstat.core.ConsoleSearch;
  76. import org.openspcoop2.web.ctrlstat.costanti.ConnettoreServletType;
  77. import org.openspcoop2.web.ctrlstat.costanti.CostantiControlStation;
  78. import org.openspcoop2.web.ctrlstat.plugins.ExtendedConnettore;
  79. import org.openspcoop2.web.ctrlstat.plugins.servlet.ServletExtendedConnettoreUtils;
  80. import org.openspcoop2.web.ctrlstat.servlet.GeneralHelper;
  81. import org.openspcoop2.web.ctrlstat.servlet.OggettoDialogEnum;
  82. import org.openspcoop2.web.ctrlstat.servlet.apc.AccordiServizioParteComuneCore;
  83. import org.openspcoop2.web.ctrlstat.servlet.aps.AccordiServizioParteSpecificaCore;
  84. import org.openspcoop2.web.ctrlstat.servlet.aps.AccordiServizioParteSpecificaCostanti;
  85. import org.openspcoop2.web.ctrlstat.servlet.aps.erogazioni.ErogazioniCostanti;
  86. import org.openspcoop2.web.ctrlstat.servlet.config.ConfigurazioneCore;
  87. import org.openspcoop2.web.ctrlstat.servlet.connettori.ConnettoreStatusParams;
  88. import org.openspcoop2.web.ctrlstat.servlet.connettori.ConnettoriCostanti;
  89. import org.openspcoop2.web.ctrlstat.servlet.connettori.ConnettoriHelper;
  90. import org.openspcoop2.web.ctrlstat.servlet.sa.ServiziApplicativiCore;
  91. import org.openspcoop2.web.ctrlstat.servlet.sa.ServiziApplicativiCostanti;
  92. import org.openspcoop2.web.ctrlstat.servlet.sa.ServiziApplicativiHelper;
  93. import org.openspcoop2.web.ctrlstat.servlet.sa.ServiziApplicativiUtilities;
  94. import org.openspcoop2.web.ctrlstat.servlet.soggetti.SoggettiCore;
  95. import org.openspcoop2.web.lib.mvc.Costanti;
  96. import org.openspcoop2.web.lib.mvc.DataElement;
  97. import org.openspcoop2.web.lib.mvc.ForwardParams;
  98. import org.openspcoop2.web.lib.mvc.GeneralData;
  99. import org.openspcoop2.web.lib.mvc.PageData;
  100. import org.openspcoop2.web.lib.mvc.Parameter;
  101. import org.openspcoop2.web.lib.mvc.ServletUtils;
  102. import org.openspcoop2.web.lib.mvc.TipoOperazione;

  103. /**
  104.  * PorteApplicativeConnettoriMultipliChange
  105.  *
  106.  * @author Andrea Poli (apoli@link.it)
  107.  * @author Giuliano Pintori (pintori@link.it)
  108.  * @author $Author$
  109.  * @version $Rev$, $Date$
  110.  *
  111.  */
  112. public final class PorteApplicativeConnettoriMultipliChange extends Action {

  113.     @Override
  114.     public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {


  115.         HttpSession session = request.getSession(true);

  116.         // Inizializzo PageData
  117.         PageData pd = new PageData();

  118.         GeneralHelper generalHelper = new GeneralHelper(session);

  119.         // Inizializzo GeneralData
  120.         GeneralData gd = generalHelper.initGeneralData(request);

  121.         try {
  122.             PorteApplicativeHelper porteApplicativeHelper = new PorteApplicativeHelper(request, pd, session);
  123.             // prelevo il flag che mi dice da quale pagina ho acceduto la sezione delle porte applicative
  124.             Integer parentPA = ServletUtils.getIntegerAttributeFromSession(PorteApplicativeCostanti.ATTRIBUTO_PORTE_APPLICATIVE_PARENT, session, request);
  125.             if(parentPA == null) parentPA = PorteApplicativeCostanti.ATTRIBUTO_PORTE_APPLICATIVE_PARENT_NONE;
  126.             String idPorta = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID);
  127.             int idInt = Integer.parseInt(idPorta);
  128.             String idsogg = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID_SOGGETTO);
  129.             String idAsps = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID_ASPS);
  130.             if(idAsps == null)
  131.                 idAsps = "";

  132.             String idConnTab = porteApplicativeHelper.getParameter(CostantiControlStation.PARAMETRO_ID_CONN_TAB);
  133.             if(StringUtils.isNotEmpty(idConnTab)) {
  134.                 ServletUtils.setObjectIntoSession(request, session, idConnTab, CostantiControlStation.PARAMETRO_ID_CONN_TAB);
  135.             }

  136.             String nomeSAConnettore = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_CONNETTORI_MULTIPLI_NOME_SA);
  137.             String nomeConnettore = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_CONNETTORI_MULTIPLI_NOME);
  138.             String descrizioneConnettore = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_CONNETTORI_MULTIPLI_DESCRIZIONE);
  139.             String statoConnettore = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_CONNETTORI_MULTIPLI_STATO);
  140.             String filtriConnettore = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_CONNETTORI_MULTIPLI_FILTRI);

  141.             String nomeservizioApplicativo = porteApplicativeHelper.getParameter(ServiziApplicativiCostanti.PARAMETRO_SERVIZI_APPLICATIVI_NOME_SERVIZIO_APPLICATIVO);
  142.             if(nomeservizioApplicativo == null)
  143.                 nomeservizioApplicativo = "";
  144.             String idsil = porteApplicativeHelper.getParameter(ServiziApplicativiCostanti.PARAMETRO_SERVIZI_APPLICATIVI_ID_SERVIZIO_APPLICATIVO);

  145.             String tipoauthRichiesta = porteApplicativeHelper.getParameter(ConnettoriCostanti.PARAMETRO_INVOCAZIONE_CREDENZIALI_TIPO_AUTENTICAZIONE);

  146.             String sbustamento = porteApplicativeHelper.getParameter(ServiziApplicativiCostanti.PARAMETRO_SERVIZI_APPLICATIVI_SBUSTAMENTO_SOAP);
  147.             String sbustamentoInformazioniProtocolloRichiesta = porteApplicativeHelper.getParameter(ServiziApplicativiCostanti.PARAMETRO_SERVIZI_APPLICATIVI_SBUSTAMENTO_INFO_PROTOCOLLO_RICHIESTA);
  148.             String getmsg = porteApplicativeHelper.getParameter(ServiziApplicativiCostanti.PARAMETRO_SERVIZI_APPLICATIVI_MESSAGE_BOX);
  149.             String getmsgUsername = porteApplicativeHelper.getParameter(ConnettoriCostanti.PARAMETRO_CREDENZIALI_AUTENTICAZIONE_USERNAME);
  150.             String getmsgPassword = porteApplicativeHelper.getParameter(ConnettoriCostanti.PARAMETRO_CREDENZIALI_AUTENTICAZIONE_PASSWORD);
  151.             String changepwd = porteApplicativeHelper.getParameter(ConnettoriCostanti.PARAMETRO_CREDENZIALI_AUTENTICAZIONE_CHANGE_PASSWORD);
  152.             String tipoCredenzialiSSLVerificaTuttiICampi = porteApplicativeHelper.getParameter(ConnettoriCostanti.PARAMETRO_CREDENZIALI_AUTENTICAZIONE_CONFIGURAZIONE_SSL_VERIFICA_TUTTI_CAMPI);
  153.             if (tipoCredenzialiSSLVerificaTuttiICampi == null) {
  154.                 tipoCredenzialiSSLVerificaTuttiICampi = ConnettoriCostanti.DEFAULT_VALUE_PARAMETRO_CREDENZIALI_AUTENTICAZIONE_CONFIGURAZIONE_SSL_VERIFICA_TUTTI_CAMPI;
  155.             }
  156.            
  157.             String invrifRichiesta = porteApplicativeHelper.getParameter(ServiziApplicativiCostanti.PARAMETRO_SERVIZI_APPLICATIVI_INVIO_PER_RIFERIMENTO_RICHIESTA);

  158.             String risprif = porteApplicativeHelper.getParameter(ServiziApplicativiCostanti.PARAMETRO_SERVIZI_APPLICATIVI_RISPOSTA_PER_RIFERIMENTO);

  159.             Properties parametersPOST = null;

  160.             String endpointtype = porteApplicativeHelper.readEndPointType();
  161.             String tipoconn = porteApplicativeHelper.getParameter(ConnettoriCostanti.PARAMETRO_CONNETTORE_TIPO_PERSONALIZZATO );
  162.             String autenticazioneHttp = porteApplicativeHelper.getParameter(ConnettoriCostanti.PARAMETRO_CONNETTORE_ENDPOINT_TYPE_ENABLE_HTTP);

  163.             String connettoreDebug = porteApplicativeHelper.getParameter(ConnettoriCostanti.PARAMETRO_CONNETTORE_DEBUG);

  164.             // token policy
  165.             String autenticazioneTokenS = porteApplicativeHelper.getParameter(ConnettoriCostanti.PARAMETRO_CONNETTORE_TOKEN_POLICY_STATO);
  166.             boolean autenticazioneToken = ServletUtils.isCheckBoxEnabled(autenticazioneTokenS);
  167.             String tokenPolicy = porteApplicativeHelper.getParameter(ConnettoriCostanti.PARAMETRO_CONNETTORE_TOKEN_POLICY);
  168.             boolean forcePDND = false;
  169.             boolean forceOAuth = false;

  170.             // proxy
  171.             String proxyEnabled = porteApplicativeHelper.getParameter(ConnettoriCostanti.PARAMETRO_CONNETTORE_PROXY_ENABLED);
  172.             String proxyHostname = porteApplicativeHelper.getParameter(ConnettoriCostanti.PARAMETRO_CONNETTORE_PROXY_HOSTNAME);
  173.             String proxyPort = porteApplicativeHelper.getParameter(ConnettoriCostanti.PARAMETRO_CONNETTORE_PROXY_PORT);
  174.             String proxyUsername = porteApplicativeHelper.getParameter(ConnettoriCostanti.PARAMETRO_CONNETTORE_PROXY_USERNAME);
  175.             String proxyPassword = porteApplicativeHelper.getLockedParameter(ConnettoriCostanti.PARAMETRO_CONNETTORE_PROXY_PASSWORD);

  176.             // tempi risposta
  177.             String tempiRispostaEnabled = porteApplicativeHelper.getParameter(ConnettoriCostanti.PARAMETRO_CONNETTORE_TEMPI_RISPOSTA_REDEFINE);
  178.             String tempiRispostaConnectionTimeout = porteApplicativeHelper.getParameter(ConnettoriCostanti.PARAMETRO_CONNETTORE_TEMPI_RISPOSTA_CONNECTION_TIMEOUT);
  179.             String tempiRispostaReadTimeout = porteApplicativeHelper.getParameter(ConnettoriCostanti.PARAMETRO_CONNETTORE_TEMPI_RISPOSTA_READ_TIMEOUT);
  180.             String tempiRispostaTempoMedioRisposta = porteApplicativeHelper.getParameter(ConnettoriCostanti.PARAMETRO_CONNETTORE_TEMPI_RISPOSTA_TEMPO_MEDIO_RISPOSTA);

  181.             // opzioni avanzate
  182.             String transferMode = porteApplicativeHelper.getParameter(ConnettoriCostanti.PARAMETRO_CONNETTORE_OPZIONI_AVANZATE_TRANSFER_MODE);
  183.             String transferModeChunkSize = porteApplicativeHelper.getParameter(ConnettoriCostanti.PARAMETRO_CONNETTORE_OPZIONI_AVANZATE_TRANSFER_CHUNK_SIZE);
  184.             String redirectMode = porteApplicativeHelper.getParameter(ConnettoriCostanti.PARAMETRO_CONNETTORE_OPZIONI_AVANZATE_REDIRECT_MODE);
  185.             String redirectMaxHop = porteApplicativeHelper.getParameter(ConnettoriCostanti.PARAMETRO_CONNETTORE_OPZIONI_AVANZATE_REDIRECT_MAX_HOP);
  186.             String opzioniAvanzate = ConnettoriHelper.getOpzioniAvanzate(porteApplicativeHelper, transferMode, redirectMode);

  187.             String user= null;
  188.             String password =null;

  189.             // http
  190.             String url = porteApplicativeHelper.getParameter(ConnettoriCostanti.PARAMETRO_CONNETTORE_URL  );
  191.             if(TipiConnettore.HTTP.toString().equals(endpointtype)){
  192.                 user = porteApplicativeHelper.getParameter(ConnettoriCostanti.PARAMETRO_INVOCAZIONE_CREDENZIALI_AUTENTICAZIONE_USERNAME);
  193.                 password = porteApplicativeHelper.getLockedParameter(ConnettoriCostanti.PARAMETRO_INVOCAZIONE_CREDENZIALI_AUTENTICAZIONE_PASSWORD);
  194.             }

  195.             // api key
  196.             String autenticazioneApiKey = porteApplicativeHelper.getParameter(ConnettoriCostanti.PARAMETRO_CONNETTORE_ENDPOINT_TYPE_ENABLE_API_KEY);
  197.             String apiKeyHeader = porteApplicativeHelper.getParameter(ConnettoriCostanti.PARAMETRO_CONNETTORE_API_KEY_HEADER);
  198.             if(apiKeyHeader==null || StringUtils.isEmpty(apiKeyHeader)) {
  199.                 apiKeyHeader = CostantiConnettori.DEFAULT_HEADER_API_KEY;
  200.             }
  201.             String apiKeyValue = porteApplicativeHelper.getLockedParameter(ConnettoriCostanti.PARAMETRO_CONNETTORE_API_KEY_VALUE);
  202.             String appIdHeader = porteApplicativeHelper.getParameter(ConnettoriCostanti.PARAMETRO_CONNETTORE_API_KEY_APP_ID_HEADER);
  203.             if(appIdHeader==null || StringUtils.isEmpty(appIdHeader)) {
  204.                 appIdHeader = CostantiConnettori.DEFAULT_HEADER_APP_ID;
  205.             }
  206.             String appIdValue = porteApplicativeHelper.getParameter(ConnettoriCostanti.PARAMETRO_CONNETTORE_API_KEY_APP_ID_VALUE);
  207.             String useOAS3NamesTmp = porteApplicativeHelper.getParameter(ConnettoriCostanti.PARAMETRO_CONNETTORE_API_KEY_NOMI_OAS);
  208.             boolean useOAS3Names=true;
  209.             if(useOAS3NamesTmp!=null && StringUtils.isNotEmpty(useOAS3NamesTmp)) {
  210.                 useOAS3Names = ServletUtils.isCheckBoxEnabled(useOAS3NamesTmp);
  211.             }
  212.             else {
  213.                 useOAS3Names = porteApplicativeHelper.isAutenticazioneApiKeyUseOAS3Names(apiKeyHeader, appIdHeader);
  214.             }
  215.             String useAppIdTmp = porteApplicativeHelper.getParameter(ConnettoriCostanti.PARAMETRO_CONNETTORE_API_KEY_USE_APP_ID);
  216.             boolean useAppId=false;
  217.             if(useAppIdTmp!=null && StringUtils.isNotEmpty(useAppIdTmp)) {
  218.                 useAppId = ServletUtils.isCheckBoxEnabled(useAppIdTmp);
  219.             }
  220.             else {
  221.                 useAppId = porteApplicativeHelper.isAutenticazioneApiKeyUseAppId(appIdValue);
  222.             }
  223.            
  224.             // jms
  225.             String nomeCodaJms = porteApplicativeHelper.getParameter(ConnettoriCostanti.PARAMETRO_CONNETTORE_JMS_NOME_CODA);
  226.             String tipoJms = porteApplicativeHelper.getParameter(ConnettoriCostanti.PARAMETRO_CONNETTORE_JMS_TIPO_CODA);
  227.             String initcont = porteApplicativeHelper.getParameter(ConnettoriCostanti.PARAMETRO_CONNETTORE_JMS_INIT_CTX);
  228.             String urlpgk = porteApplicativeHelper.getParameter(ConnettoriCostanti.PARAMETRO_CONNETTORE_JMS_URL_PKG);
  229.             String provurl = porteApplicativeHelper.getParameter(ConnettoriCostanti.PARAMETRO_CONNETTORE_JMS_PROVIDER_URL);
  230.             String connfact = porteApplicativeHelper.getParameter(ConnettoriCostanti.PARAMETRO_CONNETTORE_JMS_CONNECTION_FACTORY);
  231.             String tipoSendas = porteApplicativeHelper.getParameter(ConnettoriCostanti.PARAMETRO_CONNETTORE_JMS_TIPO_OGGETTO_JMS);
  232.             if(TipiConnettore.JMS.toString().equals(endpointtype)){
  233.                 user = porteApplicativeHelper.getParameter(ConnettoriCostanti.PARAMETRO_CONNETTORE_JMS_USERNAME);
  234.                 password = porteApplicativeHelper.getLockedParameter(ConnettoriCostanti.PARAMETRO_CONNETTORE_JMS_PASSWORD);
  235.             }

  236.             // https
  237.             String httpsurl = url;
  238.             String httpstipologia = porteApplicativeHelper.getParameter(ConnettoriCostanti.PARAMETRO_CONNETTORE_HTTPS_SSL_TYPE );
  239.             String httpshostverifyS = porteApplicativeHelper.getParameter(ConnettoriCostanti.PARAMETRO_CONNETTORE_HTTPS_HOST_VERIFY);
  240.             String httpsTrustVerifyCertS = porteApplicativeHelper.getParameter(ConnettoriCostanti.PARAMETRO_CONNETTORE_HTTPS_TRUST_VERIFY_CERTS );
  241.             boolean httpsTrustVerifyCert = ServletUtils.isCheckBoxEnabled(httpsTrustVerifyCertS);
  242.             String httpspath = porteApplicativeHelper.getParameter(ConnettoriCostanti.PARAMETRO_CONNETTORE_HTTPS_TRUST_STORE_LOCATION );
  243.             String httpstipo = porteApplicativeHelper.getParameter(ConnettoriCostanti.PARAMETRO_CONNETTORE_HTTPS_TRUST_STORE_TYPE);
  244.             String httpspwd = porteApplicativeHelper.getLockedParameter(ConnettoriCostanti.PARAMETRO_CONNETTORE_HTTPS_TRUST_STORE_PASSWORD);
  245.             String httpsalgoritmo = porteApplicativeHelper.getParameter(ConnettoriCostanti.PARAMETRO_CONNETTORE_HTTPS_TRUST_MANAGEMENT_ALGORITM);
  246.             String httpsstatoS = porteApplicativeHelper.getParameter(ConnettoriCostanti.PARAMETRO_CONNETTORE_HTTPS_STATO);
  247.             String httpskeystore = porteApplicativeHelper.getParameter(ConnettoriCostanti.PARAMETRO_CONNETTORE_HTTPS_KEYSTORE_CLIENT_AUTH_MODE);
  248.             String httpspwdprivatekeytrust = porteApplicativeHelper.getLockedParameter(ConnettoriCostanti.PARAMETRO_CONNETTORE_HTTPS_PASSWORD_PRIVATE_KEY_STORE);
  249.             String httpspathkey = porteApplicativeHelper.getParameter(ConnettoriCostanti.PARAMETRO_CONNETTORE_HTTPS_KEY_STORE_LOCATION);
  250.             String httpstipokey = porteApplicativeHelper.getParameter(ConnettoriCostanti.PARAMETRO_CONNETTORE_HTTPS_KEY_STORE_TYPE);
  251.             String httpspwdkey = porteApplicativeHelper.getLockedParameter(ConnettoriCostanti.PARAMETRO_CONNETTORE_HTTPS_KEY_STORE_PASSWORD);
  252.             String httpspwdprivatekey = porteApplicativeHelper.getLockedParameter(ConnettoriCostanti.PARAMETRO_CONNETTORE_HTTPS_PASSWORD_PRIVATE_KEY_KEYSTORE);
  253.             String httpsalgoritmokey = porteApplicativeHelper.getParameter(ConnettoriCostanti.PARAMETRO_CONNETTORE_HTTPS_KEY_MANAGEMENT_ALGORITM);
  254.             String httpsKeyAlias = porteApplicativeHelper.getParameter(ConnettoriCostanti.PARAMETRO_CONNETTORE_HTTPS_ALIAS_PRIVATE_KEY_KEYSTORE);
  255.             String httpsTrustStoreCRLs = porteApplicativeHelper.getParameter(ConnettoriCostanti.PARAMETRO_CONNETTORE_HTTPS_TRUST_STORE_CRL);
  256.             String httpsTrustStoreOCSPPolicy = porteApplicativeHelper.getParameter(ConnettoriCostanti.PARAMETRO_CONNETTORE_HTTPS_TRUST_STORE_OCSP_POLICY);
  257.             String httpsKeyStoreBYOKPolicy = porteApplicativeHelper.getParameter(ConnettoriCostanti.PARAMETRO_CONNETTORE_HTTPS_KEY_STORE_BYOK_POLICY);
  258.             if(TipiConnettore.HTTPS.toString().equals(endpointtype)){
  259.                 user = porteApplicativeHelper.getParameter(ConnettoriCostanti.PARAMETRO_INVOCAZIONE_CREDENZIALI_AUTENTICAZIONE_USERNAME);
  260.                 password = porteApplicativeHelper.getLockedParameter(ConnettoriCostanti.PARAMETRO_INVOCAZIONE_CREDENZIALI_AUTENTICAZIONE_PASSWORD);
  261.             }

  262.             // file
  263.             String requestOutputFileName = porteApplicativeHelper.getParameter(ConnettoriCostanti.PARAMETRO_CONNETTORE_FILE_REQUEST_OUTPUT_FILE_NAME);
  264.             String requestOutputFileNamePermissions = porteApplicativeHelper.getParameter(ConnettoriCostanti.PARAMETRO_CONNETTORE_FILE_REQUEST_OUTPUT_FILE_NAME_PERMISSIONS);
  265.             String requestOutputFileNameHeaders = porteApplicativeHelper.getParameter(ConnettoriCostanti.PARAMETRO_CONNETTORE_FILE_REQUEST_OUTPUT_FILE_NAME_HEADERS);
  266.             String requestOutputFileNameHeadersPermissions = porteApplicativeHelper.getParameter(ConnettoriCostanti.PARAMETRO_CONNETTORE_FILE_REQUEST_OUTPUT_FILE_NAME_HEADERS_PERMISSIONS);
  267.             String requestOutputParentDirCreateIfNotExists = porteApplicativeHelper.getParameter(ConnettoriCostanti.PARAMETRO_CONNETTORE_FILE_REQUEST_OUTPUT_AUTO_CREATE_DIR);
  268.             String requestOutputOverwriteIfExists = porteApplicativeHelper.getParameter(ConnettoriCostanti.PARAMETRO_CONNETTORE_FILE_REQUEST_OUTPUT_OVERWRITE_FILE_NAME);
  269.             String responseInputMode = porteApplicativeHelper.getParameter(ConnettoriCostanti.PARAMETRO_CONNETTORE_FILE_RESPONSE_INPUT_MODE);
  270.             String responseInputFileName = porteApplicativeHelper.getParameter(ConnettoriCostanti.PARAMETRO_CONNETTORE_FILE_RESPONSE_INPUT_FILE_NAME);
  271.             String responseInputFileNameHeaders = porteApplicativeHelper.getParameter(ConnettoriCostanti.PARAMETRO_CONNETTORE_FILE_RESPONSE_INPUT_FILE_NAME_HEADERS);
  272.             String responseInputDeleteAfterRead = porteApplicativeHelper.getParameter(ConnettoriCostanti.PARAMETRO_CONNETTORE_FILE_RESPONSE_INPUT_FILE_NAME_DELETE_AFTER_READ);
  273.             String responseInputWaitTime = porteApplicativeHelper.getParameter(ConnettoriCostanti.PARAMETRO_CONNETTORE_FILE_RESPONSE_INPUT_WAIT_TIME);

  274.             // status
  275.             ConnettoreStatusParams connettoreStatusParams = ConnettoreStatusParams.fillFrom(porteApplicativeHelper);
  276.                        
  277.             String erogazioneServizioApplicativoServerEnabledS = porteApplicativeHelper.getParameter(AccordiServizioParteSpecificaCostanti.PARAMETRO_APS_ABILITA_USO_APPLICATIVO_SERVER);
  278.             boolean erogazioneServizioApplicativoServerEnabled = ServletUtils.isCheckBoxEnabled(erogazioneServizioApplicativoServerEnabledS);
  279.             String erogazioneServizioApplicativoServer = porteApplicativeHelper.getParameter(AccordiServizioParteSpecificaCostanti.PARAMETRO_APS_ID_APPLICATIVO_SERVER);

  280.             boolean httpshostverify = false;
  281.             if (httpshostverifyS != null && httpshostverifyS.equals(Costanti.CHECK_BOX_ENABLED))
  282.                 httpshostverify = true;
  283.             boolean httpsstato = false;
  284.             if (httpsstatoS != null && httpsstatoS.equals(Costanti.CHECK_BOX_ENABLED))
  285.                 httpsstato = true;

  286.             Boolean isConnettoreCustomUltimaImmagineSalvata = null;

  287.             Connettore conTmp = null;
  288.             List<ExtendedConnettore> listExtendedConnettore =
  289.                     ServletExtendedConnettoreUtils.getExtendedConnettore(conTmp, ConnettoreServletType.ACCORDO_SERVIZIO_PARTE_SPECIFICA_PORTA_APPLICATIVA_ADD, porteApplicativeHelper,
  290.                             parametersPOST, (endpointtype==null), endpointtype); // uso endpointtype per capire se è la prima volta che entro

  291.             boolean accessoDaListaAPS = false;
  292.             String accessoDaAPSParametro = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_CONNETTORE_DA_LISTA_APS);
  293.             if(Costanti.CHECK_BOX_ENABLED_TRUE.equals(accessoDaAPSParametro)) {
  294.                 accessoDaListaAPS = true;
  295.             }

  296.             boolean isModalitaCompleta = porteApplicativeHelper.isModalitaCompleta();
  297.             Boolean vistaErogazioni = ServletUtils.getBooleanAttributeFromSession(ErogazioniCostanti.ASPS_EROGAZIONI_ATTRIBUTO_VISTA_EROGAZIONI, session, request).getValue();

  298.             boolean postBackViaPost = true;
  299.            
  300.             // Preparo il menu
  301.             porteApplicativeHelper.makeMenu();

  302.             // Prendo nome, tipo e pdd del soggetto
  303.             PorteApplicativeCore porteApplicativeCore = new PorteApplicativeCore();
  304.             AccordiServizioParteSpecificaCore apsCore = new AccordiServizioParteSpecificaCore(porteApplicativeCore);
  305.             SoggettiCore soggettiCore = new SoggettiCore(porteApplicativeCore);
  306.             ServiziApplicativiCore saCore = new ServiziApplicativiCore(porteApplicativeCore);
  307.             AccordiServizioParteComuneCore apcCore = new AccordiServizioParteComuneCore(porteApplicativeCore);

  308.             // Prendo nome della porta applicativa
  309.             PortaApplicativa pa = porteApplicativeCore.getPortaApplicativa(idInt);
  310.             if(pa==null) {
  311.                 throw new ControlStationCoreException("PortaApplicativa con id '"+idInt+"' non trovata");
  312.             }
  313.             boolean behaviourConFiltri = ConditionalUtils.isConfigurazioneCondizionaleByFilter(pa, ControlStationCore.getLog());
  314.             String idporta = pa.getNome();
  315.             String protocollo = soggettiCore.getProtocolloAssociatoTipoSoggetto(pa.getTipoSoggettoProprietario());
  316.             TipoBehaviour beaBehaviourType = TipoBehaviour.toEnumConstant(pa.getBehaviour().getNome());
  317.             long idAspsLong = Long.parseLong(idAsps);
  318.             AccordoServizioParteSpecifica asps = apsCore.getAccordoServizioParteSpecifica(idAspsLong);
  319.             AccordoServizioParteComuneSintetico apc = apcCore.getAccordoServizioSintetico(asps.getIdAccordo());
  320.             ServiceBinding serviceBinding = apcCore.toMessageServiceBinding(apc.getServiceBinding());

  321.             // valora iniziale della configurazione
  322.             PortaApplicativaServizioApplicativo oldPaSA = null;
  323.             for (PortaApplicativaServizioApplicativo paSATmp : pa.getServizioApplicativoList()) {
  324.                 if(paSATmp.getNome().equals(nomeSAConnettore)) {
  325.                     oldPaSA = paSATmp;                  
  326.                 }
  327.             }
  328.            
  329.             boolean integrationManagerEnabled = !porteApplicativeHelper.isModalitaStandard() && porteApplicativeCore.isIntegrationManagerEnabled();
  330.             boolean isSoapOneWay = false;
  331.             if(pa!=null) {
  332.                 MappingErogazionePortaApplicativa mappingErogazionePortaApplicativa = porteApplicativeCore.getMappingErogazionePortaApplicativa(pa);
  333.                 isSoapOneWay = porteApplicativeHelper.isSoapOneWay(pa, mappingErogazionePortaApplicativa, asps, apc, serviceBinding);
  334.             }
  335.             if(integrationManagerEnabled) {
  336.                 if(TipoBehaviour.CONSEGNA_CON_NOTIFICHE.equals(beaBehaviourType)) {
  337.                     ConfigurazioneMultiDeliver confMultiDeliver = MultiDeliverUtils.read(pa);
  338.                     String nomeConnettoreSincrono = null;
  339.                     if(confMultiDeliver!=null) {
  340.                         nomeConnettoreSincrono = confMultiDeliver.getTransazioneSincrona_nomeConnettore();
  341.                     }
  342.                     String oldNomeConnettore = porteApplicativeHelper.getLabelNomePortaApplicativaServizioApplicativo(oldPaSA);
  343.                     integrationManagerEnabled = !oldNomeConnettore.equals(nomeConnettoreSincrono); // l'integration manager e' abilitato solamente se e' il connettore adibito alle notifiche
  344.                 }
  345.                 else {
  346.                     integrationManagerEnabled = isSoapOneWay; // l'integration manager e' abilitato solamente se c'e' almeno una azione oneway in api soap
  347.                 }
  348.             }
  349.            
  350.             boolean isApplicativiServerEnabled = apsCore.isApplicativiServerEnabled(porteApplicativeHelper);
  351.             String filtroTipoSA = isApplicativiServerEnabled ? ServiziApplicativiCostanti.VALUE_SERVIZI_APPLICATIVI_TIPO_SERVER : null;

  352.             String nomeProtocollo = soggettiCore.getProtocolloAssociatoTipoSoggetto(pa.getTipoSoggettoProprietario());

  353.             PortaApplicativaServizioApplicativoConnettore oldDatiConnettore = oldPaSA.getDatiConnettore();
  354.             IDServizioApplicativo idSA = new IDServizioApplicativo();
  355.             idSA.setNome(oldPaSA.getNome());
  356.             idSA.setIdSoggettoProprietario(new IDSoggetto(pa.getTipoSoggettoProprietario(), pa.getNomeSoggettoProprietario()));
  357.             IDServizioApplicativoDB idSADB = new IDServizioApplicativoDB(idSA);
  358.             idSADB.setId(oldPaSA.getId());
  359.             ServizioApplicativo oldSA = saCore.getServizioApplicativo(idSA );
  360.             if(oldSA==null) {
  361.                 throw new ControlStationCoreException("ServizioApplicativo con id '"+idSA+"' non trovata");
  362.             }
  363.             InvocazionePorta invocazionePorta = oldSA.getInvocazionePorta();
  364.             InvocazioneServizio oldIS = oldSA.getInvocazioneServizio();
  365.             if(oldIS==null) {
  366.                 throw new ControlStationCoreException("ServizioApplicativo con id '"+idSA+"' senza InvocazioneServizio");
  367.             }
  368.             InvocazioneCredenziali oldCis = oldIS.getCredenziali();
  369.             Connettore oldConnis = oldIS.getConnettore();
  370.             isConnettoreCustomUltimaImmagineSalvata = oldConnis.getCustom();
  371.             List<Property> oldCP = oldConnis.getPropertyList();
  372.             String oldTipoSA = oldSA.getTipo();

  373.             // Lista dei servizi applicativi per la creazione automatica
  374.             List<IDServizioApplicativoDB> listaIdSAServer = null;  
  375.             if ((idsogg != null) && !idsogg.equals("")) {
  376.                 long idErogatore = Long.parseLong(idsogg);

  377.                 // I servizi applicativi da visualizzare sono quelli che hanno
  378.                 // -Integration Manager (getMessage abilitato)
  379.                 // -connettore != disabilitato
  380.                 listaIdSAServer = saCore.getIdServiziApplicativiWithIdErogatore(idErogatore, filtroTipoSA, integrationManagerEnabled, true);

  381.             }

  382.             String postBackElementName = porteApplicativeHelper.getPostBackElementName();

  383.             boolean initConnettoreFromSA = false;
  384.             boolean initConnettore = false;
  385.             if(postBackElementName != null ){
  386.                
  387.                 if(postBackElementName.equalsIgnoreCase(ConnettoriCostanti.PARAMETRO_CONNETTORE_ABILITA_USO_APPLICATIVO_SERVER)){
  388.                     // devo resettare il connettore se passo da SA Server a Default
  389.                     if(!erogazioneServizioApplicativoServerEnabled) {
  390.                        
  391.                         boolean isDefault = true;
  392.                         if(oldDatiConnettore != null) {
  393.                             isDefault = !oldDatiConnettore.isNotifica();
  394.                         }
  395.                                                
  396.                         // vecchio SA era un Server allora devo fare il reinit del connettore
  397.                         if(ServiziApplicativiCostanti.VALUE_SERVIZI_APPLICATIVI_TIPO_SERVER.equals(oldTipoSA)) {
  398.                            
  399.                             if(isDefault) {
  400.                                
  401.                                 idSA.setNome(pa.getServizioApplicativoDefault());
  402.                                 idSADB.setNome(pa.getServizioApplicativoDefault());
  403.                                 oldSA = saCore.getServizioApplicativo(idSA);
  404.                                 idSADB.setId(oldSA.getId());
  405.                                 invocazionePorta = oldSA.getInvocazionePorta();
  406.                                 oldIS = oldSA.getInvocazioneServizio();
  407.                                 oldCis = oldIS.getCredenziali();
  408.                                 oldConnis = oldIS.getConnettore();
  409.                                 oldCP = oldConnis.getPropertyList();
  410.                                 oldTipoSA = oldSA.getTipo();
  411.                                
  412.                                 // reset dei fields
  413.                                 erogazioneServizioApplicativoServer = null;
  414.                                
  415.                                 sbustamento = null;
  416.                                 sbustamentoInformazioniProtocolloRichiesta = null;
  417.                                 getmsg = null;
  418.                                 getmsgUsername = null;
  419.                                 getmsgPassword = null;
  420.                                 invrifRichiesta = null;
  421.                                 risprif = null;
  422.                                 tipoauthRichiesta = null;
  423.                                 endpointtype = porteApplicativeHelper.readEndPointType();
  424.                                 tipoconn = null;
  425.                                 autenticazioneHttp = null;
  426.                                 user = null;
  427.                                 password = null;
  428.                                 connettoreDebug = null;
  429.    
  430.                                 // token policy
  431.                                 autenticazioneTokenS = null;
  432.                                 autenticazioneToken = ServletUtils.isCheckBoxEnabled(autenticazioneTokenS);
  433.                                 tokenPolicy = null;
  434.    
  435.                                 // api key
  436.                                 autenticazioneApiKey=null;
  437.                                 apiKeyValue=null;
  438.                                 apiKeyHeader=null;
  439.                                 appIdValue=null;
  440.                                 appIdHeader=null;
  441.                                
  442.                                 // proxy
  443.                                 proxyEnabled = null;
  444.                                 proxyHostname = null;
  445.                                 proxyPort = null;
  446.                                 proxyUsername = null;
  447.                                 proxyPassword = null;
  448.    
  449.                                 // tempi risposta
  450.                                 tempiRispostaEnabled = null;
  451.                                 tempiRispostaConnectionTimeout = null;
  452.                                 tempiRispostaReadTimeout = null;
  453.                                 tempiRispostaTempoMedioRisposta = null;
  454.    
  455.                                 // opzioni avanzate
  456.                                 transferMode = null;
  457.                                 transferModeChunkSize = null;
  458.                                 redirectMode = null;
  459.                                 redirectMaxHop = null;
  460.                                 opzioniAvanzate = ConnettoriHelper.getOpzioniAvanzate(porteApplicativeHelper, transferMode, redirectMode);
  461.    
  462.                                 // http
  463.                                 url = null;
  464.    
  465.                                 // jms
  466.                                 nomeCodaJms = null;
  467.                                 tipoJms = null;
  468.                                 initcont = null;
  469.                                 urlpgk = null;
  470.                                 provurl = null;
  471.                                 connfact = null;
  472.                                 tipoSendas = null;
  473.    
  474.                                 // https
  475.                                 httpsurl = url;
  476.                                 httpstipologia = null;
  477.                                 httpshostverifyS = null;
  478.                                 httpshostverify = ServletUtils.isCheckBoxEnabled(httpshostverifyS);
  479.                                 httpsTrustVerifyCertS=null;
  480.                                 httpsTrustVerifyCert = ConnettoriCostanti.DEFAULT_CONNETTORE_HTTPS_TRUST_VERIFY_CERTS;
  481.                                 httpspath = null;
  482.                                 httpstipo = null;
  483.                                 httpspwd = null;
  484.                                 httpsalgoritmo = null;
  485.                                 httpsstatoS = null;
  486.                                 httpsstato = ServletUtils.isCheckBoxEnabled(httpsstatoS);
  487.                                 httpskeystore = null;
  488.                                 httpspwdprivatekeytrust = null;
  489.                                 httpspathkey = null;
  490.                                 httpstipokey = null;
  491.                                 httpspwdkey = null;
  492.                                 httpspwdprivatekey = null;
  493.                                 httpsalgoritmokey = null;
  494.                                 httpsKeyAlias = null;
  495.                                 httpsTrustStoreCRLs = null;
  496.                                 httpsTrustStoreOCSPPolicy = null;
  497.                                 httpsKeyStoreBYOKPolicy = null;
  498.    
  499.                                 // file
  500.                                 requestOutputFileName = null;
  501.                                 requestOutputFileNamePermissions = null;
  502.                                 requestOutputFileNameHeaders = null;
  503.                                 requestOutputFileNameHeadersPermissions = null;
  504.                                 requestOutputParentDirCreateIfNotExists = null;
  505.                                 requestOutputOverwriteIfExists = null;
  506.                                 responseInputMode = null;
  507.                                 responseInputFileName = null;
  508.                                 responseInputFileNameHeaders = null;
  509.                                 responseInputDeleteAfterRead = null;
  510.                                 responseInputWaitTime = null;
  511.                                
  512.                                 initConnettoreFromSA = true; // devo rileggerlo dal nuovo SA
  513.                                
  514.                             }
  515.                             else {
  516.                                 initConnettore = true;
  517.                             }
  518.                            
  519.                         } else {
  520.                             initConnettoreFromSA = true;
  521.                         }
  522.                     } else {
  523.                         // vecchio SA non era un Server allora devo fare il reinit del connettore
  524.                         if(!ServiziApplicativiCostanti.VALUE_SERVIZI_APPLICATIVI_TIPO_SERVER.equals(oldTipoSA)) {
  525.                             initConnettoreFromSA = true;
  526.                         } else {
  527.                             initConnettore = true;
  528.                         }
  529.                     }
  530.                 }
  531.                
  532.                 // Tempi di risposta
  533.                 if(postBackElementName.equalsIgnoreCase(ConnettoriCostanti.PARAMETRO_CONNETTORE_TEMPI_RISPOSTA_REDEFINE) &&
  534.                     (tempiRispostaConnectionTimeout==null || "".equals(tempiRispostaConnectionTimeout)
  535.                             ||
  536.                             tempiRispostaReadTimeout==null || "".equals(tempiRispostaReadTimeout)
  537.                             ||
  538.                             tempiRispostaTempoMedioRisposta==null || "".equals(tempiRispostaTempoMedioRisposta) )
  539.                     ){
  540.                        
  541.                     ConfigurazioneCore configCore = new ConfigurazioneCore(porteApplicativeCore);
  542.                     ConfigurazioneGenerale configGenerale = configCore.getConfigurazioneControlloTraffico();
  543.                                            
  544.                     if(tempiRispostaConnectionTimeout==null || "".equals(tempiRispostaConnectionTimeout) ) {
  545.                         tempiRispostaConnectionTimeout = configGenerale.getTempiRispostaErogazione().getConnectionTimeout().intValue()+"";
  546.                     }
  547.                     if(tempiRispostaReadTimeout==null || "".equals(tempiRispostaReadTimeout) ) {
  548.                         tempiRispostaReadTimeout = configGenerale.getTempiRispostaErogazione().getReadTimeout().intValue()+"";
  549.                     }
  550.                     if(tempiRispostaTempoMedioRisposta==null || "".equals(tempiRispostaTempoMedioRisposta) ) {
  551.                         tempiRispostaTempoMedioRisposta = configGenerale.getTempiRispostaErogazione().getTempoMedioRisposta().intValue()+"";
  552.                     }
  553.                 }
  554.                
  555.                
  556.                 // Change Password basic/api
  557.                 if(postBackElementName.equalsIgnoreCase(ConnettoriCostanti.PARAMETRO_CREDENZIALI_AUTENTICAZIONE_CHANGE_PASSWORD) &&
  558.                     (!ServletUtils.isCheckBoxEnabled(changepwd)) &&
  559.                     (invocazionePorta != null && invocazionePorta.sizeCredenzialiList()>0)
  560.                     ){
  561.                     getmsgPassword = invocazionePorta.getCredenziali(0).getPassword();
  562.                 }
  563.             }

  564.             boolean forceEnableConnettore = false;
  565.             if(getmsg!=null && CostantiConfigurazione.ABILITATO.toString().equals(getmsg)) {
  566.                 forceEnableConnettore = false;
  567.             }
  568.             else {
  569.                 forceEnableConnettore = true;
  570.                 if(TipiConnettore.DISABILITATO.getNome().equals(endpointtype)) {
  571.                     endpointtype = TipiConnettore.HTTP.getNome();
  572.                 }
  573.             }

  574.             List<Parameter> lstParam = porteApplicativeHelper.getTitoloPA(parentPA, idsogg, idAsps);

  575.             String labelPerPorta = null;
  576.             if(parentPA!=null && (parentPA.intValue() == PorteApplicativeCostanti.ATTRIBUTO_PORTE_APPLICATIVE_PARENT_CONFIGURAZIONE)) {
  577.                 if(accessoDaListaAPS) {
  578.                     if(!isModalitaCompleta) {
  579.                         if(vistaErogazioni != null && vistaErogazioni.booleanValue()) {
  580.                             labelPerPorta = PorteApplicativeCostanti.LABEL_PARAMETRO_PORTE_APPLICATIVE_CONNETTORI_MULTIPLI;
  581.                         } else {
  582.                             labelPerPorta = PorteApplicativeCostanti.LABEL_PARAMETRO_PORTE_APPLICATIVE_CONNETTORI_MULTIPLI_DI+
  583.                                     porteApplicativeHelper.getLabelIdServizio(asps);
  584.                         }
  585.                     }
  586.                     else {
  587.                         labelPerPorta = PorteApplicativeCostanti.LABEL_PARAMETRO_PORTE_APPLICATIVE_CONNETTORI_MULTIPLI;
  588.                     }
  589.                 }
  590.                 else {
  591.                     labelPerPorta = porteApplicativeCore.getLabelRegolaMappingErogazionePortaApplicativa(
  592.                             PorteApplicativeCostanti.LABEL_PARAMETRO_PORTE_APPLICATIVE_CONNETTORI_MULTIPLI_DI,
  593.                             PorteApplicativeCostanti.LABEL_PARAMETRO_PORTE_APPLICATIVE_CONNETTORI_MULTIPLI,
  594.                             pa);
  595.                 }
  596.             }
  597.             else {
  598.                 labelPerPorta = PorteApplicativeCostanti.LABEL_PARAMETRO_PORTE_APPLICATIVE_CONNETTORI_MULTIPLI_DI+idporta;
  599.             }

  600.             if(accessoDaListaAPS) {
  601.                 lstParam.remove(lstParam.size()-1);
  602.             }

  603.             List<Parameter> listParametersConfigutazioneConnettoriMultipli = new ArrayList<>();
  604.             Parameter pIdPorta = new Parameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID, idPorta);
  605.             Parameter pNomePorta = new Parameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_NOME, pa.getNome());
  606.             Parameter pIdSogg = new Parameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID_SOGGETTO, idsogg);
  607.             Parameter pIdAsps = new Parameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID_ASPS, idAsps);
  608.             String idTabP = porteApplicativeHelper.getParameter(CostantiControlStation.PARAMETRO_ID_TAB);
  609.             Parameter pIdTab = new Parameter(CostantiControlStation.PARAMETRO_ID_TAB, idTabP != null ? idTabP : "");
  610.             Parameter pIdConnTab = new Parameter(CostantiControlStation.PARAMETRO_ID_CONN_TAB, idConnTab != null ? idConnTab : "");
  611.             Parameter pAccessoDaAPS = new Parameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_CONNETTORE_DA_LISTA_APS, accessoDaAPSParametro != null ? accessoDaAPSParametro : "");
  612.             String connettoreAccessoGruppi = porteApplicativeHelper.getParameter(CostantiControlStation.PARAMETRO_VERIFICA_CONNETTORE_ACCESSO_DA_GRUPPI);
  613.             String connettoreRegistro = porteApplicativeHelper.getParameter(CostantiControlStation.PARAMETRO_VERIFICA_CONNETTORE_REGISTRO);
  614.             Parameter pConnettoreAccessoDaGruppi = new Parameter(CostantiControlStation.PARAMETRO_VERIFICA_CONNETTORE_ACCESSO_DA_GRUPPI, connettoreAccessoGruppi);
  615.             Parameter pConnettoreAccesso = new Parameter(CostantiControlStation.PARAMETRO_VERIFICA_CONNETTORE_REGISTRO, connettoreRegistro);
  616.             String connettoreAccessoListaConnettori = porteApplicativeHelper.getParameter(CostantiControlStation.PARAMETRO_VERIFICA_CONNETTORE_ACCESSO_DA_LISTA_CONNETTORI_MULTIPLI);

  617.             String idConnTabP = porteApplicativeHelper.getParameter(CostantiControlStation.PARAMETRO_ID_CONN_TAB);
  618.             Parameter pIdConTab = new Parameter(CostantiControlStation.PARAMETRO_ID_CONN_TAB, idConnTabP != null ? idConnTabP : "");
  619.            
  620.             String visualizzaDatiGenerali = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_CONNETTORI_MULTIPLI_CONFIGURAZIONE_DATI_GENERALI);
  621.             String visualizzaDescrizione = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_CONNETTORI_MULTIPLI_CONFIGURAZIONE_DESCRIZIONE);
  622.             String visualizzaConnettore = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_CONNETTORI_MULTIPLI_CONFIGURAZIONE_CONNETTORE);
  623.             String visualizzaFiltri = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_CONNETTORI_MULTIPLI_CONFIGURAZIONE_FILTRO);
  624.             boolean visualizzaSezioneDatiGenerali = ServletUtils.isCheckBoxEnabled(visualizzaDatiGenerali);
  625.             boolean visualizzaSezioneDescrizione = ServletUtils.isCheckBoxEnabled(visualizzaDescrizione);
  626.             boolean visualizzaSezioneConnettore = ServletUtils.isCheckBoxEnabled(visualizzaConnettore);
  627.             boolean visualizzaSezioneFiltri = ServletUtils.isCheckBoxEnabled(visualizzaFiltri);
  628.            
  629.             String nomeConnettoreChangeListBreadcump = null;
  630.             if(visualizzaSezioneDatiGenerali) {
  631.                 nomeConnettoreChangeListBreadcump = nomeConnettore;
  632.             }
  633.             else {
  634.                
  635.                 // valora iniziale della configurazione
  636.                 PortaApplicativaServizioApplicativo paSA = null;
  637.                 for (PortaApplicativaServizioApplicativo paSATmp : pa.getServizioApplicativoList()) {
  638.                     if(paSATmp.getNome().equals(nomeSAConnettore)) {
  639.                         paSA = paSATmp;                
  640.                     }
  641.                 }

  642.                 PortaApplicativaServizioApplicativoConnettore datiConnettore = paSA.getDatiConnettore();
  643.                
  644.                 if(datiConnettore!=null) {
  645.                     nomeConnettoreChangeListBreadcump = datiConnettore.getNome();
  646.                 }
  647.                 if(nomeConnettoreChangeListBreadcump==null) {
  648.                     nomeConnettoreChangeListBreadcump = CostantiConfigurazione.NOME_CONNETTORE_DEFAULT;
  649.                 }
  650.             }
  651.             Parameter pChangeNomeConnettoreBreadcump = new Parameter(CostantiControlStation.PARAMETRO_FROM_BREADCUMP_CHANGE_NOME_CONNETTORE, nomeConnettoreChangeListBreadcump);
  652.                        
  653.             listParametersConfigutazioneConnettoriMultipli.add(pIdSogg);
  654.             listParametersConfigutazioneConnettoriMultipli.add(pIdPorta);
  655.             listParametersConfigutazioneConnettoriMultipli.add(pNomePorta);
  656.             listParametersConfigutazioneConnettoriMultipli.add(pIdAsps);
  657.             listParametersConfigutazioneConnettoriMultipli.add(pIdTab);
  658.             listParametersConfigutazioneConnettoriMultipli.add(pIdConnTab);
  659.             listParametersConfigutazioneConnettoriMultipli.add(pAccessoDaAPS);
  660.             listParametersConfigutazioneConnettoriMultipli.add(pConnettoreAccessoDaGruppi);
  661.             listParametersConfigutazioneConnettoriMultipli.add(pConnettoreAccesso);
  662.             listParametersConfigutazioneConnettoriMultipli.add(pChangeNomeConnettoreBreadcump);

  663.             lstParam.add(new Parameter(labelPerPorta,  PorteApplicativeCostanti.SERVLET_NAME_PORTE_APPLICATIVE_CONNETTORI_MULTIPLI_LIST, listParametersConfigutazioneConnettoriMultipli.toArray(new Parameter[1])));

  664.             // Label diversa in base all'operazione
  665.             String oldNomeConnettore = porteApplicativeHelper.getLabelNomePortaApplicativaServizioApplicativo(oldPaSA);
  666.             String labelPagina = oldNomeConnettore;




  667.             lstParam.add(new Parameter(labelPagina, null));

  668.             // Se nome = null, devo visualizzare la pagina per l'inserimento
  669.             // dati
  670.             if (porteApplicativeHelper.isEditModeInProgress()) {
  671.                 // setto la barra del titolo
  672.                 ServletUtils.setPageDataTitle(pd, lstParam);

  673.                 if(nomeConnettore == null) {
  674.                     nomeConnettore = oldNomeConnettore;
  675.                     descrizioneConnettore = oldDatiConnettore != null ? oldDatiConnettore.getDescrizione() : "";
  676.                     filtriConnettore = "";
  677.                     if(oldDatiConnettore != null) {
  678.                         filtriConnettore = StringUtils.join(oldDatiConnettore.getFiltroList(), ",");
  679.                     }

  680.                     statoConnettore = oldDatiConnettore != null ? oldDatiConnettore.getStato().getValue() : StatoFunzionalita.ABILITATO.getValue();
  681.                     initConnettoreFromSA = true;
  682.                 }

  683.                 if(initConnettore) {
  684.                     tipoconn = "";
  685.                     url = "";
  686.                     nomeCodaJms = "";
  687.                     tipoJms = ConnettoriCostanti.TIPI_CODE_JMS[0];
  688.                     user = "";
  689.                     password = "";
  690.                     initcont = "";
  691.                     urlpgk = "";
  692.                     provurl = "";
  693.                     connfact = "";
  694.                     tipoSendas = ConnettoriCostanti.TIPO_SEND_AS[0];
  695.                     httpsurl = "";
  696.                     httpstipologia = ConnettoriCostanti.DEFAULT_CONNETTORE_HTTPS_TYPE;
  697.                     httpshostverifyS = Costanti.CHECK_BOX_ENABLED_TRUE;
  698.                     httpshostverify = true;
  699.                     httpsTrustVerifyCert = ConnettoriCostanti.DEFAULT_CONNETTORE_HTTPS_TRUST_VERIFY_CERTS;
  700.                     httpspath = "";
  701.                     httpstipo = ConnettoriCostanti.DEFAULT_CONNETTORE_HTTPS_TIPOLOGIA_KEYSTORE_TYPE;
  702.                     httpspwd = "";
  703.                     httpsstato = false;
  704.                     httpskeystore = AccordiServizioParteSpecificaCostanti.DEFAULT_VALUE_DEFAULT;
  705.                     httpspwdprivatekeytrust = "";
  706.                     httpspathkey = "";
  707.                     httpstipokey =ConnettoriCostanti.DEFAULT_CONNETTORE_HTTPS_TIPOLOGIA_KEYSTORE_TYPE;
  708.                     httpspwdkey = "";
  709.                     httpspwdprivatekey = "";

  710.                     if(endpointtype==null) {
  711.                         if(!porteApplicativeHelper.isModalitaCompleta()) {
  712.                             endpointtype = TipiConnettore.HTTP.getNome();
  713.                         }
  714.                         else {
  715.                             endpointtype = AccordiServizioParteSpecificaCostanti.DEFAULT_VALUE_DISABILITATO;
  716.                         }
  717.                     }

  718.                     autenticazioneHttp = porteApplicativeHelper.getAutenticazioneHttp(autenticazioneHttp, endpointtype, user);

  719.                     tempiRispostaEnabled = null;
  720.                     ConfigurazioneCore configCore = new ConfigurazioneCore(porteApplicativeCore);
  721.                     ConfigurazioneGenerale configGenerale = configCore.getConfigurazioneControlloTraffico();
  722.                     tempiRispostaConnectionTimeout = configGenerale.getTempiRispostaErogazione().getConnectionTimeout().intValue()+"";
  723.                     tempiRispostaReadTimeout = configGenerale.getTempiRispostaErogazione().getReadTimeout().intValue()+"";
  724.                     tempiRispostaTempoMedioRisposta = configGenerale.getTempiRispostaErogazione().getTempoMedioRisposta().intValue()+"";


  725.                     // Devo cmq rileggere i valori se non definiti
  726.                     if(tempiRispostaConnectionTimeout==null || "".equals(tempiRispostaConnectionTimeout)
  727.                             ||
  728.                             tempiRispostaReadTimeout==null || "".equals(tempiRispostaReadTimeout)
  729.                             ||
  730.                             tempiRispostaTempoMedioRisposta==null || "".equals(tempiRispostaTempoMedioRisposta) ){
  731.                         if(tempiRispostaConnectionTimeout==null || "".equals(tempiRispostaConnectionTimeout) ) {
  732.                             tempiRispostaConnectionTimeout = configGenerale.getTempiRispostaErogazione().getConnectionTimeout().intValue()+"";
  733.                         }
  734.                         if(tempiRispostaReadTimeout==null || "".equals(tempiRispostaReadTimeout) ) {
  735.                             tempiRispostaReadTimeout = configGenerale.getTempiRispostaErogazione().getReadTimeout().intValue()+"";
  736.                         }
  737.                         if(tempiRispostaTempoMedioRisposta==null || "".equals(tempiRispostaTempoMedioRisposta) ) {
  738.                             tempiRispostaTempoMedioRisposta = configGenerale.getTempiRispostaErogazione().getTempoMedioRisposta().intValue()+"";
  739.                         }
  740.                     }
  741.                 }
  742.                
  743.                 // default (da inizializzare cmq)
  744.                 if (TipiConnettore.HTTPS.toString().equals(endpointtype)) {
  745.                     if(httpsalgoritmo==null || "".equals(httpsalgoritmo)){
  746.                         httpsalgoritmo = TrustManagerFactory.getDefaultAlgorithm();
  747.                     }
  748.                     if(httpsalgoritmokey==null || "".equals(httpsalgoritmokey)){
  749.                         httpsalgoritmokey = KeyManagerFactory.getDefaultAlgorithm();
  750.                     }
  751.                     if(httpstipologia==null || "".equals(httpstipologia)){
  752.                         httpstipologia = ConnettoriCostanti.DEFAULT_CONNETTORE_HTTPS_TYPE;
  753.                     }
  754.                     if(httpshostverifyS==null || "".equals(httpshostverifyS)){
  755.                         httpshostverifyS = Costanti.CHECK_BOX_ENABLED_TRUE;
  756.                         httpshostverify = true;
  757.                     }
  758.                     if(httpsTrustVerifyCertS==null || "".equals(httpsTrustVerifyCertS)){
  759.                         httpsTrustVerifyCertS = ConnettoriCostanti.DEFAULT_CONNETTORE_HTTPS_TRUST_VERIFY_CERTS ? Costanti.CHECK_BOX_ENABLED_TRUE : Costanti.CHECK_BOX_DISABLED;
  760.                         httpsTrustVerifyCert = ConnettoriCostanti.DEFAULT_CONNETTORE_HTTPS_TRUST_VERIFY_CERTS;
  761.                     }
  762.                 }

  763.                 if(initConnettoreFromSA) {
  764.                     if (erogazioneServizioApplicativoServer == null && isApplicativiServerEnabled &&
  765.                         // se in configurazione ho selezionato un server
  766.                         (ServiziApplicativiCostanti.VALUE_SERVIZI_APPLICATIVI_TIPO_SERVER.equals(oldTipoSA))
  767.                         ){
  768.                         erogazioneServizioApplicativoServer = oldSA.getNome();
  769.                         erogazioneServizioApplicativoServerEnabled = true;
  770.                     }

  771.                     if (sbustamento == null &&
  772.                         oldIS.getSbustamentoSoap()!=null) {
  773.                         sbustamento = oldIS.getSbustamentoSoap().toString();
  774.                     }
  775.                     if (sbustamentoInformazioniProtocolloRichiesta == null &&
  776.                         oldIS.getSbustamentoInformazioniProtocollo()!=null) {
  777.                         sbustamentoInformazioniProtocolloRichiesta = oldIS.getSbustamentoInformazioniProtocollo().toString();
  778.                     }
  779.                     if (getmsg == null &&
  780.                         (oldIS.getGetMessage()!=null)
  781.                         ){
  782.                         getmsg = oldIS.getGetMessage().toString();
  783.                         if(CostantiConfigurazione.ABILITATO.toString().equals(getmsg) &&
  784.                             (invocazionePorta!=null && invocazionePorta.sizeCredenzialiList()>0)
  785.                             ){
  786.                             for (int i = 0; i < invocazionePorta.sizeCredenzialiList(); i++) {
  787.                                 Credenziali c = invocazionePorta.getCredenziali(i);
  788.                                 if(CredenzialeTipo.BASIC.equals(c.getTipo())) {
  789.                                     getmsgUsername = c.getUser();
  790.                                     getmsgPassword = c.getPassword();
  791.                                     tipoCredenzialiSSLVerificaTuttiICampi = c.isCertificateStrictVerification() ? Costanti.CHECK_BOX_ENABLED : Costanti.CHECK_BOX_DISABLED;
  792.                                     break;
  793.                                 }
  794.                             }
  795.                         }
  796.                     }
  797.                                        
  798.                     if(getmsg!=null && CostantiConfigurazione.ABILITATO.toString().equals(getmsg)) {
  799.                         forceEnableConnettore = false;
  800.                     }

  801.                     if (invrifRichiesta == null) {
  802.                         if(oldIS.getInvioPerRiferimento()!=null)
  803.                             invrifRichiesta = oldIS.getInvioPerRiferimento().toString();
  804.                         if ((invrifRichiesta == null) || "".equals(invrifRichiesta)) {
  805.                             invrifRichiesta = CostantiConfigurazione.DISABILITATO.toString();
  806.                         }
  807.                     }
  808.                     if (risprif == null) {
  809.                         if(oldIS.getRispostaPerRiferimento()!=null)
  810.                             risprif = oldIS.getRispostaPerRiferimento().toString();
  811.                         if ((risprif == null) || "".equals(risprif)) {
  812.                             risprif = CostantiConfigurazione.DISABILITATO.toString();
  813.                         }
  814.                     }

  815.                     if ((tipoauthRichiesta == null) && (oldIS != null) && oldIS.getAutenticazione()!=null) {
  816.                         tipoauthRichiesta = oldIS.getAutenticazione().getValue();
  817.                         if(tipoauthRichiesta!=null) {
  818.                             // nop
  819.                         }
  820.                     }
  821.                     if ((user == null) && (oldCis != null)) {
  822.                         user = oldCis.getUser();
  823.                         password = oldCis.getPassword();
  824.                     }
  825.                     if (endpointtype == null) {
  826.                         if ((oldConnis.getCustom()!=null && oldConnis.getCustom()) &&
  827.                                 !oldConnis.getTipo().equals(TipiConnettore.HTTPS.toString()) &&
  828.                                 !oldConnis.getTipo().equals(TipiConnettore.FILE.toString()) &&
  829.                                 !oldConnis.getTipo().equals(TipiConnettore.STATUS.toString())) {
  830.                             endpointtype = TipiConnettore.CUSTOM.toString();
  831.                             tipoconn = oldConnis.getTipo();
  832.                         } else
  833.                             endpointtype = oldConnis.getTipo();
  834.                     }

  835.                     Map<String, String> props = null;
  836.                     if(oldIS!=null && oldIS.getConnettore()!=null)
  837.                         props = oldIS.getConnettore().getProperties();

  838.                     if(connettoreDebug==null && props!=null){
  839.                         String v = props.get(CostantiDB.CONNETTORE_DEBUG);
  840.                         if(v!=null){
  841.                             if("true".equals(v)){
  842.                                 connettoreDebug = Costanti.CHECK_BOX_ENABLED;
  843.                             }
  844.                             else{
  845.                                 connettoreDebug = Costanti.CHECK_BOX_DISABLED;
  846.                             }
  847.                         }
  848.                     }

  849.                     if(proxyEnabled==null && props!=null){
  850.                         String v = props.get(CostantiDB.CONNETTORE_PROXY_TYPE);
  851.                         if(v!=null && !"".equals(v)){
  852.                             proxyEnabled = Costanti.CHECK_BOX_ENABLED_TRUE;

  853.                             // raccolgo anche altre proprietà
  854.                             v = props.get(CostantiDB.CONNETTORE_PROXY_HOSTNAME);
  855.                             if(v!=null && !"".equals(v)){
  856.                                 proxyHostname = v.trim();
  857.                             }
  858.                             v = props.get(CostantiDB.CONNETTORE_PROXY_PORT);
  859.                             if(v!=null && !"".equals(v)){
  860.                                 proxyPort = v.trim();
  861.                             }
  862.                             v = props.get(CostantiDB.CONNETTORE_PROXY_USERNAME);
  863.                             if(v!=null && !"".equals(v)){
  864.                                 proxyUsername = v.trim();
  865.                             }
  866.                             v = props.get(CostantiDB.CONNETTORE_PROXY_PASSWORD);
  867.                             if(v!=null && !"".equals(v)){
  868.                                 proxyPassword = v.trim();
  869.                             }
  870.                         }
  871.                     }

  872.                     if(tempiRispostaEnabled == null ||
  873.                             tempiRispostaConnectionTimeout==null || "".equals(tempiRispostaConnectionTimeout)
  874.                             ||
  875.                             tempiRispostaReadTimeout==null || "".equals(tempiRispostaReadTimeout)
  876.                             ||
  877.                             tempiRispostaTempoMedioRisposta==null || "".equals(tempiRispostaTempoMedioRisposta) ){

  878.                         ConfigurazioneCore configCore = new ConfigurazioneCore(soggettiCore);
  879.                         ConfigurazioneGenerale configGenerale = configCore.getConfigurazioneControlloTraffico();

  880.                         if( props!=null ) {
  881.                             if(tempiRispostaConnectionTimeout==null || "".equals(tempiRispostaConnectionTimeout) ) {
  882.                                 String v = props.get(CostantiDB.CONNETTORE_CONNECTION_TIMEOUT);
  883.                                 if(v!=null && !"".equals(v)){
  884.                                     tempiRispostaConnectionTimeout = v.trim();
  885.                                     tempiRispostaEnabled =  Costanti.CHECK_BOX_ENABLED_TRUE;
  886.                                 }
  887.                                 else {
  888.                                     tempiRispostaConnectionTimeout = configGenerale.getTempiRispostaErogazione().getConnectionTimeout().intValue()+"";
  889.                                 }
  890.                             }

  891.                             if(tempiRispostaReadTimeout==null || "".equals(tempiRispostaReadTimeout) ) {
  892.                                 String v = props.get(CostantiDB.CONNETTORE_READ_CONNECTION_TIMEOUT);
  893.                                 if(v!=null && !"".equals(v)){
  894.                                     tempiRispostaReadTimeout = v.trim();
  895.                                     tempiRispostaEnabled =  Costanti.CHECK_BOX_ENABLED_TRUE;
  896.                                 }
  897.                                 else {
  898.                                     tempiRispostaReadTimeout = configGenerale.getTempiRispostaErogazione().getReadTimeout().intValue()+"";
  899.                                 }
  900.                             }

  901.                             if(tempiRispostaTempoMedioRisposta==null || "".equals(tempiRispostaTempoMedioRisposta) ) {
  902.                                 String v = props.get(CostantiDB.CONNETTORE_TEMPO_MEDIO_RISPOSTA);
  903.                                 if(v!=null && !"".equals(v)){
  904.                                     tempiRispostaTempoMedioRisposta = v.trim();
  905.                                     tempiRispostaEnabled =  Costanti.CHECK_BOX_ENABLED_TRUE;
  906.                                 }
  907.                                 else {
  908.                                     tempiRispostaTempoMedioRisposta = configGenerale.getTempiRispostaErogazione().getTempoMedioRisposta().intValue()+"";
  909.                                 }
  910.                             }
  911.                         }
  912.                         else {
  913.                             if(tempiRispostaConnectionTimeout==null || "".equals(tempiRispostaConnectionTimeout) ) {
  914.                                 tempiRispostaConnectionTimeout = configGenerale.getTempiRispostaErogazione().getConnectionTimeout().intValue()+"";
  915.                             }
  916.                             if(tempiRispostaReadTimeout==null || "".equals(tempiRispostaReadTimeout) ) {
  917.                                 tempiRispostaReadTimeout = configGenerale.getTempiRispostaErogazione().getReadTimeout().intValue()+"";
  918.                             }
  919.                             if(tempiRispostaTempoMedioRisposta==null || "".equals(tempiRispostaTempoMedioRisposta) ) {
  920.                                 tempiRispostaTempoMedioRisposta = configGenerale.getTempiRispostaErogazione().getTempoMedioRisposta().intValue()+"";
  921.                             }
  922.                         }
  923.                     }

  924.                     if(transferMode==null && props!=null){
  925.                         String v = props.get(CostantiDB.CONNETTORE_HTTP_DATA_TRANSFER_MODE);
  926.                         if(v!=null && !"".equals(v)){

  927.                             transferMode = v.trim();

  928.                             if(TransferLengthModes.TRANSFER_ENCODING_CHUNKED.getNome().equals(transferMode)){
  929.                                 // raccolgo anche altra proprietà correlata
  930.                                 v = props.get(CostantiDB.CONNETTORE_HTTP_DATA_TRANSFER_MODE_CHUNK_SIZE);
  931.                                 if(v!=null && !"".equals(v)){
  932.                                     transferModeChunkSize = v.trim();
  933.                                 }
  934.                             }

  935.                         }
  936.                     }

  937.                     if(redirectMode==null && props!=null){
  938.                         String v = props.get(CostantiDB.CONNETTORE_HTTP_REDIRECT_FOLLOW);
  939.                         if(v!=null && !"".equals(v)){

  940.                             if("true".equalsIgnoreCase(v.trim()) || CostantiConfigurazione.ABILITATO.getValue().equalsIgnoreCase(v.trim())){
  941.                                 redirectMode = CostantiConfigurazione.ABILITATO.getValue();
  942.                             }
  943.                             else{
  944.                                 redirectMode = CostantiConfigurazione.DISABILITATO.getValue();
  945.                             }                  

  946.                             if(CostantiConfigurazione.ABILITATO.getValue().equals(redirectMode)){
  947.                                 // raccolgo anche altra proprietà correlata
  948.                                 v = props.get(CostantiDB.CONNETTORE_HTTP_REDIRECT_MAX_HOP);
  949.                                 if(v!=null && !"".equals(v)){
  950.                                     redirectMaxHop = v.trim();
  951.                                 }
  952.                             }

  953.                         }
  954.                     }

  955.                     if(tokenPolicy==null && props!=null){
  956.                         String v = props.get(CostantiDB.CONNETTORE_TOKEN_POLICY);
  957.                         if(v!=null && !"".equals(v)){
  958.                             tokenPolicy = v;
  959.                             autenticazioneToken = true;
  960.                         }
  961.                     }

  962.                     opzioniAvanzate = ConnettoriHelper.getOpzioniAvanzate(porteApplicativeHelper, transferMode, redirectMode);

  963.                     autenticazioneHttp = porteApplicativeHelper.getAutenticazioneHttp(autenticazioneHttp, endpointtype, user);

  964.                     if(autenticazioneApiKey==null || StringUtils.isEmpty(autenticazioneApiKey)) {
  965.                         for (int i = 0; i < oldConnis.sizePropertyList(); i++) {
  966.                             Property singlecp = oldCP.get(i);
  967.                             if (singlecp.getNome().equals(CostantiDB.CONNETTORE_APIKEY_HEADER)) {
  968.                                 apiKeyHeader = singlecp.getValore();
  969.                             }
  970.                             else if (singlecp.getNome().equals(CostantiDB.CONNETTORE_APIKEY)) {
  971.                                 apiKeyValue = singlecp.getValore();
  972.                             }
  973.                             else if (singlecp.getNome().equals(CostantiDB.CONNETTORE_APIKEY_APPID_HEADER)) {
  974.                                 appIdHeader = singlecp.getValore();
  975.                             }
  976.                             else if (singlecp.getNome().equals(CostantiDB.CONNETTORE_APIKEY_APPID)) {
  977.                                 appIdValue = singlecp.getValore();
  978.                             }
  979.                         }
  980.                        
  981.                         autenticazioneApiKey = porteApplicativeHelper.getAutenticazioneApiKey(autenticazioneApiKey, endpointtype, apiKeyValue);
  982.                         if(ServletUtils.isCheckBoxEnabled(autenticazioneApiKey)) {
  983.                             useOAS3Names = porteApplicativeHelper.isAutenticazioneApiKeyUseOAS3Names(apiKeyHeader, appIdHeader);
  984.                             useAppId = porteApplicativeHelper.isAutenticazioneApiKeyUseAppId(appIdValue);
  985.                         }
  986.                         else {
  987.                             apiKeyValue=null;
  988.                             apiKeyHeader=null;
  989.                             appIdHeader=null;
  990.                             appIdValue=null;
  991.                         }
  992.                     }
  993.                    
  994.                     for (int i = 0; i < oldConnis.sizePropertyList(); i++) {
  995.                         Property singlecp = oldCP.get(i);
  996.                         if (singlecp.getNome().equals(CostantiDB.CONNETTORE_HTTP_LOCATION) &&
  997.                             url == null) {
  998.                             url = singlecp.getValore();
  999.                         }
  1000.                         if (singlecp.getNome().equals(CostantiDB.CONNETTORE_JMS_NOME) &&
  1001.                             nomeCodaJms == null) {
  1002.                             nomeCodaJms = singlecp.getValore();
  1003.                         }
  1004.                         if (singlecp.getNome().equals(CostantiDB.CONNETTORE_JMS_TIPO) &&
  1005.                             tipoJms == null) {
  1006.                             tipoJms = singlecp.getValore();
  1007.                         }
  1008.                         if (singlecp.getNome().equals(CostantiDB.CONNETTORE_JMS_CONNECTION_FACTORY) &&
  1009.                             connfact == null) {
  1010.                             connfact = singlecp.getValore();
  1011.                         }
  1012.                         if (singlecp.getNome().equals(CostantiDB.CONNETTORE_JMS_SEND_AS) &&
  1013.                             tipoSendas == null) {
  1014.                             tipoSendas = singlecp.getValore();
  1015.                         }
  1016.                         if (singlecp.getNome().equals(CostantiDB.CONNETTORE_JMS_CONTEXT_JAVA_NAMING_FACTORY_INITIAL) &&
  1017.                             initcont == null) {
  1018.                             initcont = singlecp.getValore();
  1019.                         }
  1020.                         if (singlecp.getNome().equals(CostantiDB.CONNETTORE_JMS_CONTEXT_JAVA_NAMING_FACTORY_URL_PKG) &&
  1021.                             urlpgk == null) {
  1022.                             urlpgk = singlecp.getValore();
  1023.                         }
  1024.                         if (singlecp.getNome().equals(CostantiDB.CONNETTORE_JMS_CONTEXT_JAVA_NAMING_PROVIDER_URL) &&
  1025.                             provurl == null) {
  1026.                             provurl = singlecp.getValore();
  1027.                         }
  1028.                     }

  1029.                     if (httpstipologia == null) {
  1030.                         httpsurl = props.get(CostantiDB.CONNETTORE_HTTPS_LOCATION);
  1031.                         httpstipologia = props.get(CostantiDB.CONNETTORE_HTTPS_SSL_TYPE);
  1032.                         httpshostverifyS = props.get(CostantiDB.CONNETTORE_HTTPS_HOSTNAME_VERIFIER);
  1033.                         if(httpshostverifyS!=null){
  1034.                             httpshostverify = Boolean.valueOf(httpshostverifyS);
  1035.                         }
  1036.                         httpsTrustVerifyCertS = props.get(CostantiDB.CONNETTORE_HTTPS_TRUST_ALL_CERTS);
  1037.                         if(httpsTrustVerifyCertS!=null){
  1038.                             httpsTrustVerifyCert = !Boolean.valueOf(httpsTrustVerifyCertS);
  1039.                         }
  1040.                         else {
  1041.                             httpsTrustVerifyCert = true; // backward compatibility
  1042.                         }
  1043.                         httpspath = props.get(CostantiDB.CONNETTORE_HTTPS_TRUST_STORE_LOCATION);
  1044.                         httpstipo = props.get(CostantiDB.CONNETTORE_HTTPS_TRUST_STORE_TYPE);
  1045.                         httpspwd = props.get(CostantiDB.CONNETTORE_HTTPS_TRUST_STORE_PASSWORD);
  1046.                         httpsalgoritmo = props.get(CostantiDB.CONNETTORE_HTTPS_TRUST_MANAGEMENT_ALGORITM);
  1047.                         httpspwdprivatekeytrust = props.get(CostantiDB.CONNETTORE_HTTPS_KEY_PASSWORD);
  1048.                         httpspathkey = props.get(CostantiDB.CONNETTORE_HTTPS_KEY_STORE_LOCATION);
  1049.                         httpstipokey = props.get(CostantiDB.CONNETTORE_HTTPS_KEY_STORE_TYPE);
  1050.                         httpspwdkey = props.get(CostantiDB.CONNETTORE_HTTPS_KEY_STORE_PASSWORD);
  1051.                         httpspwdprivatekey = props.get(CostantiDB.CONNETTORE_HTTPS_KEY_PASSWORD);
  1052.                         httpsalgoritmokey = props.get(CostantiDB.CONNETTORE_HTTPS_KEY_MANAGEMENT_ALGORITM);
  1053.                         httpsKeyAlias = props.get(CostantiDB.CONNETTORE_HTTPS_KEY_ALIAS);
  1054.                         httpsTrustStoreCRLs = props.get(CostantiDB.CONNETTORE_HTTPS_TRUST_STORE_CRLS);
  1055.                         httpsTrustStoreOCSPPolicy = props.get(CostantiDB.CONNETTORE_HTTPS_TRUST_STORE_OCSP_POLICY);
  1056.                         httpsKeyStoreBYOKPolicy = props.get(CostantiDB.CONNETTORE_HTTPS_KEY_STORE_BYOK_POLICY);
  1057.                         if (httpspathkey == null) {
  1058.                             httpsstato = false;
  1059.                             httpskeystore = ConnettoriCostanti.DEFAULT_CONNETTORE_HTTPS_KEYSTORE_CLIENT_AUTH_MODE_DEFAULT;
  1060.                         } else {
  1061.                             httpsstato = true;
  1062.                             if (httpspathkey.equals(httpspath) &&
  1063.                                     httpstipokey.equals(httpstipo) &&
  1064.                                     (
  1065.                                         (httpspwdkey!=null && httpspwdkey.equals(httpspwd))
  1066.                                         ||
  1067.                                         (httpspwdkey==null && httpspwd==null)
  1068.                                     )
  1069.                                 )
  1070.                                 httpskeystore = ConnettoriCostanti.DEFAULT_CONNETTORE_HTTPS_KEYSTORE_CLIENT_AUTH_MODE_DEFAULT;
  1071.                             else
  1072.                                 httpskeystore = ConnettoriCostanti.DEFAULT_CONNETTORE_HTTPS_KEYSTORE_CLIENT_AUTH_MODE_RIDEFINISCI;
  1073.                         }
  1074.                     }

  1075.                     // default
  1076.                     if(httpsalgoritmo==null || "".equals(httpsalgoritmo)){
  1077.                         httpsalgoritmo = TrustManagerFactory.getDefaultAlgorithm();
  1078.                     }
  1079.                     if(httpsalgoritmokey==null || "".equals(httpsalgoritmokey)){
  1080.                         httpsalgoritmokey = KeyManagerFactory.getDefaultAlgorithm();
  1081.                     }
  1082.                     if(httpstipologia==null || "".equals(httpstipologia)){
  1083.                         httpstipologia = ConnettoriCostanti.DEFAULT_CONNETTORE_HTTPS_TYPE;
  1084.                     }
  1085.                     if(httpshostverifyS==null || "".equals(httpshostverifyS)){
  1086.                         /**httpshostverifyS = "true";*/
  1087.                         httpshostverify = true;
  1088.                     }
  1089.                     if(httpsTrustVerifyCertS==null || "".equals(httpsTrustVerifyCertS)){
  1090.                         /**httpsTrustVerifyCertS = ConnettoriCostanti.DEFAULT_CONNETTORE_HTTPS_TRUST_VERIFY_CERTS ? Costanti.CHECK_BOX_ENABLED_TRUE : Costanti.CHECK_BOX_DISABLED;*/
  1091.                         httpsTrustVerifyCert = ConnettoriCostanti.DEFAULT_CONNETTORE_HTTPS_TRUST_VERIFY_CERTS;
  1092.                     }

  1093.                     // file
  1094.                     if(responseInputMode==null && props!=null){

  1095.                         requestOutputFileName = props.get(CostantiDB.CONNETTORE_FILE_REQUEST_OUTPUT_FILE);  
  1096.                         requestOutputFileNamePermissions = props.get(CostantiDB.CONNETTORE_FILE_REQUEST_OUTPUT_FILE_PERMISSIONS);  
  1097.                         requestOutputFileNameHeaders = props.get(CostantiDB.CONNETTORE_FILE_REQUEST_OUTPUT_FILE_HEADERS);  
  1098.                         requestOutputFileNameHeadersPermissions = props.get(CostantiDB.CONNETTORE_FILE_REQUEST_OUTPUT_FILE_HEADERS_PERMISSIONS);    
  1099.                         String v = props.get(CostantiDB.CONNETTORE_FILE_REQUEST_OUTPUT_AUTO_CREATE_DIR);
  1100.                         if(v!=null && !"".equals(v) &&
  1101.                             ("true".equalsIgnoreCase(v) || CostantiConfigurazione.ABILITATO.getValue().equalsIgnoreCase(v) )
  1102.                             ){
  1103.                             requestOutputParentDirCreateIfNotExists = Costanti.CHECK_BOX_ENABLED_TRUE;
  1104.                         }                  
  1105.                         v = props.get(CostantiDB.CONNETTORE_FILE_REQUEST_OUTPUT_OVERWRITE_FILE);
  1106.                         if(v!=null && !"".equals(v) &&
  1107.                             ("true".equalsIgnoreCase(v) || CostantiConfigurazione.ABILITATO.getValue().equalsIgnoreCase(v) )
  1108.                             ){
  1109.                             requestOutputOverwriteIfExists = Costanti.CHECK_BOX_ENABLED_TRUE;
  1110.                         }  

  1111.                         v = props.get(CostantiDB.CONNETTORE_FILE_RESPONSE_INPUT_MODE);
  1112.                         if(v!=null && !"".equals(v) &&
  1113.                             ("true".equalsIgnoreCase(v) || CostantiConfigurazione.ABILITATO.getValue().equalsIgnoreCase(v) )
  1114.                             ){
  1115.                             responseInputMode = CostantiConfigurazione.ABILITATO.getValue();
  1116.                         }
  1117.                         if(CostantiConfigurazione.ABILITATO.getValue().equals(responseInputMode)){                      
  1118.                             responseInputFileName = props.get(CostantiDB.CONNETTORE_FILE_RESPONSE_INPUT_FILE);
  1119.                             responseInputFileNameHeaders = props.get(CostantiDB.CONNETTORE_FILE_RESPONSE_INPUT_FILE_HEADERS);
  1120.                             v = props.get(CostantiDB.CONNETTORE_FILE_RESPONSE_INPUT_FILE_DELETE_AFTER_READ);
  1121.                             if(v!=null && !"".equals(v) &&
  1122.                                 ("true".equalsIgnoreCase(v) || CostantiConfigurazione.ABILITATO.getValue().equalsIgnoreCase(v) )
  1123.                                 ){
  1124.                                 responseInputDeleteAfterRead = Costanti.CHECK_BOX_ENABLED_TRUE;
  1125.                             }                      
  1126.                             responseInputWaitTime = props.get(CostantiDB.CONNETTORE_FILE_RESPONSE_INPUT_WAIT_TIME);                    
  1127.                         }

  1128.                     }

  1129.                 } // init connettore from sa
  1130.                
  1131.                 if(!integrationManagerEnabled && CostantiConfigurazione.ABILITATO.toString().equals(getmsg)) {
  1132.                     // faccio vedere I.M. anche con interfaccia standard
  1133.                     integrationManagerEnabled = true;
  1134.                     if(erogazioneServizioApplicativoServerEnabled && ServiziApplicativiCostanti.VALUE_SERVIZI_APPLICATIVI_TIPO_SERVER.equals(oldTipoSA)) {
  1135.                         if(listaIdSAServer==null) {
  1136.                             listaIdSAServer = new ArrayList<>();
  1137.                         }
  1138.                         boolean found = false;
  1139.                         for (IDServizioApplicativoDB idServizioApplicativo : listaIdSAServer) {
  1140.                             if(idServizioApplicativo.getNome().equals(idSADB.getNome())) {
  1141.                                 found = true;
  1142.                                 break;
  1143.                             }
  1144.                         }
  1145.                         if(!found) {
  1146.                             listaIdSAServer.add(idSADB);
  1147.                         }
  1148.                     }
  1149.                 }


  1150.                 // preparo i campi
  1151.                 List<DataElement> dati = new ArrayList<>();
  1152.                 dati.add(ServletUtils.getDataElementForEditModeFinished());

  1153.                 dati = porteApplicativeHelper.addConnettoriMultipliToDati(dati, TipoOperazione.CHANGE, beaBehaviourType, nomeSAConnettore,
  1154.                         nomeConnettore, descrizioneConnettore, statoConnettore, behaviourConFiltri, filtriConnettore, visualizzaDatiGenerali, visualizzaDescrizione, visualizzaFiltri, visualizzaConnettore,
  1155.                         oldPaSA);

  1156.                 dati = porteApplicativeHelper.addHiddenFieldsToDati(TipoOperazione.CHANGE, idPorta, idsogg, idPorta,idAsps, dati);

  1157.                 dati = porteApplicativeHelper.addInformazioniGruppiAsHiddenToDati(TipoOperazione.CHANGE, dati, idTabP, idConnTab, accessoDaAPSParametro != null ? accessoDaAPSParametro : "",
  1158.                         connettoreAccessoGruppi, connettoreRegistro, connettoreAccessoListaConnettori);

  1159.                 if(visualizzaSezioneConnettore) {

  1160.                     porteApplicativeHelper.addEndPointToDati(dati,(idsil!=null ? idsil : oldSA.getId()+""),nomeservizioApplicativo,sbustamento,sbustamentoInformazioniProtocolloRichiesta,
  1161.                             getmsg,getmsgUsername,getmsgPassword,true,
  1162.                             invrifRichiesta,risprif,nomeProtocollo,true,true, true,
  1163.                             parentPA,serviceBinding, accessoDaAPSParametro, erogazioneServizioApplicativoServerEnabled,
  1164.                             null, false,
  1165.                             integrationManagerEnabled,
  1166.                             TipoOperazione.CHANGE, tipoCredenzialiSSLVerificaTuttiICampi, changepwd,
  1167.                             postBackViaPost);

  1168.                     dati = porteApplicativeHelper.addEndPointToDati(dati, serviceBinding, connettoreDebug, endpointtype, autenticazioneHttp,
  1169.                             null, //(porteApplicativeHelper.isModalitaCompleta() || !multitenant)?null:AccordiServizioParteSpecificaCostanti.LABEL_APS_APPLICATIVO_INTERNO_PREFIX ,
  1170.                             url, nomeCodaJms,
  1171.                             tipoJms, user,
  1172.                             password, initcont, urlpgk,
  1173.                             provurl, connfact, tipoSendas,
  1174.                             AccordiServizioParteSpecificaCostanti.OBJECT_NAME_APS_PORTE_APPLICATIVE,TipoOperazione.CHANGE,
  1175.                             httpsurl, httpstipologia, httpshostverify,
  1176.                             httpsTrustVerifyCert, httpspath, httpstipo, httpspwd,
  1177.                             httpsalgoritmo, httpsstato, httpskeystore,
  1178.                             httpspwdprivatekeytrust, httpspathkey,
  1179.                             httpstipokey, httpspwdkey,
  1180.                             httpspwdprivatekey, httpsalgoritmokey,
  1181.                             httpsKeyAlias, httpsTrustStoreCRLs, httpsTrustStoreOCSPPolicy, httpsKeyStoreBYOKPolicy,
  1182.                             tipoconn, PorteApplicativeCostanti.SERVLET_NAME_PORTE_APPLICATIVE_CONNETTORI_MULTIPLI_CHANGE,
  1183.                             idPorta, // elem1
  1184.                             idsogg, // elem2
  1185.                             idAsps, // elem3
  1186.                             nomeSAConnettore, // elem4
  1187.                             pa.getNome(), // elem5
  1188.                             oldSA.getId()+"", // elem6
  1189.                             pIdConTab.getValue(), // elem7
  1190.                             null, // elem8
  1191.                             true,
  1192.                             isConnettoreCustomUltimaImmagineSalvata,
  1193.                             proxyEnabled, proxyHostname, proxyPort, proxyUsername, proxyPassword,
  1194.                             tempiRispostaEnabled, tempiRispostaConnectionTimeout, tempiRispostaReadTimeout, tempiRispostaTempoMedioRisposta,
  1195.                             opzioniAvanzate, transferMode, transferModeChunkSize, redirectMode, redirectMaxHop,
  1196.                             requestOutputFileName, requestOutputFileNamePermissions, requestOutputFileNameHeaders, requestOutputFileNameHeadersPermissions,
  1197.                             requestOutputParentDirCreateIfNotExists,requestOutputOverwriteIfExists,
  1198.                             responseInputMode, responseInputFileName, responseInputFileNameHeaders, responseInputDeleteAfterRead, responseInputWaitTime,
  1199.                             autenticazioneToken,tokenPolicy, forcePDND, forceOAuth,
  1200.                             listExtendedConnettore, forceEnableConnettore,
  1201.                             protocollo,false,false, isApplicativiServerEnabled, erogazioneServizioApplicativoServerEnabled,
  1202.                             erogazioneServizioApplicativoServer, ServiziApplicativiHelper.toArray(listaIdSAServer),
  1203.                             autenticazioneApiKey, useOAS3Names, useAppId, apiKeyHeader, apiKeyValue, appIdHeader, appIdValue,
  1204.                             connettoreStatusParams,
  1205.                             postBackViaPost);
  1206.                 } else {

  1207.                     porteApplicativeHelper.addEndPointToDati(dati,(idsil!=null ? idsil : oldSA.getId()+""),nomeservizioApplicativo,sbustamento,sbustamentoInformazioniProtocolloRichiesta,
  1208.                             getmsg,getmsgUsername,getmsgPassword,true,
  1209.                             invrifRichiesta,risprif,nomeProtocollo,true,true, true,
  1210.                             parentPA,serviceBinding, accessoDaAPSParametro, true,
  1211.                             null, false,
  1212.                             integrationManagerEnabled,
  1213.                             TipoOperazione.CHANGE, tipoCredenzialiSSLVerificaTuttiICampi, changepwd,
  1214.                             postBackViaPost);

  1215.                     dati = porteApplicativeHelper.addEndPointSAServerToDatiAsHidden(dati, erogazioneServizioApplicativoServerEnabled, erogazioneServizioApplicativoServer);

  1216.                     dati = porteApplicativeHelper.addEndPointToDatiAsHidden(dati, serviceBinding, connettoreDebug,
  1217.                             endpointtype, autenticazioneHttp,
  1218.                             url, nomeCodaJms, tipoJms,
  1219.                             user, password, initcont, urlpgk,
  1220.                             provurl, connfact, tipoSendas, AccordiServizioParteSpecificaCostanti.OBJECT_NAME_APS_PORTE_APPLICATIVE,TipoOperazione.CHANGE,
  1221.                             httpsurl, httpstipologia, httpshostverify,
  1222.                             httpsTrustVerifyCert, httpspath, httpstipo, httpspwd,
  1223.                             httpsalgoritmo, httpsstato, httpskeystore,
  1224.                             httpspwdprivatekeytrust, httpspathkey,
  1225.                             httpstipokey, httpspwdkey,
  1226.                             httpspwdprivatekey, httpsalgoritmokey,
  1227.                             httpsKeyAlias, httpsTrustStoreCRLs, httpsTrustStoreOCSPPolicy, httpsKeyStoreBYOKPolicy,
  1228.                             tipoconn, PorteApplicativeCostanti.SERVLET_NAME_PORTE_APPLICATIVE_CONNETTORI_MULTIPLI_CHANGE,
  1229.                             idPorta, // elem1
  1230.                             idsogg, // elem2
  1231.                             idAsps, // elem3
  1232.                             nomeSAConnettore, // elem4
  1233.                             pa.getNome(), // elem5
  1234.                             oldSA.getId()+"", // elem6
  1235.                             pIdConTab.getValue(), // elem7
  1236.                             null, // elem8
  1237.                             proxyEnabled, proxyHostname, proxyPort, proxyUsername, proxyPassword,
  1238.                             tempiRispostaEnabled, tempiRispostaConnectionTimeout, tempiRispostaReadTimeout, tempiRispostaTempoMedioRisposta,
  1239.                             opzioniAvanzate, transferMode, transferModeChunkSize, redirectMode, redirectMaxHop,
  1240.                             requestOutputFileName, requestOutputFileNamePermissions, requestOutputFileNameHeaders, requestOutputFileNameHeadersPermissions,
  1241.                             requestOutputParentDirCreateIfNotExists,requestOutputOverwriteIfExists,
  1242.                             responseInputMode, responseInputFileName, responseInputFileNameHeaders, responseInputDeleteAfterRead, responseInputWaitTime,
  1243.                             autenticazioneToken,tokenPolicy,
  1244.                             autenticazioneApiKey, useOAS3Names, useAppId, apiKeyHeader, apiKeyValue, appIdHeader, appIdValue,
  1245.                             connettoreStatusParams);
  1246.                 }

  1247.                 pd.setDati(dati);

  1248.                 ServletUtils.setGeneralAndPageDataIntoSession(request, session, gd, pd);

  1249.                 return ServletUtils.getStrutsForwardEditModeInProgress(mapping, PorteApplicativeCostanti.OBJECT_NAME_PORTE_APPLICATIVE_CONNETTORI_MULTIPLI,
  1250.                         ForwardParams.CHANGE());
  1251.             }

  1252.             // Controlli sui campi immessi
  1253.             boolean isOk = porteApplicativeHelper.connettoriMultipliCheckData(TipoOperazione.CHANGE, pa, beaBehaviourType, nomeSAConnettore,
  1254.                     oldNomeConnettore, nomeConnettore, descrizioneConnettore, statoConnettore, filtriConnettore,  visualizzaDatiGenerali, visualizzaDescrizione, visualizzaFiltri, visualizzaConnettore,
  1255.                     getmsg, getmsgUsername, getmsgPassword, oldSA);

  1256.             if(isOk) {
  1257.                 isOk = porteApplicativeHelper.endPointCheckData(serviceBinding, protocollo, true,
  1258.                         endpointtype, url, nomeCodaJms, tipoJms,
  1259.                         user, password, initcont, urlpgk, provurl, connfact,
  1260.                         tipoSendas, httpsurl, httpstipologia, httpshostverify,
  1261.                         httpsTrustVerifyCert, httpspath, httpstipo, httpspwd, httpsalgoritmo, httpsstato,
  1262.                         httpskeystore, httpspwdprivatekeytrust, httpspathkey,
  1263.                         httpstipokey, httpspwdkey,
  1264.                         httpspwdprivatekey, httpsalgoritmokey,
  1265.                         httpsKeyAlias, httpsTrustStoreCRLs, httpsTrustStoreOCSPPolicy, httpsKeyStoreBYOKPolicy,
  1266.                         tipoconn,autenticazioneHttp,
  1267.                         proxyEnabled, proxyHostname, proxyPort, proxyUsername, proxyPassword,
  1268.                         tempiRispostaEnabled, tempiRispostaConnectionTimeout, tempiRispostaReadTimeout, tempiRispostaTempoMedioRisposta,
  1269.                         opzioniAvanzate, transferMode, transferModeChunkSize, redirectMode, redirectMaxHop,
  1270.                         requestOutputFileName, requestOutputFileNamePermissions, requestOutputFileNameHeaders, requestOutputFileNameHeadersPermissions,
  1271.                         requestOutputParentDirCreateIfNotExists,requestOutputOverwriteIfExists,
  1272.                         responseInputMode, responseInputFileName, responseInputFileNameHeaders, responseInputDeleteAfterRead, responseInputWaitTime,
  1273.                         autenticazioneToken,tokenPolicy,
  1274.                         autenticazioneApiKey, useOAS3Names, useAppId, apiKeyHeader, apiKeyValue, appIdHeader, appIdValue,
  1275.                         listExtendedConnettore,erogazioneServizioApplicativoServerEnabled,  erogazioneServizioApplicativoServer);
  1276.             }

  1277.             if (!isOk) {
  1278.                 // setto la barra del titolo
  1279.                 ServletUtils.setPageDataTitle(pd, lstParam);

  1280.                 // preparo i campi
  1281.                 List<DataElement> dati = new ArrayList<>();

  1282.                 dati.add(ServletUtils.getDataElementForEditModeFinished());

  1283.                 dati = porteApplicativeHelper.addConnettoriMultipliToDati(dati, TipoOperazione.CHANGE, beaBehaviourType, nomeSAConnettore,
  1284.                         nomeConnettore, descrizioneConnettore, statoConnettore, behaviourConFiltri, filtriConnettore,  visualizzaDatiGenerali, visualizzaDescrizione, visualizzaFiltri, visualizzaConnettore,
  1285.                         oldPaSA);

  1286.                 dati = porteApplicativeHelper.addHiddenFieldsToDati(TipoOperazione.CHANGE, idPorta, idsogg, idPorta, idAsps, dati);

  1287.                 dati = porteApplicativeHelper.addInformazioniGruppiAsHiddenToDati(TipoOperazione.CHANGE, dati, idTabP, idConnTab, accessoDaAPSParametro != null ? accessoDaAPSParametro : "",
  1288.                         connettoreAccessoGruppi, connettoreRegistro, connettoreAccessoListaConnettori);

  1289.                 if(visualizzaSezioneConnettore) {

  1290.                     porteApplicativeHelper.addEndPointToDati(dati,(idsil!=null ? idsil : oldSA.getId()+""),nomeservizioApplicativo,sbustamento,sbustamentoInformazioniProtocolloRichiesta,
  1291.                             getmsg,getmsgUsername,getmsgPassword,true,
  1292.                             invrifRichiesta,risprif,nomeProtocollo,true,true, true,
  1293.                             parentPA,serviceBinding, accessoDaAPSParametro, erogazioneServizioApplicativoServerEnabled,
  1294.                             null, false,
  1295.                             integrationManagerEnabled,
  1296.                             TipoOperazione.CHANGE, tipoCredenzialiSSLVerificaTuttiICampi, changepwd,
  1297.                             postBackViaPost);

  1298.                     dati = porteApplicativeHelper.addEndPointToDati(dati, serviceBinding, connettoreDebug, endpointtype, autenticazioneHttp,
  1299.                             null, //(porteApplicativeHelper.isModalitaCompleta() || !multitenant)?null:AccordiServizioParteSpecificaCostanti.LABEL_APS_APPLICATIVO_INTERNO_PREFIX ,
  1300.                             url, nomeCodaJms,
  1301.                             tipoJms, user,
  1302.                             password, initcont, urlpgk,
  1303.                             provurl, connfact, tipoSendas,
  1304.                             AccordiServizioParteSpecificaCostanti.OBJECT_NAME_APS_PORTE_APPLICATIVE,TipoOperazione.CHANGE,
  1305.                             httpsurl, httpstipologia, httpshostverify,
  1306.                             httpsTrustVerifyCert, httpspath, httpstipo, httpspwd,
  1307.                             httpsalgoritmo, httpsstato, httpskeystore,
  1308.                             httpspwdprivatekeytrust, httpspathkey,
  1309.                             httpstipokey, httpspwdkey,
  1310.                             httpspwdprivatekey, httpsalgoritmokey,
  1311.                             httpsKeyAlias, httpsTrustStoreCRLs, httpsTrustStoreOCSPPolicy, httpsKeyStoreBYOKPolicy,
  1312.                             tipoconn, PorteApplicativeCostanti.SERVLET_NAME_PORTE_APPLICATIVE_CONNETTORI_MULTIPLI_CHANGE,
  1313.                             idPorta, // elem1
  1314.                             idsogg, // elem2
  1315.                             idAsps, // elem3
  1316.                             nomeSAConnettore, // elem4
  1317.                             pa.getNome(), // elem5
  1318.                             oldSA.getId()+"", // elem6
  1319.                             pIdConTab.getValue(), // elem7
  1320.                             null, // elem8
  1321.                             true,
  1322.                             isConnettoreCustomUltimaImmagineSalvata,
  1323.                             proxyEnabled, proxyHostname, proxyPort, proxyUsername, proxyPassword,
  1324.                             tempiRispostaEnabled, tempiRispostaConnectionTimeout, tempiRispostaReadTimeout, tempiRispostaTempoMedioRisposta,
  1325.                             opzioniAvanzate, transferMode, transferModeChunkSize, redirectMode, redirectMaxHop,
  1326.                             requestOutputFileName, requestOutputFileNamePermissions, requestOutputFileNameHeaders, requestOutputFileNameHeadersPermissions,
  1327.                             requestOutputParentDirCreateIfNotExists,requestOutputOverwriteIfExists,
  1328.                             responseInputMode, responseInputFileName, responseInputFileNameHeaders, responseInputDeleteAfterRead, responseInputWaitTime,
  1329.                             autenticazioneToken,tokenPolicy, forcePDND, forceOAuth,
  1330.                             listExtendedConnettore, forceEnableConnettore,
  1331.                             protocollo,false,false, isApplicativiServerEnabled, erogazioneServizioApplicativoServerEnabled,
  1332.                             erogazioneServizioApplicativoServer, ServiziApplicativiHelper.toArray(listaIdSAServer),
  1333.                             autenticazioneApiKey, useOAS3Names, useAppId, apiKeyHeader, apiKeyValue, appIdHeader, appIdValue,
  1334.                             connettoreStatusParams,
  1335.                             postBackViaPost);
  1336.                 } else {

  1337.                     porteApplicativeHelper.addEndPointToDati(dati,(idsil!=null ? idsil : oldSA.getId()+""),nomeservizioApplicativo,sbustamento,sbustamentoInformazioniProtocolloRichiesta,
  1338.                             getmsg,getmsgUsername,getmsgPassword,true,
  1339.                             invrifRichiesta,risprif,nomeProtocollo,true,true, true,
  1340.                             parentPA,serviceBinding, accessoDaAPSParametro, true,
  1341.                             null, false,
  1342.                             integrationManagerEnabled,
  1343.                             TipoOperazione.CHANGE, tipoCredenzialiSSLVerificaTuttiICampi, changepwd,
  1344.                             postBackViaPost);

  1345.                     dati = porteApplicativeHelper.addEndPointSAServerToDatiAsHidden(dati, erogazioneServizioApplicativoServerEnabled, erogazioneServizioApplicativoServer);

  1346.                     dati = porteApplicativeHelper.addEndPointToDatiAsHidden(dati, serviceBinding, connettoreDebug,
  1347.                             endpointtype, autenticazioneHttp,
  1348.                             url, nomeCodaJms, tipoJms,
  1349.                             user, password, initcont, urlpgk,
  1350.                             provurl, connfact, tipoSendas, AccordiServizioParteSpecificaCostanti.OBJECT_NAME_APS_PORTE_APPLICATIVE,TipoOperazione.CHANGE,
  1351.                             httpsurl, httpstipologia, httpshostverify,
  1352.                             httpsTrustVerifyCert, httpspath, httpstipo, httpspwd,
  1353.                             httpsalgoritmo, httpsstato, httpskeystore,
  1354.                             httpspwdprivatekeytrust, httpspathkey,
  1355.                             httpstipokey, httpspwdkey,
  1356.                             httpspwdprivatekey, httpsalgoritmokey,
  1357.                             httpsKeyAlias, httpsTrustStoreCRLs, httpsTrustStoreOCSPPolicy, httpsKeyStoreBYOKPolicy,
  1358.                             tipoconn, PorteApplicativeCostanti.SERVLET_NAME_PORTE_APPLICATIVE_CONNETTORI_MULTIPLI_CHANGE,
  1359.                             idPorta, // elem1
  1360.                             idsogg, // elem2
  1361.                             idAsps, // elem3
  1362.                             nomeSAConnettore, // elem4
  1363.                             pa.getNome(), // elem5
  1364.                             oldSA.getId()+"", // elem6
  1365.                             pIdConTab.getValue(), // elem7
  1366.                             null, // elem8
  1367.                             proxyEnabled, proxyHostname, proxyPort, proxyUsername, proxyPassword,
  1368.                             tempiRispostaEnabled, tempiRispostaConnectionTimeout, tempiRispostaReadTimeout, tempiRispostaTempoMedioRisposta,
  1369.                             opzioniAvanzate, transferMode, transferModeChunkSize, redirectMode, redirectMaxHop,
  1370.                             requestOutputFileName, requestOutputFileNamePermissions, requestOutputFileNameHeaders, requestOutputFileNameHeadersPermissions,
  1371.                             requestOutputParentDirCreateIfNotExists,requestOutputOverwriteIfExists,
  1372.                             responseInputMode, responseInputFileName, responseInputFileNameHeaders, responseInputDeleteAfterRead, responseInputWaitTime,
  1373.                             autenticazioneToken,tokenPolicy,
  1374.                             autenticazioneApiKey, useOAS3Names, useAppId, apiKeyHeader, apiKeyValue, appIdHeader, appIdValue,
  1375.                             connettoreStatusParams);
  1376.                 }

  1377.                 pd.setDati(dati);

  1378.                 ServletUtils.setGeneralAndPageDataIntoSession(request, session, gd, pd);

  1379.                 return ServletUtils.getStrutsForwardEditModeCheckError(mapping, PorteApplicativeCostanti.OBJECT_NAME_PORTE_APPLICATIVE_CONNETTORI_MULTIPLI,
  1380.                         ForwardParams.CHANGE());
  1381.             }

  1382.             String userLogin = ServletUtils.getUserLoginFromSession(session);

  1383.             List<Object> listaOggettiDaCreare = new ArrayList<>();
  1384.             List<Object> listaOggettiDaModificare = new ArrayList<>();
  1385.             List<Object> listaOggettiDaEliminare = new ArrayList<>();

  1386.             // valora iniziale della configurazione
  1387.             PortaApplicativaServizioApplicativo paSA = null;
  1388.             for (PortaApplicativaServizioApplicativo paSATmp : pa.getServizioApplicativoList()) {
  1389.                 if(paSATmp.getNome().equals(nomeSAConnettore)) {
  1390.                     paSA = paSATmp;                
  1391.                 }
  1392.             }

  1393.             PortaApplicativaServizioApplicativoConnettore datiConnettore = paSA.getDatiConnettore();

  1394.             if(datiConnettore == null) { // succede solo se e' la prima volta che modifico la configurazione di default
  1395.                 datiConnettore = new PortaApplicativaServizioApplicativoConnettore();
  1396.                 datiConnettore.setNome(CostantiConfigurazione.NOME_CONNETTORE_DEFAULT);
  1397.             }

  1398.             if(datiConnettore.getProprietaOggetto()==null) {
  1399.                 datiConnettore.setProprietaOggetto(new ProprietaOggetto());
  1400.             }
  1401.             datiConnettore.getProprietaOggetto().setUtenteUltimaModifica(userLogin);
  1402.             datiConnettore.getProprietaOggetto().setDataUltimaModifica(DateManager.getDate());
  1403.            
  1404.             paSA.setDatiConnettore(datiConnettore);

  1405.             boolean isDefault = true;
  1406.             if( datiConnettore != null ) {
  1407.                 isDefault = !datiConnettore.isNotifica();
  1408.             }

  1409.             String nomeConnettoreChangeList = null;
  1410.            
  1411.             if(visualizzaSezioneDatiGenerali) {
  1412.                 datiConnettore.setNome(nomeConnettore);

  1413.                 nomeConnettoreChangeList = nomeConnettore;
  1414.                
  1415.                 if(!nomeConnettore.equals(oldNomeConnettore) &&
  1416.                    
  1417.                     (pa.getBehaviour() != null)
  1418.                     ){

  1419.                     TipoBehaviour behaviourType = TipoBehaviour.toEnumConstant(pa.getBehaviour().getNome());

  1420.                     boolean consegnaCondizionale = false;
  1421.                     if(behaviourType.equals(TipoBehaviour.CONSEGNA_MULTIPLA)
  1422.                             || behaviourType.equals(TipoBehaviour.CONSEGNA_CON_NOTIFICHE)
  1423.                             || behaviourType.equals(TipoBehaviour.CONSEGNA_CONDIZIONALE)
  1424.                             || behaviourType.equals(TipoBehaviour.CONSEGNA_LOAD_BALANCE)) {
  1425.                         consegnaCondizionale = org.openspcoop2.pdd.core.behaviour.conditional.ConditionalUtils.isConfigurazioneCondizionale(pa, ControlStationCore.getLog());

  1426.                         if( behaviourType.equals(TipoBehaviour.CONSEGNA_CON_NOTIFICHE)) {
  1427.                             org.openspcoop2.pdd.core.behaviour.built_in.multi_deliver.ConfigurazioneMultiDeliver configurazioneMultiDeliver =
  1428.                                     org.openspcoop2.pdd.core.behaviour.built_in.multi_deliver.MultiDeliverUtils.read(pa);

  1429.                             if(configurazioneMultiDeliver != null &&
  1430.                                 configurazioneMultiDeliver.getTransazioneSincrona_nomeConnettore() != null &&
  1431.                                     configurazioneMultiDeliver.getTransazioneSincrona_nomeConnettore().equals(oldNomeConnettore)) {
  1432.                                 // modifica riferimento
  1433.                                 configurazioneMultiDeliver.setTransazioneSincrona_nomeConnettore(nomeConnettore);
  1434.                                 boolean differenziazioneConsegnaDaNotifiche = TipoBehaviour.CONSEGNA_CON_NOTIFICHE.equals(behaviourType);
  1435.                                 org.openspcoop2.pdd.core.behaviour.built_in.multi_deliver.MultiDeliverUtils.save(pa, configurazioneMultiDeliver, differenziazioneConsegnaDaNotifiche);
  1436.                             }
  1437.                         }

  1438.                         if(consegnaCondizionale) {
  1439.                             boolean save = false;
  1440.                             org.openspcoop2.pdd.core.behaviour.conditional.ConfigurazioneCondizionale configurazioneCondizionale =
  1441.                                     org.openspcoop2.pdd.core.behaviour.conditional.ConditionalUtils.read(pa, ControlStationCore.getLog());

  1442.                             for (String nomeRegola : configurazioneCondizionale.getRegoleOrdinate()) {
  1443.                                 ConfigurazioneSelettoreCondizioneRegola regola = configurazioneCondizionale.getRegola(nomeRegola);
  1444.                                 if(!configurazioneCondizionale.isByFilter() &&
  1445.                                     regola.getStaticInfo() != null &&
  1446.                                         regola.getStaticInfo().equals(nomeConnettore)) {
  1447.                                     regola.setStaticInfo(nomeConnettore);
  1448.                                 }
  1449.                             }

  1450.                             org.openspcoop2.pdd.core.behaviour.conditional.IdentificazioneFallitaConfigurazione condizioneNonIdentificata =
  1451.                                     configurazioneCondizionale.getCondizioneNonIdentificata();

  1452.                             if(condizioneNonIdentificata.getNomeConnettore() != null &&
  1453.                                 condizioneNonIdentificata.getNomeConnettore().equals(oldNomeConnettore)) {
  1454.                                 // modifica riferimento
  1455.                                 condizioneNonIdentificata.setNomeConnettore(nomeConnettore);
  1456.                                 save = true;
  1457.                             }

  1458.                             org.openspcoop2.pdd.core.behaviour.conditional.IdentificazioneFallitaConfigurazione connettoreNonTrovato =
  1459.                                     configurazioneCondizionale.getNessunConnettoreTrovato();

  1460.                             if(connettoreNonTrovato.getNomeConnettore() != null &&
  1461.                                 connettoreNonTrovato.getNomeConnettore().equals(oldNomeConnettore)) {
  1462.                                 // modifica riferimento
  1463.                                 connettoreNonTrovato.setNomeConnettore(nomeConnettore);
  1464.                                 save = true;
  1465.                             }

  1466.                             if(save) {
  1467.                                 org.openspcoop2.pdd.core.behaviour.conditional.ConditionalUtils.save(pa, configurazioneCondizionale);
  1468.                             }
  1469.                         }
  1470.                     }
  1471.                 }
  1472.             }
  1473.             else {
  1474.                 nomeConnettoreChangeList = datiConnettore.getNome();
  1475.                 if(nomeConnettoreChangeList==null) {
  1476.                     nomeConnettoreChangeList = CostantiConfigurazione.NOME_CONNETTORE_DEFAULT;
  1477.                 }
  1478.             }

  1479.             if(visualizzaSezioneDescrizione)
  1480.                 datiConnettore.setDescrizione(descrizioneConnettore);

  1481.             if(visualizzaSezioneFiltri) {
  1482.                
  1483.                 datiConnettore.getFiltroList().clear();
  1484.                
  1485.                 if(StringUtils.isNotEmpty(filtriConnettore)) {
  1486.                    
  1487.                     List<String> filtri = Arrays.asList(filtriConnettore.split(","));

  1488.                     for (String filtro : filtri) {
  1489.                         datiConnettore.addFiltro(filtro);
  1490.                     }
  1491.                 }
  1492.             }

  1493.             boolean secret = false;
  1494.             String secretPassword  = null;
  1495.             String secretUser = null;
  1496.             boolean secretAppId = false;
  1497.            
  1498.             if(visualizzaSezioneConnettore) {
  1499.                 // la modifica del connettore  
  1500.                 idSA = new IDServizioApplicativo();
  1501.                 idSA.setNome(paSA.getNome());
  1502.                 idSA.setIdSoggettoProprietario(new IDSoggetto(pa.getTipoSoggettoProprietario(), pa.getNomeSoggettoProprietario()));
  1503.                 ServizioApplicativo sa = saCore.getServizioApplicativo(idSA );
  1504.                 invocazionePorta = sa.getInvocazionePorta();
  1505.                 InvocazioneServizio is = sa.getInvocazioneServizio();
  1506.                 InvocazioneCredenziali cis = is.getCredenziali();
  1507.                 Connettore connis = is.getConnettore();

  1508.                 // ho scelto un SA server
  1509.                 // 1. cambio un SA server con un altro
  1510.                 // 2. non cambio
  1511.                 // 3. Sostituzione di un connettore definito nella form con uno SA server

  1512.                 if(erogazioneServizioApplicativoServerEnabled) {
  1513.                     if(!erogazioneServizioApplicativoServer.equals(sa.getNome())) {
  1514.    
  1515.                         if(!isDefault) {
  1516.                            
  1517.                             paSA.setNome(erogazioneServizioApplicativoServer);
  1518.                            
  1519.                             // se non sono il connettore di default imposto il nome dell SA Server e cancello il SA collegato al connettore definito nella form
  1520.                             if(!ServiziApplicativiCostanti.VALUE_SERVIZI_APPLICATIVI_TIPO_SERVER.equals(sa.getTipo()))
  1521.                                 listaOggettiDaEliminare.add(sa);
  1522.                            
  1523.                         } else {

  1524.                             // se sono il connettore di defautl allora devo comportarmi come il connettore nel caso non multiplo
  1525.                             // prelevo l'associazione con il vecchio servizio applicativo
  1526.                             PortaApplicativaServizioApplicativo paSAtmp = null;
  1527.                             for (PortaApplicativaServizioApplicativo paSA2 : pa.getServizioApplicativoList()) {
  1528.                                 if(paSA2.getNome().equals(sa.getNome())) {
  1529.                                     paSAtmp = paSA2;
  1530.                                     break;
  1531.                                 }
  1532.                             }
  1533.    
  1534.                             if(paSAtmp!= null) {
  1535.                                 // se ho modificato il server che sto utilizzando lo rimuovo
  1536.                                 if(ServiziApplicativiCostanti.VALUE_SERVIZI_APPLICATIVI_TIPO_SERVER.equals(sa.getTipo())){
  1537.                                     pa.getServizioApplicativoList().remove(paSAtmp);    
  1538.                                 } else {
  1539.                                     // SA di default da conservare
  1540.                                     pa.getServizioApplicativoList().remove(paSAtmp);
  1541.                                     pa.setServizioApplicativoDefault(sa.getNome());
  1542.                                 }
  1543.                             }

  1544.                             // nuovo SA da aggiungere
  1545.                             paSA.setNome(erogazioneServizioApplicativoServer);
  1546.                             pa.getServizioApplicativoList().add(paSA);

  1547.                             // aggiorno eventuali connettori associati alla conigurazioni non default
  1548.                             porteApplicativeHelper.impostaSAServerAlleConfigurazioniCheUsanoConnettoreDelMappingDiDefault(idAsps, erogazioneServizioApplicativoServer, pa, sa, listaOggettiDaModificare);
  1549.                         }
  1550.                     }
  1551.                 }else {
  1552.                     // ho salvato un connettore form
  1553.                     // 1. modifico il vecchio connettore form
  1554.                     // 2. avevo associato un SAServer lo disassocio e inserisco quello Form

  1555.                     if(!isDefault) {
  1556.                         // in questo caso devo solo creare il nuovo connettore.
  1557.                     } else {
  1558.                         // se sono nella configurazione di default devo ripristinare la situazione precedente
  1559.                         if(pa.getServizioApplicativoDefault() != null) {

  1560.                             String oldServizioApplicativoDefault = pa.getServizioApplicativoDefault();

  1561.                             // prelevo l'associazione con il vecchio servizio applicativo server
  1562.                             PortaApplicativaServizioApplicativo paSAtmp = null;
  1563.                             for (PortaApplicativaServizioApplicativo paSA2 : pa.getServizioApplicativoList()) {
  1564.                                 if(paSA2.getNome().equals(sa.getNome())) {
  1565.                                     paSAtmp = paSA2;
  1566.                                     break;
  1567.                                 }
  1568.                             }

  1569.                             if(paSAtmp!= null &&
  1570.                                 // se ho modificato il server che sto utilizzando lo rimuovo
  1571.                                 (ServiziApplicativiCostanti.VALUE_SERVIZI_APPLICATIVI_TIPO_SERVER.equals(sa.getTipo()))
  1572.                                 ){
  1573.                                 pa.getServizioApplicativoList().remove(paSAtmp);    
  1574.                             }

  1575.                             paSA.setNome(oldServizioApplicativoDefault);
  1576.                             pa.getServizioApplicativoList().add(paSA);
  1577.                             pa.setServizioApplicativoDefault(null);

  1578.                             porteApplicativeHelper.impostaSADefaultAlleConfigurazioniCheUsanoConnettoreDelMappingDiDefault(idAsps, pa, sa, listaOggettiDaModificare);

  1579.                             // rileggo la vecchia configurazione dal db di default
  1580.                             idSA = new IDServizioApplicativo();
  1581.                             idSA.setNome(oldServizioApplicativoDefault);
  1582.                             IDSoggetto idSoggettoProprietario = new IDSoggetto();
  1583.                             idSoggettoProprietario.setTipo(pa.getTipoSoggettoProprietario());
  1584.                             idSoggettoProprietario.setNome(pa.getNomeSoggettoProprietario());
  1585.                             idSA.setIdSoggettoProprietario(idSoggettoProprietario );
  1586.                             sa = saCore.getServizioApplicativo(idSA);
  1587.                             invocazionePorta = sa.getInvocazionePorta();
  1588.                             is = sa.getInvocazioneServizio();
  1589.                             cis = is.getCredenziali();
  1590.                             connis = is.getConnettore();
  1591.                         }


  1592.                     }

  1593.                     if(!ServiziApplicativiCostanti.VALUE_SERVIZI_APPLICATIVI_TIPO_SERVER.equals(sa.getTipo())){
  1594.                         // Modifico i dati del servizioApplicativo nel db
  1595.                         if(sbustamento==null){
  1596.                             is.setSbustamentoSoap(CostantiConfigurazione.DISABILITATO);
  1597.                         }else{
  1598.                             is.setSbustamentoSoap(StatoFunzionalita.toEnumConstant(sbustamento));
  1599.                         }
  1600.                         if(sbustamentoInformazioniProtocolloRichiesta==null){
  1601.                             is.setSbustamentoInformazioniProtocollo(CostantiConfigurazione.ABILITATO);
  1602.                         }else{
  1603.                             is.setSbustamentoInformazioniProtocollo(StatoFunzionalita.toEnumConstant(sbustamentoInformazioniProtocolloRichiesta));
  1604.                         }
  1605.                         is.setGetMessage(StatoFunzionalita.toEnumConstant(getmsg));
  1606.                         is.setInvioPerRiferimento(StatoFunzionalita.toEnumConstant(invrifRichiesta));
  1607.                         is.setRispostaPerRiferimento(StatoFunzionalita.toEnumConstant(risprif));
  1608.                         if (tipoauthRichiesta!=null && tipoauthRichiesta.equals(CostantiConfigurazione.INVOCAZIONE_SERVIZIO_AUTENTICAZIONE_BASIC.toString())) {
  1609.                             if (cis == null) {
  1610.                                 cis = new InvocazioneCredenziali();
  1611.                             }
  1612.                             cis.setUser(user);
  1613.                             cis.setPassword(password);
  1614.                             is.setCredenziali(cis);
  1615.                             is.setAutenticazione(InvocazioneServizioTipoAutenticazione.BASIC);
  1616.                         }
  1617.                         else if(endpointtype.equals(TipiConnettore.JMS.toString())){
  1618.                             if(user!=null && password!=null){
  1619.                                 if (cis == null) {
  1620.                                     cis = new InvocazioneCredenziali();
  1621.                                 }
  1622.                                 cis.setUser(user);
  1623.                                 cis.setPassword(password);
  1624.                             }
  1625.                             is.setCredenziali(cis);
  1626.                             is.setAutenticazione(InvocazioneServizioTipoAutenticazione.BASIC);
  1627.                         }
  1628.                         else {
  1629.                             is.setCredenziali(null);
  1630.                             is.setAutenticazione(InvocazioneServizioTipoAutenticazione.NONE);
  1631.                         }
  1632.                         String oldConnT = connis.getTipo();
  1633.                         if ((connis.getCustom()!=null && connis.getCustom()) &&
  1634.                                 !connis.getTipo().equals(TipiConnettore.HTTPS.toString()) &&
  1635.                                 !connis.getTipo().equals(TipiConnettore.FILE.toString()) &&
  1636.                                 !oldConnis.getTipo().equals(TipiConnettore.STATUS.toString()))
  1637.                             oldConnT = TipiConnettore.CUSTOM.toString();
  1638.                         porteApplicativeHelper.fillConnettore(connis, connettoreDebug, endpointtype, oldConnT, tipoconn, url,
  1639.                                 nomeCodaJms, tipoJms, user, password,
  1640.                                 initcont, urlpgk, provurl, connfact,
  1641.                                 tipoSendas, httpsurl, httpstipologia, httpshostverify,
  1642.                                 httpsTrustVerifyCert, httpspath, httpstipo,
  1643.                                 httpspwd, httpsalgoritmo, httpsstato,
  1644.                                 httpskeystore, httpspwdprivatekeytrust,
  1645.                                 httpspathkey, httpstipokey,
  1646.                                 httpspwdkey, httpspwdprivatekey,
  1647.                                 httpsalgoritmokey,
  1648.                                 httpsKeyAlias, httpsTrustStoreCRLs, httpsTrustStoreOCSPPolicy, httpsKeyStoreBYOKPolicy,
  1649.                                 proxyEnabled, proxyHostname, proxyPort, proxyUsername, proxyPassword,
  1650.                                 tempiRispostaEnabled, tempiRispostaConnectionTimeout, tempiRispostaReadTimeout, tempiRispostaTempoMedioRisposta,
  1651.                                 opzioniAvanzate, transferMode, transferModeChunkSize, redirectMode, redirectMaxHop,
  1652.                                 requestOutputFileName, requestOutputFileNamePermissions, requestOutputFileNameHeaders, requestOutputFileNameHeadersPermissions,
  1653.                                 requestOutputParentDirCreateIfNotExists,requestOutputOverwriteIfExists,
  1654.                                 responseInputMode, responseInputFileName, responseInputFileNameHeaders, responseInputDeleteAfterRead, responseInputWaitTime,
  1655.                                 tokenPolicy,
  1656.                                 apiKeyHeader, apiKeyValue, appIdHeader, appIdValue,
  1657.                                 connettoreStatusParams,
  1658.                                 listExtendedConnettore);
  1659.                         is.setConnettore(connis);
  1660.                         sa.setInvocazioneServizio(is);

  1661.                         if(StatoFunzionalita.ABILITATO.equals(is.getGetMessage()) ||
  1662.                                 !TipiConnettore.DISABILITATO.toString().equals(endpointtype)){
  1663.                             sa.setTipologiaErogazione(TipologiaErogazione.TRASPARENTE.getValue());
  1664.                         }
  1665.                         else{
  1666.                             sa.setTipologiaErogazione(TipologiaErogazione.DISABILITATO.getValue());
  1667.                         }

  1668.                         // rif bug#45
  1669.                         // se il connettore e' disabilitato oppure il Salvataggio in MessageBox e'
  1670.                         // disabilitato
  1671.                         // bisogna controllare che il servizio applicativo non sia in uso in
  1672.                         // porte applicative
  1673.                         StringBuilder inUsoMessage = new StringBuilder();
  1674.                         ServiziApplicativiUtilities.checkStatoConnettore(saCore, sa, connis, inUsoMessage, org.openspcoop2.core.constants.Costanti.WEB_NEW_LINE);
  1675.                         if(inUsoMessage.length()>0) {
  1676.                             pd.setMessage(inUsoMessage.toString());
  1677.                             ServletUtils.setGeneralAndPageDataIntoSession(request, session, gd, pd);
  1678.                             return ServletUtils.getStrutsForwardGeneralError(mapping, PorteApplicativeCostanti.OBJECT_NAME_PORTE_APPLICATIVE_CONNETTORI_MULTIPLI, ForwardParams.CHANGE());
  1679.                         }

  1680.                         if(CostantiConfigurazione.ABILITATO.toString().equals(getmsg)) {
  1681.                             boolean found = false;
  1682.                             boolean encryptOldPlainPwd = false;
  1683.                             if(invocazionePorta!=null && invocazionePorta.sizeCredenzialiList()>0) {
  1684.                                 for (int i = 0; i < invocazionePorta.sizeCredenzialiList(); i++) {
  1685.                                     Credenziali c = invocazionePorta.getCredenziali(i);
  1686.                                     if(CredenzialeTipo.BASIC.equals(c.getTipo())) {
  1687.                                         c.setUser(getmsgUsername);
  1688.                                         c.setPassword(getmsgPassword);
  1689.                                         found = true;
  1690.                                        
  1691.                                         encryptOldPlainPwd = !c.isCertificateStrictVerification() && saCore.isApplicativiPasswordEncryptEnabled();
  1692.                                        
  1693.                                         if(ServletUtils.isCheckBoxEnabled(changepwd)) {
  1694.                                             c.setCertificateStrictVerification(false); // se è abilitata la cifratura, verrà impostata a true nel perform update
  1695.                                             if(saCore.isApplicativiPasswordEncryptEnabled()) {
  1696.                                                 secret = true;
  1697.                                             }
  1698.                                         }
  1699.                                         else if(encryptOldPlainPwd) {
  1700.                                             secret = true;
  1701.                                         }
  1702.                                         else {
  1703.                                             c.setCertificateStrictVerification(ServletUtils.isCheckBoxEnabled(tipoCredenzialiSSLVerificaTuttiICampi));
  1704.                                         }
  1705.                                        
  1706.                                         if(secret) {
  1707.                                             secretUser = c.getUser();
  1708.                                             secretPassword = c.getPassword();
  1709.                                             secretAppId = c.isAppId();
  1710.                                         }
  1711.                                     }
  1712.                                 }
  1713.                             }
  1714.                             if(!found) {
  1715.                                 if(invocazionePorta==null) {
  1716.                                     sa.setInvocazionePorta(new InvocazionePorta());
  1717.                                     invocazionePorta = sa.getInvocazionePorta();
  1718.                                 }
  1719.                                 Credenziali c = new Credenziali();
  1720.                                 c.setTipo(CredenzialeTipo.BASIC);
  1721.                                 c.setUser(getmsgUsername);
  1722.                                 c.setPassword(getmsgPassword);
  1723.                                
  1724.                                 c.setCertificateStrictVerification(false); // se è abilitata la cifratura, verrà impostata a true nel perform update
  1725.                                 if(saCore.isApplicativiPasswordEncryptEnabled()) {
  1726.                                     secret = true;
  1727.                                 }
  1728.                                
  1729.                                 if(secret) {
  1730.                                     secretUser = c.getUser();
  1731.                                     secretPassword = c.getPassword();
  1732.                                     secretAppId = c.isAppId();
  1733.                                 }
  1734.                                
  1735.                                 invocazionePorta.addCredenziali(c);
  1736.                             }
  1737.                         }
  1738.                         else {
  1739.                             // Fix: altrimenti rimaneva assegnate le credenziali quando si disabilitava l'integration manager
  1740.                             if(!porteApplicativeHelper.isModalitaCompleta() &&
  1741.                                 invocazionePorta!=null) {
  1742.                                 while (invocazionePorta.sizeCredenzialiList()>0) {
  1743.                                     invocazionePorta.removeCredenziali(0);
  1744.                                 }
  1745.                             }
  1746.                         }

  1747.                         listaOggettiDaModificare.add(sa);
  1748.                     } else {
  1749.                         // 1. Creo connettore
  1750.                         Connettore connettore = null;

  1751.                         // Connettore
  1752.                         connettore = new Connettore();
  1753.                         if (endpointtype.equals(ConnettoriCostanti.DEFAULT_CONNETTORE_TYPE_CUSTOM))
  1754.                             connettore.setTipo(tipoconn);
  1755.                         else
  1756.                             connettore.setTipo(endpointtype);

  1757.                         porteApplicativeHelper.fillConnettore(connettore, connettoreDebug, endpointtype, endpointtype, tipoconn, url,
  1758.                                 nomeCodaJms, tipoJms, user, password,
  1759.                                 initcont, urlpgk, provurl, connfact,
  1760.                                 tipoSendas, httpsurl, httpstipologia, httpshostverify,
  1761.                                 httpsTrustVerifyCert, httpspath, httpstipo,
  1762.                                 httpspwd, httpsalgoritmo, httpsstato,
  1763.                                 httpskeystore, httpspwdprivatekeytrust,
  1764.                                 httpspathkey, httpstipokey,
  1765.                                 httpspwdkey, httpspwdprivatekey,
  1766.                                 httpsalgoritmokey,
  1767.                                 httpsKeyAlias, httpsTrustStoreCRLs, httpsTrustStoreOCSPPolicy, httpsKeyStoreBYOKPolicy,
  1768.                                 proxyEnabled, proxyHostname, proxyPort, proxyUsername, proxyPassword,
  1769.                                 tempiRispostaEnabled, tempiRispostaConnectionTimeout, tempiRispostaReadTimeout, tempiRispostaTempoMedioRisposta,
  1770.                                 opzioniAvanzate, transferMode, transferModeChunkSize, redirectMode, redirectMaxHop,
  1771.                                 requestOutputFileName, requestOutputFileNamePermissions, requestOutputFileNameHeaders, requestOutputFileNameHeadersPermissions,
  1772.                                 requestOutputParentDirCreateIfNotExists,requestOutputOverwriteIfExists,
  1773.                                 responseInputMode, responseInputFileName, responseInputFileNameHeaders, responseInputDeleteAfterRead, responseInputWaitTime,
  1774.                                 tokenPolicy,
  1775.                                 apiKeyHeader, apiKeyValue, appIdHeader, appIdValue,  
  1776.                                 connettoreStatusParams,
  1777.                                 listExtendedConnettore);

  1778.                         // creare un servizio applicativo
  1779.                         String nomeServizioApplicativoErogatore = pa.getNome() + PorteApplicativeCostanti.LABEL_PARAMETRO_PORTE_APPLICATIVE_CONNETTORI_MULTIPLI_SAX_PREFIX +
  1780.                                 porteApplicativeHelper.getIdxNuovoConnettoreMultiplo(pa);

  1781.                         ServizioApplicativo nuovoSA = new ServizioApplicativo();
  1782.                         nuovoSA.setNome(nomeServizioApplicativoErogatore);
  1783.                         nuovoSA.setTipologiaFruizione(TipologiaFruizione.DISABILITATO.getValue());
  1784.                         nuovoSA.setTipologiaErogazione(TipologiaErogazione.TRASPARENTE.getValue());
  1785.                         long soggInt = Long.parseLong(idsogg);
  1786.                         nuovoSA.setIdSoggetto(soggInt);
  1787.                         nuovoSA.setTipoSoggettoProprietario(pa.getTipoSoggettoProprietario());
  1788.                         nuovoSA.setNomeSoggettoProprietario(pa.getNomeSoggettoProprietario());

  1789.                         RispostaAsincrona rispostaAsinc = new RispostaAsincrona();
  1790.                         rispostaAsinc.setAutenticazione(InvocazioneServizioTipoAutenticazione.NONE);
  1791.                         rispostaAsinc.setGetMessage(CostantiConfigurazione.DISABILITATO);
  1792.                         nuovoSA.setRispostaAsincrona(rispostaAsinc);

  1793.                         InvocazioneServizio nuovaIS = new InvocazioneServizio();
  1794.                         nuovaIS.setAutenticazione(InvocazioneServizioTipoAutenticazione.NONE);
  1795.                         nuovaIS.setGetMessage(CostantiConfigurazione.DISABILITATO);
  1796.                         nuovaIS.setConnettore(connettore);
  1797.                         nuovoSA.setInvocazioneServizio(nuovaIS);

  1798.                         InvocazioneCredenziali nuovaCIS = null;

  1799.                         // Modifico i dati del servizioApplicativo nel db
  1800.                         if(sbustamento==null){
  1801.                             nuovaIS.setSbustamentoSoap(CostantiConfigurazione.DISABILITATO);
  1802.                         }else{
  1803.                             nuovaIS.setSbustamentoSoap(StatoFunzionalita.toEnumConstant(sbustamento));
  1804.                         }
  1805.                         if(sbustamentoInformazioniProtocolloRichiesta==null){
  1806.                             nuovaIS.setSbustamentoInformazioniProtocollo(CostantiConfigurazione.ABILITATO);
  1807.                         }else{
  1808.                             nuovaIS.setSbustamentoInformazioniProtocollo(StatoFunzionalita.toEnumConstant(sbustamentoInformazioniProtocolloRichiesta));
  1809.                         }
  1810.                         nuovaIS.setGetMessage(StatoFunzionalita.toEnumConstant(getmsg));
  1811.                         nuovaIS.setInvioPerRiferimento(StatoFunzionalita.toEnumConstant(invrifRichiesta));
  1812.                         nuovaIS.setRispostaPerRiferimento(StatoFunzionalita.toEnumConstant(risprif));
  1813.                         if (tipoauthRichiesta!=null && tipoauthRichiesta.equals(CostantiConfigurazione.INVOCAZIONE_SERVIZIO_AUTENTICAZIONE_BASIC.toString())) {
  1814.                             if (nuovaCIS == null) {
  1815.                                 nuovaCIS = new InvocazioneCredenziali();
  1816.                             }
  1817.                             nuovaCIS.setUser(user);
  1818.                             nuovaCIS.setPassword(password);
  1819.                             nuovaIS.setCredenziali(nuovaCIS);
  1820.                             nuovaIS.setAutenticazione(InvocazioneServizioTipoAutenticazione.BASIC);
  1821.                         }
  1822.                         else if(endpointtype.equals(TipiConnettore.JMS.toString())){
  1823.                             if(user!=null && password!=null){
  1824.                                 if (nuovaCIS == null) {
  1825.                                     nuovaCIS = new InvocazioneCredenziali();
  1826.                                 }
  1827.                                 nuovaCIS.setUser(user);
  1828.                                 nuovaCIS.setPassword(password);
  1829.                             }
  1830.                             nuovaIS.setCredenziali(nuovaCIS);
  1831.                             nuovaIS.setAutenticazione(InvocazioneServizioTipoAutenticazione.BASIC);
  1832.                         }
  1833.                         else {
  1834.                             nuovaIS.setCredenziali(null);
  1835.                             nuovaIS.setAutenticazione(InvocazioneServizioTipoAutenticazione.NONE);
  1836.                         }

  1837.                         if(StatoFunzionalita.ABILITATO.equals(nuovaIS.getGetMessage()) ||
  1838.                                 !TipiConnettore.DISABILITATO.toString().equals(endpointtype)){
  1839.                             nuovoSA.setTipologiaErogazione(TipologiaErogazione.TRASPARENTE.getValue());
  1840.                         }
  1841.                         else{
  1842.                             nuovoSA.setTipologiaErogazione(TipologiaErogazione.DISABILITATO.getValue());
  1843.                         }

  1844.                         listaOggettiDaCreare.add(nuovoSA);
  1845.                         paSA.setNome(nomeServizioApplicativoErogatore);
  1846.                     }
  1847.                 }
  1848.             }


  1849.             listaOggettiDaModificare.add(pa);

  1850.             if(!listaOggettiDaCreare.isEmpty())
  1851.                 porteApplicativeCore.performCreateOperation(userLogin, porteApplicativeHelper.smista(), listaOggettiDaCreare.toArray(new Object[listaOggettiDaCreare.size()]));

  1852.             porteApplicativeCore.performUpdateOperation(userLogin, porteApplicativeHelper.smista(), listaOggettiDaModificare.toArray(new Object[listaOggettiDaModificare.size()]));

  1853.             // L'eliminazione degli oggetti non più necessari deve essere effettuata dopo l'update, altrimenti si ha un errore di foreign key violata
  1854.             if(!listaOggettiDaEliminare.isEmpty())
  1855.                 porteApplicativeCore.performDeleteOperation(userLogin, porteApplicativeHelper.smista(), listaOggettiDaEliminare.toArray(new Object[listaOggettiDaEliminare.size()]));
  1856.            
  1857.             ServletUtils.removeRisultatiRicercaFromSession(request, session, Liste.PORTE_APPLICATIVE_CONNETTORI_MULTIPLI);
  1858.            
  1859.             // Messaggio 'Please Copy'
  1860.             if(secret) {
  1861.                 porteApplicativeHelper.setSecretPleaseCopy(secretPassword, secretUser, secretAppId, ConnettoriCostanti.AUTENTICAZIONE_TIPO_BASIC, OggettoDialogEnum.CONNETTORE_MULTIPLO, nomeConnettore);
  1862.             }
  1863.            
  1864.             // Preparo la lista
  1865.             ConsoleSearch ricerca = (ConsoleSearch) ServletUtils.getSearchObjectFromSession(request, session, ConsoleSearch.class);

  1866.             int idLista = Liste.PORTE_APPLICATIVE_CONNETTORI_MULTIPLI;

  1867.             ricerca = porteApplicativeHelper.checkSearchParameters(idLista, ricerca);

  1868.             // ricarico la configurazione
  1869.             pa = porteApplicativeCore.getPortaApplicativa(Integer.parseInt(idPorta));
  1870.             IDSoggetto idSoggettoProprietario = new IDSoggetto(pa.getTipoSoggettoProprietario(), pa.getNomeSoggettoProprietario());
  1871.             List<PortaApplicativaServizioApplicativo> listaFiltrata = porteApplicativeHelper.applicaFiltriRicercaConnettoriMultipli(ricerca, idLista, pa.getServizioApplicativoList(), idSoggettoProprietario);
  1872.            
  1873.             porteApplicativeHelper.preparePorteAppConnettoriMultipliList_fromChangeConnettore(pa.getNome(), ricerca, listaFiltrata, pa,
  1874.                     nomeConnettoreChangeList);

  1875.             ServletUtils.setGeneralAndPageDataIntoSession(request, session, gd, pd);
  1876.             // Forward control to the specified success URI
  1877.             return ServletUtils.getStrutsForwardEditModeFinished(mapping, PorteApplicativeCostanti.OBJECT_NAME_PORTE_APPLICATIVE_CONNETTORI_MULTIPLI,
  1878.                     ForwardParams.CHANGE());
  1879.         } catch (Exception e) {
  1880.             return ServletUtils.getStrutsForwardError(ControlStationCore.getLog(), e, pd, request, session, gd, mapping,
  1881.                     PorteApplicativeCostanti.OBJECT_NAME_PORTE_APPLICATIVE_CONNETTORI_MULTIPLI,
  1882.                     ForwardParams.CHANGE());
  1883.         }  
  1884.     }
  1885. }