GestoreHandlers.java

  1. /*
  2.  * GovWay - A customizable API Gateway
  3.  * https://govway.org
  4.  *
  5.  * Copyright (c) 2005-2025 Link.it srl (https://link.it).
  6.  *
  7.  * This program is free software: you can redistribute it and/or modify
  8.  * it under the terms of the GNU General Public License version 3, as published by
  9.  * the Free Software Foundation.
  10.  *
  11.  * This program is distributed in the hope that it will be useful,
  12.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.  * GNU General Public License for more details.
  15.  *
  16.  * You should have received a copy of the GNU General Public License
  17.  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  18.  *
  19.  */


  20. package org.openspcoop2.pdd.core.handlers;

  21. import java.util.ArrayList;
  22. import java.util.Collections;
  23. import java.util.HashMap;
  24. import java.util.List;
  25. import java.util.Map;

  26. import org.openspcoop2.core.config.PortaApplicativa;
  27. import org.openspcoop2.core.config.PortaDelegata;
  28. import org.openspcoop2.core.constants.TipoPdD;
  29. import org.openspcoop2.core.id.IDPortaApplicativa;
  30. import org.openspcoop2.core.id.IDPortaDelegata;
  31. import org.openspcoop2.pdd.config.ClassNameProperties;
  32. import org.openspcoop2.pdd.config.ConfigurazionePdDManager;
  33. import org.openspcoop2.pdd.config.OpenSPCoop2Properties;
  34. import org.openspcoop2.pdd.config.dynamic.PddPluginLoader;
  35. import org.openspcoop2.pdd.core.PdDContext;
  36. import org.openspcoop2.pdd.core.handlers.notifier.NotifierConstants;
  37. import org.openspcoop2.pdd.core.handlers.notifier.NotifierInRequestHandler;
  38. import org.openspcoop2.pdd.core.handlers.notifier.NotifierInRequestProtocolHandler;
  39. import org.openspcoop2.pdd.core.handlers.notifier.NotifierInResponseHandler;
  40. import org.openspcoop2.pdd.core.handlers.notifier.NotifierOutRequestHandler;
  41. import org.openspcoop2.pdd.core.handlers.notifier.NotifierOutResponseHandler;
  42. import org.openspcoop2.pdd.core.handlers.notifier.NotifierPostOutRequestHandler;
  43. import org.openspcoop2.pdd.core.handlers.notifier.NotifierPostOutResponseHandler;
  44. import org.openspcoop2.pdd.core.handlers.notifier.NotifierPreInRequestHandler;
  45. import org.openspcoop2.pdd.core.handlers.notifier.NotifierPreInResponseHandler;
  46. import org.openspcoop2.pdd.logger.MsgDiagnostico;
  47. import org.openspcoop2.protocol.sdk.state.IState;
  48. import org.openspcoop2.protocol.sdk.state.RequestInfo;
  49. import org.openspcoop2.utils.date.DateManager;
  50. import org.openspcoop2.utils.id.UniqueIdentifierManager;
  51. import org.openspcoop2.utils.resources.Loader;
  52. import org.slf4j.Logger;


  53. /**
  54.  * Utility per la registrazione delle informazioni di attraversamento della richiesta/risposta nella porta di dominio
  55.  *
  56.  * @author Poli Andrea (apoli@link.it)
  57.  * @author $Author$
  58.  * @version $Rev$, $Date$
  59.  */
  60. public class GestoreHandlers  {

  61.     private static boolean initialize = false;
  62.     private static OpenSPCoop2Properties properties = null;
  63.     private static GeneratoreCasualeDate generatoreCasualeDati = null;
  64.    
  65.     // Handlers BuiltIn
  66.    
  67.     private static InitHandler [] initHandlersBuiltIn = null;
  68.     private static String [] tipiInitHandlersBuiltIn = null;
  69.    
  70.     private static ExitHandler [] exitHandlersBuiltIn = null;
  71.     private static String [] tipiExitHandlersBuiltIn = null;
  72.    
  73.     private static PreInRequestHandler [] preInRequestHandlersBuiltIn = null;
  74.     private static String [] tipiPreInRequestHandlersBuiltIn = null;
  75.    
  76.     private static InRequestHandler [] inRequestHandlersBuiltIn = null;
  77.     private static String [] tipiInRequestHandlersBuiltIn = null;
  78.    
  79.     private static InRequestProtocolHandler [] inRequestProtocolHandlersBuiltIn = null;
  80.     private static String [] tipiInRequestProtocolHandlersBuiltIn = null;
  81.    
  82.     private static OutRequestHandler [] outRequestHandlersBuiltIn = null;
  83.     private static String [] tipiOutRequestHandlersBuiltIn = null;
  84.    
  85.     private static PostOutRequestHandler [] postOutRequestHandlersBuiltIn = null;
  86.     private static String [] tipiPostOutRequestHandlersBuiltIn = null;
  87.    
  88.     private static PreInResponseHandler [] preInResponseHandlersBuiltIn = null;
  89.     private static String [] tipiPreInResponseHandlersBuiltIn = null;
  90.    
  91.     private static InResponseHandler [] inResponseHandlersBuiltIn = null;
  92.     private static String [] tipiInResponseHandlersBuiltIn = null;
  93.    
  94.     private static OutResponseHandler [] outResponseHandlersBuiltIn = null;
  95.     private static String [] tipiOutResponseHandlersBuiltIn = null;
  96.    
  97.     private static PostOutResponseHandler [] postOutResponseHandlersBuiltIn = null;
  98.     private static String [] tipiPostOutResponseHandlersBuiltIn = null;
  99.    
  100.     private static IntegrationManagerRequestHandler [] integrationManagerRequestHandlersBuiltIn = null;
  101.     private static String [] tipiIntegrationManagerRequestHandlersBuiltIn = null;
  102.    
  103.     private static IntegrationManagerResponseHandler [] integrationManagerResponseHandlersBuiltIn = null;
  104.     private static String [] tipiIntegrationManagerResponseHandlersBuiltIn = null;
  105.    
  106.     // Handlers Utente
  107.    
  108.     private static InitHandler [] initHandlers = null;
  109.     private static String [] tipiInitHandlers = null;
  110.    
  111.     private static ExitHandler [] exitHandlers = null;
  112.     private static String [] tipiExitHandlers = null;
  113.    
  114.     private static PreInRequestHandler [] preInRequestHandlers = null;
  115.     private static String [] tipiPreInRequestHandlers = null;
  116.    
  117.     private static InRequestHandler [] inRequestHandlers = null;
  118.     private static String [] tipiInRequestHandlers = null;
  119.    
  120.     private static InRequestProtocolHandler [] inRequestProtocolHandlers = null;
  121.     private static String [] tipiInRequestProtocolHandlers = null;
  122.    
  123.     private static OutRequestHandler [] outRequestHandlers = null;
  124.     private static String [] tipiOutRequestHandlers = null;
  125.    
  126.     private static PostOutRequestHandler [] postOutRequestHandlers = null;
  127.     private static String [] tipiPostOutRequestHandlers = null;
  128.    
  129.     private static PreInResponseHandler [] preInResponseHandlers = null;
  130.     private static String [] tipiPreInResponseHandlers = null;
  131.    
  132.     private static InResponseHandler [] inResponseHandlers = null;
  133.     private static String [] tipiInResponseHandlers = null;
  134.    
  135.     private static OutResponseHandler [] outResponseHandlers = null;
  136.     private static String [] tipiOutResponseHandlers = null;
  137.    
  138.     private static PostOutResponseHandler [] postOutResponseHandlers = null;
  139.     private static String [] tipiPostOutResponseHandlers = null;
  140.    
  141.     private static IntegrationManagerRequestHandler [] integrationManagerRequestHandlers = null;
  142.     private static String [] tipiIntegrationManagerRequestHandlers = null;
  143.    
  144.     private static IntegrationManagerResponseHandler [] integrationManagerResponseHandlers = null;
  145.     private static String [] tipiIntegrationManagerResponseHandlers = null;

  146.     private static String [] toStringArray(Object [] tipiHandlersO) {
  147.         List<String> h = new ArrayList<>();
  148.         if(tipiHandlersO!=null && tipiHandlersO.length>0) {
  149.             for (Object o : tipiHandlersO) {
  150.                 if(o instanceof String) {
  151.                     h.add((String)o);
  152.                 }
  153.             }
  154.         }
  155.         if(!h.isEmpty()) {
  156.             return h.toArray(new String[1]);
  157.         }
  158.         return null;
  159.     }
  160.    
  161.    
  162.     private static void initialize(MsgDiagnostico msgDiag,Logger logConsoleInit,IState state){
  163.         initialize(msgDiag,null,logConsoleInit, state);
  164.     }
  165.     private static void initialize(Logger logCore,Logger logConsoleInit){
  166.         initialize(null,logCore,logConsoleInit, null);
  167.     }
  168.     private static synchronized void initialize(MsgDiagnostico msgDiag,Logger logCore, Logger logConsoleInit,IState state){
  169.         if(!GestoreHandlers.initialize){
  170.            
  171.             GestoreHandlers.properties = OpenSPCoop2Properties.getInstance();
  172.             ClassNameProperties classNameProperties = ClassNameProperties.getInstance();
  173.             Loader loader = Loader.getInstance();
  174.             PddPluginLoader pluginLoader = PddPluginLoader.getInstance();
  175.             if(GestoreHandlers.properties.generazioneDateCasualiLogAbilitato() && !UniqueIdentifierManager.isGenerazioneUIDDisabilitata()){
  176.                 GestoreHandlers.generatoreCasualeDati = GeneratoreCasualeDate.getGeneratoreCasualeDate();
  177.             }
  178.        
  179.            
  180.             // Handlers BuiltIn
  181.            
  182.             boolean printInfoBuiltIn = GestoreHandlers.properties.isPrintInfoHandlerBuiltIn();
  183.            
  184.             // InitHandler
  185.             GestoreHandlers.tipiInitHandlersBuiltIn = GestoreHandlers.properties.getInitHandlerBuiltIn();
  186.             if(GestoreHandlers.tipiInitHandlersBuiltIn!=null){
  187.                 GestoreHandlers.initHandlersBuiltIn = new InitHandler[GestoreHandlers.tipiInitHandlersBuiltIn.length];
  188.                 for(int i=0; i<GestoreHandlers.tipiInitHandlersBuiltIn.length; i++){
  189.                     try{
  190.                         String tipo=GestoreHandlers.tipiInitHandlersBuiltIn[i];
  191.                         String classe = classNameProperties.getInitHandlerBuiltIn(tipo);
  192.                         GestoreHandlers.initHandlersBuiltIn[i] = (InitHandler) loader.newInstance(classe);
  193.                         if(printInfoBuiltIn)
  194.                             logConsoleInit.info("InitHandler BuiltIn di tipo ["+tipo+"] correttamente inizializzato.");
  195.                     }catch(Throwable e){
  196.                         if(msgDiag!=null) {
  197.                             msgDiag.logErroreGenerico(e, "Inizializzazione InitHandler BuiltIn ["+GestoreHandlers.tipiInitHandlersBuiltIn[i]+"]");
  198.                         }
  199.                         else if(logCore!=null) {
  200.                             logCore.error("Inizializzazione InitHandler BuiltIn ["+GestoreHandlers.tipiInitHandlersBuiltIn[i]+"]", e);
  201.                         }
  202.                     }
  203.                 }
  204.                 GestoreHandlers.initHandlersBuiltIn = reorder(GestoreHandlers.initHandlersBuiltIn, new InitHandler[1]);
  205.             }
  206.            
  207.             // ExitHandler
  208.             GestoreHandlers.tipiExitHandlersBuiltIn = GestoreHandlers.properties.getExitHandlerBuiltIn();
  209.             if(GestoreHandlers.tipiExitHandlersBuiltIn!=null){
  210.                 GestoreHandlers.exitHandlersBuiltIn = new ExitHandler[GestoreHandlers.tipiExitHandlersBuiltIn.length];
  211.                 for(int i=0; i<GestoreHandlers.tipiExitHandlersBuiltIn.length; i++){
  212.                     try{
  213.                         String tipo=GestoreHandlers.tipiExitHandlersBuiltIn[i];
  214.                         String classe = classNameProperties.getExitHandlerBuiltIn(tipo);
  215.                         GestoreHandlers.exitHandlersBuiltIn[i] = (ExitHandler) loader.newInstance(classe);
  216.                         if(printInfoBuiltIn)
  217.                             logConsoleInit.info("ExitHandler BuiltIn di tipo ["+tipo+"] correttamente inizializzato.");
  218.                     }catch(Throwable e){
  219.                         if(msgDiag!=null) {
  220.                             msgDiag.logErroreGenerico(e, "Inizializzazione ExitHandler BuiltIn ["+GestoreHandlers.tipiExitHandlersBuiltIn[i]+"]");
  221.                         }
  222.                         else if(logCore!=null) {
  223.                             logCore.error("Inizializzazione ExitHandler BuiltIn ["+GestoreHandlers.tipiExitHandlersBuiltIn[i]+"]", e);
  224.                         }
  225.                     }
  226.                 }
  227.                 GestoreHandlers.exitHandlersBuiltIn = reorder(GestoreHandlers.exitHandlersBuiltIn, new ExitHandler[1]);
  228.             }
  229.            
  230.             // PreInRequestHandler
  231.             GestoreHandlers.tipiPreInRequestHandlersBuiltIn = GestoreHandlers.properties.getPreInRequestHandlerBuiltIn();
  232.             GestoreHandlers.tipiPreInRequestHandlersBuiltIn = updateNotifierCallback(GestoreHandlers.tipiPreInRequestHandlersBuiltIn);
  233.             if(GestoreHandlers.tipiPreInRequestHandlersBuiltIn!=null){
  234.                 GestoreHandlers.preInRequestHandlersBuiltIn = new PreInRequestHandler[GestoreHandlers.tipiPreInRequestHandlersBuiltIn.length];
  235.                 for(int i=0; i<GestoreHandlers.tipiPreInRequestHandlersBuiltIn.length; i++){
  236.                     try{
  237.                         String tipo=GestoreHandlers.tipiPreInRequestHandlersBuiltIn[i];
  238.                         String classe = null;
  239.                         if(NotifierConstants.TIPO_NOTIFIER.equals(tipo)){
  240.                             classe = NotifierPreInRequestHandler.class.getName();
  241.                         }else{
  242.                             classe = classNameProperties.getPreInRequestHandlerBuiltIn(tipo);
  243.                         }
  244.                         GestoreHandlers.preInRequestHandlersBuiltIn[i] = (PreInRequestHandler) loader.newInstance(classe);
  245.                         if(printInfoBuiltIn)
  246.                             logConsoleInit.info("PreInRequestHandler BuiltIn di tipo ["+tipo+"] correttamente inizializzato.");
  247.                     }catch(Throwable e){
  248.                         if(msgDiag!=null) {
  249.                             msgDiag.logErroreGenerico(e, "Inizializzazione PreInRequestHandler BuiltIn ["+GestoreHandlers.tipiPreInRequestHandlersBuiltIn[i]+"]");
  250.                         }
  251.                         else if(logCore!=null) {
  252.                             logCore.error("Inizializzazione PreInRequestHandler BuiltIn ["+GestoreHandlers.tipiPreInRequestHandlersBuiltIn[i]+"]", e);
  253.                         }
  254.                     }
  255.                 }
  256.                 GestoreHandlers.preInRequestHandlersBuiltIn = reorder(GestoreHandlers.preInRequestHandlersBuiltIn, new PreInRequestHandler[1]);
  257.             }
  258.            
  259.             // InRequestHandler
  260.             GestoreHandlers.tipiInRequestHandlersBuiltIn = GestoreHandlers.properties.getInRequestHandlerBuiltIn();
  261.             GestoreHandlers.tipiInRequestHandlersBuiltIn = updateNotifierCallback(GestoreHandlers.tipiInRequestHandlersBuiltIn);
  262.             if(GestoreHandlers.tipiInRequestHandlersBuiltIn!=null){
  263.                 GestoreHandlers.inRequestHandlersBuiltIn = new InRequestHandler[GestoreHandlers.tipiInRequestHandlersBuiltIn.length];
  264.                 for(int i=0; i<GestoreHandlers.tipiInRequestHandlersBuiltIn.length; i++){
  265.                     try{
  266.                         String tipo=GestoreHandlers.tipiInRequestHandlersBuiltIn[i];
  267.                         String classe = null;
  268.                         if(NotifierConstants.TIPO_NOTIFIER.equals(tipo)){
  269.                             classe = NotifierInRequestHandler.class.getName();
  270.                         }else{
  271.                             classe = classNameProperties.getInRequestHandlerBuiltIn(tipo);
  272.                         }
  273.                         GestoreHandlers.inRequestHandlersBuiltIn[i] = (InRequestHandler) loader.newInstance(classe);
  274.                         if(printInfoBuiltIn)
  275.                             logConsoleInit.info("InRequestHandler BuiltIn di tipo ["+tipo+"] correttamente inizializzato.");
  276.                     }catch(Throwable e){
  277.                         if(msgDiag!=null) {
  278.                             msgDiag.logErroreGenerico(e, "Inizializzazione InRequestHandler BuiltIn ["+GestoreHandlers.tipiInRequestHandlersBuiltIn[i]+"]");
  279.                         }
  280.                         else if(logCore!=null) {
  281.                             logCore.error("Inizializzazione InRequestHandler BuiltIn ["+GestoreHandlers.tipiInRequestHandlersBuiltIn[i]+"]", e);
  282.                         }
  283.                     }
  284.                 }
  285.                 GestoreHandlers.inRequestHandlersBuiltIn = reorder(GestoreHandlers.inRequestHandlersBuiltIn, new InRequestHandler[1]);
  286.             }
  287.            
  288.             // InRequestProtocolHandler
  289.             GestoreHandlers.tipiInRequestProtocolHandlersBuiltIn = GestoreHandlers.properties.getInRequestProtocolHandlerBuiltIn();
  290.             GestoreHandlers.tipiInRequestProtocolHandlersBuiltIn = updateNotifierCallback(GestoreHandlers.tipiInRequestProtocolHandlersBuiltIn);
  291.             if(GestoreHandlers.tipiInRequestProtocolHandlersBuiltIn!=null){
  292.                 GestoreHandlers.inRequestProtocolHandlersBuiltIn = new InRequestProtocolHandler[GestoreHandlers.tipiInRequestProtocolHandlersBuiltIn.length];
  293.                 for(int i=0; i<GestoreHandlers.tipiInRequestProtocolHandlersBuiltIn.length; i++){
  294.                     try{
  295.                         String tipo=GestoreHandlers.tipiInRequestProtocolHandlersBuiltIn[i];
  296.                         String classe = null;
  297.                         if(NotifierConstants.TIPO_NOTIFIER.equals(tipo)){
  298.                             classe = NotifierInRequestProtocolHandler.class.getName();
  299.                         }else{
  300.                             classe = classNameProperties.getInRequestProtocolHandlerBuiltIn(tipo);
  301.                         }
  302.                         GestoreHandlers.inRequestProtocolHandlersBuiltIn[i] = (InRequestProtocolHandler) loader.newInstance(classe);
  303.                         if(printInfoBuiltIn)
  304.                             logConsoleInit.info("InRequestProtocolHandler BuiltIn di tipo ["+tipo+"] correttamente inizializzato.");
  305.                     }catch(Throwable e){
  306.                         if(msgDiag!=null) {
  307.                             msgDiag.logErroreGenerico(e, "Inizializzazione InRequestProtocolHandler BuiltIn ["+GestoreHandlers.tipiInRequestProtocolHandlersBuiltIn[i]+"]");
  308.                         }
  309.                         else if(logCore!=null) {
  310.                             logCore.error("Inizializzazione InRequestProtocolHandler BuiltIn ["+GestoreHandlers.tipiInRequestProtocolHandlersBuiltIn[i]+"]", e);
  311.                         }
  312.                     }
  313.                 }
  314.                 GestoreHandlers.inRequestProtocolHandlersBuiltIn = reorder(GestoreHandlers.inRequestProtocolHandlersBuiltIn, new InRequestProtocolHandler[1]);
  315.             }
  316.            
  317.             // OutRequestHandler
  318.             GestoreHandlers.tipiOutRequestHandlersBuiltIn = GestoreHandlers.properties.getOutRequestHandlerBuiltIn();
  319.             GestoreHandlers.tipiOutRequestHandlersBuiltIn = updateNotifierCallback(GestoreHandlers.tipiOutRequestHandlersBuiltIn);
  320.             if(GestoreHandlers.tipiOutRequestHandlersBuiltIn!=null){
  321.                 GestoreHandlers.outRequestHandlersBuiltIn = new OutRequestHandler[GestoreHandlers.tipiOutRequestHandlersBuiltIn.length];
  322.                 for(int i=0; i<GestoreHandlers.tipiOutRequestHandlersBuiltIn.length; i++){
  323.                     try{
  324.                         String tipo=GestoreHandlers.tipiOutRequestHandlersBuiltIn[i];
  325.                         String classe = null;
  326.                         if(NotifierConstants.TIPO_NOTIFIER.equals(tipo)){
  327.                             classe = NotifierOutRequestHandler.class.getName();
  328.                         }else{
  329.                             classe = classNameProperties.getOutRequestHandlerBuiltIn(tipo);
  330.                         }
  331.                         GestoreHandlers.outRequestHandlersBuiltIn[i] = (OutRequestHandler) loader.newInstance(classe);
  332.                         if(printInfoBuiltIn)
  333.                             logConsoleInit.info("OutRequestHandler BuiltIn di tipo ["+tipo+"] correttamente inizializzato.");
  334.                     }catch(Throwable e){
  335.                         if(msgDiag!=null) {
  336.                             msgDiag.logErroreGenerico(e, "Inizializzazione OutRequestHandler BuiltIn ["+GestoreHandlers.tipiOutRequestHandlersBuiltIn[i]+"]");
  337.                         }
  338.                         else if(logCore!=null) {
  339.                             logCore.error("Inizializzazione OutRequestHandler BuiltIn ["+GestoreHandlers.tipiOutRequestHandlersBuiltIn[i]+"]", e);
  340.                         }
  341.                     }
  342.                 }
  343.                 GestoreHandlers.outRequestHandlersBuiltIn = reorder(GestoreHandlers.outRequestHandlersBuiltIn, new OutRequestHandler[1]);
  344.             }
  345.            
  346.             // PostOutRequestHandler
  347.             GestoreHandlers.tipiPostOutRequestHandlersBuiltIn = properties.getPostOutRequestHandlerBuiltIn();
  348.             GestoreHandlers.tipiPostOutRequestHandlersBuiltIn = updateNotifierCallback(GestoreHandlers.tipiPostOutRequestHandlersBuiltIn);
  349.             if(GestoreHandlers.tipiPostOutRequestHandlersBuiltIn!=null){
  350.                 GestoreHandlers.postOutRequestHandlersBuiltIn = new PostOutRequestHandler[GestoreHandlers.tipiPostOutRequestHandlersBuiltIn.length];
  351.                 for(int i=0; i<GestoreHandlers.tipiPostOutRequestHandlersBuiltIn.length; i++){
  352.                     try{
  353.                         String tipo=GestoreHandlers.tipiPostOutRequestHandlersBuiltIn[i];
  354.                         String classe = null;
  355.                         if(NotifierConstants.TIPO_NOTIFIER.equals(tipo)){
  356.                             classe = NotifierPostOutRequestHandler.class.getName();
  357.                         }else{
  358.                             classe = classNameProperties.getPostOutRequestHandlerBuiltIn(tipo);
  359.                         }
  360.                         GestoreHandlers.postOutRequestHandlersBuiltIn[i] = (PostOutRequestHandler) loader.newInstance(classe);
  361.                         if(printInfoBuiltIn)
  362.                             logConsoleInit.info("PostOutRequestHandler BuiltIn di tipo ["+tipo+"] correttamente inizializzato.");
  363.                     }catch(Throwable e){
  364.                         if(msgDiag!=null) {
  365.                             msgDiag.logErroreGenerico(e, "Inizializzazione PostOutRequestHandler BuiltIn ["+GestoreHandlers.tipiPostOutRequestHandlersBuiltIn[i]+"]");
  366.                         }
  367.                         else if(logCore!=null) {
  368.                             logCore.error("Inizializzazione PostOutRequestHandler BuiltIn ["+GestoreHandlers.tipiPostOutRequestHandlersBuiltIn[i]+"]", e);
  369.                         }
  370.                     }
  371.                 }
  372.                 GestoreHandlers.postOutRequestHandlersBuiltIn = reorder(GestoreHandlers.postOutRequestHandlersBuiltIn, new PostOutRequestHandler[1]);
  373.             }
  374.            
  375.             // PreInResponseHandler
  376.             GestoreHandlers.tipiPreInResponseHandlersBuiltIn = properties.getPreInResponseHandlerBuiltIn();
  377.             GestoreHandlers.tipiPreInResponseHandlersBuiltIn = updateNotifierCallback(GestoreHandlers.tipiPreInResponseHandlersBuiltIn);
  378.             if(GestoreHandlers.tipiPreInResponseHandlersBuiltIn!=null){
  379.                 GestoreHandlers.preInResponseHandlersBuiltIn = new PreInResponseHandler[GestoreHandlers.tipiPreInResponseHandlersBuiltIn.length];
  380.                 for(int i=0; i<GestoreHandlers.tipiPreInResponseHandlersBuiltIn.length; i++){
  381.                     try{
  382.                         String tipo=GestoreHandlers.tipiPreInResponseHandlersBuiltIn[i];
  383.                         String classe = null;
  384.                         if(NotifierConstants.TIPO_NOTIFIER.equals(tipo)){
  385.                             classe = NotifierPreInResponseHandler.class.getName();
  386.                         }else{
  387.                             classe = classNameProperties.getPreInResponseHandlerBuiltIn(tipo);
  388.                         }
  389.                         GestoreHandlers.preInResponseHandlersBuiltIn[i] = (PreInResponseHandler) loader.newInstance(classe);
  390.                         if(printInfoBuiltIn)
  391.                             logConsoleInit.info("PreInResponseHandler BuiltIn di tipo ["+tipo+"] correttamente inizializzato.");
  392.                     }catch(Throwable e){
  393.                         if(msgDiag!=null) {
  394.                             msgDiag.logErroreGenerico(e, "Inizializzazione PreInResponseHandler BuiltIn ["+GestoreHandlers.tipiPreInResponseHandlersBuiltIn[i]+"]");
  395.                         }
  396.                         else if(logCore!=null) {
  397.                             logCore.error("Inizializzazione PreInResponseHandler BuiltIn ["+GestoreHandlers.tipiPreInResponseHandlersBuiltIn[i]+"]", e);
  398.                         }
  399.                     }
  400.                 }
  401.                 GestoreHandlers.preInResponseHandlersBuiltIn = reorder(GestoreHandlers.preInResponseHandlersBuiltIn, new PreInResponseHandler[1]);
  402.             }
  403.            
  404.             // InResponseHandler
  405.             GestoreHandlers.tipiInResponseHandlersBuiltIn = GestoreHandlers.properties.getInResponseHandlerBuiltIn();
  406.             GestoreHandlers.tipiInResponseHandlersBuiltIn = updateNotifierCallback(GestoreHandlers.tipiInResponseHandlersBuiltIn);
  407.             if(GestoreHandlers.tipiInResponseHandlersBuiltIn!=null){
  408.                 GestoreHandlers.inResponseHandlersBuiltIn = new InResponseHandler[GestoreHandlers.tipiInResponseHandlersBuiltIn.length];
  409.                 for(int i=0; i<GestoreHandlers.tipiInResponseHandlersBuiltIn.length; i++){
  410.                     try{
  411.                         String tipo=GestoreHandlers.tipiInResponseHandlersBuiltIn[i];
  412.                         String classe = null;
  413.                         if(NotifierConstants.TIPO_NOTIFIER.equals(tipo)){
  414.                             classe = NotifierInResponseHandler.class.getName();
  415.                         }else{
  416.                             classe = classNameProperties.getInResponseHandlerBuiltIn(tipo);
  417.                         }
  418.                         GestoreHandlers.inResponseHandlersBuiltIn[i] = (InResponseHandler) loader.newInstance(classe);
  419.                         if(printInfoBuiltIn)
  420.                             logConsoleInit.info("InResponseHandler BuiltIn di tipo ["+tipo+"] correttamente inizializzato.");
  421.                     }catch(Throwable e){
  422.                         if(msgDiag!=null) {
  423.                             msgDiag.logErroreGenerico(e, "Inizializzazione InResponseHandler BuiltIn ["+GestoreHandlers.tipiInResponseHandlersBuiltIn[i]+"]");
  424.                         }
  425.                         else if(logCore!=null) {
  426.                             logCore.error("Inizializzazione InResponseHandler BuiltIn ["+GestoreHandlers.tipiInResponseHandlersBuiltIn[i]+"]", e);
  427.                         }
  428.                     }
  429.                 }
  430.                 GestoreHandlers.inResponseHandlersBuiltIn = reorder(GestoreHandlers.inResponseHandlersBuiltIn, new InResponseHandler[1]);
  431.             }
  432.            
  433.             // OutResponseHandler
  434.             GestoreHandlers.tipiOutResponseHandlersBuiltIn = GestoreHandlers.properties.getOutResponseHandlerBuiltIn();
  435.             GestoreHandlers.tipiOutResponseHandlersBuiltIn = updateNotifierCallback(GestoreHandlers.tipiOutResponseHandlersBuiltIn);
  436.             if(GestoreHandlers.tipiOutResponseHandlersBuiltIn!=null){
  437.                 GestoreHandlers.outResponseHandlersBuiltIn = new OutResponseHandler[GestoreHandlers.tipiOutResponseHandlersBuiltIn.length];
  438.                 for(int i=0; i<GestoreHandlers.tipiOutResponseHandlersBuiltIn.length; i++){
  439.                     try{
  440.                         String tipo=GestoreHandlers.tipiOutResponseHandlersBuiltIn[i];
  441.                         String classe = null;
  442.                         if(NotifierConstants.TIPO_NOTIFIER.equals(tipo)){
  443.                             classe = NotifierOutResponseHandler.class.getName();
  444.                         }else{
  445.                             classe = classNameProperties.getOutResponseHandlerBuiltIn(tipo);
  446.                         }
  447.                         GestoreHandlers.outResponseHandlersBuiltIn[i] = (OutResponseHandler) loader.newInstance(classe);
  448.                         if(printInfoBuiltIn)
  449.                             logConsoleInit.info("OutResponseHandler BuiltIn di tipo ["+tipo+"] correttamente inizializzato.");
  450.                     }catch(Throwable e){
  451.                         if(msgDiag!=null) {
  452.                             msgDiag.logErroreGenerico(e, "Inizializzazione OutResponseHandler BuiltIn ["+GestoreHandlers.tipiOutResponseHandlersBuiltIn[i]+"]");
  453.                         }
  454.                         else if(logCore!=null) {
  455.                             logCore.error("Inizializzazione OutResponseHandler BuiltIn ["+GestoreHandlers.tipiOutResponseHandlersBuiltIn[i]+"]", e);
  456.                         }
  457.                     }
  458.                 }
  459.                 GestoreHandlers.outResponseHandlersBuiltIn = reorder(GestoreHandlers.outResponseHandlersBuiltIn, new OutResponseHandler[1]);
  460.             }
  461.            
  462.             // PostOutResponseHandler
  463.             GestoreHandlers.tipiPostOutResponseHandlersBuiltIn = GestoreHandlers.properties.getPostOutResponseHandlerBuiltIn();
  464.             GestoreHandlers.tipiPostOutResponseHandlersBuiltIn = updateNotifierCallback(GestoreHandlers.tipiPostOutResponseHandlersBuiltIn);
  465.             if(GestoreHandlers.tipiPostOutResponseHandlersBuiltIn!=null){
  466.                 GestoreHandlers.postOutResponseHandlersBuiltIn = new PostOutResponseHandler[GestoreHandlers.tipiPostOutResponseHandlersBuiltIn.length];
  467.                 for(int i=0; i<GestoreHandlers.tipiPostOutResponseHandlersBuiltIn.length; i++){
  468.                     try{
  469.                         String tipo=GestoreHandlers.tipiPostOutResponseHandlersBuiltIn[i];
  470.                         String classe = null;
  471.                         if(NotifierConstants.TIPO_NOTIFIER.equals(tipo)){
  472.                             classe = NotifierPostOutResponseHandler.class.getName();
  473.                         }else{
  474.                             classe = classNameProperties.getPostOutResponseHandlerBuiltIn(tipo);
  475.                         }
  476.                         GestoreHandlers.postOutResponseHandlersBuiltIn[i] = (PostOutResponseHandler) loader.newInstance(classe);
  477.                         if(printInfoBuiltIn)
  478.                             logConsoleInit.info("PostOutResponseHandler BuiltIn di tipo ["+tipo+"] correttamente inizializzato.");
  479.                     }catch(Throwable e){
  480.                         if(msgDiag!=null) {
  481.                             msgDiag.logErroreGenerico(e, "Inizializzazione PostOutResponseHandler BuiltIn ["+GestoreHandlers.tipiPostOutResponseHandlersBuiltIn[i]+"]");
  482.                         }
  483.                         else if(logCore!=null) {
  484.                             logCore.error("Inizializzazione PostOutResponseHandler BuiltIn ["+GestoreHandlers.tipiPostOutResponseHandlersBuiltIn[i]+"]", e);
  485.                         }
  486.                     }
  487.                 }
  488.                 GestoreHandlers.postOutResponseHandlersBuiltIn = reorder(GestoreHandlers.postOutResponseHandlersBuiltIn, new PostOutResponseHandler[1]);
  489.             }
  490.            
  491.             // IntegrationManagerRequestHandler
  492.             GestoreHandlers.tipiIntegrationManagerRequestHandlersBuiltIn = GestoreHandlers.properties.getIntegrationManagerRequestHandlerBuiltIn();
  493.             if(GestoreHandlers.tipiIntegrationManagerRequestHandlersBuiltIn!=null){
  494.                 GestoreHandlers.integrationManagerRequestHandlersBuiltIn = new IntegrationManagerRequestHandler[GestoreHandlers.tipiIntegrationManagerRequestHandlersBuiltIn.length];
  495.                 for(int i=0; i<GestoreHandlers.tipiIntegrationManagerRequestHandlersBuiltIn.length; i++){
  496.                     try{
  497.                         String tipo=GestoreHandlers.tipiIntegrationManagerRequestHandlersBuiltIn[i];
  498.                         String classe = classNameProperties.getIntegrationManagerRequestHandlerBuiltIn(tipo);
  499.                         GestoreHandlers.integrationManagerRequestHandlersBuiltIn[i] = (IntegrationManagerRequestHandler) loader.newInstance(classe);
  500.                         if(printInfoBuiltIn)
  501.                             logConsoleInit.info("IntegrationManagerRequestHandler BuiltIn di tipo ["+tipo+"] correttamente inizializzato.");
  502.                     }catch(Throwable e){
  503.                         if(msgDiag!=null) {
  504.                             msgDiag.logErroreGenerico(e, "Inizializzazione IntegrationManagerRequestHandler BuiltIn ["+GestoreHandlers.tipiIntegrationManagerRequestHandlersBuiltIn[i]+"]");
  505.                         }
  506.                         else if(logCore!=null) {
  507.                             logCore.error("Inizializzazione IntegrationManagerRequestHandler BuiltIn ["+GestoreHandlers.tipiIntegrationManagerRequestHandlersBuiltIn[i]+"]", e);
  508.                         }
  509.                     }
  510.                 }
  511.                 GestoreHandlers.integrationManagerRequestHandlersBuiltIn = reorder(GestoreHandlers.integrationManagerRequestHandlersBuiltIn, new IntegrationManagerRequestHandler[1]);
  512.             }
  513.            
  514.             // IntegrationManagerResponseHandler
  515.             GestoreHandlers.tipiIntegrationManagerResponseHandlersBuiltIn = GestoreHandlers.properties.getIntegrationManagerResponseHandlerBuiltIn();
  516.             if(GestoreHandlers.tipiIntegrationManagerResponseHandlersBuiltIn!=null){
  517.                 GestoreHandlers.integrationManagerResponseHandlersBuiltIn = new IntegrationManagerResponseHandler[GestoreHandlers.tipiIntegrationManagerResponseHandlersBuiltIn.length];
  518.                 for(int i=0; i<GestoreHandlers.tipiIntegrationManagerResponseHandlersBuiltIn.length; i++){
  519.                     try{
  520.                         String tipo=GestoreHandlers.tipiIntegrationManagerResponseHandlersBuiltIn[i];
  521.                         String classe = classNameProperties.getIntegrationManagerResponseHandlerBuiltIn(tipo);
  522.                         GestoreHandlers.integrationManagerResponseHandlersBuiltIn[i] = (IntegrationManagerResponseHandler) loader.newInstance(classe);
  523.                         if(printInfoBuiltIn)
  524.                             logConsoleInit.info("IntegrationManagerResponseHandler BuiltIn di tipo ["+tipo+"] correttamente inizializzato.");
  525.                     }catch(Throwable e){
  526.                         if(msgDiag!=null) {
  527.                             msgDiag.logErroreGenerico(e, "Inizializzazione IntegrationManagerResponseHandler BuiltIn ["+GestoreHandlers.tipiIntegrationManagerResponseHandlersBuiltIn[i]+"]");
  528.                         }
  529.                         else if(logCore!=null) {
  530.                             logCore.error("Inizializzazione IntegrationManagerResponseHandler BuiltIn ["+GestoreHandlers.tipiIntegrationManagerResponseHandlersBuiltIn[i]+"]", e);
  531.                         }
  532.                     }
  533.                 }
  534.                 GestoreHandlers.integrationManagerResponseHandlersBuiltIn = reorder(GestoreHandlers.integrationManagerResponseHandlersBuiltIn, new IntegrationManagerResponseHandler[1]);
  535.             }
  536.            
  537.            
  538.            
  539.             // Handlers Utente

  540.             boolean printInfo = GestoreHandlers.properties.isPrintInfoHandler();
  541.            
  542.             // InitHandler
  543.             List<String> tipiInitHandlersConfig = null;
  544.             try {
  545.                 tipiInitHandlersConfig=ConfigurazionePdDManager.getInstance(state).getInitHandlers();
  546.             }catch(Throwable e) {
  547.                 if(msgDiag!=null) {
  548.                     msgDiag.logErroreGenerico(e, "Raccolta InitHandlers");
  549.                 }
  550.                 else if(logCore!=null) {
  551.                     logCore.error("Raccolta InitHandlers", e);
  552.                 }
  553.             }
  554.             GestoreHandlers.tipiInitHandlers = _mergeTipi(GestoreHandlers.properties.getInitHandler(),
  555.                     tipiInitHandlersConfig);
  556.             if(GestoreHandlers.tipiInitHandlers!=null){
  557.                 GestoreHandlers.initHandlers = new InitHandler[GestoreHandlers.tipiInitHandlers.length];
  558.                 for(int i=0; i<GestoreHandlers.tipiInitHandlers.length; i++){
  559.                     try{
  560.                         String tipo=GestoreHandlers.tipiInitHandlers[i];
  561.                         GestoreHandlers.initHandlers[i] = (InitHandler) pluginLoader.newInitHandler(tipo);
  562.                         if(printInfo)
  563.                             logConsoleInit.info("InitHandler di tipo ["+tipo+"] correttamente inizializzato.");
  564.                     }catch(Throwable e){
  565.                         if(msgDiag!=null) {
  566.                             msgDiag.logErroreGenerico(e, "Inizializzazione InitHandler ["+GestoreHandlers.tipiInitHandlers[i]+"]");
  567.                         }
  568.                         else if(logCore!=null) {
  569.                             logCore.error("Inizializzazione InitHandler ["+GestoreHandlers.tipiInitHandlers[i]+"]", e);
  570.                         }
  571.                     }
  572.                 }
  573.                 GestoreHandlers.initHandlers = reorder(GestoreHandlers.initHandlers, new InitHandler[1]);
  574.             }
  575.            
  576.             // ExitHandler
  577.             List<String> tipiExitHandlersConfig = null;
  578.             try {
  579.                 tipiExitHandlersConfig=ConfigurazionePdDManager.getInstance(state).getExitHandlers();
  580.             }catch(Throwable e) {
  581.                 if(msgDiag!=null) {
  582.                     msgDiag.logErroreGenerico(e, "Raccolta ExitHandlers");
  583.                 }
  584.                 else if(logCore!=null) {
  585.                     logCore.error("Raccolta ExitHandlers", e);
  586.                 }
  587.             }
  588.             GestoreHandlers.tipiExitHandlers = _mergeTipi(GestoreHandlers.properties.getExitHandler(),
  589.                     tipiExitHandlersConfig);
  590.             if(GestoreHandlers.tipiExitHandlers!=null){
  591.                 GestoreHandlers.exitHandlers = new ExitHandler[GestoreHandlers.tipiExitHandlers.length];
  592.                 for(int i=0; i<GestoreHandlers.tipiExitHandlers.length; i++){
  593.                     try{
  594.                         String tipo=GestoreHandlers.tipiExitHandlers[i];
  595.                         GestoreHandlers.exitHandlers[i] = (ExitHandler) pluginLoader.newExitHandler(tipo);
  596.                         if(printInfo)
  597.                             logConsoleInit.info("ExitHandler di tipo ["+tipo+"] correttamente inizializzato.");
  598.                     }catch(Throwable e){
  599.                         if(msgDiag!=null) {
  600.                             msgDiag.logErroreGenerico(e, "Inizializzazione ExitHandler ["+GestoreHandlers.tipiExitHandlers[i]+"]");
  601.                         }
  602.                         else if(logCore!=null) {
  603.                             logCore.error("Inizializzazione ExitHandler ["+GestoreHandlers.tipiExitHandlers[i]+"]", e);
  604.                         }
  605.                     }
  606.                 }
  607.                 GestoreHandlers.exitHandlers = reorder(GestoreHandlers.exitHandlers, new ExitHandler[1]);
  608.             }
  609.            
  610.             // PreInRequestHandler
  611.             List<String> tipiPreInRequestHandlersConfig = null;
  612.             try {
  613.                 tipiPreInRequestHandlersConfig=ConfigurazionePdDManager.getInstance(state).getPreInRequestHandlers();
  614.             }catch(Throwable e) {
  615.                 if(msgDiag!=null) {
  616.                     msgDiag.logErroreGenerico(e, "Raccolta PreInRequestHandlers");
  617.                 }
  618.                 else if(logCore!=null) {
  619.                     logCore.error("Raccolta PreInRequestHandlers", e);
  620.                 }
  621.             }
  622.             GestoreHandlers.tipiPreInRequestHandlers = _mergeTipi(GestoreHandlers.properties.getPreInRequestHandler(),
  623.                     tipiPreInRequestHandlersConfig);
  624.             GestoreHandlers.tipiPreInRequestHandlers = updateNotifierCallback(GestoreHandlers.tipiPreInRequestHandlers);
  625.             if(GestoreHandlers.tipiPreInRequestHandlers!=null){
  626.                 GestoreHandlers.preInRequestHandlers = new PreInRequestHandler[GestoreHandlers.tipiPreInRequestHandlers.length];
  627.                 for(int i=0; i<GestoreHandlers.tipiPreInRequestHandlers.length; i++){
  628.                     try{
  629.                         String tipo=GestoreHandlers.tipiPreInRequestHandlers[i];
  630.                         if(NotifierConstants.TIPO_NOTIFIER.equals(tipo)){
  631.                             String classe = NotifierPreInRequestHandler.class.getName();
  632.                             GestoreHandlers.preInRequestHandlers[i] = (PreInRequestHandler) loader.newInstance(classe);
  633.                         }else{
  634.                             GestoreHandlers.preInRequestHandlers[i] = pluginLoader.newPreInRequestHandler(tipo);
  635.                         }
  636.                         if(printInfo)
  637.                             logConsoleInit.info("PreInRequestHandler di tipo ["+tipo+"] correttamente inizializzato.");
  638.                     }catch(Throwable e){
  639.                         if(msgDiag!=null) {
  640.                             msgDiag.logErroreGenerico(e, "Inizializzazione PreInRequestHandler ["+GestoreHandlers.tipiPreInRequestHandlers[i]+"]");
  641.                         }
  642.                         else if(logCore!=null) {
  643.                             logCore.error("Inizializzazione PreInRequestHandler ["+GestoreHandlers.tipiPreInRequestHandlers[i]+"]", e);
  644.                         }
  645.                     }
  646.                 }
  647.                 GestoreHandlers.preInRequestHandlers = reorder(GestoreHandlers.preInRequestHandlers, new PreInRequestHandler[1]);
  648.             }
  649.            
  650.             // InRequestHandler
  651.             List<String> tipiInRequestHandlersConfig = null;
  652.             try {
  653.                 tipiInRequestHandlersConfig=ConfigurazionePdDManager.getInstance(state).getInRequestHandlers();
  654.             }catch(Throwable e) {
  655.                 if(msgDiag!=null) {
  656.                     msgDiag.logErroreGenerico(e, "Raccolta InRequestHandlers");
  657.                 }
  658.                 else if(logCore!=null) {
  659.                     logCore.error("Raccolta InRequestHandlers", e);
  660.                 }
  661.             }
  662.             GestoreHandlers.tipiInRequestHandlers = _mergeTipi(GestoreHandlers.properties.getInRequestHandler(),
  663.                     tipiInRequestHandlersConfig);
  664.             GestoreHandlers.tipiInRequestHandlers = updateNotifierCallback(GestoreHandlers.tipiInRequestHandlers);
  665.             if(GestoreHandlers.tipiInRequestHandlers!=null){
  666.                 GestoreHandlers.inRequestHandlers = new InRequestHandler[GestoreHandlers.tipiInRequestHandlers.length];
  667.                 for(int i=0; i<GestoreHandlers.tipiInRequestHandlers.length; i++){
  668.                     try{
  669.                         String tipo=GestoreHandlers.tipiInRequestHandlers[i];
  670.                         if(NotifierConstants.TIPO_NOTIFIER.equals(tipo)){
  671.                             String classe = NotifierInRequestHandler.class.getName();
  672.                             GestoreHandlers.inRequestHandlers[i] = (InRequestHandler) loader.newInstance(classe);
  673.                         }else{
  674.                             GestoreHandlers.inRequestHandlers[i] = pluginLoader.newInRequestHandler(tipo);
  675.                         }
  676.                         if(printInfo)
  677.                             logConsoleInit.info("InRequestHandler di tipo ["+tipo+"] correttamente inizializzato.");
  678.                     }catch(Throwable e){
  679.                         if(msgDiag!=null) {
  680.                             msgDiag.logErroreGenerico(e, "Inizializzazione InRequestHandler ["+GestoreHandlers.tipiInRequestHandlers[i]+"]");
  681.                         }
  682.                         else if(logCore!=null) {
  683.                             logCore.error("Inizializzazione InRequestHandler ["+GestoreHandlers.tipiInRequestHandlers[i]+"]", e);
  684.                         }
  685.                     }
  686.                 }
  687.                 GestoreHandlers.inRequestHandlers = reorder(GestoreHandlers.inRequestHandlers, new InRequestHandler[1]);
  688.             }
  689.            
  690.             // InRequestProtocolHandler
  691.             List<String> tipiInRequestProtocolHandlersConfig = null;
  692.             try {
  693.                 tipiInRequestProtocolHandlersConfig=ConfigurazionePdDManager.getInstance(state).getInRequestProtocolHandlers();
  694.             }catch(Throwable e) {
  695.                 if(msgDiag!=null) {
  696.                     msgDiag.logErroreGenerico(e, "Raccolta InRequestProtocolHandlers");
  697.                 }
  698.                 else if(logCore!=null) {
  699.                     logCore.error("Raccolta InRequestProtocolHandlers", e);
  700.                 }
  701.             }
  702.             GestoreHandlers.tipiInRequestProtocolHandlers = _mergeTipi(GestoreHandlers.properties.getInRequestProtocolHandler(),
  703.                     tipiInRequestProtocolHandlersConfig);
  704.             GestoreHandlers.tipiInRequestProtocolHandlers = updateNotifierCallback(GestoreHandlers.tipiInRequestProtocolHandlers);
  705.             if(GestoreHandlers.tipiInRequestProtocolHandlers!=null){
  706.                 GestoreHandlers.inRequestProtocolHandlers = new InRequestProtocolHandler[GestoreHandlers.tipiInRequestProtocolHandlers.length];
  707.                 for(int i=0; i<GestoreHandlers.tipiInRequestProtocolHandlers.length; i++){
  708.                     try{
  709.                         String tipo=GestoreHandlers.tipiInRequestProtocolHandlers[i];
  710.                         if(NotifierConstants.TIPO_NOTIFIER.equals(tipo)){
  711.                             String classe = NotifierInRequestProtocolHandler.class.getName();
  712.                             GestoreHandlers.inRequestProtocolHandlers[i] = (InRequestProtocolHandler) loader.newInstance(classe);
  713.                         }else{
  714.                             GestoreHandlers.inRequestProtocolHandlers[i] = pluginLoader.newInRequestProtocolHandler(tipo);
  715.                         }
  716.                         if(printInfo)
  717.                             logConsoleInit.info("InRequestProtocolHandler di tipo ["+tipo+"] correttamente inizializzato.");
  718.                     }catch(Throwable e){
  719.                         if(msgDiag!=null) {
  720.                             msgDiag.logErroreGenerico(e, "Inizializzazione InRequestProtocolHandler ["+GestoreHandlers.tipiInRequestProtocolHandlers[i]+"]");
  721.                         }
  722.                         else if(logCore!=null) {
  723.                             logCore.error("Inizializzazione InRequestProtocolHandler ["+GestoreHandlers.tipiInRequestProtocolHandlers[i]+"]", e);
  724.                         }
  725.                     }
  726.                 }
  727.                 GestoreHandlers.inRequestProtocolHandlers = reorder(GestoreHandlers.inRequestProtocolHandlers, new InRequestProtocolHandler[1]);
  728.             }
  729.            
  730.             // OutRequestHandler
  731.             List<String> tipiOutRequestHandlersConfig = null;
  732.             try {
  733.                 tipiOutRequestHandlersConfig=ConfigurazionePdDManager.getInstance(state).getOutRequestHandlers();
  734.             }catch(Throwable e) {
  735.                 if(msgDiag!=null) {
  736.                     msgDiag.logErroreGenerico(e, "Raccolta OutRequestHandlers");
  737.                 }
  738.                 else if(logCore!=null) {
  739.                     logCore.error("Raccolta OutRequestHandlers", e);
  740.                 }
  741.             }
  742.             GestoreHandlers.tipiOutRequestHandlers = _mergeTipi(GestoreHandlers.properties.getOutRequestHandler(),
  743.                     tipiOutRequestHandlersConfig);
  744.             GestoreHandlers.tipiOutRequestHandlers = updateNotifierCallback(GestoreHandlers.tipiOutRequestHandlers);
  745.             if(GestoreHandlers.tipiOutRequestHandlers!=null){
  746.                 GestoreHandlers.outRequestHandlers = new OutRequestHandler[GestoreHandlers.tipiOutRequestHandlers.length];
  747.                 for(int i=0; i<GestoreHandlers.tipiOutRequestHandlers.length; i++){
  748.                     try{
  749.                         String tipo=GestoreHandlers.tipiOutRequestHandlers[i];
  750.                         if(NotifierConstants.TIPO_NOTIFIER.equals(tipo)){
  751.                             String classe = NotifierOutRequestHandler.class.getName();
  752.                             GestoreHandlers.outRequestHandlers[i] = (OutRequestHandler) loader.newInstance(classe);
  753.                         }else{
  754.                             GestoreHandlers.outRequestHandlers[i] = pluginLoader.newOutRequestHandler(tipo);
  755.                         }
  756.                         if(printInfo)
  757.                             logConsoleInit.info("OutRequestHandler di tipo ["+tipo+"] correttamente inizializzato.");
  758.                     }catch(Throwable e){
  759.                         if(msgDiag!=null) {
  760.                             msgDiag.logErroreGenerico(e, "Inizializzazione OutRequestHandler ["+GestoreHandlers.tipiOutRequestHandlers[i]+"]");
  761.                         }
  762.                         else if(logCore!=null) {
  763.                             logCore.error("Inizializzazione OutRequestHandler ["+GestoreHandlers.tipiOutRequestHandlers[i]+"]", e);
  764.                         }
  765.                     }
  766.                 }
  767.                 GestoreHandlers.outRequestHandlers = reorder(GestoreHandlers.outRequestHandlers, new OutRequestHandler[1]);
  768.             }
  769.            
  770.             // PostOutRequestHandler
  771.             List<String> tipiPostOutRequestHandlersConfig = null;
  772.             try {
  773.                 tipiPostOutRequestHandlersConfig=ConfigurazionePdDManager.getInstance(state).getPostOutRequestHandlers();
  774.             }catch(Throwable e) {
  775.                 if(msgDiag!=null) {
  776.                     msgDiag.logErroreGenerico(e, "Raccolta PostOutRequestHandlers");
  777.                 }
  778.                 else if(logCore!=null) {
  779.                     logCore.error("Raccolta PostOutRequestHandlers", e);
  780.                 }
  781.             }
  782.             GestoreHandlers.tipiPostOutRequestHandlers = _mergeTipi(GestoreHandlers.properties.getPostOutRequestHandler(),
  783.                     tipiPostOutRequestHandlersConfig);
  784.             GestoreHandlers.tipiPostOutRequestHandlers = updateNotifierCallback(GestoreHandlers.tipiPostOutRequestHandlers);
  785.             if(GestoreHandlers.tipiPostOutRequestHandlers!=null){
  786.                 GestoreHandlers.postOutRequestHandlers = new PostOutRequestHandler[GestoreHandlers.tipiPostOutRequestHandlers.length];
  787.                 for(int i=0; i<GestoreHandlers.tipiPostOutRequestHandlers.length; i++){
  788.                     try{
  789.                         String tipo=GestoreHandlers.tipiPostOutRequestHandlers[i];
  790.                         if(NotifierConstants.TIPO_NOTIFIER.equals(tipo)){
  791.                             String classe = NotifierPostOutRequestHandler.class.getName();
  792.                             GestoreHandlers.postOutRequestHandlers[i] = (PostOutRequestHandler) loader.newInstance(classe);
  793.                         }else{
  794.                             GestoreHandlers.postOutRequestHandlers[i] = pluginLoader.newPostOutRequestHandler(tipo);
  795.                         }
  796.                         if(printInfo)
  797.                             logConsoleInit.info("PostOutRequestHandler di tipo ["+tipo+"] correttamente inizializzato.");
  798.                     }catch(Throwable e){
  799.                         if(msgDiag!=null) {
  800.                             msgDiag.logErroreGenerico(e, "Inizializzazione PostOutRequestHandler ["+GestoreHandlers.tipiPostOutRequestHandlers[i]+"]");
  801.                         }
  802.                         else if(logCore!=null) {
  803.                             logCore.error("Inizializzazione PostOutRequestHandler ["+GestoreHandlers.tipiPostOutRequestHandlers[i]+"]", e);
  804.                         }
  805.                     }
  806.                 }
  807.                 GestoreHandlers.postOutRequestHandlers = reorder(GestoreHandlers.postOutRequestHandlers, new PostOutRequestHandler[1]);
  808.             }
  809.            
  810.             // PreInResponseHandler
  811.             List<String> tipiPreInResponseHandlersConfig = null;
  812.             try {
  813.                 tipiPreInResponseHandlersConfig=ConfigurazionePdDManager.getInstance(state).getPreInResponseHandlers();
  814.             }catch(Throwable e) {
  815.                 if(msgDiag!=null) {
  816.                     msgDiag.logErroreGenerico(e, "Raccolta PreInResponseHandlers");
  817.                 }
  818.                 else if(logCore!=null) {
  819.                     logCore.error("Raccolta PreInResponseHandlers", e);
  820.                 }
  821.             }
  822.             GestoreHandlers.tipiPreInResponseHandlers = _mergeTipi(GestoreHandlers.properties.getPreInResponseHandler(),
  823.                     tipiPreInResponseHandlersConfig);
  824.             GestoreHandlers.tipiPreInResponseHandlers = updateNotifierCallback(GestoreHandlers.tipiPreInResponseHandlers);
  825.             if(GestoreHandlers.tipiPreInResponseHandlers!=null){
  826.                 GestoreHandlers.preInResponseHandlers = new PreInResponseHandler[GestoreHandlers.tipiPreInResponseHandlers.length];
  827.                 for(int i=0; i<GestoreHandlers.tipiPreInResponseHandlers.length; i++){
  828.                     try{
  829.                         String tipo=GestoreHandlers.tipiPreInResponseHandlers[i];
  830.                         if(NotifierConstants.TIPO_NOTIFIER.equals(tipo)){
  831.                             String classe = NotifierPreInResponseHandler.class.getName();
  832.                             GestoreHandlers.preInResponseHandlers[i] = (PreInResponseHandler) loader.newInstance(classe);
  833.                         }else{
  834.                             GestoreHandlers.preInResponseHandlers[i] = pluginLoader.newPreInResponseHandler(tipo);
  835.                         }
  836.                         if(printInfo)
  837.                             logConsoleInit.info("PreInResponseHandler di tipo ["+tipo+"] correttamente inizializzato.");
  838.                     }catch(Throwable e){
  839.                         if(msgDiag!=null) {
  840.                             msgDiag.logErroreGenerico(e, "Inizializzazione PreInResponseHandler ["+GestoreHandlers.tipiPreInResponseHandlers[i]+"]");
  841.                         }
  842.                         else if(logCore!=null) {
  843.                             logCore.error("Inizializzazione PreInResponseHandler ["+GestoreHandlers.tipiPreInResponseHandlers[i]+"]", e);
  844.                         }
  845.                     }
  846.                 }
  847.                 GestoreHandlers.preInResponseHandlers = reorder(GestoreHandlers.preInResponseHandlers, new PreInResponseHandler[1]);
  848.             }
  849.            
  850.             // InResponseHandler
  851.             List<String> tipiInResponseHandlersConfig = null;
  852.             try {
  853.                 tipiInResponseHandlersConfig=ConfigurazionePdDManager.getInstance(state).getInResponseHandlers();
  854.             }catch(Throwable e) {
  855.                 if(msgDiag!=null) {
  856.                     msgDiag.logErroreGenerico(e, "Raccolta InResponseHandlers");
  857.                 }
  858.                 else if(logCore!=null) {
  859.                     logCore.error("Raccolta InResponseHandlers", e);
  860.                 }
  861.             }
  862.             GestoreHandlers.tipiInResponseHandlers = _mergeTipi(GestoreHandlers.properties.getInResponseHandler(),
  863.                     tipiInResponseHandlersConfig);
  864.             GestoreHandlers.tipiInResponseHandlers = updateNotifierCallback(GestoreHandlers.tipiInResponseHandlers);
  865.             if(GestoreHandlers.tipiInResponseHandlers!=null){
  866.                 GestoreHandlers.inResponseHandlers = new InResponseHandler[GestoreHandlers.tipiInResponseHandlers.length];
  867.                 for(int i=0; i<GestoreHandlers.tipiInResponseHandlers.length; i++){
  868.                     try{
  869.                         String tipo=GestoreHandlers.tipiInResponseHandlers[i];
  870.                         if(NotifierConstants.TIPO_NOTIFIER.equals(tipo)){
  871.                             String classe = NotifierInResponseHandler.class.getName();
  872.                             GestoreHandlers.inResponseHandlers[i] = (InResponseHandler) loader.newInstance(classe);
  873.                         }else{
  874.                             GestoreHandlers.inResponseHandlers[i] = pluginLoader.newInResponseHandler(tipo);
  875.                         }
  876.                         if(printInfo)
  877.                             logConsoleInit.info("InResponseHandler di tipo ["+tipo+"] correttamente inizializzato.");
  878.                     }catch(Throwable e){
  879.                         if(msgDiag!=null) {
  880.                             msgDiag.logErroreGenerico(e, "Inizializzazione InResponseHandler ["+GestoreHandlers.tipiInResponseHandlers[i]+"]");
  881.                         }
  882.                         else if(logCore!=null) {
  883.                             logCore.error("Inizializzazione InResponseHandler ["+GestoreHandlers.tipiInResponseHandlers[i]+"]", e);
  884.                         }
  885.                     }
  886.                 }
  887.                 GestoreHandlers.inResponseHandlers = reorder(GestoreHandlers.inResponseHandlers, new InResponseHandler[1]);
  888.             }
  889.            
  890.             // OutResponseHandler
  891.             List<String> tipiOutResponseHandlersConfig = null;
  892.             try {
  893.                 tipiOutResponseHandlersConfig=ConfigurazionePdDManager.getInstance(state).getOutResponseHandlers();
  894.             }catch(Throwable e) {
  895.                 if(msgDiag!=null) {
  896.                     msgDiag.logErroreGenerico(e, "Raccolta OutResponseHandlers");
  897.                 }
  898.                 else if(logCore!=null) {
  899.                     logCore.error("Raccolta OutResponseHandlers", e);
  900.                 }
  901.             }
  902.             GestoreHandlers.tipiOutResponseHandlers = _mergeTipi(GestoreHandlers.properties.getOutResponseHandler(),
  903.                     tipiOutResponseHandlersConfig);
  904.             GestoreHandlers.tipiOutResponseHandlers = updateNotifierCallback(GestoreHandlers.tipiOutResponseHandlers);
  905.             if(GestoreHandlers.tipiOutResponseHandlers!=null){
  906.                 GestoreHandlers.outResponseHandlers = new OutResponseHandler[GestoreHandlers.tipiOutResponseHandlers.length];
  907.                 for(int i=0; i<GestoreHandlers.tipiOutResponseHandlers.length; i++){
  908.                     try{
  909.                         String tipo=GestoreHandlers.tipiOutResponseHandlers[i];
  910.                         if(NotifierConstants.TIPO_NOTIFIER.equals(tipo)){
  911.                             String classe = NotifierOutResponseHandler.class.getName();
  912.                             GestoreHandlers.outResponseHandlers[i] = (OutResponseHandler) loader.newInstance(classe);
  913.                         }else{
  914.                             GestoreHandlers.outResponseHandlers[i] = pluginLoader.newOutResponseHandler(tipo);
  915.                         }
  916.                         if(printInfo)
  917.                             logConsoleInit.info("OutResponseHandler di tipo ["+tipo+"] correttamente inizializzato.");
  918.                     }catch(Throwable e){
  919.                         if(msgDiag!=null) {
  920.                             msgDiag.logErroreGenerico(e, "Inizializzazione OutResponseHandler ["+GestoreHandlers.tipiOutResponseHandlers[i]+"]");
  921.                         }
  922.                         else if(logCore!=null) {
  923.                             logCore.error("Inizializzazione OutResponseHandler ["+GestoreHandlers.tipiOutResponseHandlers[i]+"]", e);
  924.                         }
  925.                     }
  926.                 }
  927.                 GestoreHandlers.outResponseHandlers = reorder(GestoreHandlers.outResponseHandlers, new OutResponseHandler[1]);
  928.             }
  929.            
  930.             // PostOutResponseHandler
  931.             List<String> tipiPostOutResponseHandlersConfig = null;
  932.             try {
  933.                 tipiPostOutResponseHandlersConfig=ConfigurazionePdDManager.getInstance(state).getPostOutResponseHandlers();
  934.             }catch(Throwable e) {
  935.                 if(msgDiag!=null) {
  936.                     msgDiag.logErroreGenerico(e, "Raccolta PostOutResponseHandlers");
  937.                 }
  938.                 else if(logCore!=null) {
  939.                     logCore.error("Raccolta PostOutResponseHandlers", e);
  940.                 }
  941.             }
  942.             GestoreHandlers.tipiPostOutResponseHandlers = _mergeTipi(GestoreHandlers.properties.getPostOutResponseHandler(),
  943.                     tipiPostOutResponseHandlersConfig);
  944.             GestoreHandlers.tipiPostOutResponseHandlers = updateNotifierCallback(GestoreHandlers.tipiPostOutResponseHandlers);
  945.             if(GestoreHandlers.tipiPostOutResponseHandlers!=null){
  946.                 GestoreHandlers.postOutResponseHandlers = new PostOutResponseHandler[GestoreHandlers.tipiPostOutResponseHandlers.length];
  947.                 for(int i=0; i<GestoreHandlers.tipiPostOutResponseHandlers.length; i++){
  948.                     try{
  949.                         String tipo=GestoreHandlers.tipiPostOutResponseHandlers[i];
  950.                         if(NotifierConstants.TIPO_NOTIFIER.equals(tipo)){
  951.                             String classe = NotifierPostOutResponseHandler.class.getName();
  952.                             GestoreHandlers.postOutResponseHandlers[i] = (PostOutResponseHandler) loader.newInstance(classe);
  953.                         }else{
  954.                             GestoreHandlers.postOutResponseHandlers[i] = pluginLoader.newPostOutResponseHandler(tipo);
  955.                         }
  956.                         if(printInfo)
  957.                             logConsoleInit.info("PostOutResponseHandler di tipo ["+tipo+"] correttamente inizializzato.");
  958.                     }catch(Throwable e){
  959.                         if(msgDiag!=null) {
  960.                             msgDiag.logErroreGenerico(e, "Inizializzazione PostOutResponseHandler ["+GestoreHandlers.tipiPostOutResponseHandlers[i]+"]");
  961.                         }
  962.                         else if(logCore!=null) {
  963.                             logCore.error("Inizializzazione PostOutResponseHandler ["+GestoreHandlers.tipiPostOutResponseHandlers[i]+"]", e);
  964.                         }
  965.                     }
  966.                 }
  967.                 GestoreHandlers.postOutResponseHandlers = reorder(GestoreHandlers.postOutResponseHandlers, new PostOutResponseHandler[1]);
  968.             }
  969.            
  970.             // IntegrationManagerRequestHandler
  971.             List<String> tipiIntegrationManagerRequestHandlersConfig = null;
  972.             try {
  973.                 tipiIntegrationManagerRequestHandlersConfig=ConfigurazionePdDManager.getInstance(state).getIntegrationManagerRequestHandlers();
  974.             }catch(Throwable e) {
  975.                 if(msgDiag!=null) {
  976.                     msgDiag.logErroreGenerico(e, "Raccolta IntegrationManagerRequestHandlers");
  977.                 }
  978.                 else if(logCore!=null) {
  979.                     logCore.error("Raccolta IntegrationManagerRequestHandlers", e);
  980.                 }
  981.             }
  982.             GestoreHandlers.tipiIntegrationManagerRequestHandlers = _mergeTipi(GestoreHandlers.properties.getIntegrationManagerRequestHandler(),
  983.                     tipiIntegrationManagerRequestHandlersConfig);
  984.             if(GestoreHandlers.tipiIntegrationManagerRequestHandlers!=null){
  985.                 GestoreHandlers.integrationManagerRequestHandlers = new IntegrationManagerRequestHandler[GestoreHandlers.tipiIntegrationManagerRequestHandlers.length];
  986.                 for(int i=0; i<GestoreHandlers.tipiIntegrationManagerRequestHandlers.length; i++){
  987.                     try{
  988.                         String tipo=GestoreHandlers.tipiIntegrationManagerRequestHandlers[i];
  989.                         GestoreHandlers.integrationManagerRequestHandlers[i] = (IntegrationManagerRequestHandler) pluginLoader.newIntegrationManagerRequestHandler(tipo);
  990.                         if(printInfo)
  991.                             logConsoleInit.info("IntegrationManagerRequestHandler di tipo ["+tipo+"] correttamente inizializzato.");
  992.                     }catch(Throwable e){
  993.                         if(msgDiag!=null) {
  994.                             msgDiag.logErroreGenerico(e, "Inizializzazione IntegrationManagerRequestHandler ["+GestoreHandlers.tipiIntegrationManagerRequestHandlers[i]+"]");
  995.                         }
  996.                         else if(logCore!=null) {
  997.                             logCore.error("Inizializzazione IntegrationManagerRequestHandler ["+GestoreHandlers.tipiIntegrationManagerRequestHandlers[i]+"]", e);
  998.                         }
  999.                     }
  1000.                 }
  1001.                 GestoreHandlers.integrationManagerRequestHandlers = reorder(GestoreHandlers.integrationManagerRequestHandlers, new IntegrationManagerRequestHandler[1]);
  1002.             }
  1003.            
  1004.             // IntegrationManagerResponseHandler
  1005.             List<String> tipiIntegrationManagerResponseHandlersConfig = null;
  1006.             try {
  1007.                 tipiIntegrationManagerResponseHandlersConfig=ConfigurazionePdDManager.getInstance(state).getIntegrationManagerResponseHandlers();
  1008.             }catch(Throwable e) {
  1009.                 if(msgDiag!=null) {
  1010.                     msgDiag.logErroreGenerico(e, "Raccolta IntegrationManagerResponseHandlers");
  1011.                 }
  1012.                 else if(logCore!=null) {
  1013.                     logCore.error("Raccolta IntegrationManagerResponseHandlers", e);
  1014.                 }
  1015.             }
  1016.             GestoreHandlers.tipiIntegrationManagerResponseHandlers = _mergeTipi(GestoreHandlers.properties.getIntegrationManagerResponseHandler(),
  1017.                     tipiIntegrationManagerResponseHandlersConfig);
  1018.             if(GestoreHandlers.tipiIntegrationManagerResponseHandlers!=null){
  1019.                 GestoreHandlers.integrationManagerResponseHandlers = new IntegrationManagerResponseHandler[GestoreHandlers.tipiIntegrationManagerResponseHandlers.length];
  1020.                 for(int i=0; i<GestoreHandlers.tipiIntegrationManagerResponseHandlers.length; i++){
  1021.                     try{
  1022.                         String tipo=GestoreHandlers.tipiIntegrationManagerResponseHandlers[i];
  1023.                         GestoreHandlers.integrationManagerResponseHandlers[i] = (IntegrationManagerResponseHandler) pluginLoader.newIntegrationManagerResponseHandler(tipo);
  1024.                         if(printInfo)
  1025.                             logConsoleInit.info("IntegrationManagerResponseHandler di tipo ["+tipo+"] correttamente inizializzato.");
  1026.                     }catch(Throwable e){
  1027.                         if(msgDiag!=null) {
  1028.                             msgDiag.logErroreGenerico(e, "Inizializzazione IntegrationManagerResponseHandler ["+GestoreHandlers.tipiIntegrationManagerResponseHandlers[i]+"]");
  1029.                         }
  1030.                         else if(logCore!=null) {
  1031.                             logCore.error("Inizializzazione IntegrationManagerResponseHandler ["+GestoreHandlers.tipiIntegrationManagerResponseHandlers[i]+"]", e);
  1032.                         }
  1033.                     }
  1034.                 }
  1035.                 GestoreHandlers.integrationManagerResponseHandlers = reorder(GestoreHandlers.integrationManagerResponseHandlers, new IntegrationManagerResponseHandler[1]);
  1036.             }
  1037.            
  1038.         }
  1039.        
  1040.         GestoreHandlers.initialize=true;
  1041.     }
  1042.    
  1043.     private static String [] _mergeTipi(String [] fromProperties, List<String> fromConfig) {
  1044.         List<String> merge = new ArrayList<>();
  1045.         if(fromProperties!=null && fromProperties.length>0) {
  1046.             for (int i = 0; i < fromProperties.length; i++) {
  1047.                 merge.add(fromProperties[i]);
  1048.             }
  1049.         }
  1050.         if(fromConfig!=null && !fromConfig.isEmpty()) {
  1051.             for (int i = 0; i < fromConfig.size(); i++) {
  1052.                 merge.add(fromConfig.get(i));
  1053.             }
  1054.         }
  1055.         if(!merge.isEmpty()) {
  1056.             return merge.toArray(new String[merge.size()]);
  1057.         }
  1058.         return null;
  1059.     }
  1060.    
  1061.     private static final boolean printOrderInfo = false;
  1062.     private static <T> T[] reorder(T [] handlers, T[] bufferReturn){
  1063.         if(handlers!=null && handlers.length>0){
  1064.            
  1065.             List<String> handlerPositionHeadId = new ArrayList<>();
  1066.             Map<String,T> handlerPositionHeadMap = new HashMap<String,T>();
  1067.            
  1068.             List<String> handlerPositionTailId = new ArrayList<>();
  1069.             Map<String,T> handlerPositionTailMap = new HashMap<String,T>();
  1070.            
  1071.             List<T> handlerPositionMiddle = new ArrayList<T>();
  1072.            
  1073.             if(printOrderInfo){
  1074.                 System.out.println("================== "+handlers.getClass().getName()+" =====================");
  1075.                 System.out.println("PRE ORDER:");
  1076.             }
  1077.             for(int i=0; i<handlers.length; i++){
  1078.                
  1079.                 if(handlers[i]==null) {
  1080.                     continue;
  1081.                 }
  1082.                
  1083.                 boolean position = false;
  1084.                 if(handlers[i] instanceof PositionHandler){
  1085.                     PositionHandler p = (PositionHandler) handlers[i];
  1086.                     if(p.getIdPosition()!=null){
  1087.                         if(p.isHeadHandler()){
  1088.                             handlerPositionHeadId.add(p.getIdPosition());
  1089.                             handlerPositionHeadMap.put(p.getIdPosition(), handlers[i]);
  1090.                         }
  1091.                         else{
  1092.                             handlerPositionTailId.add(p.getIdPosition());
  1093.                             handlerPositionTailMap.put(p.getIdPosition(), handlers[i]);
  1094.                         }
  1095.                         position = true;
  1096.                     }
  1097.                 }
  1098.                 if(position==false){
  1099.                     handlerPositionMiddle.add(handlers[i]);
  1100.                 }
  1101.                
  1102.                 if(printOrderInfo){
  1103.                     System.out.println("\t(Pos:"+position+")["+handlers[i].getClass().getName()+"]");
  1104.                 }
  1105.             }
  1106.            
  1107.             // reorder
  1108.             List<T> orderedList = new ArrayList<T>();
  1109.            
  1110.             if(handlerPositionHeadId.size()>0){
  1111.                 Collections.sort(handlerPositionHeadId);
  1112.                 for (String positionId : handlerPositionHeadId) {
  1113.                     orderedList.add(handlerPositionHeadMap.get(positionId));
  1114.                 }
  1115.             }
  1116.            
  1117.             if(handlerPositionMiddle.size()>0){
  1118.                 for (T t : handlerPositionMiddle) {
  1119.                     orderedList.add(t);
  1120.                 }
  1121.             }
  1122.            
  1123.             if(handlerPositionTailId.size()>0){
  1124.                 Collections.sort(handlerPositionTailId);
  1125.                 for (String positionId : handlerPositionTailId) {
  1126.                     orderedList.add(handlerPositionTailMap.get(positionId));
  1127.                 }
  1128.             }
  1129.            
  1130.             if(orderedList!=null && !orderedList.isEmpty()) {
  1131.                 if(printOrderInfo){
  1132.                     System.out.println("POST ORDER:");
  1133.                     for (T t : orderedList) {
  1134.                         System.out.println("\t["+t.getClass().getName()+"]");
  1135.                     }
  1136.                 }
  1137.                
  1138.                 return (T[]) orderedList.toArray(bufferReturn);
  1139.             }
  1140.             else {
  1141.                 return null;
  1142.             }
  1143.         }
  1144.         else{
  1145.             return null;
  1146.         }
  1147.     }
  1148.    
  1149.     @SuppressWarnings("unchecked")
  1150.     private static <T> List<Object[]> merge(T [] handlers1, String [] tipiHandlers1,
  1151.             T [] handlers2, String [] tipiHandlers2, T[] bufferReturn){
  1152.         List<Object[]> lists = new ArrayList<>();
  1153.         if(handlers1==null || handlers1.length<=0) {
  1154.             lists.add(handlers2);
  1155.             lists.add(tipiHandlers2);
  1156.             return lists;
  1157.         }
  1158.         if(handlers2==null || handlers2.length<=0) {
  1159.             lists.add(handlers1);
  1160.             lists.add(tipiHandlers1);
  1161.             return lists;
  1162.         }
  1163.        
  1164.         List<T> listUnsorted = new ArrayList<>();
  1165.         for (int i = 0; i < handlers1.length; i++) {
  1166.             listUnsorted.add(handlers1[i]);
  1167.         }
  1168.         for (int i = 0; i < handlers2.length; i++) {
  1169.             listUnsorted.add(handlers2[i]);
  1170.         }
  1171.         T [] sorted = reorder((T[])listUnsorted.toArray(), bufferReturn);
  1172.         if(sorted!=null) {
  1173.             lists.add(sorted);
  1174.            
  1175.             List<String> listSortedType = new ArrayList<>();
  1176.             for (int i = 0; i < sorted.length; i++) {
  1177.                 T sortHandler = sorted[i];
  1178.                 boolean found = false;
  1179.                 for (int j = 0; j < handlers1.length; j++) {
  1180.                     String sortHandlerClassName = sortHandler.getClass().getName();
  1181.                     if(sortHandlerClassName.equals(handlers1[j].getClass().getName())) {
  1182.                         listSortedType.add(tipiHandlers1[j]);
  1183.                         found = true;
  1184.                         break;
  1185.                     }
  1186.                 }
  1187.                 if(!found) {
  1188.                     for (int j = 0; j < handlers2.length; j++) {
  1189.                         String sortHandlerClassName = sortHandler.getClass().getName();
  1190.                         if(sortHandlerClassName.equals(handlers2[j].getClass().getName())) {
  1191.                             listSortedType.add(tipiHandlers2[j]);
  1192.                             found = true;
  1193.                             break;
  1194.                         }
  1195.                     }
  1196.                 }
  1197.                 if(!found) {
  1198.                     throw new RuntimeException("Errore inatteso durante la gestione dell'handler: "+sortHandler.getClass().getName());
  1199.                 }
  1200.             }
  1201.             lists.add(listSortedType.toArray());
  1202.         }
  1203.        
  1204.         return lists;
  1205.        
  1206.     }
  1207.    
  1208.    
  1209.     private static String[] updateNotifierCallback(String [] tipi) {
  1210.         String notifierInputStreamCallback = null;
  1211.         try{
  1212.             if(properties.isNotifierInputStreamEnabled()) {
  1213.                 notifierInputStreamCallback = properties.getNotifierInputStreamCallback();
  1214.             }
  1215.         }catch(Throwable e){}
  1216.         if(notifierInputStreamCallback!=null){
  1217.             List<String> list = new ArrayList<>();
  1218.             list.add(NotifierConstants.TIPO_NOTIFIER);
  1219.             if(tipi!=null){
  1220.                 for (int i = 0; i < tipi.length; i++) {
  1221.                     list.add(tipi[i]);
  1222.                 }
  1223.             }
  1224.             return list.toArray(new String[1]);
  1225.         }
  1226.         else{
  1227.             return tipi;
  1228.         }
  1229.     }  
  1230.    
  1231.     private static void emitDiagnosticInvokeHandlerStart(Object object, MsgDiagnostico msgDiag,Logger log){
  1232.         try{
  1233.             if(object!=null && msgDiag!=null){
  1234.                 msgDiag.mediumDebug("["+object.getClass().getName()+"] invocazione in corso");
  1235.             }
  1236.         }catch(Throwable t){
  1237.             if(log!=null){
  1238.                 log.error("Errore durante l'emissione del diagnostico: "+t.getMessage(),t);
  1239.             }
  1240.         }
  1241.     }
  1242.     private static void emitDiagnosticInvokeHandlerEnd(Object object, MsgDiagnostico msgDiag,Logger log){
  1243.         try{
  1244.             if(object!=null && msgDiag!=null){
  1245.                 msgDiag.mediumDebug("["+object.getClass().getName()+"] invocazione terminata");
  1246.             }
  1247.         }catch(Throwable t){
  1248.             if(log!=null){
  1249.                 log.error("Errore durante l'emissione del diagnostico: "+t.getMessage(),t);
  1250.             }
  1251.         }
  1252.     }
  1253.    
  1254.     public static void init(InitContext context,MsgDiagnostico msgDiag,Logger log) throws HandlerException{
  1255.        
  1256.         if(GestoreHandlers.initialize==false){
  1257.             GestoreHandlers.initialize(msgDiag,log,null);
  1258.         }
  1259.        
  1260.         if(properties.isMergeHandlerBuiltInAndHandlerUser()) {
  1261.             List<Object[]> list =  merge(GestoreHandlers.initHandlersBuiltIn, GestoreHandlers.tipiInitHandlersBuiltIn,
  1262.                     GestoreHandlers.initHandlers, GestoreHandlers.tipiInitHandlers, new InitHandler [1]);
  1263.             InitHandler [] handlers = (InitHandler []) list.get(0);
  1264.             String [] tipiHandlers = toStringArray(list.get(1));
  1265.             _initHandler(context, msgDiag, log, handlers, tipiHandlers, "InitHandler");
  1266.         }
  1267.         else {
  1268.             _initHandler(context, msgDiag, log, GestoreHandlers.initHandlersBuiltIn, GestoreHandlers.tipiInitHandlersBuiltIn, "InitHandler");
  1269.             _initHandler(context, msgDiag, log, GestoreHandlers.initHandlers, GestoreHandlers.tipiInitHandlers, "InitHandler");
  1270.         }
  1271.        
  1272.     }
  1273.     private static void _initHandler(InitContext context,MsgDiagnostico msgDiag,Logger log, InitHandler [] handlers, String [] tipiHandlers, String name) throws HandlerException{
  1274.         if(handlers!=null){
  1275.             for(int i=0; i<handlers.length; i++){
  1276.                 try{
  1277.                     emitDiagnosticInvokeHandlerStart(handlers[i], msgDiag, log);
  1278.                     handlers[i].invoke(context);
  1279.                     emitDiagnosticInvokeHandlerEnd(handlers[i], msgDiag, log);
  1280.                 }catch(Throwable e){
  1281.                    
  1282.                     if(log!=null){
  1283.                         log.error(name+" ["+tipiHandlers[i]+"] (class:"+handlers[i].getClass().getName()+")",e);
  1284.                     }
  1285.                    
  1286.                     // Sollevo l'eccezione
  1287.                     HandlerException ex = new HandlerException(e.getMessage(),e);
  1288.                     ex.setIdentitaHandler(name+" ["+tipiHandlers[i]+"]");
  1289.                     throw ex;
  1290.                 }
  1291.             }
  1292.         }
  1293.     }
  1294.    
  1295.     public static void exit(ExitContext context){
  1296.        
  1297.         Logger log = null;
  1298.         if(context!=null){
  1299.             if(context.getLogCore()!=null){
  1300.                 log = context.getLogCore();
  1301.             }else{
  1302.                 log = context.getLogConsole();
  1303.             }
  1304.         }
  1305.        
  1306.         if(GestoreHandlers.initialize){
  1307.            
  1308.             // inizializzati cmq dall'init
  1309.            
  1310.             if(properties.isMergeHandlerBuiltInAndHandlerUser()) {
  1311.                 List<Object[]> list =  merge(GestoreHandlers.exitHandlersBuiltIn, GestoreHandlers.tipiExitHandlersBuiltIn,
  1312.                         GestoreHandlers.exitHandlers, GestoreHandlers.tipiExitHandlers, new ExitHandler [1]);
  1313.                 ExitHandler [] handlers = (ExitHandler []) list.get(0);
  1314.                 String [] tipiHandlers = toStringArray(list.get(1));
  1315.                 _exitHandler(context, log, handlers, tipiHandlers, "ExitHandler");
  1316.             }
  1317.             else {
  1318.                 _exitHandler(context, log, GestoreHandlers.exitHandlersBuiltIn, GestoreHandlers.tipiExitHandlersBuiltIn, "ExitHandler");
  1319.                 _exitHandler(context, log, GestoreHandlers.exitHandlers, GestoreHandlers.tipiExitHandlers, "ExitHandler");
  1320.             }
  1321.         }
  1322.     }
  1323.     private static void _exitHandler(ExitContext context,Logger log, ExitHandler [] handlers, String [] tipiHandlers, String name) {
  1324.         if(handlers!=null){
  1325.             for(int i=0; i<handlers.length; i++){
  1326.                 try{
  1327.                     handlers[i].invoke(context);
  1328.                 }catch(Throwable e){
  1329.                     // Gli handler di tipo exit non dovrebbero sollevare una eccezione.
  1330.                     // Eventualmento loggo l'errore
  1331.                     if(log!=null){
  1332.                         log.error(name+" ["+tipiHandlers[i]+"] (class:"+handlers[i].getClass().getName()+")",e);
  1333.                     }
  1334.                 }
  1335.             }
  1336.         }
  1337.     }
  1338.    
  1339.    
  1340.     public static void preInRequest(PreInAcceptRequestContext context,Logger logCore,Logger log) {
  1341.         _engine_preInRequest(null, context, null, logCore, log);
  1342.     }
  1343.     public static void emitDiagnostic(MsgDiagnostico msgDiag, PreInAcceptRequestContext context, PdDContext pddContext,Logger logCore,Logger log) {
  1344.         _engine_preInRequest(msgDiag, context, pddContext, logCore, log);
  1345.     }
  1346.     public static void _engine_preInRequest(MsgDiagnostico msgDiag, PreInAcceptRequestContext context, PdDContext pddContext,Logger logCore,Logger log) {
  1347.        
  1348.         if(!GestoreHandlers.initialize){
  1349.             GestoreHandlers.initialize(logCore,log);
  1350.         }
  1351.        
  1352.         // unisco handler generali (props+config) con eventuali handler definiti sulla porta
  1353.         List<Object[]> mergeWithImplementation = mergeWithImplementationEngine(msgDiag, context, pddContext,GestoreHandlers.preInRequestHandlers, GestoreHandlers.tipiPreInRequestHandlers, log);
  1354.         PreInRequestHandler [] preInRequestHandlersUsers = (PreInRequestHandler []) mergeWithImplementation.get(0);
  1355.         String [] tipiPreInRequestHandlersUsers = (String []) mergeWithImplementation.get(1);
  1356.        
  1357.         // gestisco handler built-in e user
  1358.         if(properties.isMergeHandlerBuiltInAndHandlerUser()) {
  1359.             List<Object[]> list =  merge(GestoreHandlers.preInRequestHandlersBuiltIn, GestoreHandlers.tipiPreInRequestHandlersBuiltIn,
  1360.                     preInRequestHandlersUsers, tipiPreInRequestHandlersUsers, new PreInRequestHandler [1]);
  1361.             PreInRequestHandler [] handlers = (PreInRequestHandler []) list.get(0);
  1362.             String [] tipiHandlers = toStringArray(list.get(1));
  1363.             _preInRequestHandler(msgDiag, context, pddContext, log, handlers, tipiHandlers, "PreInRequestHandler");
  1364.         }
  1365.         else {
  1366.             _preInRequestHandler(msgDiag, context, pddContext, log, GestoreHandlers.preInRequestHandlersBuiltIn, GestoreHandlers.tipiPreInRequestHandlersBuiltIn, "PreInRequestHandler");
  1367.             _preInRequestHandler(msgDiag, context, pddContext, log, preInRequestHandlersUsers, tipiPreInRequestHandlersUsers, "PreInRequestHandler");
  1368.         }
  1369.        
  1370.     }
  1371.     private static List<Object[]> mergeWithImplementationEngine(MsgDiagnostico msgDiag, PreInAcceptRequestContext context, PdDContext pddContext,
  1372.             PreInRequestHandler [] preInRequestHandlers,String [] tipiPreInRequestHandlers,
  1373.             Logger log) {
  1374.         List<Object[]> mergeList = null;
  1375.         try{
  1376.             List<String> tipiPorta=null;
  1377.             if(context!=null && context.getRequestInfo()!=null && context.getRequestInfo().getProtocolContext()!=null &&
  1378.                     context.getRequestInfo().getProtocolContext().getInterfaceName()!=null) {
  1379.                 ConfigurazionePdDManager configurazionePdDManager = ConfigurazionePdDManager.getInstance();
  1380.                 if(TipoPdD.DELEGATA.equals(context.getTipoPorta())) {
  1381.                     IDPortaDelegata idPD = new IDPortaDelegata();
  1382.                     idPD.setNome(context.getRequestInfo().getProtocolContext().getInterfaceName());
  1383.                     PortaDelegata pd=configurazionePdDManager.getPortaDelegataSafeMethod(idPD, context.getRequestInfo());
  1384.                     tipiPorta=configurazionePdDManager.getPreInRequestHandlers(pd);
  1385.                     /**System.out.println("PreInRequestContext find PD '"+pd.getNome()+"'");*/
  1386.                 }
  1387.                 else if(TipoPdD.APPLICATIVA.equals(context.getTipoPorta())) {
  1388.                     IDPortaApplicativa idPA = new IDPortaApplicativa();
  1389.                     idPA.setNome(context.getRequestInfo().getProtocolContext().getInterfaceName());
  1390.                     PortaApplicativa pa=configurazionePdDManager.getPortaApplicativaSafeMethod(idPA, context.getRequestInfo());
  1391.                     tipiPorta=configurazionePdDManager.getPreInRequestHandlers(pa);
  1392.                     /**System.out.println("PreInRequestContext find PA '"+pa.getNome()+"'");*/
  1393.                 }
  1394.             }
  1395.             if(tipiPorta!=null && !tipiPorta.isEmpty()) {
  1396.                 List<PreInRequestHandler> listHandler = new ArrayList<>();
  1397.                 List<String> listTipi = new ArrayList<>();
  1398.                 if(preInRequestHandlers!=null && preInRequestHandlers.length>0) {
  1399.                     for (int i = 0; i < preInRequestHandlers.length; i++) {
  1400.                         listHandler.add(preInRequestHandlers[i]);
  1401.                         listTipi.add(tipiPreInRequestHandlers[i]);
  1402.                     }
  1403.                 }
  1404.                 PddPluginLoader pluginLoader = PddPluginLoader.getInstance();
  1405.                 for (String tipoPorta : tipiPorta) {
  1406.                     if(!listTipi.contains(tipoPorta)) {
  1407.                         try {
  1408.                             PreInRequestHandler handler = pluginLoader.newPreInRequestHandler(tipoPorta);
  1409.                             listHandler.add(handler);
  1410.                             listTipi.add(tipoPorta);
  1411.                         }catch(Throwable t) {
  1412.                             log.error("NewInstance '"+tipoPorta+"' failed: "+t.getMessage(),t);
  1413.                             // Sollevo l'eccezione
  1414.                             HandlerException ex = new HandlerException(t.getMessage(),t);
  1415.                             ex.setIdentitaHandler("PreInRequestHandler"+" ["+tipoPorta+"]");
  1416.                             throw ex;
  1417.                         }
  1418.                     }
  1419.                 }
  1420.                 if(!listHandler.isEmpty()) {
  1421.                     mergeList = new ArrayList<>();
  1422.                     mergeList.add(listHandler.toArray(new PreInRequestHandler[listHandler.size()]));
  1423.                     mergeList.add(listTipi.toArray(new String[listTipi.size()]));
  1424.                 }
  1425.             }
  1426.         }catch(Throwable t) {
  1427.             log.error(t.getMessage(),t);
  1428.         }
  1429.         if(mergeList==null) {
  1430.             mergeList = new ArrayList<>();
  1431.             mergeList.add(preInRequestHandlers);
  1432.             mergeList.add(tipiPreInRequestHandlers);
  1433.         }
  1434.         return mergeList;
  1435.     }
  1436.     private static void _preInRequestHandler(MsgDiagnostico msgDiag, PreInAcceptRequestContext context, PdDContext pddContext,Logger log,
  1437.             PreInRequestHandler [] handlers, String [] tipiHandlers, String name) {
  1438.         if(handlers!=null){
  1439.             for(int i=0; i<handlers.length; i++){
  1440.                 try{
  1441.                     if(msgDiag!=null) {
  1442.                         handlers[i].emitDiagnostic(msgDiag, context, pddContext);
  1443.                     }
  1444.                     else {
  1445.                         emitDiagnosticInvokeHandlerStart(handlers[i], null, log);
  1446.                         handlers[i].invoke(context);
  1447.                         emitDiagnosticInvokeHandlerEnd(handlers[i], null, log);
  1448.                     }
  1449.                 }catch(Throwable e){
  1450.                     // Sollevo l'eccezione
  1451.                     /*HandlerException ex = null;
  1452.                     if(e instanceof HandlerException){
  1453.                         ex = (HandlerException) e;
  1454.                     }else{
  1455.                         ex = new HandlerException(e.getMessage(),e);
  1456.                     }
  1457.                     ex.setIdentitaHandler(name+" ["+tipiHandlers[i]+"]");
  1458.                     throw ex;
  1459.                     */
  1460.                     // L'handler invocato con il contesto 'PreInAcceptRequestContext' non dovrebbe sollevare una eccezione
  1461.                     // Eventualmento loggo l'errore
  1462.                     if(log!=null){
  1463.                         log.error(name+" ["+tipiHandlers[i]+"] 'PreInAcceptRequestContext' (class:"+handlers[i].getClass().getName()+")",e);
  1464.                     }
  1465.                 }
  1466.             }
  1467.         }
  1468.     }
  1469.    
  1470.     public static void preInRequest(PreInRequestContext context,MsgDiagnostico msgDiag,Logger log) throws HandlerException{
  1471.        
  1472.         if(!GestoreHandlers.initialize){
  1473.             GestoreHandlers.initialize(msgDiag,log,null);
  1474.         }
  1475.        
  1476.         // unisco handler generali (props+config) con eventuali handler definiti sulla porta
  1477.         List<Object[]> mergeWithImplementation = mergeWithImplementationEngine(context,GestoreHandlers.preInRequestHandlers, GestoreHandlers.tipiPreInRequestHandlers, log);
  1478.         PreInRequestHandler [] preInRequestHandlersUsers = (PreInRequestHandler []) mergeWithImplementation.get(0);
  1479.         String [] tipiPreInRequestHandlersUsers = (String []) mergeWithImplementation.get(1);
  1480.        
  1481.         // gestisco handler built-in e user
  1482.         if(properties.isMergeHandlerBuiltInAndHandlerUser()) {
  1483.             List<Object[]> list =  merge(GestoreHandlers.preInRequestHandlersBuiltIn, GestoreHandlers.tipiPreInRequestHandlersBuiltIn,
  1484.                     preInRequestHandlersUsers, tipiPreInRequestHandlersUsers, new PreInRequestHandler [1]);
  1485.             PreInRequestHandler [] handlers = (PreInRequestHandler []) list.get(0);
  1486.             String [] tipiHandlers = toStringArray(list.get(1));
  1487.             _preInRequestHandler(context, msgDiag, log, handlers, tipiHandlers, "PreInRequestHandler");
  1488.         }
  1489.         else {
  1490.             _preInRequestHandler(context, msgDiag, log, GestoreHandlers.preInRequestHandlersBuiltIn, GestoreHandlers.tipiPreInRequestHandlersBuiltIn, "PreInRequestHandler");
  1491.             _preInRequestHandler(context, msgDiag, log, preInRequestHandlersUsers, tipiPreInRequestHandlersUsers, "PreInRequestHandler");
  1492.         }
  1493.        
  1494.     }
  1495.     private static List<Object[]> mergeWithImplementationEngine(PreInRequestContext context,PreInRequestHandler [] preInRequestHandlers,String [] tipiPreInRequestHandlers,
  1496.             Logger log) {
  1497.         List<Object[]> mergeList = null;
  1498.         try{
  1499.             List<String> tipiPorta=null;
  1500.             if(context!=null && context.getRequestInfo()!=null && context.getRequestInfo().getProtocolContext()!=null &&
  1501.                     context.getRequestInfo().getProtocolContext().getInterfaceName()!=null) {
  1502.                 ConfigurazionePdDManager configurazionePdDManager = ConfigurazionePdDManager.getInstance();
  1503.                 if(TipoPdD.DELEGATA.equals(context.getTipoPorta())) {
  1504.                     IDPortaDelegata idPD = new IDPortaDelegata();
  1505.                     idPD.setNome(context.getRequestInfo().getProtocolContext().getInterfaceName());
  1506.                     PortaDelegata pd=configurazionePdDManager.getPortaDelegataSafeMethod(idPD, context.getRequestInfo());
  1507.                     tipiPorta=configurazionePdDManager.getPreInRequestHandlers(pd);
  1508.                     /**System.out.println("PreInRequestContext find PD '"+pd.getNome()+"'");*/
  1509.                 }
  1510.                 else if(TipoPdD.APPLICATIVA.equals(context.getTipoPorta())) {
  1511.                     IDPortaApplicativa idPA = new IDPortaApplicativa();
  1512.                     idPA.setNome(context.getRequestInfo().getProtocolContext().getInterfaceName());
  1513.                     PortaApplicativa pa=configurazionePdDManager.getPortaApplicativaSafeMethod(idPA, context.getRequestInfo());
  1514.                     tipiPorta=configurazionePdDManager.getPreInRequestHandlers(pa);
  1515.                     /**System.out.println("PreInRequestContext find PA '"+pa.getNome()+"'");*/
  1516.                 }
  1517.             }
  1518.             if(tipiPorta!=null && !tipiPorta.isEmpty()) {
  1519.                 List<PreInRequestHandler> listHandler = new ArrayList<>();
  1520.                 List<String> listTipi = new ArrayList<>();
  1521.                 if(preInRequestHandlers!=null && preInRequestHandlers.length>0) {
  1522.                     for (int i = 0; i < preInRequestHandlers.length; i++) {
  1523.                         listHandler.add(preInRequestHandlers[i]);
  1524.                         listTipi.add(tipiPreInRequestHandlers[i]);
  1525.                     }
  1526.                 }
  1527.                 PddPluginLoader pluginLoader = PddPluginLoader.getInstance();
  1528.                 for (String tipoPorta : tipiPorta) {
  1529.                     if(!listTipi.contains(tipoPorta)) {
  1530.                         try {
  1531.                             PreInRequestHandler handler = pluginLoader.newPreInRequestHandler(tipoPorta);
  1532.                             listHandler.add(handler);
  1533.                             listTipi.add(tipoPorta);
  1534.                         }catch(Throwable t) {
  1535.                             log.error("NewInstance '"+tipoPorta+"' failed: "+t.getMessage(),t);
  1536.                             // Sollevo l'eccezione
  1537.                             HandlerException ex = new HandlerException(t.getMessage(),t);
  1538.                             ex.setIdentitaHandler("PreInRequestHandler"+" ["+tipoPorta+"]");
  1539.                             throw ex;
  1540.                         }
  1541.                     }
  1542.                 }
  1543.                 if(!listHandler.isEmpty()) {
  1544.                     mergeList = new ArrayList<>();
  1545.                     mergeList.add(listHandler.toArray(new PreInRequestHandler[listHandler.size()]));
  1546.                     mergeList.add(listTipi.toArray(new String[listTipi.size()]));
  1547.                 }
  1548.             }
  1549.         }catch(Throwable t) {
  1550.             log.error(t.getMessage(),t);
  1551.         }
  1552.         if(mergeList==null) {
  1553.             mergeList = new ArrayList<>();
  1554.             mergeList.add(preInRequestHandlers);
  1555.             mergeList.add(tipiPreInRequestHandlers);
  1556.         }
  1557.         return mergeList;
  1558.     }
  1559.     private static void _preInRequestHandler(PreInRequestContext context,MsgDiagnostico msgDiag,Logger log, PreInRequestHandler [] handlers, String [] tipiHandlers, String name) throws HandlerException{
  1560.         if(handlers!=null){
  1561.             for(int i=0; i<handlers.length; i++){
  1562.                 try{
  1563.                     emitDiagnosticInvokeHandlerStart(handlers[i], msgDiag, log);
  1564.                     handlers[i].invoke(context);
  1565.                     emitDiagnosticInvokeHandlerEnd(handlers[i], msgDiag, log);
  1566.                 }catch(Throwable e){
  1567.                     // Sollevo l'eccezione
  1568.                     HandlerException ex = null;
  1569.                     if(e instanceof HandlerException){
  1570.                         ex = (HandlerException) e;
  1571.                     }else{
  1572.                         ex = new HandlerException(e.getMessage(),e);
  1573.                     }
  1574.                     ex.setIdentitaHandler(name+" ["+tipiHandlers[i]+"]");
  1575.                     throw ex;
  1576.                 }
  1577.             }
  1578.         }
  1579.     }
  1580.    
  1581.     public static void inRequest(InRequestContext context,MsgDiagnostico msgDiag,Logger log) throws HandlerException{
  1582.        
  1583.         if(!GestoreHandlers.initialize){
  1584.             GestoreHandlers.initialize(msgDiag,log,context.getStato());
  1585.         }
  1586.    
  1587.         if(context.getDataElaborazioneMessaggio()==null){
  1588.             context.setDataElaborazioneMessaggio(DateManager.getDate());
  1589.         }
  1590.        
  1591.         // genero date casuali
  1592.         if(GestoreHandlers.properties.generazioneDateCasualiLogAbilitato() && context.getPddContext().getObject(org.openspcoop2.core.constants.Costanti.ID_TRANSAZIONE)!=null){
  1593.             context.setDataElaborazioneMessaggio(GestoreHandlers.generatoreCasualeDati.getProssimaData((String)context.getPddContext().getObject(org.openspcoop2.core.constants.Costanti.ID_TRANSAZIONE)));
  1594.         }
  1595.        
  1596.         // unisco handler generali (props+config) con eventuali handler definiti sulla porta
  1597.         List<Object[]> mergeWithImplementation = mergeWithImplementationEngine(context,GestoreHandlers.inRequestHandlers, GestoreHandlers.tipiInRequestHandlers, log);
  1598.         InRequestHandler [] inRequestHandlersUsers = (InRequestHandler []) mergeWithImplementation.get(0);
  1599.         String [] tipiInRequestHandlersUsers = (String []) mergeWithImplementation.get(1);
  1600.        
  1601.         // gestisco handler built-in e user
  1602.         if(properties.isMergeHandlerBuiltInAndHandlerUser()) {
  1603.             List<Object[]> list =  merge(GestoreHandlers.inRequestHandlersBuiltIn, GestoreHandlers.tipiInRequestHandlersBuiltIn,
  1604.                     inRequestHandlersUsers, tipiInRequestHandlersUsers, new InRequestHandler [1]);
  1605.             InRequestHandler [] handlers = (InRequestHandler []) list.get(0);
  1606.             String [] tipiHandlers = toStringArray(list.get(1));
  1607.             _inRequestHandler(context, msgDiag, log, handlers, tipiHandlers, "InRequestHandler");
  1608.         }
  1609.         else {
  1610.             _inRequestHandler(context, msgDiag, log, GestoreHandlers.inRequestHandlersBuiltIn, GestoreHandlers.tipiInRequestHandlersBuiltIn, "InRequestHandler");
  1611.             _inRequestHandler(context, msgDiag, log, inRequestHandlersUsers, tipiInRequestHandlersUsers, "InRequestHandler");
  1612.         }
  1613.        
  1614.     }
  1615.     private static List<Object[]> mergeWithImplementationEngine(InRequestContext context,InRequestHandler [] inRequestHandlers,String [] tipiInRequestHandlers,
  1616.             Logger log) {
  1617.         List<Object[]> mergeList = null;
  1618.         try{
  1619.             List<String> tipiPorta=null;
  1620.             if(context!=null) {
  1621.                 ConfigurazionePdDManager configurazionePdDManager = ConfigurazionePdDManager.getInstance(context.getStato());
  1622.                
  1623.                 RequestInfo requestInfo = null;
  1624.                 if(context.getPddContext()!=null && context.getPddContext().containsKey(org.openspcoop2.core.constants.Costanti.REQUEST_INFO)) {
  1625.                     requestInfo = (RequestInfo) context.getPddContext().getObject(org.openspcoop2.core.constants.Costanti.REQUEST_INFO);
  1626.                 }
  1627.                
  1628.                 if(TipoPdD.DELEGATA.equals(context.getTipoPorta())) {
  1629.                     IDPortaDelegata idPD = null;
  1630.                     if(context.getConnettore()!=null && context.getConnettore().getUrlProtocolContext()!=null &&
  1631.                             context.getConnettore().getUrlProtocolContext().getInterfaceName()!=null) {
  1632.                         idPD = new IDPortaDelegata();
  1633.                         idPD.setNome(context.getConnettore().getUrlProtocolContext().getInterfaceName());
  1634.                     }
  1635.                     else if(requestInfo!=null && requestInfo.getProtocolContext()!=null && requestInfo.getProtocolContext().getInterfaceName()!=null) {
  1636.                         idPD = new IDPortaDelegata();
  1637.                         idPD.setNome(requestInfo.getProtocolContext().getInterfaceName());
  1638.                     }
  1639.                     PortaDelegata pd=configurazionePdDManager.getPortaDelegataSafeMethod(idPD, requestInfo);
  1640.                     tipiPorta=configurazionePdDManager.getInRequestHandlers(pd);
  1641.                     /**System.out.println("InRequestContext find PD '"+pd.getNome()+"'");*/
  1642.                 }
  1643.                 else if(TipoPdD.APPLICATIVA.equals(context.getTipoPorta())) {
  1644.                     IDPortaApplicativa idPA = null;
  1645.                     if(context.getConnettore()!=null && context.getConnettore().getUrlProtocolContext()!=null &&
  1646.                             context.getConnettore().getUrlProtocolContext().getInterfaceName()!=null) {
  1647.                         idPA = new IDPortaApplicativa();
  1648.                         idPA.setNome(context.getConnettore().getUrlProtocolContext().getInterfaceName());
  1649.                     }
  1650.                     else if(requestInfo!=null && requestInfo.getProtocolContext()!=null && requestInfo.getProtocolContext().getInterfaceName()!=null) {
  1651.                         idPA = new IDPortaApplicativa();
  1652.                         idPA.setNome(requestInfo.getProtocolContext().getInterfaceName());
  1653.                     }
  1654.                     PortaApplicativa pa=configurazionePdDManager.getPortaApplicativaSafeMethod(idPA, requestInfo);
  1655.                     tipiPorta=configurazionePdDManager.getInRequestHandlers(pa);
  1656.                     /**System.out.println("InRequestContext find PA '"+pa.getNome()+"'");*/
  1657.                 }
  1658.             }
  1659.             if(tipiPorta!=null && !tipiPorta.isEmpty()) {
  1660.                 List<InRequestHandler> listHandler = new ArrayList<>();
  1661.                 List<String> listTipi = new ArrayList<>();
  1662.                 if(inRequestHandlers!=null && inRequestHandlers.length>0) {
  1663.                     for (int i = 0; i < inRequestHandlers.length; i++) {
  1664.                         listHandler.add(inRequestHandlers[i]);
  1665.                         listTipi.add(tipiInRequestHandlers[i]);
  1666.                     }
  1667.                 }
  1668.                 PddPluginLoader pluginLoader = PddPluginLoader.getInstance();
  1669.                 for (String tipoPorta : tipiPorta) {
  1670.                     if(!listTipi.contains(tipoPorta)) {
  1671.                         try {
  1672.                             InRequestHandler handler = pluginLoader.newInRequestHandler(tipoPorta);
  1673.                             listHandler.add(handler);
  1674.                             listTipi.add(tipoPorta);
  1675.                         }catch(Throwable t) {
  1676.                             log.error("NewInstance '"+tipoPorta+"' failed: "+t.getMessage(),t);
  1677.                             // Sollevo l'eccezione
  1678.                             HandlerException ex = new HandlerException(t.getMessage(),t);
  1679.                             ex.setIdentitaHandler("InRequestHandler"+" ["+tipoPorta+"]");
  1680.                             throw ex;
  1681.                         }
  1682.                     }
  1683.                 }
  1684.                 if(!listHandler.isEmpty()) {
  1685.                     mergeList = new ArrayList<>();
  1686.                     mergeList.add(listHandler.toArray(new InRequestHandler[listHandler.size()]));
  1687.                     mergeList.add(listTipi.toArray(new String[listTipi.size()]));
  1688.                 }
  1689.             }
  1690.         }catch(Throwable t) {
  1691.             log.error(t.getMessage(),t);
  1692.         }
  1693.         if(mergeList==null) {
  1694.             mergeList = new ArrayList<>();
  1695.             mergeList.add(inRequestHandlers);
  1696.             mergeList.add(tipiInRequestHandlers);
  1697.         }
  1698.         return mergeList;
  1699.     }
  1700.     private static void _inRequestHandler(InRequestContext context,MsgDiagnostico msgDiag,Logger log, InRequestHandler [] handlers, String [] tipiHandlers, String name) throws HandlerException{
  1701.         if(handlers!=null){
  1702.             for(int i=0; i<handlers.length; i++){
  1703.                 try{
  1704.                     emitDiagnosticInvokeHandlerStart(handlers[i], msgDiag, log);
  1705.                     handlers[i].invoke(context);
  1706.                     emitDiagnosticInvokeHandlerEnd(handlers[i], msgDiag, log);
  1707.                 }catch(Throwable e){
  1708.                     // Sollevo l'eccezione
  1709.                     HandlerException ex = null;
  1710.                     if(e instanceof HandlerException){
  1711.                         ex = (HandlerException) e;
  1712.                     }else{
  1713.                         ex = new HandlerException(e.getMessage(),e);
  1714.                     }
  1715.                     ex.setIdentitaHandler(name+" ["+tipiHandlers[i]+"]");
  1716.                     throw ex;
  1717.                 }
  1718.             }
  1719.         }
  1720.     }
  1721.    
  1722.     public static void inRequestProtocol(InRequestProtocolContext context,MsgDiagnostico msgDiag,Logger log) throws HandlerException{
  1723.        
  1724.         if(!GestoreHandlers.initialize){
  1725.             GestoreHandlers.initialize(msgDiag,log,context.getStato());
  1726.         }
  1727.    
  1728.         if(context.getDataElaborazioneMessaggio()==null){
  1729.             context.setDataElaborazioneMessaggio(DateManager.getDate());
  1730.         }
  1731.        
  1732.         // genero date casuali
  1733.         if(GestoreHandlers.properties.generazioneDateCasualiLogAbilitato() && context.getPddContext().getObject(org.openspcoop2.core.constants.Costanti.ID_TRANSAZIONE)!=null){
  1734.             context.setDataElaborazioneMessaggio(GestoreHandlers.generatoreCasualeDati.getProssimaData((String)context.getPddContext().getObject(org.openspcoop2.core.constants.Costanti.ID_TRANSAZIONE)));
  1735.         }
  1736.        
  1737.         // unisco handler generali (props+config) con eventuali handler definiti sulla porta
  1738.         List<Object[]> mergeWithImplementation = mergeWithImplementationEngine(context,GestoreHandlers.inRequestProtocolHandlers, GestoreHandlers.tipiInRequestProtocolHandlers, log);
  1739.         InRequestProtocolHandler [] inRequestProtocolHandlersUsers = (InRequestProtocolHandler []) mergeWithImplementation.get(0);
  1740.         String [] tipiInRequestProtocolHandlersUsers = (String []) mergeWithImplementation.get(1);
  1741.        
  1742.         // gestisco handler built-in e user
  1743.         if(properties.isMergeHandlerBuiltInAndHandlerUser()) {
  1744.             List<Object[]> list =  merge(GestoreHandlers.inRequestProtocolHandlersBuiltIn, GestoreHandlers.tipiInRequestProtocolHandlersBuiltIn,
  1745.                     inRequestProtocolHandlersUsers, tipiInRequestProtocolHandlersUsers, new InRequestProtocolHandler [1]);
  1746.             InRequestProtocolHandler [] handlers = (InRequestProtocolHandler []) list.get(0);
  1747.             String [] tipiHandlers = toStringArray(list.get(1));
  1748.             _inRequestProtocolHandler(context, msgDiag, log, handlers, tipiHandlers, "InRequestProtocolHandler");
  1749.         }
  1750.         else {
  1751.             _inRequestProtocolHandler(context, msgDiag, log, GestoreHandlers.inRequestProtocolHandlersBuiltIn, GestoreHandlers.tipiInRequestProtocolHandlersBuiltIn, "InRequestProtocolHandler");
  1752.             _inRequestProtocolHandler(context, msgDiag, log, inRequestProtocolHandlersUsers, tipiInRequestProtocolHandlersUsers, "InRequestProtocolHandler");
  1753.         }
  1754.        
  1755.     }
  1756.     private static List<Object[]> mergeWithImplementationEngine(InRequestProtocolContext context,InRequestProtocolHandler [] intRequestProtocolHandlers,String [] tipiInRequestProtocolHandlers,
  1757.             Logger log) {
  1758.         List<Object[]> mergeList = null;
  1759.         try{
  1760.             List<String> tipiPorta=null;
  1761.             if(context!=null) {
  1762.                 ConfigurazionePdDManager configurazionePdDManager = ConfigurazionePdDManager.getInstance(context.getStato());
  1763.                
  1764.                 RequestInfo requestInfo = null;
  1765.                 if(context.getPddContext()!=null && context.getPddContext().containsKey(org.openspcoop2.core.constants.Costanti.REQUEST_INFO)) {
  1766.                     requestInfo = (RequestInfo) context.getPddContext().getObject(org.openspcoop2.core.constants.Costanti.REQUEST_INFO);
  1767.                 }
  1768.                
  1769.                 if(TipoPdD.DELEGATA.equals(context.getTipoPorta())) {
  1770.                     IDPortaDelegata idPD = null;
  1771.                     if(context.getIntegrazione()!=null && context.getIntegrazione().getIdPD()!=null) {
  1772.                         idPD = context.getIntegrazione().getIdPD();
  1773.                     }
  1774.                     else if(requestInfo!=null && requestInfo.getProtocolContext()!=null && requestInfo.getProtocolContext().getInterfaceName()!=null) {
  1775.                         idPD = new IDPortaDelegata();
  1776.                         idPD.setNome(requestInfo.getProtocolContext().getInterfaceName());
  1777.                     }
  1778.                     PortaDelegata pd=configurazionePdDManager.getPortaDelegataSafeMethod(idPD, requestInfo);
  1779.                     tipiPorta=configurazionePdDManager.getInRequestProtocolHandlers(pd);
  1780.                     /**System.out.println("InRequestProtocolContext find PD '"+pd.getNome()+"'");*/
  1781.                 }
  1782.                 else if(TipoPdD.APPLICATIVA.equals(context.getTipoPorta())) {
  1783.                     IDPortaApplicativa idPA = null;
  1784.                     if(context.getIntegrazione()!=null && context.getIntegrazione().getIdPA()!=null) {
  1785.                         idPA = context.getIntegrazione().getIdPA();
  1786.                     }
  1787.                     else if(requestInfo!=null && requestInfo.getProtocolContext()!=null && requestInfo.getProtocolContext().getInterfaceName()!=null) {
  1788.                         idPA = new IDPortaApplicativa();
  1789.                         idPA.setNome(requestInfo.getProtocolContext().getInterfaceName());
  1790.                     }
  1791.                     PortaApplicativa pa=configurazionePdDManager.getPortaApplicativaSafeMethod(idPA, requestInfo);
  1792.                     tipiPorta=configurazionePdDManager.getInRequestProtocolHandlers(pa);
  1793.                     /**System.out.println("InRequestProtocolContext find PA '"+pa.getNome()+"'");*/
  1794.                 }
  1795.             }
  1796.             if(tipiPorta!=null && !tipiPorta.isEmpty()) {
  1797.                 List<InRequestProtocolHandler> listHandler = new ArrayList<>();
  1798.                 List<String> listTipi = new ArrayList<>();
  1799.                 if(intRequestProtocolHandlers!=null && intRequestProtocolHandlers.length>0) {
  1800.                     for (int i = 0; i < intRequestProtocolHandlers.length; i++) {
  1801.                         listHandler.add(intRequestProtocolHandlers[i]);
  1802.                         listTipi.add(tipiInRequestProtocolHandlers[i]);
  1803.                     }
  1804.                 }
  1805.                 PddPluginLoader pluginLoader = PddPluginLoader.getInstance();
  1806.                 for (String tipoPorta : tipiPorta) {
  1807.                     if(!listTipi.contains(tipoPorta)) {
  1808.                         try {
  1809.                             InRequestProtocolHandler handler = pluginLoader.newInRequestProtocolHandler(tipoPorta);
  1810.                             listHandler.add(handler);
  1811.                             listTipi.add(tipoPorta);
  1812.                         }catch(Throwable t) {
  1813.                             log.error("NewInstance '"+tipoPorta+"' failed: "+t.getMessage(),t);
  1814.                             // Sollevo l'eccezione
  1815.                             HandlerException ex = new HandlerException(t.getMessage(),t);
  1816.                             ex.setIdentitaHandler("InRequestProtocolHandler"+" ["+tipoPorta+"]");
  1817.                             throw ex;
  1818.                         }
  1819.                     }
  1820.                 }
  1821.                 if(!listHandler.isEmpty()) {
  1822.                     mergeList = new ArrayList<>();
  1823.                     mergeList.add(listHandler.toArray(new InRequestProtocolHandler[listHandler.size()]));
  1824.                     mergeList.add(listTipi.toArray(new String[listTipi.size()]));
  1825.                 }
  1826.             }
  1827.         }catch(Throwable t) {
  1828.             log.error(t.getMessage(),t);
  1829.         }
  1830.         if(mergeList==null) {
  1831.             mergeList = new ArrayList<>();
  1832.             mergeList.add(intRequestProtocolHandlers);
  1833.             mergeList.add(tipiInRequestProtocolHandlers);
  1834.         }
  1835.         return mergeList;
  1836.     }
  1837.     private static void _inRequestProtocolHandler(InRequestProtocolContext context,MsgDiagnostico msgDiag,Logger log, InRequestProtocolHandler [] handlers, String [] tipiHandlers, String name) throws HandlerException{
  1838.         if(handlers!=null){
  1839.             for(int i=0; i<handlers.length; i++){
  1840.                 try{
  1841.                     emitDiagnosticInvokeHandlerStart(handlers[i], msgDiag, log);
  1842.                     handlers[i].invoke(context);
  1843.                     emitDiagnosticInvokeHandlerEnd(handlers[i], msgDiag, log);
  1844.                 }catch(Throwable e){
  1845.                     // Sollevo l'eccezione
  1846.                     HandlerException ex = null;
  1847.                     if(e instanceof HandlerException){
  1848.                         ex = (HandlerException) e;
  1849.                     }else{
  1850.                         ex = new HandlerException(e.getMessage(),e);
  1851.                     }
  1852.                     ex.setIdentitaHandler(name+" ["+tipiHandlers[i]+"]");
  1853.                     throw ex;
  1854.                 }
  1855.             }
  1856.         }
  1857.     }
  1858.    
  1859.     public static void outRequest(OutRequestContext context,MsgDiagnostico msgDiag,Logger log) throws HandlerException{
  1860.        
  1861.         if(!GestoreHandlers.initialize){
  1862.             GestoreHandlers.initialize(msgDiag,log,context.getStato());
  1863.         }
  1864.    
  1865.         if(context.getDataElaborazioneMessaggio()==null){
  1866.             context.setDataElaborazioneMessaggio(DateManager.getDate());
  1867.         }
  1868.        
  1869.         // genero date casuali
  1870.         if(GestoreHandlers.properties.generazioneDateCasualiLogAbilitato() && context.getPddContext().getObject(org.openspcoop2.core.constants.Costanti.ID_TRANSAZIONE)!=null){
  1871.             context.setDataElaborazioneMessaggio(GestoreHandlers.generatoreCasualeDati.getProssimaData((String)context.getPddContext().getObject(org.openspcoop2.core.constants.Costanti.ID_TRANSAZIONE)));
  1872.         }
  1873.        
  1874.         // unisco handler generali (props+config) con eventuali handler definiti sulla porta
  1875.         List<Object[]> mergeWithImplementation = mergeWithImplementationEngine(context,GestoreHandlers.outRequestHandlers, GestoreHandlers.tipiOutRequestHandlers, log);
  1876.         OutRequestHandler [] outRequestHandlersUsers = (OutRequestHandler []) mergeWithImplementation.get(0);
  1877.         String [] tipiOutRequestHandlersUsers = (String []) mergeWithImplementation.get(1);
  1878.        
  1879.         // gestisco handler built-in e user
  1880.         if(properties.isMergeHandlerBuiltInAndHandlerUser()) {
  1881.             List<Object[]> list =  merge(GestoreHandlers.outRequestHandlersBuiltIn, GestoreHandlers.tipiOutRequestHandlersBuiltIn,
  1882.                     outRequestHandlersUsers, tipiOutRequestHandlersUsers, new OutRequestHandler [1]);
  1883.             OutRequestHandler [] handlers = (OutRequestHandler []) list.get(0);
  1884.             String [] tipiHandlers = toStringArray(list.get(1));
  1885.             _outRequestHandler(context, msgDiag, log, handlers, tipiHandlers, "OutRequestHandler");
  1886.         }
  1887.         else {
  1888.             _outRequestHandler(context, msgDiag, log, GestoreHandlers.outRequestHandlersBuiltIn, GestoreHandlers.tipiOutRequestHandlersBuiltIn, "OutRequestHandler");
  1889.             _outRequestHandler(context, msgDiag, log, outRequestHandlersUsers, tipiOutRequestHandlersUsers, "OutRequestHandler");
  1890.         }
  1891.        
  1892.     }
  1893.     private static List<Object[]> mergeWithImplementationEngine(OutRequestContext context,OutRequestHandler [] outRequestHandlers,String [] tipiOutRequestHandlers,
  1894.             Logger log) {
  1895.         List<Object[]> mergeList = null;
  1896.         try{
  1897.             List<String> tipiPorta=null;
  1898.             if(context!=null) {
  1899.                 ConfigurazionePdDManager configurazionePdDManager = ConfigurazionePdDManager.getInstance(context.getStato());
  1900.                
  1901.                 RequestInfo requestInfo = null;
  1902.                 if(context.getPddContext()!=null && context.getPddContext().containsKey(org.openspcoop2.core.constants.Costanti.REQUEST_INFO)) {
  1903.                     requestInfo = (RequestInfo) context.getPddContext().getObject(org.openspcoop2.core.constants.Costanti.REQUEST_INFO);
  1904.                 }
  1905.                
  1906.                 if(TipoPdD.DELEGATA.equals(context.getTipoPorta())) {
  1907.                     IDPortaDelegata idPD = null;
  1908.                     if(context.getIntegrazione()!=null && context.getIntegrazione().getIdPD()!=null) {
  1909.                         idPD = context.getIntegrazione().getIdPD();
  1910.                     }
  1911.                     else if(requestInfo!=null && requestInfo.getProtocolContext()!=null && requestInfo.getProtocolContext().getInterfaceName()!=null) {
  1912.                         idPD = new IDPortaDelegata();
  1913.                         idPD.setNome(requestInfo.getProtocolContext().getInterfaceName());
  1914.                     }
  1915.                     PortaDelegata pd=configurazionePdDManager.getPortaDelegataSafeMethod(idPD, requestInfo);
  1916.                     tipiPorta=configurazionePdDManager.getOutRequestHandlers(pd);
  1917.                     /**System.out.println("OutRequestContext find PD '"+pd.getNome()+"'");*/
  1918.                 }
  1919.                 else if(TipoPdD.APPLICATIVA.equals(context.getTipoPorta())) {
  1920.                     IDPortaApplicativa idPA = null;
  1921.                     if(context.getIntegrazione()!=null && context.getIntegrazione().getIdPA()!=null) {
  1922.                         idPA = context.getIntegrazione().getIdPA();
  1923.                     }
  1924.                     else if(requestInfo!=null && requestInfo.getProtocolContext()!=null && requestInfo.getProtocolContext().getInterfaceName()!=null) {
  1925.                         idPA = new IDPortaApplicativa();
  1926.                         idPA.setNome(requestInfo.getProtocolContext().getInterfaceName());
  1927.                     }
  1928.                     PortaApplicativa pa=configurazionePdDManager.getPortaApplicativaSafeMethod(idPA, requestInfo);
  1929.                     tipiPorta=configurazionePdDManager.getOutRequestHandlers(pa);
  1930.                     /**System.out.println("OutRequestContext find PA '"+pa.getNome()+"'");*/
  1931.                 }
  1932.             }
  1933.             if(tipiPorta!=null && !tipiPorta.isEmpty()) {
  1934.                 List<OutRequestHandler> listHandler = new ArrayList<>();
  1935.                 List<String> listTipi = new ArrayList<>();
  1936.                 if(outRequestHandlers!=null && outRequestHandlers.length>0) {
  1937.                     for (int i = 0; i < outRequestHandlers.length; i++) {
  1938.                         listHandler.add(outRequestHandlers[i]);
  1939.                         listTipi.add(tipiOutRequestHandlers[i]);
  1940.                     }
  1941.                 }
  1942.                 PddPluginLoader pluginLoader = PddPluginLoader.getInstance();
  1943.                 for (String tipoPorta : tipiPorta) {
  1944.                     if(!listTipi.contains(tipoPorta)) {
  1945.                         try {
  1946.                             OutRequestHandler handler = pluginLoader.newOutRequestHandler(tipoPorta);
  1947.                             listHandler.add(handler);
  1948.                             listTipi.add(tipoPorta);
  1949.                         }catch(Throwable t) {
  1950.                             log.error("NewInstance '"+tipoPorta+"' failed: "+t.getMessage(),t);
  1951.                             // Sollevo l'eccezione
  1952.                             HandlerException ex = new HandlerException(t.getMessage(),t);
  1953.                             ex.setIdentitaHandler("OutRequestHandler"+" ["+tipoPorta+"]");
  1954.                             throw ex;
  1955.                         }
  1956.                     }
  1957.                 }
  1958.                 if(!listHandler.isEmpty()) {
  1959.                     mergeList = new ArrayList<>();
  1960.                     mergeList.add(listHandler.toArray(new OutRequestHandler[listHandler.size()]));
  1961.                     mergeList.add(listTipi.toArray(new String[listTipi.size()]));
  1962.                 }
  1963.             }
  1964.         }catch(Throwable t) {
  1965.             log.error(t.getMessage(),t);
  1966.         }
  1967.         if(mergeList==null) {
  1968.             mergeList = new ArrayList<>();
  1969.             mergeList.add(outRequestHandlers);
  1970.             mergeList.add(tipiOutRequestHandlers);
  1971.         }
  1972.         return mergeList;
  1973.     }
  1974.     private static void _outRequestHandler(OutRequestContext context,MsgDiagnostico msgDiag,Logger log, OutRequestHandler [] handlers, String [] tipiHandlers, String name) throws HandlerException{
  1975.         if(handlers!=null){
  1976.             for(int i=0; i<handlers.length; i++){
  1977.                 try{
  1978.                     emitDiagnosticInvokeHandlerStart(handlers[i], msgDiag, log);
  1979.                     handlers[i].invoke(context);
  1980.                     emitDiagnosticInvokeHandlerEnd(handlers[i], msgDiag, log);
  1981.                 }catch(Throwable e){
  1982.                     // Sollevo l'eccezione
  1983.                     HandlerException ex = null;
  1984.                     if(e instanceof HandlerException){
  1985.                         ex = (HandlerException) e;
  1986.                     }else{
  1987.                         ex = new HandlerException(e.getMessage(),e);
  1988.                     }
  1989.                     ex.setIdentitaHandler(name+" ["+tipiHandlers[i]+"]");
  1990.                     throw ex;
  1991.                 }
  1992.             }
  1993.         }
  1994.     }
  1995.    
  1996.     public static void postOutRequest(PostOutRequestContext context,MsgDiagnostico msgDiag,Logger log) throws HandlerException{
  1997.        
  1998.         if(!GestoreHandlers.initialize){
  1999.             GestoreHandlers.initialize(msgDiag,log,context.getStato());
  2000.         }
  2001.    
  2002.         if(context.getDataElaborazioneMessaggio()==null){
  2003.             context.setDataElaborazioneMessaggio(DateManager.getDate());
  2004.         }
  2005.        
  2006.         // genero date casuali
  2007.         if(GestoreHandlers.properties.generazioneDateCasualiLogAbilitato() && context.getPddContext().getObject(org.openspcoop2.core.constants.Costanti.ID_TRANSAZIONE)!=null){
  2008.             context.setDataElaborazioneMessaggio(GestoreHandlers.generatoreCasualeDati.getProssimaData((String)context.getPddContext().getObject(org.openspcoop2.core.constants.Costanti.ID_TRANSAZIONE)));
  2009.         }
  2010.        
  2011.         // unisco handler generali (props+config) con eventuali handler definiti sulla porta
  2012.         List<Object[]> mergeWithImplementation = mergeWithImplementationEngine(context,GestoreHandlers.postOutRequestHandlers, GestoreHandlers.tipiPostOutRequestHandlers, log);
  2013.         PostOutRequestHandler [] postOutRequestHandlersUsers = (PostOutRequestHandler []) mergeWithImplementation.get(0);
  2014.         String [] tipiPostOutRequestHandlersUsers = (String []) mergeWithImplementation.get(1);
  2015.        
  2016.         // gestisco handler built-in e user
  2017.         if(properties.isMergeHandlerBuiltInAndHandlerUser()) {
  2018.             List<Object[]> list =  merge(GestoreHandlers.postOutRequestHandlersBuiltIn, GestoreHandlers.tipiPostOutRequestHandlersBuiltIn,
  2019.                     postOutRequestHandlersUsers, tipiPostOutRequestHandlersUsers, new PostOutRequestHandler [1]);
  2020.             PostOutRequestHandler [] handlers = (PostOutRequestHandler []) list.get(0);
  2021.             String [] tipiHandlers = toStringArray(list.get(1));
  2022.             _postOutRequestHandler(context, msgDiag, log, handlers, tipiHandlers, "PostOutRequestHandler");
  2023.         }
  2024.         else {
  2025.             _postOutRequestHandler(context, msgDiag, log, GestoreHandlers.postOutRequestHandlersBuiltIn, GestoreHandlers.tipiPostOutRequestHandlersBuiltIn, "PostOutRequestHandler");
  2026.             _postOutRequestHandler(context, msgDiag, log, postOutRequestHandlersUsers, tipiPostOutRequestHandlersUsers, "PostOutRequestHandler");
  2027.         }
  2028.        
  2029.     }
  2030.     private static List<Object[]> mergeWithImplementationEngine(PostOutRequestContext context,PostOutRequestHandler [] postOutRequestHandlers,String [] tipiPostOutRequestHandlers,
  2031.             Logger log) {
  2032.         List<Object[]> mergeList = null;
  2033.         try{
  2034.             List<String> tipiPorta=null;
  2035.             if(context!=null) {
  2036.                 ConfigurazionePdDManager configurazionePdDManager = ConfigurazionePdDManager.getInstance(context.getStato());
  2037.                
  2038.                 RequestInfo requestInfo = null;
  2039.                 if(context.getPddContext()!=null && context.getPddContext().containsKey(org.openspcoop2.core.constants.Costanti.REQUEST_INFO)) {
  2040.                     requestInfo = (RequestInfo) context.getPddContext().getObject(org.openspcoop2.core.constants.Costanti.REQUEST_INFO);
  2041.                 }
  2042.                
  2043.                 if(TipoPdD.DELEGATA.equals(context.getTipoPorta())) {
  2044.                     IDPortaDelegata idPD = null;
  2045.                     if(context.getIntegrazione()!=null && context.getIntegrazione().getIdPD()!=null) {
  2046.                         idPD = context.getIntegrazione().getIdPD();
  2047.                     }
  2048.                     else if(requestInfo!=null && requestInfo.getProtocolContext()!=null && requestInfo.getProtocolContext().getInterfaceName()!=null) {
  2049.                         idPD = new IDPortaDelegata();
  2050.                         idPD.setNome(requestInfo.getProtocolContext().getInterfaceName());
  2051.                     }
  2052.                     PortaDelegata pd=configurazionePdDManager.getPortaDelegataSafeMethod(idPD, requestInfo);
  2053.                     tipiPorta=configurazionePdDManager.getPostOutRequestHandlers(pd);
  2054.                     /**System.out.println("PostOutRequestContext find PD '"+pd.getNome()+"'");*/
  2055.                 }
  2056.                 else if(TipoPdD.APPLICATIVA.equals(context.getTipoPorta())) {
  2057.                     IDPortaApplicativa idPA = null;
  2058.                     if(context.getIntegrazione()!=null && context.getIntegrazione().getIdPA()!=null) {
  2059.                         idPA = context.getIntegrazione().getIdPA();
  2060.                     }
  2061.                     else if(requestInfo!=null && requestInfo.getProtocolContext()!=null && requestInfo.getProtocolContext().getInterfaceName()!=null) {
  2062.                         idPA = new IDPortaApplicativa();
  2063.                         idPA.setNome(requestInfo.getProtocolContext().getInterfaceName());
  2064.                     }
  2065.                     PortaApplicativa pa=configurazionePdDManager.getPortaApplicativaSafeMethod(idPA, requestInfo);
  2066.                     tipiPorta=configurazionePdDManager.getPostOutRequestHandlers(pa);
  2067.                     /**System.out.println("PostOutRequestContext find PA '"+pa.getNome()+"'");*/
  2068.                 }
  2069.             }
  2070.             if(tipiPorta!=null && !tipiPorta.isEmpty()) {
  2071.                 List<PostOutRequestHandler> listHandler = new ArrayList<>();
  2072.                 List<String> listTipi = new ArrayList<>();
  2073.                 if(postOutRequestHandlers!=null && postOutRequestHandlers.length>0) {
  2074.                     for (int i = 0; i < postOutRequestHandlers.length; i++) {
  2075.                         listHandler.add(postOutRequestHandlers[i]);
  2076.                         listTipi.add(tipiPostOutRequestHandlers[i]);
  2077.                     }
  2078.                 }
  2079.                 PddPluginLoader pluginLoader = PddPluginLoader.getInstance();
  2080.                 for (String tipoPorta : tipiPorta) {
  2081.                     if(!listTipi.contains(tipoPorta)) {
  2082.                         try {
  2083.                             PostOutRequestHandler handler = pluginLoader.newPostOutRequestHandler(tipoPorta);
  2084.                             listHandler.add(handler);
  2085.                             listTipi.add(tipoPorta);
  2086.                         }catch(Throwable t) {
  2087.                             log.error("NewInstance '"+tipoPorta+"' failed: "+t.getMessage(),t);
  2088.                             // Sollevo l'eccezione
  2089.                             HandlerException ex = new HandlerException(t.getMessage(),t);
  2090.                             ex.setIdentitaHandler("PostOutRequestHandler"+" ["+tipoPorta+"]");
  2091.                             throw ex;
  2092.                         }
  2093.                     }
  2094.                 }
  2095.                 if(!listHandler.isEmpty()) {
  2096.                     mergeList = new ArrayList<>();
  2097.                     mergeList.add(listHandler.toArray(new PostOutRequestHandler[listHandler.size()]));
  2098.                     mergeList.add(listTipi.toArray(new String[listTipi.size()]));
  2099.                 }
  2100.             }
  2101.         }catch(Throwable t) {
  2102.             log.error(t.getMessage(),t);
  2103.         }
  2104.         if(mergeList==null) {
  2105.             mergeList = new ArrayList<>();
  2106.             mergeList.add(postOutRequestHandlers);
  2107.             mergeList.add(tipiPostOutRequestHandlers);
  2108.         }
  2109.         return mergeList;
  2110.     }
  2111.     private static void _postOutRequestHandler(PostOutRequestContext context,MsgDiagnostico msgDiag,Logger log, PostOutRequestHandler [] handlers, String [] tipiHandlers, String name) throws HandlerException{
  2112.         if(handlers!=null){
  2113.             for(int i=0; i<handlers.length; i++){
  2114.                 try{
  2115.                     emitDiagnosticInvokeHandlerStart(handlers[i], msgDiag, log);
  2116.                     handlers[i].invoke(context);
  2117.                     emitDiagnosticInvokeHandlerEnd(handlers[i], msgDiag, log);
  2118.                 }catch(Throwable e){
  2119.                     // Sollevo l'eccezione
  2120.                     HandlerException ex = null;
  2121.                     if(e instanceof HandlerException){
  2122.                         ex = (HandlerException) e;
  2123.                     }else{
  2124.                         ex = new HandlerException(e.getMessage(),e);
  2125.                     }
  2126.                     ex.setIdentitaHandler(name+" ["+tipiHandlers[i]+"]");
  2127.                     throw ex;
  2128.                 }
  2129.             }
  2130.         }
  2131.     }
  2132.    
  2133.     public static void preInResponse(PreInResponseContext context,MsgDiagnostico msgDiag,Logger log) throws HandlerException{
  2134.        
  2135.         if(!GestoreHandlers.initialize){
  2136.             GestoreHandlers.initialize(msgDiag,log,context.getStato());
  2137.         }
  2138.    
  2139.         if(context.getDataElaborazioneMessaggio()==null){
  2140.             context.setDataElaborazioneMessaggio(DateManager.getDate());
  2141.         }
  2142.        
  2143.         // genero date casuali
  2144.         if(GestoreHandlers.properties.generazioneDateCasualiLogAbilitato() && context.getPddContext().getObject(org.openspcoop2.core.constants.Costanti.ID_TRANSAZIONE)!=null){
  2145.             context.setDataElaborazioneMessaggio(GestoreHandlers.generatoreCasualeDati.getProssimaData((String)context.getPddContext().getObject(org.openspcoop2.core.constants.Costanti.ID_TRANSAZIONE)));
  2146.         }
  2147.        
  2148.         // unisco handler generali (props+config) con eventuali handler definiti sulla porta
  2149.         List<Object[]> mergeWithImplementation = mergeWithImplementationEngine(context,GestoreHandlers.preInResponseHandlers, GestoreHandlers.tipiPreInResponseHandlers, log);
  2150.         PreInResponseHandler [] preInResponseHandlersUsers = (PreInResponseHandler []) mergeWithImplementation.get(0);
  2151.         String [] tipiPreInResponseHandlersUsers = (String []) mergeWithImplementation.get(1);
  2152.        
  2153.         // gestisco handler built-in e user
  2154.         if(properties.isMergeHandlerBuiltInAndHandlerUser()) {
  2155.             List<Object[]> list =  merge(GestoreHandlers.preInResponseHandlersBuiltIn, GestoreHandlers.tipiPreInResponseHandlersBuiltIn,
  2156.                     preInResponseHandlersUsers, tipiPreInResponseHandlersUsers, new PreInResponseHandler [1]);
  2157.             PreInResponseHandler [] handlers = (PreInResponseHandler []) list.get(0);
  2158.             String [] tipiHandlers = toStringArray(list.get(1));
  2159.             _preInResponseHandler(context, msgDiag, log, handlers, tipiHandlers, "PreInResponseHandler");
  2160.         }
  2161.         else {
  2162.             _preInResponseHandler(context, msgDiag, log, GestoreHandlers.preInResponseHandlersBuiltIn, GestoreHandlers.tipiPreInResponseHandlersBuiltIn, "PreInResponseHandler");
  2163.             _preInResponseHandler(context, msgDiag, log, preInResponseHandlersUsers, tipiPreInResponseHandlersUsers, "PreInResponseHandler");
  2164.         }
  2165.        
  2166.     }
  2167.     private static List<Object[]> mergeWithImplementationEngine(PreInResponseContext context,PreInResponseHandler [] preInResponseHandlers,String [] tipiPreInResponseHandlers,
  2168.             Logger log) {
  2169.         List<Object[]> mergeList = null;
  2170.         try{
  2171.             List<String> tipiPorta=null;
  2172.             if(context!=null) {
  2173.                 ConfigurazionePdDManager configurazionePdDManager = ConfigurazionePdDManager.getInstance(context.getStato());
  2174.                
  2175.                 RequestInfo requestInfo = null;
  2176.                 if(context.getPddContext()!=null && context.getPddContext().containsKey(org.openspcoop2.core.constants.Costanti.REQUEST_INFO)) {
  2177.                     requestInfo = (RequestInfo) context.getPddContext().getObject(org.openspcoop2.core.constants.Costanti.REQUEST_INFO);
  2178.                 }
  2179.                
  2180.                 if(TipoPdD.DELEGATA.equals(context.getTipoPorta())) {
  2181.                     IDPortaDelegata idPD = null;
  2182.                     if(context.getIntegrazione()!=null && context.getIntegrazione().getIdPD()!=null) {
  2183.                         idPD = context.getIntegrazione().getIdPD();
  2184.                     }
  2185.                     else if(requestInfo!=null && requestInfo.getProtocolContext()!=null && requestInfo.getProtocolContext().getInterfaceName()!=null) {
  2186.                         idPD = new IDPortaDelegata();
  2187.                         idPD.setNome(requestInfo.getProtocolContext().getInterfaceName());
  2188.                     }
  2189.                     PortaDelegata pd=configurazionePdDManager.getPortaDelegataSafeMethod(idPD, requestInfo);
  2190.                     tipiPorta=configurazionePdDManager.getPreInResponseHandlers(pd);
  2191.                     /**System.out.println("PreInResponseContext find PD '"+pd.getNome()+"'");*/
  2192.                 }
  2193.                 else if(TipoPdD.APPLICATIVA.equals(context.getTipoPorta())) {
  2194.                     IDPortaApplicativa idPA = null;
  2195.                     if(context.getIntegrazione()!=null && context.getIntegrazione().getIdPA()!=null) {
  2196.                         idPA = context.getIntegrazione().getIdPA();
  2197.                     }
  2198.                     else if(requestInfo!=null && requestInfo.getProtocolContext()!=null && requestInfo.getProtocolContext().getInterfaceName()!=null) {
  2199.                         idPA = new IDPortaApplicativa();
  2200.                         idPA.setNome(requestInfo.getProtocolContext().getInterfaceName());
  2201.                     }
  2202.                     PortaApplicativa pa=configurazionePdDManager.getPortaApplicativaSafeMethod(idPA, requestInfo);
  2203.                     tipiPorta=configurazionePdDManager.getPreInResponseHandlers(pa);
  2204.                     /**System.out.println("PreInResponseContext find PA '"+pa.getNome()+"'");*/
  2205.                 }
  2206.             }
  2207.             if(tipiPorta!=null && !tipiPorta.isEmpty()) {
  2208.                 List<PreInResponseHandler> listHandler = new ArrayList<>();
  2209.                 List<String> listTipi = new ArrayList<>();
  2210.                 if(preInResponseHandlers!=null && preInResponseHandlers.length>0) {
  2211.                     for (int i = 0; i < preInResponseHandlers.length; i++) {
  2212.                         listHandler.add(preInResponseHandlers[i]);
  2213.                         listTipi.add(tipiPreInResponseHandlers[i]);
  2214.                     }
  2215.                 }
  2216.                 PddPluginLoader pluginLoader = PddPluginLoader.getInstance();
  2217.                 for (String tipoPorta : tipiPorta) {
  2218.                     if(!listTipi.contains(tipoPorta)) {
  2219.                         try {
  2220.                             PreInResponseHandler handler = pluginLoader.newPreInResponseHandler(tipoPorta);
  2221.                             listHandler.add(handler);
  2222.                             listTipi.add(tipoPorta);
  2223.                         }catch(Throwable t) {
  2224.                             log.error("NewInstance '"+tipoPorta+"' failed: "+t.getMessage(),t);
  2225.                             // Sollevo l'eccezione
  2226.                             HandlerException ex = new HandlerException(t.getMessage(),t);
  2227.                             ex.setIdentitaHandler("PreInResponseHandler"+" ["+tipoPorta+"]");
  2228.                             throw ex;
  2229.                         }
  2230.                     }
  2231.                 }
  2232.                 if(!listHandler.isEmpty()) {
  2233.                     mergeList = new ArrayList<>();
  2234.                     mergeList.add(listHandler.toArray(new PreInResponseHandler[listHandler.size()]));
  2235.                     mergeList.add(listTipi.toArray(new String[listTipi.size()]));
  2236.                 }
  2237.             }
  2238.         }catch(Throwable t) {
  2239.             log.error(t.getMessage(),t);
  2240.         }
  2241.         if(mergeList==null) {
  2242.             mergeList = new ArrayList<>();
  2243.             mergeList.add(preInResponseHandlers);
  2244.             mergeList.add(tipiPreInResponseHandlers);
  2245.         }
  2246.         return mergeList;
  2247.     }
  2248.     private static void _preInResponseHandler(PreInResponseContext context,MsgDiagnostico msgDiag,Logger log, PreInResponseHandler [] handlers, String [] tipiHandlers, String name) throws HandlerException{
  2249.         if(handlers!=null){
  2250.             for(int i=0; i<handlers.length; i++){
  2251.                 try{
  2252.                     emitDiagnosticInvokeHandlerStart(handlers[i], msgDiag, log);
  2253.                     handlers[i].invoke(context);
  2254.                     emitDiagnosticInvokeHandlerEnd(handlers[i], msgDiag, log);
  2255.                 }catch(Throwable e){
  2256.                     // Sollevo l'eccezione
  2257.                     HandlerException ex = null;
  2258.                     if(e instanceof HandlerException){
  2259.                         ex = (HandlerException) e;
  2260.                     }else{
  2261.                         ex = new HandlerException(e.getMessage(),e);
  2262.                     }
  2263.                     ex.setIdentitaHandler(name+" ["+tipiHandlers[i]+"]");
  2264.                     throw ex;
  2265.                 }
  2266.             }
  2267.         }
  2268.     }
  2269.    
  2270.     public static void inResponse(InResponseContext context,MsgDiagnostico msgDiag,Logger log) throws HandlerException{
  2271.        
  2272.         if(!GestoreHandlers.initialize){
  2273.             GestoreHandlers.initialize(msgDiag,log,context.getStato());
  2274.         }
  2275.    
  2276.         if(context.getDataElaborazioneMessaggio()==null){
  2277.             context.setDataElaborazioneMessaggio(DateManager.getDate());
  2278.         }
  2279.        
  2280.         // genero date casuali
  2281.         if(GestoreHandlers.properties.generazioneDateCasualiLogAbilitato() && context.getPddContext().getObject(org.openspcoop2.core.constants.Costanti.ID_TRANSAZIONE)!=null){
  2282.             context.setDataElaborazioneMessaggio(GestoreHandlers.generatoreCasualeDati.getProssimaData((String)context.getPddContext().getObject(org.openspcoop2.core.constants.Costanti.ID_TRANSAZIONE)));
  2283.         }
  2284.        
  2285.         // unisco handler generali (props+config) con eventuali handler definiti sulla porta
  2286.         List<Object[]> mergeWithImplementation = mergeWithImplementationEngine(context,GestoreHandlers.inResponseHandlers, GestoreHandlers.tipiInResponseHandlers, log);
  2287.         InResponseHandler [] inResponseHandlersUsers = (InResponseHandler []) mergeWithImplementation.get(0);
  2288.         String [] tipiInResponseHandlersUsers = (String []) mergeWithImplementation.get(1);
  2289.        
  2290.         // gestisco handler built-in e user
  2291.         if(properties.isMergeHandlerBuiltInAndHandlerUser()) {
  2292.             List<Object[]> list =  merge(GestoreHandlers.inResponseHandlersBuiltIn, GestoreHandlers.tipiInResponseHandlersBuiltIn,
  2293.                     inResponseHandlersUsers, tipiInResponseHandlersUsers, new InResponseHandler [1]);
  2294.             InResponseHandler [] handlers = (InResponseHandler []) list.get(0);
  2295.             String [] tipiHandlers = toStringArray(list.get(1));
  2296.             _inResponseHandler(context, msgDiag, log, handlers, tipiHandlers, "InResponseHandler");
  2297.         }
  2298.         else {
  2299.             _inResponseHandler(context, msgDiag, log, GestoreHandlers.inResponseHandlersBuiltIn, GestoreHandlers.tipiInResponseHandlersBuiltIn, "InResponseHandler");
  2300.             _inResponseHandler(context, msgDiag, log, inResponseHandlersUsers, tipiInResponseHandlersUsers, "InResponseHandler");
  2301.         }
  2302.        
  2303.     }
  2304.     private static List<Object[]> mergeWithImplementationEngine(InResponseContext context,InResponseHandler [] inResponseHandlers,String [] tipiInResponseHandlers,
  2305.             Logger log) {
  2306.         List<Object[]> mergeList = null;
  2307.         try{
  2308.             List<String> tipiPorta=null;
  2309.             if(context!=null) {
  2310.                 ConfigurazionePdDManager configurazionePdDManager = ConfigurazionePdDManager.getInstance(context.getStato());
  2311.                
  2312.                 RequestInfo requestInfo = null;
  2313.                 if(context.getPddContext()!=null && context.getPddContext().containsKey(org.openspcoop2.core.constants.Costanti.REQUEST_INFO)) {
  2314.                     requestInfo = (RequestInfo) context.getPddContext().getObject(org.openspcoop2.core.constants.Costanti.REQUEST_INFO);
  2315.                 }
  2316.                
  2317.                 if(TipoPdD.DELEGATA.equals(context.getTipoPorta())) {
  2318.                     IDPortaDelegata idPD = null;
  2319.                     if(context.getIntegrazione()!=null && context.getIntegrazione().getIdPD()!=null) {
  2320.                         idPD = context.getIntegrazione().getIdPD();
  2321.                     }
  2322.                     else if(requestInfo!=null && requestInfo.getProtocolContext()!=null && requestInfo.getProtocolContext().getInterfaceName()!=null) {
  2323.                         idPD = new IDPortaDelegata();
  2324.                         idPD.setNome(requestInfo.getProtocolContext().getInterfaceName());
  2325.                     }
  2326.                     PortaDelegata pd=configurazionePdDManager.getPortaDelegataSafeMethod(idPD, requestInfo);
  2327.                     tipiPorta=configurazionePdDManager.getInResponseHandlers(pd);
  2328.                     /**System.out.println("InResponseContext find PD '"+pd.getNome()+"'");*/
  2329.                 }
  2330.                 else if(TipoPdD.APPLICATIVA.equals(context.getTipoPorta())) {
  2331.                     IDPortaApplicativa idPA = null;
  2332.                     if(context.getIntegrazione()!=null && context.getIntegrazione().getIdPA()!=null) {
  2333.                         idPA = context.getIntegrazione().getIdPA();
  2334.                     }
  2335.                     else if(requestInfo!=null && requestInfo.getProtocolContext()!=null && requestInfo.getProtocolContext().getInterfaceName()!=null) {
  2336.                         idPA = new IDPortaApplicativa();
  2337.                         idPA.setNome(requestInfo.getProtocolContext().getInterfaceName());
  2338.                     }
  2339.                     PortaApplicativa pa=configurazionePdDManager.getPortaApplicativaSafeMethod(idPA, requestInfo);
  2340.                     tipiPorta=configurazionePdDManager.getInResponseHandlers(pa);
  2341.                     /**System.out.println("InResponseContext find PA '"+pa.getNome()+"'");*/
  2342.                 }
  2343.             }
  2344.             if(tipiPorta!=null && !tipiPorta.isEmpty()) {
  2345.                 List<InResponseHandler> listHandler = new ArrayList<>();
  2346.                 List<String> listTipi = new ArrayList<>();
  2347.                 if(inResponseHandlers!=null && inResponseHandlers.length>0) {
  2348.                     for (int i = 0; i < inResponseHandlers.length; i++) {
  2349.                         listHandler.add(inResponseHandlers[i]);
  2350.                         listTipi.add(tipiInResponseHandlers[i]);
  2351.                     }
  2352.                 }
  2353.                 PddPluginLoader pluginLoader = PddPluginLoader.getInstance();
  2354.                 for (String tipoPorta : tipiPorta) {
  2355.                     if(!listTipi.contains(tipoPorta)) {
  2356.                         try {
  2357.                             InResponseHandler handler = pluginLoader.newInResponseHandler(tipoPorta);
  2358.                             listHandler.add(handler);
  2359.                             listTipi.add(tipoPorta);
  2360.                         }catch(Throwable t) {
  2361.                             log.error("NewInstance '"+tipoPorta+"' failed: "+t.getMessage(),t);
  2362.                             // Sollevo l'eccezione
  2363.                             HandlerException ex = new HandlerException(t.getMessage(),t);
  2364.                             ex.setIdentitaHandler("InResponseHandler"+" ["+tipoPorta+"]");
  2365.                             throw ex;
  2366.                         }
  2367.                     }
  2368.                 }
  2369.                 if(!listHandler.isEmpty()) {
  2370.                     mergeList = new ArrayList<>();
  2371.                     mergeList.add(listHandler.toArray(new InResponseHandler[listHandler.size()]));
  2372.                     mergeList.add(listTipi.toArray(new String[listTipi.size()]));
  2373.                 }
  2374.             }
  2375.         }catch(Throwable t) {
  2376.             log.error(t.getMessage(),t);
  2377.         }
  2378.         if(mergeList==null) {
  2379.             mergeList = new ArrayList<>();
  2380.             mergeList.add(inResponseHandlers);
  2381.             mergeList.add(tipiInResponseHandlers);
  2382.         }
  2383.         return mergeList;
  2384.     }
  2385.     private static void _inResponseHandler(InResponseContext context,MsgDiagnostico msgDiag,Logger log, InResponseHandler [] handlers, String [] tipiHandlers, String name) throws HandlerException{
  2386.         if(handlers!=null){
  2387.             for(int i=0; i<handlers.length; i++){
  2388.                 try{
  2389.                     emitDiagnosticInvokeHandlerStart(handlers[i], msgDiag, log);
  2390.                     handlers[i].invoke(context);
  2391.                     emitDiagnosticInvokeHandlerEnd(handlers[i], msgDiag, log);
  2392.                 }catch(Throwable e){
  2393.                     // Sollevo l'eccezione
  2394.                     HandlerException ex = null;
  2395.                     if(e instanceof HandlerException){
  2396.                         ex = (HandlerException) e;
  2397.                     }else{
  2398.                         ex = new HandlerException(e.getMessage(),e);
  2399.                     }
  2400.                     ex.setIdentitaHandler(name+" ["+tipiHandlers[i]+"]");
  2401.                     throw ex;
  2402.                 }
  2403.             }
  2404.         }
  2405.     }
  2406.    
  2407.     public static void outResponse(OutResponseContext context,MsgDiagnostico msgDiag,Logger log) throws HandlerException{
  2408.        
  2409.         if(!GestoreHandlers.initialize){
  2410.             GestoreHandlers.initialize(msgDiag,log,context.getStato());
  2411.         }
  2412.    
  2413.         if(context.getDataElaborazioneMessaggio()==null){
  2414.             context.setDataElaborazioneMessaggio(DateManager.getDate());
  2415.         }
  2416.        
  2417.         // genero date casuali
  2418.         if(GestoreHandlers.properties.generazioneDateCasualiLogAbilitato() && context.getPddContext().getObject(org.openspcoop2.core.constants.Costanti.ID_TRANSAZIONE)!=null){
  2419.             context.setDataElaborazioneMessaggio(GestoreHandlers.generatoreCasualeDati.getProssimaData((String)context.getPddContext().getObject(org.openspcoop2.core.constants.Costanti.ID_TRANSAZIONE)));
  2420.         }
  2421.        
  2422.         // unisco handler generali (props+config) con eventuali handler definiti sulla porta
  2423.         List<Object[]> mergeWithImplementation = mergeWithImplementationEngine(context,GestoreHandlers.outResponseHandlers, GestoreHandlers.tipiOutResponseHandlers, log);
  2424.         OutResponseHandler [] outResponseHandlersUsers = (OutResponseHandler []) mergeWithImplementation.get(0);
  2425.         String [] tipiOutResponseHandlersUsers = (String []) mergeWithImplementation.get(1);
  2426.        
  2427.         // gestisco handler built-in e user
  2428.         if(properties.isMergeHandlerBuiltInAndHandlerUser()) {
  2429.             List<Object[]> list =  merge(GestoreHandlers.outResponseHandlersBuiltIn, GestoreHandlers.tipiOutResponseHandlersBuiltIn,
  2430.                     outResponseHandlersUsers, tipiOutResponseHandlersUsers, new OutResponseHandler [1]);
  2431.             OutResponseHandler [] handlers = (OutResponseHandler []) list.get(0);
  2432.             String [] tipiHandlers = toStringArray(list.get(1));
  2433.             _outResponseHandler(context, msgDiag, log, handlers, tipiHandlers, "OutResponseHandler");
  2434.         }
  2435.         else {
  2436.             _outResponseHandler(context, msgDiag, log, GestoreHandlers.outResponseHandlersBuiltIn, GestoreHandlers.tipiOutResponseHandlersBuiltIn, "OutResponseHandler");
  2437.             _outResponseHandler(context, msgDiag, log, outResponseHandlersUsers, tipiOutResponseHandlersUsers, "OutResponseHandler");
  2438.         }
  2439.        
  2440.     }
  2441.     private static List<Object[]> mergeWithImplementationEngine(OutResponseContext context,OutResponseHandler [] outResponseHandlers,String [] tipiOutResponseHandlers,
  2442.             Logger log) {
  2443.         List<Object[]> mergeList = null;
  2444.         try{
  2445.             List<String> tipiPorta=null;
  2446.             if(context!=null) {
  2447.                 ConfigurazionePdDManager configurazionePdDManager = ConfigurazionePdDManager.getInstance(context.getStato());
  2448.                
  2449.                 RequestInfo requestInfo = null;
  2450.                 if(context.getPddContext()!=null && context.getPddContext().containsKey(org.openspcoop2.core.constants.Costanti.REQUEST_INFO)) {
  2451.                     requestInfo = (RequestInfo) context.getPddContext().getObject(org.openspcoop2.core.constants.Costanti.REQUEST_INFO);
  2452.                 }
  2453.                
  2454.                 if(TipoPdD.DELEGATA.equals(context.getTipoPorta())) {
  2455.                     IDPortaDelegata idPD = null;
  2456.                     if(context.getIntegrazione()!=null && context.getIntegrazione().getIdPD()!=null) {
  2457.                         idPD = context.getIntegrazione().getIdPD();
  2458.                     }
  2459.                     else if(requestInfo!=null && requestInfo.getProtocolContext()!=null && requestInfo.getProtocolContext().getInterfaceName()!=null) {
  2460.                         idPD = new IDPortaDelegata();
  2461.                         idPD.setNome(requestInfo.getProtocolContext().getInterfaceName());
  2462.                     }
  2463.                     PortaDelegata pd=configurazionePdDManager.getPortaDelegataSafeMethod(idPD, requestInfo);
  2464.                     tipiPorta=configurazionePdDManager.getOutResponseHandlers(pd);
  2465.                     /**System.out.println("OutResponseContext find PD '"+pd.getNome()+"'");*/
  2466.                 }
  2467.                 else if(TipoPdD.APPLICATIVA.equals(context.getTipoPorta())) {
  2468.                     IDPortaApplicativa idPA = null;
  2469.                     if(context.getIntegrazione()!=null && context.getIntegrazione().getIdPA()!=null) {
  2470.                         idPA = context.getIntegrazione().getIdPA();
  2471.                     }
  2472.                     else if(requestInfo!=null && requestInfo.getProtocolContext()!=null && requestInfo.getProtocolContext().getInterfaceName()!=null) {
  2473.                         idPA = new IDPortaApplicativa();
  2474.                         idPA.setNome(requestInfo.getProtocolContext().getInterfaceName());
  2475.                     }
  2476.                     PortaApplicativa pa=configurazionePdDManager.getPortaApplicativaSafeMethod(idPA, requestInfo);
  2477.                     tipiPorta=configurazionePdDManager.getOutResponseHandlers(pa);
  2478.                     /**System.out.println("OutResponseContext find PA '"+pa.getNome()+"'");*/
  2479.                 }
  2480.             }
  2481.             if(tipiPorta!=null && !tipiPorta.isEmpty()) {
  2482.                 List<OutResponseHandler> listHandler = new ArrayList<>();
  2483.                 List<String> listTipi = new ArrayList<>();
  2484.                 if(outResponseHandlers!=null && outResponseHandlers.length>0) {
  2485.                     for (int i = 0; i < outResponseHandlers.length; i++) {
  2486.                         listHandler.add(outResponseHandlers[i]);
  2487.                         listTipi.add(tipiOutResponseHandlers[i]);
  2488.                     }
  2489.                 }
  2490.                 PddPluginLoader pluginLoader = PddPluginLoader.getInstance();
  2491.                 for (String tipoPorta : tipiPorta) {
  2492.                     if(!listTipi.contains(tipoPorta)) {
  2493.                         try {
  2494.                             OutResponseHandler handler = pluginLoader.newOutResponseHandler(tipoPorta);
  2495.                             listHandler.add(handler);
  2496.                             listTipi.add(tipoPorta);
  2497.                         }catch(Throwable t) {
  2498.                             log.error("NewInstance '"+tipoPorta+"' failed: "+t.getMessage(),t);
  2499.                             // Sollevo l'eccezione
  2500.                             HandlerException ex = new HandlerException(t.getMessage(),t);
  2501.                             ex.setIdentitaHandler("OutResponseHandler"+" ["+tipoPorta+"]");
  2502.                             throw ex;
  2503.                         }
  2504.                     }
  2505.                 }
  2506.                 if(!listHandler.isEmpty()) {
  2507.                     mergeList = new ArrayList<>();
  2508.                     mergeList.add(listHandler.toArray(new OutResponseHandler[listHandler.size()]));
  2509.                     mergeList.add(listTipi.toArray(new String[listTipi.size()]));
  2510.                 }
  2511.             }
  2512.         }catch(Throwable t) {
  2513.             log.error(t.getMessage(),t);
  2514.         }
  2515.         if(mergeList==null) {
  2516.             mergeList = new ArrayList<>();
  2517.             mergeList.add(outResponseHandlers);
  2518.             mergeList.add(tipiOutResponseHandlers);
  2519.         }
  2520.         return mergeList;
  2521.     }
  2522.     private static void _outResponseHandler(OutResponseContext context,MsgDiagnostico msgDiag,Logger log, OutResponseHandler [] handlers, String [] tipiHandlers, String name) throws HandlerException{
  2523.         if(handlers!=null){
  2524.             for(int i=0; i<handlers.length; i++){
  2525.                 try{
  2526.                     emitDiagnosticInvokeHandlerStart(handlers[i], msgDiag, log);
  2527.                     handlers[i].invoke(context);
  2528.                     emitDiagnosticInvokeHandlerEnd(handlers[i], msgDiag, log);
  2529.                 }catch(Throwable e){
  2530.                     // Sollevo l'eccezione
  2531.                     HandlerException ex = null;
  2532.                     if(e instanceof HandlerException){
  2533.                         ex = (HandlerException) e;
  2534.                     }else{
  2535.                         ex = new HandlerException(e.getMessage(),e);
  2536.                     }
  2537.                     ex.setIdentitaHandler(name+" ["+tipiHandlers[i]+"]");
  2538.                     throw ex;
  2539.                 }
  2540.             }
  2541.         }
  2542.     }
  2543.    
  2544.     public static void postOutResponse(PostOutResponseContext context,MsgDiagnostico msgDiag,Logger log) {
  2545.        
  2546.         if(!GestoreHandlers.initialize){
  2547.             GestoreHandlers.initialize(msgDiag,log,context.getStato());
  2548.         }
  2549.    
  2550.         if(context.getDataElaborazioneMessaggio()==null){
  2551.             context.setDataElaborazioneMessaggio(DateManager.getDate());
  2552.         }
  2553.        
  2554.         // genero date casuali
  2555.         if(GestoreHandlers.properties.generazioneDateCasualiLogAbilitato() && context.getPddContext().getObject(org.openspcoop2.core.constants.Costanti.ID_TRANSAZIONE)!=null){
  2556.             context.setDataElaborazioneMessaggio(GestoreHandlers.generatoreCasualeDati.getProssimaData((String)context.getPddContext().getObject(org.openspcoop2.core.constants.Costanti.ID_TRANSAZIONE)));
  2557.         }
  2558.        
  2559.         // unisco handler generali (props+config) con eventuali handler definiti sulla porta
  2560.         List<Object[]> mergeWithImplementation = mergeWithImplementationEngine(context,GestoreHandlers.postOutResponseHandlers, GestoreHandlers.tipiPostOutResponseHandlers, log);
  2561.         PostOutResponseHandler [] postOutResponseHandlersUsers = (PostOutResponseHandler []) mergeWithImplementation.get(0);
  2562.         String [] tipiPostOutResponseHandlersUsers = (String []) mergeWithImplementation.get(1);
  2563.        
  2564.         // gestisco handler built-in e user
  2565.         if(properties.isMergeHandlerBuiltInAndHandlerUser()) {
  2566.             List<Object[]> list =  merge(GestoreHandlers.postOutResponseHandlersBuiltIn, GestoreHandlers.tipiPostOutResponseHandlersBuiltIn,
  2567.                     postOutResponseHandlersUsers, tipiPostOutResponseHandlersUsers, new PostOutResponseHandler [1]);
  2568.             PostOutResponseHandler [] handlers = (PostOutResponseHandler []) list.get(0);
  2569.             String [] tipiHandlers = toStringArray(list.get(1));
  2570.             _postOutResponseHandler(context, msgDiag, log, handlers, tipiHandlers, "PostOutResponseHandler");
  2571.         }
  2572.         else {
  2573.             _postOutResponseHandler(context, msgDiag, log, GestoreHandlers.postOutResponseHandlersBuiltIn, GestoreHandlers.tipiPostOutResponseHandlersBuiltIn, "PostOutResponseHandler");
  2574.             _postOutResponseHandler(context, msgDiag, log, postOutResponseHandlersUsers, tipiPostOutResponseHandlersUsers, "PostOutResponseHandler");
  2575.         }

  2576.         // Rilascio risorse per la generazione di date casuali
  2577.         GestoreHandlers.rilasciaRisorseDemoMode((String)context.getPddContext().getObject(org.openspcoop2.core.constants.Costanti.ID_TRANSAZIONE));
  2578.     }
  2579.     private static List<Object[]> mergeWithImplementationEngine(PostOutResponseContext context,PostOutResponseHandler [] postOutResponseHandlers,String [] tipiPostOutResponseHandlers,
  2580.             Logger log) {
  2581.         List<Object[]> mergeList = null;
  2582.         try{
  2583.             List<String> tipiPorta=null;
  2584.             if(context!=null) {
  2585.                 ConfigurazionePdDManager configurazionePdDManager = ConfigurazionePdDManager.getInstance(context.getStato());
  2586.                
  2587.                 RequestInfo requestInfo = null;
  2588.                 if(context.getPddContext()!=null && context.getPddContext().containsKey(org.openspcoop2.core.constants.Costanti.REQUEST_INFO)) {
  2589.                     requestInfo = (RequestInfo) context.getPddContext().getObject(org.openspcoop2.core.constants.Costanti.REQUEST_INFO);
  2590.                 }
  2591.                
  2592.                 if(TipoPdD.DELEGATA.equals(context.getTipoPorta())) {
  2593.                     IDPortaDelegata idPD = null;
  2594.                     if(context.getIntegrazione()!=null && context.getIntegrazione().getIdPD()!=null) {
  2595.                         idPD = context.getIntegrazione().getIdPD();
  2596.                     }
  2597.                     else if(requestInfo!=null && requestInfo.getProtocolContext()!=null && requestInfo.getProtocolContext().getInterfaceName()!=null) {
  2598.                         idPD = new IDPortaDelegata();
  2599.                         idPD.setNome(requestInfo.getProtocolContext().getInterfaceName());
  2600.                     }
  2601.                     PortaDelegata pd=configurazionePdDManager.getPortaDelegataSafeMethod(idPD, requestInfo);
  2602.                     tipiPorta=configurazionePdDManager.getPostOutResponseHandlers(pd);
  2603.                     /**System.out.println("PostOutResponseContext find PD '"+pd.getNome()+"'");*/
  2604.                 }
  2605.                 else if(TipoPdD.APPLICATIVA.equals(context.getTipoPorta())) {
  2606.                     IDPortaApplicativa idPA = null;
  2607.                     if(context.getIntegrazione()!=null && context.getIntegrazione().getIdPA()!=null) {
  2608.                         idPA = context.getIntegrazione().getIdPA();
  2609.                     }
  2610.                     else if(requestInfo!=null && requestInfo.getProtocolContext()!=null && requestInfo.getProtocolContext().getInterfaceName()!=null) {
  2611.                         idPA = new IDPortaApplicativa();
  2612.                         idPA.setNome(requestInfo.getProtocolContext().getInterfaceName());
  2613.                     }
  2614.                     PortaApplicativa pa=configurazionePdDManager.getPortaApplicativaSafeMethod(idPA, requestInfo);
  2615.                     tipiPorta=configurazionePdDManager.getPostOutResponseHandlers(pa);
  2616.                     /**System.out.println("PostOutResponseContext find PA '"+pa.getNome()+"'");*/
  2617.                 }
  2618.             }
  2619.             if(tipiPorta!=null && !tipiPorta.isEmpty()) {
  2620.                 List<PostOutResponseHandler> listHandler = new ArrayList<>();
  2621.                 List<String> listTipi = new ArrayList<>();
  2622.                 if(postOutResponseHandlers!=null && postOutResponseHandlers.length>0) {
  2623.                     for (int i = 0; i < postOutResponseHandlers.length; i++) {
  2624.                         listHandler.add(postOutResponseHandlers[i]);
  2625.                         listTipi.add(tipiPostOutResponseHandlers[i]);
  2626.                     }
  2627.                 }
  2628.                 PddPluginLoader pluginLoader = PddPluginLoader.getInstance();
  2629.                 for (String tipoPorta : tipiPorta) {
  2630.                     if(!listTipi.contains(tipoPorta)) {
  2631.                         try {
  2632.                             PostOutResponseHandler handler = pluginLoader.newPostOutResponseHandler(tipoPorta);
  2633.                             listHandler.add(handler);
  2634.                             listTipi.add(tipoPorta);
  2635.                         }catch(Throwable t) {
  2636.                             // Non sollevo l'eccezione poiche' dove viene chiamato questo handler e' finita la gestione, quindi l'eccezione non causa altri avvenimenti
  2637.                             log.error("NewInstance '"+tipoPorta+"' failed: "+t.getMessage(),t);
  2638.                         }
  2639.                     }
  2640.                 }
  2641.                 if(!listHandler.isEmpty()) {
  2642.                     mergeList = new ArrayList<>();
  2643.                     mergeList.add(listHandler.toArray(new PostOutResponseHandler[listHandler.size()]));
  2644.                     mergeList.add(listTipi.toArray(new String[listTipi.size()]));
  2645.                 }
  2646.             }
  2647.         }catch(Throwable t) {
  2648.             log.error(t.getMessage(),t);
  2649.         }
  2650.         if(mergeList==null) {
  2651.             mergeList = new ArrayList<>();
  2652.             mergeList.add(postOutResponseHandlers);
  2653.             mergeList.add(tipiPostOutResponseHandlers);
  2654.         }
  2655.         return mergeList;
  2656.     }
  2657.     private static void _postOutResponseHandler(PostOutResponseContext context,MsgDiagnostico msgDiag,Logger log, PostOutResponseHandler [] handlers, String [] tipiHandlers, String name) {
  2658.         if(handlers!=null){
  2659.             for(int i=0; i<handlers.length; i++){
  2660.                 try{
  2661.                     emitDiagnosticInvokeHandlerStart(handlers[i], msgDiag, log);
  2662.                     handlers[i].invoke(context);
  2663.                     emitDiagnosticInvokeHandlerEnd(handlers[i], msgDiag, log);
  2664.                 }catch(Throwable e){
  2665.                     // Non sollevo l'eccezione poiche' dove viene chiamato questo handler e' finita la gestione, quindi l'eccezione non causa altri avvenimenti
  2666.                     // Registro solamento l'evento
  2667.                     if(handlers[i] instanceof org.openspcoop2.pdd.core.handlers.transazioni.PostOutResponseHandler) {
  2668.                         // altrimenti succede questo errore, non esistendo più la transazione:
  2669.                         // Errore durante l'emissione del msg diagnostico nel contesto della transazione: Non abilitata la gestione delle transazioni stateful
  2670.                         // org.openspcoop2.pdd.core.transazioni.TransactionStatefulNotSupportedException: Non abilitata la gestione delle transazioni stateful
  2671.                         if(log!=null) {
  2672.                             log.error(name+" ["+tipiHandlers[i]+"]"+e.getMessage(),e);
  2673.                         }
  2674.                     }
  2675.                     else {
  2676.                         msgDiag.logErroreGenerico(e,name+" ["+tipiHandlers[i]+"]");
  2677.                     }
  2678.                 }
  2679.             }
  2680.         }
  2681.     }
  2682.    
  2683.    
  2684.    
  2685.     public static void integrationManagerRequest(IntegrationManagerRequestContext context,MsgDiagnostico msgDiag,Logger log) throws HandlerException{
  2686.        
  2687.         if(GestoreHandlers.initialize==false){
  2688.             GestoreHandlers.initialize(msgDiag,log,null);
  2689.         }
  2690.        
  2691.         if(GestoreHandlers.properties.generazioneDateCasualiLogAbilitato() && context.getPddContext().getObject(org.openspcoop2.core.constants.Costanti.ID_TRANSAZIONE)!=null){
  2692.             // genero date casuali
  2693.             if(context.getDataRichiestaOperazione()!=null){
  2694.                 context.setDataRichiestaOperazione(GestoreHandlers.generatoreCasualeDati.getProssimaData((String)context.getPddContext().getObject(org.openspcoop2.core.constants.Costanti.ID_TRANSAZIONE)));
  2695.             }
  2696.         }
  2697.        
  2698.         // gestisco handler built-in e user
  2699.         if(properties.isMergeHandlerBuiltInAndHandlerUser()) {
  2700.             List<Object[]> list =  merge(GestoreHandlers.integrationManagerRequestHandlersBuiltIn, GestoreHandlers.tipiIntegrationManagerRequestHandlersBuiltIn,
  2701.                     GestoreHandlers.integrationManagerRequestHandlers, GestoreHandlers.tipiIntegrationManagerRequestHandlers, new IntegrationManagerRequestHandler [1]);
  2702.             IntegrationManagerRequestHandler [] handlers = (IntegrationManagerRequestHandler []) list.get(0);
  2703.             String [] tipiHandlers = toStringArray(list.get(1));
  2704.             _integrationManagerRequestHandler(context, msgDiag, log, handlers, tipiHandlers, "IntegrationManagerRequestHandler");
  2705.         }
  2706.         else {
  2707.             _integrationManagerRequestHandler(context, msgDiag, log, GestoreHandlers.integrationManagerRequestHandlersBuiltIn, GestoreHandlers.tipiIntegrationManagerRequestHandlersBuiltIn, "IntegrationManagerRequestHandler");
  2708.             _integrationManagerRequestHandler(context, msgDiag, log, GestoreHandlers.integrationManagerRequestHandlers, GestoreHandlers.tipiIntegrationManagerRequestHandlers, "IntegrationManagerRequestHandler");
  2709.         }
  2710.     }
  2711.     private static void _integrationManagerRequestHandler(IntegrationManagerRequestContext context,MsgDiagnostico msgDiag,Logger log, IntegrationManagerRequestHandler [] handlers, String [] tipiHandlers, String name) throws HandlerException{
  2712.         if(handlers!=null){
  2713.             for(int i=0; i<handlers.length; i++){
  2714.                 try{
  2715.                     emitDiagnosticInvokeHandlerStart(handlers[i], msgDiag, log);
  2716.                     handlers[i].invoke(context);
  2717.                     emitDiagnosticInvokeHandlerEnd(handlers[i], msgDiag, log);
  2718.                 }catch(Throwable e){
  2719.                     // Sollevo l'eccezione
  2720.                     HandlerException ex = null;
  2721.                     if(e instanceof HandlerException){
  2722.                         ex = (HandlerException) e;
  2723.                     }else{
  2724.                         ex = new HandlerException(e.getMessage(),e);
  2725.                     }
  2726.                     ex.setIdentitaHandler(name+" ["+tipiHandlers[i]+"]");
  2727.                     throw ex;
  2728.                 }
  2729.             }
  2730.         }
  2731.     }
  2732.    
  2733.    
  2734.     public static void integrationManagerResponse(IntegrationManagerResponseContext context,MsgDiagnostico msgDiag,Logger log) throws HandlerException{
  2735.        
  2736.         if(GestoreHandlers.initialize==false){
  2737.             GestoreHandlers.initialize(msgDiag,log,null);
  2738.         }
  2739.        
  2740.         if(GestoreHandlers.properties.generazioneDateCasualiLogAbilitato() && context.getPddContext().getObject(org.openspcoop2.core.constants.Costanti.ID_TRANSAZIONE)!=null){
  2741.             // genero date casuali
  2742.             if(context.getDataRichiestaOperazione()!=null){
  2743.                 context.setDataRichiestaOperazione(GestoreHandlers.generatoreCasualeDati.getProssimaData((String)context.getPddContext().getObject(org.openspcoop2.core.constants.Costanti.ID_TRANSAZIONE)));
  2744.             }
  2745.             if(context.getDataCompletamentoOperazione()!=null){
  2746.                 context.setDataCompletamentoOperazione(GestoreHandlers.generatoreCasualeDati.getProssimaData((String)context.getPddContext().getObject(org.openspcoop2.core.constants.Costanti.ID_TRANSAZIONE)));
  2747.             }
  2748.         }
  2749.        
  2750.         // gestisco handler built-in e user
  2751.         if(properties.isMergeHandlerBuiltInAndHandlerUser()) {
  2752.             List<Object[]> list =  merge(GestoreHandlers.integrationManagerResponseHandlersBuiltIn, GestoreHandlers.tipiIntegrationManagerResponseHandlersBuiltIn,
  2753.                     GestoreHandlers.integrationManagerResponseHandlers, GestoreHandlers.tipiIntegrationManagerResponseHandlers, new IntegrationManagerResponseHandler [1]);
  2754.             IntegrationManagerResponseHandler [] handlers = (IntegrationManagerResponseHandler []) list.get(0);
  2755.             String [] tipiHandlers = toStringArray(list.get(1));
  2756.             _integrationManagerResponseHandler(context, msgDiag, log, handlers, tipiHandlers, "IntegrationManagerResponseHandler");
  2757.         }
  2758.         else {
  2759.             _integrationManagerResponseHandler(context, msgDiag, log, GestoreHandlers.integrationManagerResponseHandlersBuiltIn, GestoreHandlers.tipiIntegrationManagerResponseHandlersBuiltIn, "IntegrationManagerResponseHandler");
  2760.             _integrationManagerResponseHandler(context, msgDiag, log, GestoreHandlers.integrationManagerResponseHandlers, GestoreHandlers.tipiIntegrationManagerResponseHandlers, "IntegrationManagerResponseHandler");
  2761.         }
  2762.        
  2763.         // Rilascio risorse per la generazione di date casuali
  2764.         GestoreHandlers.rilasciaRisorseDemoMode((String)context.getPddContext().getObject(org.openspcoop2.core.constants.Costanti.ID_TRANSAZIONE));
  2765.     }
  2766.     private static void _integrationManagerResponseHandler(IntegrationManagerResponseContext context,MsgDiagnostico msgDiag,Logger log, IntegrationManagerResponseHandler [] handlers, String [] tipiHandlers, String name) throws HandlerException{
  2767.         if(handlers!=null){
  2768.             for(int i=0; i<handlers.length; i++){
  2769.                 try{
  2770.                     emitDiagnosticInvokeHandlerStart(handlers[i], msgDiag, log);
  2771.                     handlers[i].invoke(context);
  2772.                     emitDiagnosticInvokeHandlerEnd(handlers[i], msgDiag, log);
  2773.                 }catch(Throwable e){
  2774.                     // Sollevo l'eccezione
  2775.                     HandlerException ex = null;
  2776.                     if(e instanceof HandlerException){
  2777.                         ex = (HandlerException) e;
  2778.                     }else{
  2779.                         ex = new HandlerException(e.getMessage(),e);
  2780.                     }
  2781.                     ex.setIdentitaHandler(name+" ["+tipiHandlers[i]+"]");
  2782.                     throw ex;
  2783.                 }
  2784.             }
  2785.         }
  2786.     }

  2787.    
  2788.     private static void rilasciaRisorseDemoMode(String idCluster){
  2789.         if(GestoreHandlers.properties.generazioneDateCasualiLogAbilitato() && idCluster!=null){
  2790.             GeneratoreCasualeDate.getGeneratoreCasualeDate().releaseResource(idCluster);
  2791.         }
  2792.     }
  2793. }