UtilitiesIntegrazioneBC.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.integrazione.backward_compatibility;


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

  26. import javax.xml.namespace.QName;
  27. import javax.xml.soap.SOAPElement;
  28. import javax.xml.soap.SOAPHeader;
  29. import javax.xml.soap.SOAPHeaderElement;

  30. import org.apache.commons.lang.StringUtils;
  31. import org.openspcoop2.core.constants.CostantiLabel;
  32. import org.openspcoop2.core.id.IDServizio;
  33. import org.openspcoop2.core.id.IDSoggetto;
  34. import org.openspcoop2.message.OpenSPCoop2MessageFactory;
  35. import org.openspcoop2.message.OpenSPCoop2SoapMessage;
  36. import org.openspcoop2.message.constants.MessageType;
  37. import org.openspcoop2.message.exception.MessageNotSupportedException;
  38. import org.openspcoop2.message.soap.SoapUtils;
  39. import org.openspcoop2.message.xml.ValidatoreXSD;
  40. import org.openspcoop2.pdd.config.OpenSPCoop2Properties;
  41. import org.openspcoop2.pdd.core.CostantiPdD;
  42. import org.openspcoop2.pdd.core.PdDContext;
  43. import org.openspcoop2.pdd.core.integrazione.HeaderIntegrazione;
  44. import org.openspcoop2.pdd.core.integrazione.HeaderIntegrazioneBusta;
  45. import org.openspcoop2.pdd.core.integrazione.HeaderIntegrazioneException;
  46. import org.openspcoop2.pdd.core.integrazione.UtilitiesIntegrazione;
  47. import org.openspcoop2.pdd.logger.OpenSPCoop2Logger;
  48. import org.openspcoop2.utils.MapKey;
  49. import org.openspcoop2.utils.transport.TransportUtils;
  50. import org.openspcoop2.utils.transport.http.HttpConstants;
  51. import org.openspcoop2.utils.xml.XSDResourceResolver;
  52. import org.slf4j.Logger;


  53. /**
  54.  * Classe contenenti utilities per le integrazioni.
  55.  *
  56.  * @author Poli Andrea (apoli@link.it)
  57.  * @author $Author$
  58.  * @version $Rev$, $Date$
  59.  */
  60. public class UtilitiesIntegrazioneBC {

  61.     /** Costante che indica il valore dell'header X che indica la versione della PdD*/
  62.     public static final String OPENSPCOOP2_HEADER_HTTP_X_PDD = "X-OpenSPCoop2-Pdd";
  63.     /** Costante che indica il valore dell'header X che indica il dettaglio della versione della PdD*/
  64.     public static final String OPENSPCOOP2_HEADER_HTTP_X_PDD_DETAILS = "X-OpenSPCoop2-PddDetails";
  65.    
  66.     /** Costante che indica il valore dell'header X che indica la versione della PdD*/
  67.     public static final String OPENSPCOOP2_URL_BASED_PDD = "OpenSPCoop2Pdd";
  68.     /** Costante che indica il valore dell'header X che indica il dettaglio della versione della PdD*/
  69.     public static final String OPENSPCOOP2_URL_BASED_PDD_DETAILS = "OpenSPCoop2PddDetails";
  70.    
  71.     /** Costante che indica il valore dell'attributo dell'header di integrazione SOAP proprietario di OpenSPCoop che indica la versione della PdD*/
  72.     public static final String OPENSPCOOP2_HEADER_INTEGRAZIONE_SOAP_PDD_VERSION = "OpenSPCoop2Pdd";
  73.     /** Costante che indica il valore dell'attributo dell'header di integrazione SOAP proprietario di OpenSPCoop che indica il dettaglio della versione della PdD*/
  74.     public static final String OPENSPCOOP2_HEADER_INTEGRAZIONE_SOAP_PDD_DETAILS = "OpenSPCoop2PddDetails";
  75.    
  76.    
  77.    
  78.     /** Costante che indica il valore dell'header X che indica la versione della PdD*/
  79.     public static final String OPENSPCOOP1_HEADER_HTTP_X_PDD = "X-SPCoop-Pdd";
  80.     /** Costante che indica il valore dell'header X che indica il dettaglio della versione della PdD*/
  81.     public static final String OPENSPCOOP1_HEADER_HTTP_X_PDD_DETAILS = "X-SPCoop-PddDetails";
  82.    
  83.     /** Costante che indica il valore dell'header X che indica la versione della PdD*/
  84.     public static final String OPENSPCOOP1_URL_BASED_PDD = "SPCoopPdd";
  85.     /** Costante che indica il valore dell'header X che indica il dettaglio della versione della PdD*/
  86.     public static final String OPENSPCOOP1_URL_BASED_PDD_DETAILS = "SPCoopDettagliPdd";
  87.    
  88.     /** Costante che indica il valore dell'attributo dell'header di integrazione SOAP proprietario di OpenSPCoop che indica la versione della PdD*/
  89.     public static final String OPENSPCOOP1_HEADER_INTEGRAZIONE_SOAP_PDD_VERSION = "SPCoopPdd";
  90.     /** Costante che indica il valore dell'attributo dell'header di integrazione SOAP proprietario di OpenSPCoop che indica il dettaglio della versione della PdD*/
  91.     public static final String OPENSPCOOP1_HEADER_INTEGRAZIONE_SOAP_PDD_DETAILS = "SPCoopPddDetails";
  92.    

  93.    

  94.     // ***** STATIC *****

  95.     private static final boolean PORTA_DELEGATA = true;
  96.     private static final boolean PORTA_APPLICATIVA = false;
  97.     private static final boolean REQUEST = true;
  98.     private static final boolean RESPONSE = false;
  99.     public static final boolean OPENSPCOOP_V2 = true;
  100.     public static final boolean OPENSPCOOP_V1 = false;
  101.     public static final boolean X_PREFIX = true;
  102.     public static final boolean NOT_X_PREFIX = false;
  103.    
  104.     private static UtilitiesIntegrazioneBC utilitiesIntegrazionePDRequest_op2_xPrefix = null;
  105.     private static UtilitiesIntegrazioneBC utilitiesIntegrazionePDRequest_op2 = null;
  106.     private static UtilitiesIntegrazioneBC utilitiesIntegrazionePDRequest_op1_xPrefix = null;
  107.     private static UtilitiesIntegrazioneBC utilitiesIntegrazionePDRequest_op1 = null;
  108.     public static UtilitiesIntegrazioneBC getInstancePDRequest(Logger log, boolean openspcoop2, boolean x_prefix){
  109.         if(openspcoop2) {
  110.             if(x_prefix) {
  111.                 if(UtilitiesIntegrazioneBC.utilitiesIntegrazionePDRequest_op2_xPrefix==null){
  112.                     // spotbugs warning 'SING_SINGLETON_GETTER_NOT_SYNCHRONIZED': l'istanza viene creata allo startup
  113.                     synchronized (UtilitiesIntegrazioneBC.class) {
  114.                         UtilitiesIntegrazioneBC.initialize(log,PORTA_DELEGATA,REQUEST, openspcoop2, x_prefix);
  115.                     }
  116.                 }
  117.                 return UtilitiesIntegrazioneBC.utilitiesIntegrazionePDRequest_op2_xPrefix;
  118.             }
  119.             else {
  120.                 if(UtilitiesIntegrazioneBC.utilitiesIntegrazionePDRequest_op2==null){
  121.                     // spotbugs warning 'SING_SINGLETON_GETTER_NOT_SYNCHRONIZED': l'istanza viene creata allo startup
  122.                     synchronized (UtilitiesIntegrazioneBC.class) {
  123.                         UtilitiesIntegrazioneBC.initialize(log,PORTA_DELEGATA,REQUEST, openspcoop2, x_prefix);
  124.                     }
  125.                 }
  126.                 return UtilitiesIntegrazioneBC.utilitiesIntegrazionePDRequest_op2;
  127.             }
  128.         }
  129.         else {
  130.             if(x_prefix) {
  131.                 if(UtilitiesIntegrazioneBC.utilitiesIntegrazionePDRequest_op1_xPrefix==null){
  132.                     // spotbugs warning 'SING_SINGLETON_GETTER_NOT_SYNCHRONIZED': l'istanza viene creata allo startup
  133.                     synchronized (UtilitiesIntegrazioneBC.class) {
  134.                         UtilitiesIntegrazioneBC.initialize(log,PORTA_DELEGATA,REQUEST, openspcoop2, x_prefix);
  135.                     }
  136.                 }
  137.                 return UtilitiesIntegrazioneBC.utilitiesIntegrazionePDRequest_op1_xPrefix;
  138.             }
  139.             else {
  140.                 if(UtilitiesIntegrazioneBC.utilitiesIntegrazionePDRequest_op1==null){
  141.                     // spotbugs warning 'SING_SINGLETON_GETTER_NOT_SYNCHRONIZED': l'istanza viene creata allo startup
  142.                     synchronized (UtilitiesIntegrazioneBC.class) {
  143.                         UtilitiesIntegrazioneBC.initialize(log,PORTA_DELEGATA,REQUEST, openspcoop2, x_prefix);
  144.                     }
  145.                 }
  146.                 return UtilitiesIntegrazioneBC.utilitiesIntegrazionePDRequest_op1;
  147.             }
  148.         }
  149.     }
  150.    
  151.     private static UtilitiesIntegrazioneBC utilitiesIntegrazionePDResponse_op2_xPrefix = null;
  152.     private static UtilitiesIntegrazioneBC utilitiesIntegrazionePDResponse_op2 = null;
  153.     private static UtilitiesIntegrazioneBC utilitiesIntegrazionePDResponse_op1_xPrefix = null;
  154.     private static UtilitiesIntegrazioneBC utilitiesIntegrazionePDResponse_op1 = null;
  155.     public static UtilitiesIntegrazioneBC getInstancePDResponse(Logger log, boolean openspcoop2, boolean x_prefix){
  156.         if(openspcoop2) {
  157.             if(x_prefix) {
  158.                 if(UtilitiesIntegrazioneBC.utilitiesIntegrazionePDResponse_op2_xPrefix==null){
  159.                     // spotbugs warning 'SING_SINGLETON_GETTER_NOT_SYNCHRONIZED': l'istanza viene creata allo startup
  160.                     synchronized (UtilitiesIntegrazioneBC.class) {
  161.                         UtilitiesIntegrazioneBC.initialize(log,PORTA_DELEGATA,RESPONSE, openspcoop2, x_prefix);
  162.                     }
  163.                 }
  164.                 return UtilitiesIntegrazioneBC.utilitiesIntegrazionePDResponse_op2_xPrefix;
  165.             }
  166.             else {
  167.                 if(UtilitiesIntegrazioneBC.utilitiesIntegrazionePDResponse_op2==null){
  168.                     // spotbugs warning 'SING_SINGLETON_GETTER_NOT_SYNCHRONIZED': l'istanza viene creata allo startup
  169.                     synchronized (UtilitiesIntegrazioneBC.class) {
  170.                         UtilitiesIntegrazioneBC.initialize(log,PORTA_DELEGATA,RESPONSE, openspcoop2, x_prefix);
  171.                     }
  172.                 }
  173.                 return UtilitiesIntegrazioneBC.utilitiesIntegrazionePDResponse_op2;
  174.             }
  175.         }
  176.         else {
  177.             if(x_prefix) {
  178.                 if(UtilitiesIntegrazioneBC.utilitiesIntegrazionePDResponse_op1_xPrefix==null){
  179.                     // spotbugs warning 'SING_SINGLETON_GETTER_NOT_SYNCHRONIZED': l'istanza viene creata allo startup
  180.                     synchronized (UtilitiesIntegrazioneBC.class) {
  181.                         UtilitiesIntegrazioneBC.initialize(log,PORTA_DELEGATA,RESPONSE, openspcoop2, x_prefix);
  182.                     }
  183.                 }
  184.                 return UtilitiesIntegrazioneBC.utilitiesIntegrazionePDResponse_op1_xPrefix;
  185.             }
  186.             else {
  187.                 if(UtilitiesIntegrazioneBC.utilitiesIntegrazionePDResponse_op1==null){
  188.                     // spotbugs warning 'SING_SINGLETON_GETTER_NOT_SYNCHRONIZED': l'istanza viene creata allo startup
  189.                     synchronized (UtilitiesIntegrazioneBC.class) {
  190.                         UtilitiesIntegrazioneBC.initialize(log,PORTA_DELEGATA,RESPONSE, openspcoop2, x_prefix);
  191.                     }
  192.                 }
  193.                 return UtilitiesIntegrazioneBC.utilitiesIntegrazionePDResponse_op1;
  194.             }
  195.         }
  196.     }
  197.    
  198.     private static UtilitiesIntegrazioneBC utilitiesIntegrazionePARequest_op2_xPrefix = null;
  199.     private static UtilitiesIntegrazioneBC utilitiesIntegrazionePARequest_op2 = null;
  200.     private static UtilitiesIntegrazioneBC utilitiesIntegrazionePARequest_op1_xPrefix = null;
  201.     private static UtilitiesIntegrazioneBC utilitiesIntegrazionePARequest_op1 = null;
  202.     public static UtilitiesIntegrazioneBC getInstancePARequest(Logger log, boolean openspcoop2, boolean x_prefix){
  203.         if(openspcoop2) {
  204.             if(x_prefix) {
  205.                 if(UtilitiesIntegrazioneBC.utilitiesIntegrazionePARequest_op2_xPrefix==null){
  206.                     // spotbugs warning 'SING_SINGLETON_GETTER_NOT_SYNCHRONIZED': l'istanza viene creata allo startup
  207.                     synchronized (UtilitiesIntegrazioneBC.class) {
  208.                         UtilitiesIntegrazioneBC.initialize(log,PORTA_APPLICATIVA,REQUEST, openspcoop2, x_prefix);
  209.                     }
  210.                 }
  211.                 return UtilitiesIntegrazioneBC.utilitiesIntegrazionePARequest_op2_xPrefix;
  212.             }
  213.             else {
  214.                 if(UtilitiesIntegrazioneBC.utilitiesIntegrazionePARequest_op2==null){
  215.                     // spotbugs warning 'SING_SINGLETON_GETTER_NOT_SYNCHRONIZED': l'istanza viene creata allo startup
  216.                     synchronized (UtilitiesIntegrazioneBC.class) {
  217.                         UtilitiesIntegrazioneBC.initialize(log,PORTA_APPLICATIVA,REQUEST, openspcoop2, x_prefix);
  218.                     }
  219.                 }
  220.                 return UtilitiesIntegrazioneBC.utilitiesIntegrazionePARequest_op2;
  221.             }
  222.         }
  223.         else {
  224.             if(x_prefix) {
  225.                 if(UtilitiesIntegrazioneBC.utilitiesIntegrazionePARequest_op1_xPrefix==null){
  226.                     // spotbugs warning 'SING_SINGLETON_GETTER_NOT_SYNCHRONIZED': l'istanza viene creata allo startup
  227.                     synchronized (UtilitiesIntegrazioneBC.class) {
  228.                         UtilitiesIntegrazioneBC.initialize(log,PORTA_APPLICATIVA,REQUEST, openspcoop2, x_prefix);
  229.                     }
  230.                 }
  231.                 return UtilitiesIntegrazioneBC.utilitiesIntegrazionePARequest_op1_xPrefix;
  232.             }
  233.             else {
  234.                 if(UtilitiesIntegrazioneBC.utilitiesIntegrazionePARequest_op1==null){
  235.                     // spotbugs warning 'SING_SINGLETON_GETTER_NOT_SYNCHRONIZED': l'istanza viene creata allo startup
  236.                     synchronized (UtilitiesIntegrazioneBC.class) {
  237.                         UtilitiesIntegrazioneBC.initialize(log,PORTA_APPLICATIVA,REQUEST, openspcoop2, x_prefix);
  238.                     }
  239.                 }
  240.                 return UtilitiesIntegrazioneBC.utilitiesIntegrazionePARequest_op1;
  241.             }
  242.         }
  243.     }
  244.    
  245.     private static UtilitiesIntegrazioneBC utilitiesIntegrazionePAResponse_op2_xPrefix = null;
  246.     private static UtilitiesIntegrazioneBC utilitiesIntegrazionePAResponse_op2 = null;
  247.     private static UtilitiesIntegrazioneBC utilitiesIntegrazionePAResponse_op1_xPrefix = null;
  248.     private static UtilitiesIntegrazioneBC utilitiesIntegrazionePAResponse_op1 = null;
  249.     public static UtilitiesIntegrazioneBC getInstancePAResponse(Logger log, boolean openspcoop2, boolean x_prefix){
  250.         if(openspcoop2) {
  251.             if(x_prefix) {
  252.                 if(UtilitiesIntegrazioneBC.utilitiesIntegrazionePAResponse_op2_xPrefix==null){
  253.                     // spotbugs warning 'SING_SINGLETON_GETTER_NOT_SYNCHRONIZED': l'istanza viene creata allo startup
  254.                     synchronized (UtilitiesIntegrazioneBC.class) {
  255.                         UtilitiesIntegrazioneBC.initialize(log,PORTA_APPLICATIVA,RESPONSE, openspcoop2, x_prefix);
  256.                     }
  257.                 }
  258.                 return UtilitiesIntegrazioneBC.utilitiesIntegrazionePAResponse_op2_xPrefix;
  259.             }
  260.             else {
  261.                 if(UtilitiesIntegrazioneBC.utilitiesIntegrazionePAResponse_op2==null){
  262.                     // spotbugs warning 'SING_SINGLETON_GETTER_NOT_SYNCHRONIZED': l'istanza viene creata allo startup
  263.                     synchronized (UtilitiesIntegrazioneBC.class) {
  264.                         UtilitiesIntegrazioneBC.initialize(log,PORTA_APPLICATIVA,RESPONSE, openspcoop2, x_prefix);
  265.                     }
  266.                 }
  267.                 return UtilitiesIntegrazioneBC.utilitiesIntegrazionePAResponse_op2;
  268.             }
  269.         }
  270.         else {
  271.             if(x_prefix) {
  272.                 if(UtilitiesIntegrazioneBC.utilitiesIntegrazionePAResponse_op1_xPrefix==null){
  273.                     // spotbugs warning 'SING_SINGLETON_GETTER_NOT_SYNCHRONIZED': l'istanza viene creata allo startup
  274.                     synchronized (UtilitiesIntegrazioneBC.class) {
  275.                         UtilitiesIntegrazioneBC.initialize(log,PORTA_APPLICATIVA,RESPONSE, openspcoop2, x_prefix);
  276.                     }
  277.                 }
  278.                 return UtilitiesIntegrazioneBC.utilitiesIntegrazionePAResponse_op1_xPrefix;
  279.             }
  280.             else {
  281.                 if(UtilitiesIntegrazioneBC.utilitiesIntegrazionePAResponse_op1==null){
  282.                     // spotbugs warning 'SING_SINGLETON_GETTER_NOT_SYNCHRONIZED': l'istanza viene creata allo startup
  283.                     synchronized (UtilitiesIntegrazioneBC.class) {
  284.                         UtilitiesIntegrazioneBC.initialize(log,PORTA_APPLICATIVA,RESPONSE, openspcoop2, x_prefix);
  285.                     }
  286.                 }
  287.                 return UtilitiesIntegrazioneBC.utilitiesIntegrazionePAResponse_op1;
  288.             }
  289.         }
  290.     }



  291.     private static synchronized void initialize(Logger log,boolean portaDelegata, boolean request, boolean openspcoop2, boolean x_prefix){
  292.         if(portaDelegata) {
  293.             if(request) {
  294.                 if(openspcoop2) {
  295.                     if(x_prefix) {
  296.                         if(UtilitiesIntegrazioneBC.utilitiesIntegrazionePDRequest_op2_xPrefix==null){
  297.                             UtilitiesIntegrazioneBC.utilitiesIntegrazionePDRequest_op2_xPrefix = new UtilitiesIntegrazioneBC(log, portaDelegata, request, openspcoop2, x_prefix);
  298.                         }
  299.                     }
  300.                     else {
  301.                         if(UtilitiesIntegrazioneBC.utilitiesIntegrazionePDRequest_op2==null){
  302.                             UtilitiesIntegrazioneBC.utilitiesIntegrazionePDRequest_op2 = new UtilitiesIntegrazioneBC(log, portaDelegata, request, openspcoop2, x_prefix);
  303.                         }
  304.                     }
  305.                 }
  306.                 else {
  307.                     if(x_prefix) {
  308.                         if(UtilitiesIntegrazioneBC.utilitiesIntegrazionePDRequest_op1_xPrefix==null){
  309.                             UtilitiesIntegrazioneBC.utilitiesIntegrazionePDRequest_op1_xPrefix = new UtilitiesIntegrazioneBC(log, portaDelegata, request, openspcoop2, x_prefix);
  310.                         }
  311.                     }
  312.                     else {
  313.                         if(UtilitiesIntegrazioneBC.utilitiesIntegrazionePDRequest_op1==null){
  314.                             UtilitiesIntegrazioneBC.utilitiesIntegrazionePDRequest_op1 = new UtilitiesIntegrazioneBC(log, portaDelegata, request, openspcoop2, x_prefix);
  315.                         }
  316.                     }
  317.                 }
  318.             }
  319.             else {
  320.                 if(openspcoop2) {
  321.                     if(x_prefix) {
  322.                         if(UtilitiesIntegrazioneBC.utilitiesIntegrazionePDResponse_op2_xPrefix==null){
  323.                             UtilitiesIntegrazioneBC.utilitiesIntegrazionePDResponse_op2_xPrefix = new UtilitiesIntegrazioneBC(log, portaDelegata, request, openspcoop2, x_prefix);
  324.                         }
  325.                     }
  326.                     else {
  327.                         if(UtilitiesIntegrazioneBC.utilitiesIntegrazionePDResponse_op2==null){
  328.                             UtilitiesIntegrazioneBC.utilitiesIntegrazionePDResponse_op2 = new UtilitiesIntegrazioneBC(log, portaDelegata, request, openspcoop2, x_prefix);
  329.                         }
  330.                     }
  331.                 }
  332.                 else {
  333.                     if(x_prefix) {
  334.                         if(UtilitiesIntegrazioneBC.utilitiesIntegrazionePDResponse_op1_xPrefix==null){
  335.                             UtilitiesIntegrazioneBC.utilitiesIntegrazionePDResponse_op1_xPrefix = new UtilitiesIntegrazioneBC(log, portaDelegata, request, openspcoop2, x_prefix);
  336.                         }
  337.                     }
  338.                     else {
  339.                         if(UtilitiesIntegrazioneBC.utilitiesIntegrazionePDResponse_op1==null){
  340.                             UtilitiesIntegrazioneBC.utilitiesIntegrazionePDResponse_op1 = new UtilitiesIntegrazioneBC(log, portaDelegata, request, openspcoop2, x_prefix);
  341.                         }
  342.                     }
  343.                 }
  344.             }
  345.         }
  346.         else {
  347.             if(request) {
  348.                 if(openspcoop2) {
  349.                     if(x_prefix) {
  350.                         if(UtilitiesIntegrazioneBC.utilitiesIntegrazionePARequest_op2_xPrefix==null){
  351.                             UtilitiesIntegrazioneBC.utilitiesIntegrazionePARequest_op2_xPrefix = new UtilitiesIntegrazioneBC(log, portaDelegata, request, openspcoop2, x_prefix);
  352.                         }
  353.                     }
  354.                     else {
  355.                         if(UtilitiesIntegrazioneBC.utilitiesIntegrazionePARequest_op2==null){
  356.                             UtilitiesIntegrazioneBC.utilitiesIntegrazionePARequest_op2 = new UtilitiesIntegrazioneBC(log, portaDelegata, request, openspcoop2, x_prefix);
  357.                         }
  358.                     }
  359.                 }
  360.                 else {
  361.                     if(x_prefix) {
  362.                         if(UtilitiesIntegrazioneBC.utilitiesIntegrazionePARequest_op1_xPrefix==null){
  363.                             UtilitiesIntegrazioneBC.utilitiesIntegrazionePARequest_op1_xPrefix = new UtilitiesIntegrazioneBC(log, portaDelegata, request, openspcoop2, x_prefix);
  364.                         }
  365.                     }
  366.                     else {
  367.                         if(UtilitiesIntegrazioneBC.utilitiesIntegrazionePARequest_op1==null){
  368.                             UtilitiesIntegrazioneBC.utilitiesIntegrazionePARequest_op1 = new UtilitiesIntegrazioneBC(log, portaDelegata, request, openspcoop2, x_prefix);
  369.                         }
  370.                     }
  371.                 }
  372.             }
  373.             else {
  374.                 if(openspcoop2) {
  375.                     if(x_prefix) {
  376.                         if(UtilitiesIntegrazioneBC.utilitiesIntegrazionePAResponse_op2_xPrefix==null){
  377.                             UtilitiesIntegrazioneBC.utilitiesIntegrazionePAResponse_op2_xPrefix = new UtilitiesIntegrazioneBC(log, portaDelegata, request, openspcoop2, x_prefix);
  378.                         }
  379.                     }
  380.                     else {
  381.                         if(UtilitiesIntegrazioneBC.utilitiesIntegrazionePAResponse_op2==null){
  382.                             UtilitiesIntegrazioneBC.utilitiesIntegrazionePAResponse_op2 = new UtilitiesIntegrazioneBC(log, portaDelegata, request, openspcoop2, x_prefix);
  383.                         }
  384.                     }
  385.                 }
  386.                 else {
  387.                     if(x_prefix) {
  388.                         if(UtilitiesIntegrazioneBC.utilitiesIntegrazionePAResponse_op1_xPrefix==null){
  389.                             UtilitiesIntegrazioneBC.utilitiesIntegrazionePAResponse_op1_xPrefix = new UtilitiesIntegrazioneBC(log, portaDelegata, request, openspcoop2, x_prefix);
  390.                         }
  391.                     }
  392.                     else {
  393.                         if(UtilitiesIntegrazioneBC.utilitiesIntegrazionePAResponse_op1==null){
  394.                             UtilitiesIntegrazioneBC.utilitiesIntegrazionePAResponse_op1 = new UtilitiesIntegrazioneBC(log, portaDelegata, request, openspcoop2, x_prefix);
  395.                         }
  396.                     }
  397.                 }
  398.             }
  399.         }
  400.     }

  401.    
  402.    
  403.    
  404.     // ***** INSTANCE *****

  405.     private List<MapKey<String>> keywordsIntegrazione = null;
  406.    
  407.     private Map<MapKey<String>, String> keyValueIntegrazioneTrasporto = null;
  408.     private Map<MapKey<String>, Boolean> keySetEnabled_HeaderIntegrazioneTrasporto = null;
  409.     private Map<MapKey<String>, Boolean> keyReadEnabled_HeaderIntegrazioneTrasporto = null;
  410.    
  411.     private Map<MapKey<String>, String> keyValueIntegrazioneUrlBased = null;
  412.     private Map<MapKey<String>, Boolean> keySetEnabled_HeaderIntegrazioneUrlBased = null;
  413.     private Map<MapKey<String>, Boolean> keyReadEnabled_HeaderIntegrazioneUrlBased = null;
  414.    
  415.     private Map<MapKey<String>, String> keyValueIntegrazioneSoap = null;
  416.     private Map<MapKey<String>, Boolean> keySetEnabled_HeaderIntegrazioneSoap = null;
  417.     private Map<MapKey<String>, Boolean> keyReadEnabled_HeaderIntegrazioneSoap = null;
  418.    
  419.     private OpenSPCoop2Properties openspcoopProperties = null;
  420.     private Map<String, ValidatoreXSD> validatoreXSD_soap11_map = new HashMap<String, ValidatoreXSD>();
  421.     private Map<String, ValidatoreXSD> validatoreXSD_soap12_map = new HashMap<String, ValidatoreXSD>();
  422.    
  423.     private Map<String, String> govway2openspcoop_Mapping_trasparente_soggetto = null;
  424.     private Map<String, String> govway2openspcoop_Mapping_trasparente_servizio = null;
  425.     private Map<String, String> govway2openspcoop_Mapping_spcoop_soggetto = null;
  426.     private Map<String, String> govway2openspcoop_Mapping_spcoop_servizio = null;
  427.     private Map<String, String> govway2openspcoop_Mapping_sdi_soggetto = null;
  428.     private Map<String, String> govway2openspcoop_Mapping_sdi_servizio = null;
  429.    
  430.     private Map<String, String> openspcoop2govway_Mapping_trasparente_soggetto = null;
  431.     private Map<String, String> openspcoop2govway_Mapping_trasparente_servizio = null;
  432.     private Map<String, String> openspcoop2govway_Mapping_spcoop_soggetto = null;
  433.     private Map<String, String> openspcoop2govway_Mapping_spcoop_servizio = null;
  434.     private Map<String, String> openspcoop2govway_Mapping_sdi_soggetto = null;
  435.     private Map<String, String> openspcoop2govway_Mapping_sdi_servizio = null;
  436.    
  437.     private boolean request;
  438.     private boolean openspcoop2;
  439.     private boolean x_prefix;
  440.    
  441.     private Logger log;
  442.    
  443.     private UtilitiesIntegrazioneBC(Logger log, boolean portaDelegata, boolean request, boolean openspcoop2, boolean x_prefix){
  444.        
  445.         this.log = log;
  446.        
  447.         this.openspcoopProperties = OpenSPCoop2Properties.getInstance();
  448.        
  449.         this.request = request;
  450.         this.openspcoop2 = openspcoop2;
  451.         this.x_prefix = x_prefix;
  452.        
  453.         this.keywordsIntegrazione = this.openspcoopProperties.getKeywordsIntegrazione();
  454.         this.keywordsIntegrazione.remove(CostantiPdD.HEADER_INTEGRAZIONE_VERSIONE_SERVIZIO);
  455.         if(!this.openspcoop2) {
  456.             this.keywordsIntegrazione.remove(CostantiPdD.HEADER_INTEGRAZIONE_ID_TRANSAZIONE);
  457.         }
  458.        
  459.         if(this.openspcoop2) {
  460.             this.keyValueIntegrazioneTrasporto = this.openspcoopProperties.getKeyValue_HeaderIntegrazioneTrasporto_backwardCompatibility_openspcoop2();
  461.         }
  462.         else {
  463.             this.keyValueIntegrazioneTrasporto = this.openspcoopProperties.getKeyValue_HeaderIntegrazioneTrasporto_backwardCompatibility_openspcoop1();
  464.         }
  465.         try{
  466.             if(portaDelegata) {
  467.                 this.keySetEnabled_HeaderIntegrazioneTrasporto = this.openspcoopProperties.getKeyPDSetEnabled_HeaderIntegrazioneTrasporto(request);
  468.                 this.keyReadEnabled_HeaderIntegrazioneTrasporto = this.openspcoopProperties.getKeyPDReadEnabled_HeaderIntegrazioneTrasporto();
  469.             }
  470.             else {
  471.                 this.keySetEnabled_HeaderIntegrazioneTrasporto = this.openspcoopProperties.getKeyPASetEnabled_HeaderIntegrazioneTrasporto(request);
  472.                 this.keyReadEnabled_HeaderIntegrazioneTrasporto = this.openspcoopProperties.getKeyPAReadEnabled_HeaderIntegrazioneTrasporto();
  473.             }
  474.         }catch(Exception e){
  475.             log.error("Integrazione, errore durante la lettura del file di configurazione: "+e.getMessage(),e);
  476.         }
  477.        
  478.         if(this.openspcoop2) {
  479.             this.keyValueIntegrazioneUrlBased = this.openspcoopProperties.getKeyValue_HeaderIntegrazioneUrlBased_backwardCompatibility_openspcoop2();
  480.         }
  481.         else {
  482.             this.keyValueIntegrazioneUrlBased = this.openspcoopProperties.getKeyValue_HeaderIntegrazioneUrlBased_backwardCompatibility_openspcoop1();
  483.         }
  484.         try{
  485.             if(portaDelegata) {
  486.                 this.keySetEnabled_HeaderIntegrazioneUrlBased = this.openspcoopProperties.getKeyPDSetEnabled_HeaderIntegrazioneUrlBased();
  487.                 this.keyReadEnabled_HeaderIntegrazioneUrlBased = this.openspcoopProperties.getKeyPDReadEnabled_HeaderIntegrazioneUrlBased();
  488.             }
  489.             else {
  490.                 this.keySetEnabled_HeaderIntegrazioneUrlBased = this.openspcoopProperties.getKeyPASetEnabled_HeaderIntegrazioneUrlBased();
  491.                 this.keyReadEnabled_HeaderIntegrazioneUrlBased = this.openspcoopProperties.getKeyPAReadEnabled_HeaderIntegrazioneUrlBased();
  492.             }
  493.         }catch(Exception e){
  494.             log.error("Integrazione, errore durante la lettura del file di configurazione: "+e.getMessage(),e);
  495.         }
  496.        
  497.         if(this.openspcoop2) {
  498.             this.keyValueIntegrazioneSoap = this.openspcoopProperties.getKeyValue_HeaderIntegrazioneSoap_backwardCompatibility_openspcoop2();
  499.         }
  500.         else {
  501.             this.keyValueIntegrazioneSoap = this.openspcoopProperties.getKeyValue_HeaderIntegrazioneSoap_backwardCompatibility_openspcoop1();
  502.         }
  503.         try{
  504.             if(portaDelegata) {
  505.                 this.keySetEnabled_HeaderIntegrazioneSoap = this.openspcoopProperties.getKeyPDSetEnabled_HeaderIntegrazioneSoap(request);
  506.                 this.keyReadEnabled_HeaderIntegrazioneSoap = this.openspcoopProperties.getKeyPDReadEnabled_HeaderIntegrazioneSoap();
  507.             }
  508.             else {
  509.                 this.keySetEnabled_HeaderIntegrazioneSoap = this.openspcoopProperties.getKeyPASetEnabled_HeaderIntegrazioneSoap(request);
  510.                 this.keyReadEnabled_HeaderIntegrazioneSoap = this.openspcoopProperties.getKeyPAReadEnabled_HeaderIntegrazioneSoap();
  511.             }
  512.         }catch(Exception e){
  513.             log.error("Integrazione, errore durante la lettura del file di configurazione: "+e.getMessage(),e);
  514.         }
  515.        
  516.         try {
  517.             this.govway2openspcoop_Mapping_trasparente_soggetto = this.openspcoopProperties.getNewOldMapping_backward_compatibility_trasparente_soggetto();
  518.             if(this.govway2openspcoop_Mapping_trasparente_soggetto!=null && !this.govway2openspcoop_Mapping_trasparente_soggetto.isEmpty()) {
  519.                 this.openspcoop2govway_Mapping_trasparente_soggetto = new HashMap<>();
  520.                 for (String govway : this.govway2openspcoop_Mapping_trasparente_soggetto.keySet()) {
  521.                     String openspcoop = this.govway2openspcoop_Mapping_trasparente_soggetto.get(govway);
  522.                     this.openspcoop2govway_Mapping_trasparente_soggetto.put(openspcoop, govway);
  523.                 }
  524.             }
  525.         }catch(Exception e){
  526.             log.error("Integrazione, errore durante la lettura del file di configurazione: "+e.getMessage(),e);
  527.         }
  528.         try {
  529.             this.govway2openspcoop_Mapping_trasparente_servizio = this.openspcoopProperties.getNewOldMapping_backward_compatibility_trasparente_servizio();
  530.             if(this.govway2openspcoop_Mapping_trasparente_servizio!=null && !this.govway2openspcoop_Mapping_trasparente_servizio.isEmpty()) {
  531.                 this.openspcoop2govway_Mapping_trasparente_servizio = new HashMap<>();
  532.                 for (String govway : this.govway2openspcoop_Mapping_trasparente_servizio.keySet()) {
  533.                     String openspcoop = this.govway2openspcoop_Mapping_trasparente_servizio.get(govway);
  534.                     this.openspcoop2govway_Mapping_trasparente_servizio.put(openspcoop, govway);
  535.                 }
  536.             }
  537.         }catch(Exception e){
  538.             log.error("Integrazione, errore durante la lettura del file di configurazione: "+e.getMessage(),e);
  539.         }
  540.        
  541.         try {
  542.             this.govway2openspcoop_Mapping_spcoop_soggetto = this.openspcoopProperties.getNewOldMapping_backward_compatibility_spcoop_soggetto();
  543.             if(this.govway2openspcoop_Mapping_spcoop_soggetto!=null && !this.govway2openspcoop_Mapping_spcoop_soggetto.isEmpty()) {
  544.                 this.openspcoop2govway_Mapping_spcoop_soggetto = new HashMap<>();
  545.                 for (String govway : this.govway2openspcoop_Mapping_spcoop_soggetto.keySet()) {
  546.                     String openspcoop = this.govway2openspcoop_Mapping_spcoop_soggetto.get(govway);
  547.                     this.openspcoop2govway_Mapping_spcoop_soggetto.put(openspcoop, govway);
  548.                 }
  549.             }
  550.         }catch(Exception e){
  551.             log.error("Integrazione, errore durante la lettura del file di configurazione: "+e.getMessage(),e);
  552.         }
  553.         try {
  554.             this.govway2openspcoop_Mapping_spcoop_servizio = this.openspcoopProperties.getNewOldMapping_backward_compatibility_spcoop_servizio();
  555.             if(this.govway2openspcoop_Mapping_spcoop_servizio!=null && !this.govway2openspcoop_Mapping_spcoop_servizio.isEmpty()) {
  556.                 this.openspcoop2govway_Mapping_spcoop_servizio = new HashMap<>();
  557.                 for (String govway : this.govway2openspcoop_Mapping_spcoop_servizio.keySet()) {
  558.                     String openspcoop = this.govway2openspcoop_Mapping_spcoop_servizio.get(govway);
  559.                     this.openspcoop2govway_Mapping_spcoop_servizio.put(openspcoop, govway);
  560.                 }
  561.             }
  562.         }catch(Exception e){
  563.             log.error("Integrazione, errore durante la lettura del file di configurazione: "+e.getMessage(),e);
  564.         }
  565.        
  566.         try {
  567.             this.govway2openspcoop_Mapping_sdi_soggetto = this.openspcoopProperties.getNewOldMapping_backward_compatibility_sdi_soggetto();
  568.             if(this.govway2openspcoop_Mapping_sdi_soggetto!=null && !this.govway2openspcoop_Mapping_sdi_soggetto.isEmpty()) {
  569.                 this.openspcoop2govway_Mapping_sdi_soggetto = new HashMap<>();
  570.                 for (String govway : this.govway2openspcoop_Mapping_sdi_soggetto.keySet()) {
  571.                     String openspcoop = this.govway2openspcoop_Mapping_sdi_soggetto.get(govway);
  572.                     this.openspcoop2govway_Mapping_sdi_soggetto.put(openspcoop, govway);
  573.                 }
  574.             }
  575.         }catch(Exception e){
  576.             log.error("Integrazione, errore durante la lettura del file di configurazione: "+e.getMessage(),e);
  577.         }
  578.         try {
  579.             this.govway2openspcoop_Mapping_sdi_servizio = this.openspcoopProperties.getNewOldMapping_backward_compatibility_sdi_servizio();
  580.             if(this.govway2openspcoop_Mapping_sdi_servizio!=null && !this.govway2openspcoop_Mapping_sdi_servizio.isEmpty()) {
  581.                 this.openspcoop2govway_Mapping_sdi_servizio = new HashMap<>();
  582.                 for (String govway : this.govway2openspcoop_Mapping_sdi_servizio.keySet()) {
  583.                     String openspcoop = this.govway2openspcoop_Mapping_sdi_servizio.get(govway);
  584.                     this.openspcoop2govway_Mapping_sdi_servizio.put(openspcoop, govway);
  585.                 }
  586.             }
  587.         }catch(Exception e){
  588.             log.error("Integrazione, errore durante la lettura del file di configurazione: "+e.getMessage(),e);
  589.         }
  590.        
  591.     }
  592.    
  593.     private synchronized void initValidatoreXSD(OpenSPCoop2MessageFactory messageFactory) {
  594.         String key = messageFactory.getClass().getName();
  595.         if(this.openspcoop2) {
  596.            
  597.             if(!this.validatoreXSD_soap11_map.containsKey(key)) {
  598.                 try{
  599.                     XSDResourceResolver xsdResourceResolver_soap11 = new XSDResourceResolver();
  600.                     xsdResourceResolver_soap11.addResource("soapEnvelope.xsd", UtilitiesIntegrazioneBC.class.getResourceAsStream("/soapEnvelope.xsd"));
  601.                     this.validatoreXSD_soap11_map.put(key, new ValidatoreXSD(messageFactory, this.log,xsdResourceResolver_soap11,UtilitiesIntegrazioneBC.class.getResourceAsStream("/integrazione_soap11_openspcoop2.xsd")));
  602.                 }catch(Exception e){
  603.                     this.log.error("Integrazione.xsd, errore durante la costruzione del validatore xsd per Soap11: "+e.getMessage(),e);
  604.                 }
  605.             }
  606.            
  607.             if(!this.validatoreXSD_soap12_map.containsKey(key)) {
  608.                 try{
  609.                     XSDResourceResolver xsdResourceResolver_soap12 = new XSDResourceResolver();
  610.                     xsdResourceResolver_soap12.addResource("soapEnvelope12.xsd", UtilitiesIntegrazioneBC.class.getResourceAsStream("/soapEnvelope12.xsd"));
  611.                     xsdResourceResolver_soap12.addResource("xml.xsd", UtilitiesIntegrazioneBC.class.getResourceAsStream("/xml.xsd"));
  612.                     this.validatoreXSD_soap12_map.put(key, new ValidatoreXSD(messageFactory, this.log,xsdResourceResolver_soap12,UtilitiesIntegrazioneBC.class.getResourceAsStream("/integrazione_soap12_openspcoop2.xsd")));
  613.                 }catch(Exception e){
  614.                     this.log.error("Integrazione.xsd, errore durante la costruzione del validatore xsd per Soap12: "+e.getMessage(),e);
  615.                 }
  616.             }
  617.         }
  618.         else {
  619.            
  620.             if(!this.validatoreXSD_soap11_map.containsKey(key)) {
  621.                 try{
  622.                     XSDResourceResolver xsdResourceResolver_soap11 = new XSDResourceResolver();
  623.                     xsdResourceResolver_soap11.addResource("soapEnvelope.xsd", UtilitiesIntegrazioneBC.class.getResourceAsStream("/soapEnvelope.xsd"));
  624.                     this.validatoreXSD_soap11_map.put(key, new ValidatoreXSD(messageFactory, this.log,xsdResourceResolver_soap11,UtilitiesIntegrazioneBC.class.getResourceAsStream("/integrazione_soap11_openspcoop1.xsd")));
  625.                 }catch(Exception e){
  626.                     this.log.error("Integrazione.xsd, errore durante la costruzione del validatore xsd per Soap11: "+e.getMessage(),e);
  627.                 }
  628.             }
  629.            
  630.         }
  631.     }
  632.     private void checkInitValidatoreXSD(OpenSPCoop2MessageFactory messageFactory) {
  633.         String key = messageFactory.getClass().getName();
  634.         if(this.openspcoop2) {
  635.             if(!this.validatoreXSD_soap11_map.containsKey(key)) {
  636.                 initValidatoreXSD(messageFactory);
  637.             }
  638.             if(!this.validatoreXSD_soap12_map.containsKey(key)) {
  639.                 initValidatoreXSD(messageFactory);
  640.             }
  641.         }
  642.         else {
  643.             if(!this.validatoreXSD_soap11_map.containsKey(key)) {
  644.                 initValidatoreXSD(messageFactory);
  645.             }
  646.            
  647.         }
  648.     }
  649.     private ValidatoreXSD getValidatoreXSD(boolean soap12, OpenSPCoop2MessageFactory messageFactory) {
  650.        
  651.         checkInitValidatoreXSD(messageFactory);
  652.        
  653.         String key = messageFactory.getClass().getName();
  654.         if(this.openspcoop2) {
  655.             if(soap12) {
  656.                 return this.validatoreXSD_soap12_map.get(key);
  657.             }
  658.             else {
  659.                 return this.validatoreXSD_soap11_map.get(key);
  660.             }
  661.         }
  662.         else {
  663.             return this.validatoreXSD_soap11_map.get(key);
  664.         }
  665.        
  666.     }
  667.    
  668.     private String normalizeX_(String hdr) {
  669.         if(!this.x_prefix) {
  670.             if(hdr.toLowerCase().startsWith("x-") && hdr.length()>2) {
  671.                 hdr = hdr.substring(2);
  672.             }
  673.         }
  674.         return hdr;
  675.     }
  676.    
  677.     private String normalizeOpenSPCoop2GovWay_tipoSoggetto(String tipoSoggetto, String protocollo) {
  678.         String tipo = null;
  679.         if(protocollo!=null && CostantiLabel.TRASPARENTE_PROTOCOL_NAME.equals(protocollo) && this.openspcoop2govway_Mapping_trasparente_soggetto!=null) {
  680.             tipo = this.openspcoop2govway_Mapping_trasparente_soggetto.get(tipoSoggetto);
  681.         }
  682.         else if(protocollo!=null && CostantiLabel.SPCOOP_PROTOCOL_NAME.equals(protocollo) && this.openspcoop2govway_Mapping_spcoop_soggetto!=null) {
  683.             tipo = this.openspcoop2govway_Mapping_spcoop_soggetto.get(tipoSoggetto);
  684.         }
  685.         else if(protocollo!=null && CostantiLabel.SDI_PROTOCOL_NAME.equals(protocollo) && this.openspcoop2govway_Mapping_sdi_soggetto!=null) {
  686.             tipo = this.openspcoop2govway_Mapping_sdi_soggetto.get(tipoSoggetto);
  687.         }
  688.         if(tipo!=null && StringUtils.isNotEmpty(tipo)) {
  689.             return tipo;
  690.         }
  691.         return tipoSoggetto;
  692.     }
  693.     private String normalizeOpenSPCoop2GovWay_tipoServizio(String tipoServizio, String protocollo) {
  694.         String tipo = null;
  695.         if(protocollo!=null && CostantiLabel.TRASPARENTE_PROTOCOL_NAME.equals(protocollo) && this.openspcoop2govway_Mapping_trasparente_servizio!=null) {
  696.             tipo = this.openspcoop2govway_Mapping_trasparente_servizio.get(tipoServizio);
  697.         }
  698.         else if(protocollo!=null && CostantiLabel.SPCOOP_PROTOCOL_NAME.equals(protocollo) && this.openspcoop2govway_Mapping_spcoop_servizio!=null) {
  699.             tipo = this.openspcoop2govway_Mapping_spcoop_servizio.get(tipoServizio);
  700.         }
  701.         else if(protocollo!=null && CostantiLabel.SDI_PROTOCOL_NAME.equals(protocollo) && this.openspcoop2govway_Mapping_sdi_servizio!=null) {
  702.             tipo = this.openspcoop2govway_Mapping_sdi_servizio.get(tipoServizio);
  703.         }
  704.         if(tipo!=null && StringUtils.isNotEmpty(tipo)) {
  705.             return tipo;
  706.         }
  707.         return tipoServizio;
  708.     }
  709.    
  710.     private String normalizeGovWay2OpenSPCoop_tipoSoggetto(String tipoSoggetto, String protocollo) {
  711.         String tipo = null;
  712.         if(protocollo!=null && CostantiLabel.TRASPARENTE_PROTOCOL_NAME.equals(protocollo) && this.govway2openspcoop_Mapping_trasparente_soggetto!=null) {
  713.             tipo = this.govway2openspcoop_Mapping_trasparente_soggetto.get(tipoSoggetto);
  714.         }
  715.         else if(protocollo!=null && CostantiLabel.SPCOOP_PROTOCOL_NAME.equals(protocollo) && this.govway2openspcoop_Mapping_spcoop_soggetto!=null) {
  716.             tipo = this.govway2openspcoop_Mapping_spcoop_soggetto.get(tipoSoggetto);
  717.         }
  718.         else if(protocollo!=null && CostantiLabel.SDI_PROTOCOL_NAME.equals(protocollo) && this.govway2openspcoop_Mapping_sdi_soggetto!=null) {
  719.             tipo = this.govway2openspcoop_Mapping_sdi_soggetto.get(tipoSoggetto);
  720.         }
  721.         if(tipo!=null && StringUtils.isNotEmpty(tipo)) {
  722.             return tipo;
  723.         }
  724.         return tipoSoggetto;
  725.     }
  726.     private String normalizeGovWay2OpenSPCoop_tipoServizio(String tipoServizio, String protocollo) {
  727.         String tipo = null;
  728.         if(protocollo!=null && CostantiLabel.TRASPARENTE_PROTOCOL_NAME.equals(protocollo) && this.govway2openspcoop_Mapping_trasparente_servizio!=null) {
  729.             tipo = this.govway2openspcoop_Mapping_trasparente_servizio.get(tipoServizio);
  730.         }
  731.         else if(protocollo!=null && CostantiLabel.SPCOOP_PROTOCOL_NAME.equals(protocollo) && this.govway2openspcoop_Mapping_spcoop_servizio!=null) {
  732.             tipo = this.govway2openspcoop_Mapping_spcoop_servizio.get(tipoServizio);
  733.         }
  734.         else if(protocollo!=null && CostantiLabel.SDI_PROTOCOL_NAME.equals(protocollo) && this.govway2openspcoop_Mapping_sdi_servizio!=null) {
  735.             tipo = this.govway2openspcoop_Mapping_sdi_servizio.get(tipoServizio);
  736.         }
  737.         if(tipo!=null && StringUtils.isNotEmpty(tipo)) {
  738.             return tipo;
  739.         }
  740.         return tipoServizio;
  741.     }
  742.    
  743.     public void readTransportProperties(Map<String, List<String>> prop,
  744.             HeaderIntegrazione integrazione,
  745.             String protocollo) throws HeaderIntegrazioneException{
  746.         try{
  747.             if(prop!=null && integrazione!=null){
  748.                                
  749.                 // Ricerca tra l'header del trasporto
  750.                 Iterator<String> it = prop.keySet().iterator();
  751.                 while (it.hasNext()) {
  752.                     String key = (String) it.next();
  753.                    
  754.                     if(key!=null){
  755.                        
  756.                         for (MapKey<String> keywordIntegrazione : this.keywordsIntegrazione) {
  757.                             String header = normalizeX_((String)this.keyValueIntegrazioneTrasporto.get(keywordIntegrazione));
  758.                             if(key.equalsIgnoreCase(header)) {
  759.                                
  760.                                 if(this.keyReadEnabled_HeaderIntegrazioneTrasporto.get(keywordIntegrazione)) {
  761.                                
  762.                                     // Busta
  763.                                     if(CostantiPdD.HEADER_INTEGRAZIONE_TIPO_MITTENTE.equals(keywordIntegrazione)) {
  764.                                         String tipo = TransportUtils.getFirstValue(prop,key);
  765.                                         String normalized = normalizeOpenSPCoop2GovWay_tipoSoggetto(tipo, protocollo);
  766.                                         integrazione.getBusta().setTipoMittente(normalized);    
  767.                                     }
  768.                                     else if(CostantiPdD.HEADER_INTEGRAZIONE_MITTENTE.equals(keywordIntegrazione)) {
  769.                                         integrazione.getBusta().setMittente(TransportUtils.getFirstValue(prop,key));    
  770.                                     }
  771.                                     else if(CostantiPdD.HEADER_INTEGRAZIONE_TIPO_DESTINATARIO.equals(keywordIntegrazione)) {
  772.                                         String tipo = TransportUtils.getFirstValue(prop,key);
  773.                                         String normalized = normalizeOpenSPCoop2GovWay_tipoSoggetto(tipo, protocollo);
  774.                                         integrazione.getBusta().setTipoDestinatario(normalized);    
  775.                                     }
  776.                                     else if(CostantiPdD.HEADER_INTEGRAZIONE_DESTINATARIO.equals(keywordIntegrazione)) {
  777.                                         integrazione.getBusta().setDestinatario(TransportUtils.getFirstValue(prop,key));    
  778.                                     }
  779.                                     else if(CostantiPdD.HEADER_INTEGRAZIONE_TIPO_SERVIZIO.equals(keywordIntegrazione)) {
  780.                                         String tipo = TransportUtils.getFirstValue(prop,key);
  781.                                         String normalized = normalizeOpenSPCoop2GovWay_tipoServizio(tipo, protocollo);
  782.                                         integrazione.getBusta().setTipoServizio(normalized);    
  783.                                     }
  784.                                     else if(CostantiPdD.HEADER_INTEGRAZIONE_SERVIZIO.equals(keywordIntegrazione)) {
  785.                                         integrazione.getBusta().setServizio(TransportUtils.getFirstValue(prop,key));    
  786.                                     }
  787. //                                  else if(CostantiPdD.HEADER_INTEGRAZIONE_VERSIONE_SERVIZIO.equals(keywordIntegrazione)) {
  788. //                                      String v = TransportUtils.getFirstValue(prop,key);
  789. //                                      try{
  790. //                                          if(v!=null) {
  791. //                                              integrazione.getBusta().setVersioneServizio(Integer.parseInt(v));
  792. //                                          }
  793. //                                      }catch(Exception e){
  794. //                                          throw new Exception("Formato versione ["+v+"] non corretto: "+e.getMessage(),e);
  795. //                                      }
  796. //                                  }
  797.                                     else if(CostantiPdD.HEADER_INTEGRAZIONE_AZIONE.equals(keywordIntegrazione)) {
  798.                                         integrazione.getBusta().setAzione(TransportUtils.getFirstValue(prop,key));  
  799.                                     }
  800.                                     else if(CostantiPdD.HEADER_INTEGRAZIONE_ID_MESSAGGIO.equals(keywordIntegrazione)) {
  801.                                         integrazione.getBusta().setID(TransportUtils.getFirstValue(prop,key));  
  802.                                     }
  803.                                     else if(CostantiPdD.HEADER_INTEGRAZIONE_RIFERIMENTO_MESSAGGIO.equals(keywordIntegrazione)) {
  804.                                         integrazione.getBusta().setRiferimentoMessaggio(TransportUtils.getFirstValue(prop,key));    
  805.                                     }
  806.                                     else if(CostantiPdD.HEADER_INTEGRAZIONE_COLLABORAZIONE.equals(keywordIntegrazione)) {
  807.                                         integrazione.getBusta().setIdCollaborazione(TransportUtils.getFirstValue(prop,key));    
  808.                                     }
  809.                                    
  810.                                     // id e servizio applicativo
  811.                                     else if(CostantiPdD.HEADER_INTEGRAZIONE_ID_APPLICATIVO.equals(keywordIntegrazione)) {
  812.                                         integrazione.setIdApplicativo(TransportUtils.getFirstValue(prop,key));  
  813.                                     }
  814.                                     else if(CostantiPdD.HEADER_INTEGRAZIONE_SERVIZIO_APPLICATIVO.equals(keywordIntegrazione)) {
  815.                                         integrazione.setServizioApplicativo(TransportUtils.getFirstValue(prop,key));    
  816.                                     }
  817.                                     else if(this.openspcoop2 && CostantiPdD.HEADER_INTEGRAZIONE_ID_TRANSAZIONE.equals(keywordIntegrazione)) {
  818.                                         integrazione.setIdTransazione(TransportUtils.getFirstValue(prop,key));  
  819.                                     }
  820.                                 }
  821.                                 break;
  822.                             }
  823.                         }
  824.                        
  825.                     }
  826.                 }
  827.             }
  828.         }catch(Exception e){
  829.             throw new HeaderIntegrazioneException("UtilitiesIntegrazione, lettura dell'header non riuscita: "+e.getMessage(),e);
  830.         }
  831.     }
  832.    
  833.     public void readUrlProperties(Map<String, List<String>> prop,
  834.             HeaderIntegrazione integrazione,
  835.             String protocollo) throws HeaderIntegrazioneException{
  836.         try{
  837.             if(prop!=null && integrazione!=null){
  838.            
  839.                 // Ricerca tra le proprieta' dell'url
  840.                 Iterator<String> it = prop.keySet().iterator();
  841.                 while (it.hasNext()) {
  842.                     String key = (String) it.next();

  843.                     if(key!=null){
  844.                        
  845.                         for (MapKey<String> keywordIntegrazione : this.keywordsIntegrazione) {
  846.                             if(key.equalsIgnoreCase((String)this.keyValueIntegrazioneUrlBased.get(keywordIntegrazione))) {
  847.                                
  848.                                 if(this.keyReadEnabled_HeaderIntegrazioneUrlBased.get(keywordIntegrazione)) {
  849.                                
  850.                                     // Busta
  851.                                     if(CostantiPdD.HEADER_INTEGRAZIONE_TIPO_MITTENTE.equals(keywordIntegrazione)) {
  852.                                         String tipo = TransportUtils.getFirstValue(prop,key);
  853.                                         String normalized = normalizeOpenSPCoop2GovWay_tipoSoggetto(tipo, protocollo);
  854.                                         integrazione.getBusta().setTipoMittente(normalized);    
  855.                                     }
  856.                                     else if(CostantiPdD.HEADER_INTEGRAZIONE_MITTENTE.equals(keywordIntegrazione)) {
  857.                                         integrazione.getBusta().setMittente(TransportUtils.getFirstValue(prop,key));    
  858.                                     }
  859.                                     else if(CostantiPdD.HEADER_INTEGRAZIONE_TIPO_DESTINATARIO.equals(keywordIntegrazione)) {
  860.                                         String tipo = TransportUtils.getFirstValue(prop,key);
  861.                                         String normalized = normalizeOpenSPCoop2GovWay_tipoSoggetto(tipo, protocollo);
  862.                                         integrazione.getBusta().setTipoDestinatario(normalized);    
  863.                                     }
  864.                                     else if(CostantiPdD.HEADER_INTEGRAZIONE_DESTINATARIO.equals(keywordIntegrazione)) {
  865.                                         integrazione.getBusta().setDestinatario(TransportUtils.getFirstValue(prop,key));    
  866.                                     }
  867.                                     else if(CostantiPdD.HEADER_INTEGRAZIONE_TIPO_SERVIZIO.equals(keywordIntegrazione)) {
  868.                                         String tipo = TransportUtils.getFirstValue(prop,key);
  869.                                         String normalized = normalizeOpenSPCoop2GovWay_tipoServizio(tipo, protocollo);
  870.                                         integrazione.getBusta().setTipoServizio(normalized);    
  871.                                     }
  872.                                     else if(CostantiPdD.HEADER_INTEGRAZIONE_SERVIZIO.equals(keywordIntegrazione)) {
  873.                                         integrazione.getBusta().setServizio(TransportUtils.getFirstValue(prop,key));    
  874.                                     }
  875. //                                  else if(CostantiPdD.HEADER_INTEGRAZIONE_VERSIONE_SERVIZIO.equals(keywordIntegrazione)) {
  876. //                                      String v = TransportUtils.getFirstValue(prop,key);
  877. //                                      try{
  878. //                                          if(v!=null) {
  879. //                                              integrazione.getBusta().setVersioneServizio(Integer.parseInt(v));
  880. //                                          }
  881. //                                      }catch(Exception e){
  882. //                                          throw new Exception("Formato versione ["+v+"] non corretto: "+e.getMessage(),e);
  883. //                                      }
  884. //                                  }
  885.                                     else if(CostantiPdD.HEADER_INTEGRAZIONE_AZIONE.equals(keywordIntegrazione)) {
  886.                                         integrazione.getBusta().setAzione(TransportUtils.getFirstValue(prop,key));  
  887.                                     }
  888.                                     else if(CostantiPdD.HEADER_INTEGRAZIONE_ID_MESSAGGIO.equals(keywordIntegrazione)) {
  889.                                         integrazione.getBusta().setID(TransportUtils.getFirstValue(prop,key));  
  890.                                     }
  891.                                     else if(CostantiPdD.HEADER_INTEGRAZIONE_RIFERIMENTO_MESSAGGIO.equals(keywordIntegrazione)) {
  892.                                         integrazione.getBusta().setRiferimentoMessaggio(TransportUtils.getFirstValue(prop,key));    
  893.                                     }
  894.                                     else if(CostantiPdD.HEADER_INTEGRAZIONE_COLLABORAZIONE.equals(keywordIntegrazione)) {
  895.                                         integrazione.getBusta().setIdCollaborazione(TransportUtils.getFirstValue(prop,key));    
  896.                                     }
  897.                                    
  898.                                     // id e servizio applicativo
  899.                                     else if(CostantiPdD.HEADER_INTEGRAZIONE_ID_APPLICATIVO.equals(keywordIntegrazione)) {
  900.                                         integrazione.setIdApplicativo(TransportUtils.getFirstValue(prop,key));  
  901.                                     }
  902.                                     else if(CostantiPdD.HEADER_INTEGRAZIONE_SERVIZIO_APPLICATIVO.equals(keywordIntegrazione)) {
  903.                                         integrazione.setServizioApplicativo(TransportUtils.getFirstValue(prop,key));    
  904.                                     }
  905.                                     else if(this.openspcoop2 && CostantiPdD.HEADER_INTEGRAZIONE_ID_TRANSAZIONE.equals(keywordIntegrazione)) {
  906.                                         integrazione.setIdTransazione(TransportUtils.getFirstValue(prop,key));  
  907.                                     }
  908.                                 }
  909.                                 break;
  910.                             }
  911.                         }
  912.                        
  913.                     }
  914.                 }
  915.             }
  916.         }catch(Exception e){
  917.             throw new HeaderIntegrazioneException("UtilitiesIntegrazione, lettura dell'header non riuscita: "+e.getMessage(),e);
  918.         }
  919.     }
  920.    


  921.     public void setUrlProperties(HeaderIntegrazione integrazione,
  922.             Map<String, List<String>> properties,
  923.             Map<String, String> protocolInfos,
  924.             String protocollo) throws HeaderIntegrazioneException{

  925.         try{
  926.             if(properties!=null && integrazione!=null){
  927.                 if(integrazione.getBusta()!=null){              
  928.                     if(integrazione.getBusta().getTipoMittente()!=null) {
  929.                         if(this.keySetEnabled_HeaderIntegrazioneUrlBased.get(CostantiPdD.HEADER_INTEGRAZIONE_TIPO_MITTENTE)) {
  930.                             String tipo = integrazione.getBusta().getTipoMittente();
  931.                             String normalized = normalizeGovWay2OpenSPCoop_tipoSoggetto(tipo, protocollo);
  932.                             TransportUtils.setParameter(properties,this.keyValueIntegrazioneUrlBased.get(CostantiPdD.HEADER_INTEGRAZIONE_TIPO_MITTENTE), normalized);
  933.                         }
  934.                     }
  935.                     if(integrazione.getBusta().getMittente()!=null) {
  936.                         if(this.keySetEnabled_HeaderIntegrazioneUrlBased.get(CostantiPdD.HEADER_INTEGRAZIONE_MITTENTE)) {
  937.                             TransportUtils.setParameter(properties,this.keyValueIntegrazioneUrlBased.get(CostantiPdD.HEADER_INTEGRAZIONE_MITTENTE), integrazione.getBusta().getMittente());
  938.                         }
  939.                     }
  940.                     if(integrazione.getBusta().getTipoDestinatario()!=null) {
  941.                         if(this.keySetEnabled_HeaderIntegrazioneUrlBased.get(CostantiPdD.HEADER_INTEGRAZIONE_TIPO_DESTINATARIO)) {
  942.                             String tipo = integrazione.getBusta().getTipoDestinatario();
  943.                             String normalized = normalizeGovWay2OpenSPCoop_tipoSoggetto(tipo, protocollo);
  944.                             TransportUtils.setParameter(properties,this.keyValueIntegrazioneUrlBased.get(CostantiPdD.HEADER_INTEGRAZIONE_TIPO_DESTINATARIO), normalized);
  945.                         }
  946.                     }
  947.                     if(integrazione.getBusta().getDestinatario()!=null) {
  948.                         if(this.keySetEnabled_HeaderIntegrazioneUrlBased.get(CostantiPdD.HEADER_INTEGRAZIONE_DESTINATARIO)) {
  949.                             TransportUtils.setParameter(properties,this.keyValueIntegrazioneUrlBased.get(CostantiPdD.HEADER_INTEGRAZIONE_DESTINATARIO), integrazione.getBusta().getDestinatario());
  950.                         }
  951.                     }
  952.                     if(integrazione.getBusta().getTipoServizio()!=null) {
  953.                         if(this.keySetEnabled_HeaderIntegrazioneUrlBased.get(CostantiPdD.HEADER_INTEGRAZIONE_TIPO_SERVIZIO)) {
  954.                             String tipo = integrazione.getBusta().getTipoServizio();
  955.                             String normalized = normalizeGovWay2OpenSPCoop_tipoServizio(tipo, protocollo);
  956.                             TransportUtils.setParameter(properties,this.keyValueIntegrazioneUrlBased.get(CostantiPdD.HEADER_INTEGRAZIONE_TIPO_SERVIZIO), normalized);
  957.                         }
  958.                     }
  959.                     if(integrazione.getBusta().getServizio()!=null) {
  960.                         if(this.keySetEnabled_HeaderIntegrazioneUrlBased.get(CostantiPdD.HEADER_INTEGRAZIONE_SERVIZIO)) {
  961.                             TransportUtils.setParameter(properties,this.keyValueIntegrazioneUrlBased.get(CostantiPdD.HEADER_INTEGRAZIONE_SERVIZIO), integrazione.getBusta().getServizio());
  962.                         }
  963.                     }
  964. //                  if(integrazione.getBusta().getVersioneServizio()!=null) {
  965. //                      if(this.keySetEnabled_HeaderIntegrazioneUrlBased.get(CostantiPdD.HEADER_INTEGRAZIONE_VERSIONE_SERVIZIO)) {
  966. //                          TransportUtils.setParameter(properties,this.keyValueIntegrazioneUrlBased.get(CostantiPdD.HEADER_INTEGRAZIONE_VERSIONE_SERVIZIO), integrazione.getBusta().getVersioneServizio().intValue()+"");
  967. //                      }
  968. //                  }
  969.                     if(integrazione.getBusta().getAzione()!=null) {
  970.                         if(this.keySetEnabled_HeaderIntegrazioneUrlBased.get(CostantiPdD.HEADER_INTEGRAZIONE_AZIONE)) {
  971.                             TransportUtils.setParameter(properties,this.keyValueIntegrazioneUrlBased.get(CostantiPdD.HEADER_INTEGRAZIONE_AZIONE), integrazione.getBusta().getAzione());
  972.                         }
  973.                     }
  974.                     if(integrazione.getBusta().getID()!=null) {
  975.                         if(this.keySetEnabled_HeaderIntegrazioneUrlBased.get(CostantiPdD.HEADER_INTEGRAZIONE_ID_MESSAGGIO)) {
  976.                             TransportUtils.setParameter(properties,this.keyValueIntegrazioneUrlBased.get(CostantiPdD.HEADER_INTEGRAZIONE_ID_MESSAGGIO), integrazione.getBusta().getID());
  977.                         }
  978.                     }
  979.                     if(integrazione.getBusta().getRiferimentoMessaggio()!=null) {
  980.                         if(this.keySetEnabled_HeaderIntegrazioneUrlBased.get(CostantiPdD.HEADER_INTEGRAZIONE_RIFERIMENTO_MESSAGGIO)) {
  981.                             TransportUtils.setParameter(properties,this.keyValueIntegrazioneUrlBased.get(CostantiPdD.HEADER_INTEGRAZIONE_RIFERIMENTO_MESSAGGIO), integrazione.getBusta().getRiferimentoMessaggio());
  982.                         }
  983.                     }
  984.                     if(integrazione.getBusta().getIdCollaborazione()!=null) {
  985.                         if(this.keySetEnabled_HeaderIntegrazioneUrlBased.get(CostantiPdD.HEADER_INTEGRAZIONE_COLLABORAZIONE)) {
  986.                             TransportUtils.setParameter(properties,this.keyValueIntegrazioneUrlBased.get(CostantiPdD.HEADER_INTEGRAZIONE_COLLABORAZIONE), integrazione.getBusta().getIdCollaborazione());
  987.                         }
  988.                     }
  989.                 }
  990.                 if(integrazione.getIdApplicativo()!=null) {
  991.                     if(this.keySetEnabled_HeaderIntegrazioneUrlBased.get(CostantiPdD.HEADER_INTEGRAZIONE_ID_APPLICATIVO)) {
  992.                         TransportUtils.setParameter(properties,this.keyValueIntegrazioneUrlBased.get(CostantiPdD.HEADER_INTEGRAZIONE_ID_APPLICATIVO), integrazione.getIdApplicativo());
  993.                     }
  994.                 }
  995.                 if(integrazione.getServizioApplicativo()!=null) {
  996.                     if(this.keySetEnabled_HeaderIntegrazioneUrlBased.get(CostantiPdD.HEADER_INTEGRAZIONE_SERVIZIO_APPLICATIVO)) {
  997.                         TransportUtils.setParameter(properties,this.keyValueIntegrazioneUrlBased.get(CostantiPdD.HEADER_INTEGRAZIONE_SERVIZIO_APPLICATIVO), integrazione.getServizioApplicativo());
  998.                     }
  999.                 }
  1000.                 if(this.openspcoop2 && integrazione.getIdTransazione()!=null) {
  1001.                     if(this.keySetEnabled_HeaderIntegrazioneUrlBased.get(CostantiPdD.HEADER_INTEGRAZIONE_ID_TRANSAZIONE)) {
  1002.                         TransportUtils.setParameter(properties,this.keyValueIntegrazioneUrlBased.get(CostantiPdD.HEADER_INTEGRAZIONE_ID_TRANSAZIONE), integrazione.getIdTransazione());
  1003.                     }
  1004.                 }
  1005.             }
  1006.             if(properties!=null){
  1007. //              TransportUtils.setParameter(properties,CostantiPdD.URL_BASED_PDD,URLEncoder.encode(this.openspcoopProperties.getHttpServer(),"UTF-8"));
  1008. //              if(this.openspcoopProperties.getHttpXPdDDetails()!=null && !"".equals(this.openspcoopProperties.getHttpXPdDDetails())){
  1009. //                  TransportUtils.setParameter(properties,CostantiPdD.URL_BASED_PDD_DETAILS,URLEncoder.encode(this.openspcoopProperties.getHttpXPdDDetails(),"UTF-8"));
  1010. //              }
  1011.                 // Non deve essere effettuato a questo livello l'URLEncoder altrimenti si ottiene una doppia codifica, essendo poi fatta anche per tutti i valori in ConnettoreUtils.
  1012.                
  1013.                 if(this.keySetEnabled_HeaderIntegrazioneUrlBased.get(CostantiPdD.HEADER_INTEGRAZIONE_INFO)) {
  1014.                     if(this.openspcoop2) {
  1015.                         TransportUtils.setParameter(properties,OPENSPCOOP2_URL_BASED_PDD,this.openspcoopProperties.getHttpServer());
  1016.                         if(this.openspcoopProperties.getHttpXPdDDetails()!=null && !"".equals(this.openspcoopProperties.getHttpXPdDDetails())){
  1017.                             TransportUtils.setParameter(properties,OPENSPCOOP2_URL_BASED_PDD_DETAILS,this.openspcoopProperties.getHttpXPdDDetails());
  1018.                         }
  1019.                     }
  1020.                     else {
  1021.                         TransportUtils.setParameter(properties,OPENSPCOOP1_URL_BASED_PDD,this.openspcoopProperties.getHttpServer());
  1022.                         if(this.openspcoopProperties.getHttpXPdDDetails()!=null && !"".equals(this.openspcoopProperties.getHttpXPdDDetails())){
  1023.                             TransportUtils.setParameter(properties,OPENSPCOOP1_URL_BASED_PDD_DETAILS,this.openspcoopProperties.getHttpXPdDDetails());
  1024.                         }
  1025.                     }
  1026.                 }

  1027.                 if(this.openspcoop2 && this.keySetEnabled_HeaderIntegrazioneUrlBased.get(CostantiPdD.HEADER_INTEGRAZIONE_PROTOCOL_INFO)) {
  1028.                     // protocol info
  1029.                     if(protocolInfos!=null && protocolInfos.size()>0){
  1030.                        
  1031.                         String prefixProtocolInfo = this.keyValueIntegrazioneUrlBased.get(CostantiPdD.HEADER_INTEGRAZIONE_PROTOCOL_INFO);
  1032.                        
  1033.                         Iterator<String> itProtocolInfos = protocolInfos.keySet().iterator();
  1034.                         while (itProtocolInfos.hasNext()) {
  1035.                             String name = (String) itProtocolInfos.next();
  1036.                             String value = protocolInfos.get(name);
  1037.                             String nameWithPrefix = (prefixProtocolInfo!=null) ? prefixProtocolInfo.trim()+name : name;
  1038.                             TransportUtils.setParameter(properties,nameWithPrefix,value);
  1039.                         }
  1040.                     }
  1041.                 }
  1042.             }
  1043.            
  1044.         }catch(Exception e){
  1045.             throw new HeaderIntegrazioneException("UtilitiesIntegrazione, creazione delle proprieta' dell'header non riuscita: "+e.getMessage(),e);
  1046.         }
  1047.     }
  1048.    
  1049.     public void setInfoProductTransportProperties(Map<String, List<String>> properties,
  1050.             String protocollo) throws HeaderIntegrazioneException{
  1051.         setTransportProperties(null, properties, null,
  1052.                 protocollo);
  1053.     }
  1054.     public void setTransportProperties(HeaderIntegrazione integrazione,
  1055.             Map<String, List<String>> properties,
  1056.             Map<String, String> protocolInfos,
  1057.             String protocollo) throws HeaderIntegrazioneException{

  1058.         try{
  1059.             if(properties!=null && integrazione!=null){
  1060.                 if(integrazione.getBusta()!=null){
  1061.                     if(integrazione.getBusta().getTipoMittente()!=null) {
  1062.                         if(this.keySetEnabled_HeaderIntegrazioneTrasporto.get(CostantiPdD.HEADER_INTEGRAZIONE_TIPO_MITTENTE)) {
  1063.                             String tipo = integrazione.getBusta().getTipoMittente();
  1064.                             String normalized = normalizeGovWay2OpenSPCoop_tipoSoggetto(tipo, protocollo);
  1065.                             TransportUtils.setParameter(properties,normalizeX_(this.keyValueIntegrazioneTrasporto.get(CostantiPdD.HEADER_INTEGRAZIONE_TIPO_MITTENTE)), normalized);
  1066.                         }
  1067.                     }
  1068.                     if(integrazione.getBusta().getMittente()!=null) {
  1069.                         if(this.keySetEnabled_HeaderIntegrazioneTrasporto.get(CostantiPdD.HEADER_INTEGRAZIONE_MITTENTE)) {
  1070.                             TransportUtils.setParameter(properties,normalizeX_(this.keyValueIntegrazioneTrasporto.get(CostantiPdD.HEADER_INTEGRAZIONE_MITTENTE)), integrazione.getBusta().getMittente());
  1071.                         }
  1072.                     }
  1073.                     if(integrazione.getBusta().getTipoDestinatario()!=null) {
  1074.                         if(this.keySetEnabled_HeaderIntegrazioneTrasporto.get(CostantiPdD.HEADER_INTEGRAZIONE_TIPO_DESTINATARIO)) {
  1075.                             String tipo = integrazione.getBusta().getTipoDestinatario();
  1076.                             String normalized = normalizeGovWay2OpenSPCoop_tipoSoggetto(tipo, protocollo);
  1077.                             TransportUtils.setParameter(properties,normalizeX_(this.keyValueIntegrazioneTrasporto.get(CostantiPdD.HEADER_INTEGRAZIONE_TIPO_DESTINATARIO)), normalized);
  1078.                         }
  1079.                     }
  1080.                     if(integrazione.getBusta().getDestinatario()!=null) {
  1081.                         if(this.keySetEnabled_HeaderIntegrazioneTrasporto.get(CostantiPdD.HEADER_INTEGRAZIONE_DESTINATARIO)) {
  1082.                             TransportUtils.setParameter(properties,normalizeX_(this.keyValueIntegrazioneTrasporto.get(CostantiPdD.HEADER_INTEGRAZIONE_DESTINATARIO)), integrazione.getBusta().getDestinatario());
  1083.                         }
  1084.                     }
  1085.                     if(integrazione.getBusta().getTipoServizio()!=null) {
  1086.                         if(this.keySetEnabled_HeaderIntegrazioneTrasporto.get(CostantiPdD.HEADER_INTEGRAZIONE_TIPO_SERVIZIO)) {
  1087.                             String tipo = integrazione.getBusta().getTipoServizio();
  1088.                             String normalized = normalizeGovWay2OpenSPCoop_tipoServizio(tipo, protocollo);
  1089.                             TransportUtils.setParameter(properties,normalizeX_(this.keyValueIntegrazioneTrasporto.get(CostantiPdD.HEADER_INTEGRAZIONE_TIPO_SERVIZIO)), normalized);
  1090.                         }
  1091.                     }
  1092.                     if(integrazione.getBusta().getServizio()!=null) {
  1093.                         if(this.keySetEnabled_HeaderIntegrazioneTrasporto.get(CostantiPdD.HEADER_INTEGRAZIONE_SERVIZIO)) {
  1094.                             TransportUtils.setParameter(properties,normalizeX_(this.keyValueIntegrazioneTrasporto.get(CostantiPdD.HEADER_INTEGRAZIONE_SERVIZIO)), integrazione.getBusta().getServizio());
  1095.                         }
  1096.                     }
  1097. //                  if(integrazione.getBusta().getVersioneServizio()!=null) {
  1098. //                      if(this.keySetEnabled_HeaderIntegrazioneTrasporto.get(CostantiPdD.HEADER_INTEGRAZIONE_VERSIONE_SERVIZIO)) {
  1099. //                          TransportUtils.setParameter(properties,normalizeX_(this.keyValueIntegrazioneTrasporto.getProperty(CostantiPdD.HEADER_INTEGRAZIONE_VERSIONE_SERVIZIO)), integrazione.getBusta().getVersioneServizio().intValue()+"");
  1100. //                      }
  1101. //                  }
  1102.                     if(integrazione.getBusta().getAzione()!=null) {
  1103.                         if(this.keySetEnabled_HeaderIntegrazioneTrasporto.get(CostantiPdD.HEADER_INTEGRAZIONE_AZIONE)) {
  1104.                             TransportUtils.setParameter(properties,normalizeX_(this.keyValueIntegrazioneTrasporto.get(CostantiPdD.HEADER_INTEGRAZIONE_AZIONE)), integrazione.getBusta().getAzione());
  1105.                         }
  1106.                     }
  1107.                     if(integrazione.getBusta().getID()!=null) {
  1108.                         if(this.keySetEnabled_HeaderIntegrazioneTrasporto.get(CostantiPdD.HEADER_INTEGRAZIONE_ID_MESSAGGIO)) {
  1109.                             TransportUtils.setParameter(properties,normalizeX_(this.keyValueIntegrazioneTrasporto.get(CostantiPdD.HEADER_INTEGRAZIONE_ID_MESSAGGIO)), integrazione.getBusta().getID());
  1110.                         }
  1111.                     }
  1112.                     if(integrazione.getBusta().getRiferimentoMessaggio()!=null) {
  1113.                         if(this.keySetEnabled_HeaderIntegrazioneTrasporto.get(CostantiPdD.HEADER_INTEGRAZIONE_RIFERIMENTO_MESSAGGIO)) {
  1114.                             TransportUtils.setParameter(properties,normalizeX_(this.keyValueIntegrazioneTrasporto.get(CostantiPdD.HEADER_INTEGRAZIONE_RIFERIMENTO_MESSAGGIO)), integrazione.getBusta().getRiferimentoMessaggio());
  1115.                         }
  1116.                     }
  1117.                     if(integrazione.getBusta().getIdCollaborazione()!=null) {
  1118.                         if(this.keySetEnabled_HeaderIntegrazioneTrasporto.get(CostantiPdD.HEADER_INTEGRAZIONE_COLLABORAZIONE)) {
  1119.                             TransportUtils.setParameter(properties,normalizeX_(this.keyValueIntegrazioneTrasporto.get(CostantiPdD.HEADER_INTEGRAZIONE_COLLABORAZIONE)), integrazione.getBusta().getIdCollaborazione());
  1120.                         }
  1121.                     }
  1122.                 }
  1123.                 if(integrazione.getIdApplicativo()!=null) {
  1124.                     if(this.keySetEnabled_HeaderIntegrazioneTrasporto.get(CostantiPdD.HEADER_INTEGRAZIONE_ID_APPLICATIVO)) {
  1125.                         TransportUtils.setParameter(properties,normalizeX_(this.keyValueIntegrazioneTrasporto.get(CostantiPdD.HEADER_INTEGRAZIONE_ID_APPLICATIVO)), integrazione.getIdApplicativo());
  1126.                     }
  1127.                 }
  1128.                 if(integrazione.getServizioApplicativo()!=null) {
  1129.                     if(this.keySetEnabled_HeaderIntegrazioneTrasporto.get(CostantiPdD.HEADER_INTEGRAZIONE_SERVIZIO_APPLICATIVO)) {
  1130.                         TransportUtils.setParameter(properties,normalizeX_(this.keyValueIntegrazioneTrasporto.get(CostantiPdD.HEADER_INTEGRAZIONE_SERVIZIO_APPLICATIVO)), integrazione.getServizioApplicativo());
  1131.                     }
  1132.                 }
  1133.                 if(this.openspcoop2 && integrazione.getIdTransazione()!=null) {
  1134.                     if(this.keySetEnabled_HeaderIntegrazioneTrasporto.get(CostantiPdD.HEADER_INTEGRAZIONE_ID_TRANSAZIONE)) {
  1135.                         TransportUtils.setParameter(properties,normalizeX_(this.keyValueIntegrazioneTrasporto.get(CostantiPdD.HEADER_INTEGRAZIONE_ID_TRANSAZIONE)), integrazione.getIdTransazione());
  1136.                     }
  1137.                 }
  1138.             }
  1139.             if(properties!=null){
  1140.                
  1141.                 boolean infoProduct = this.keySetEnabled_HeaderIntegrazioneTrasporto.get(CostantiPdD.HEADER_INTEGRAZIONE_INFO);
  1142.                 if(infoProduct) {
  1143.                     String hdrPdd = null;
  1144.                     String hdrPddDetails = null;
  1145.                     if(this.openspcoop2) {
  1146.                         hdrPdd = normalizeX_(OPENSPCOOP2_HEADER_HTTP_X_PDD);
  1147.                         hdrPddDetails = normalizeX_(OPENSPCOOP2_HEADER_HTTP_X_PDD_DETAILS);
  1148.                     }
  1149.                     else {
  1150.                         hdrPdd = normalizeX_(OPENSPCOOP1_HEADER_HTTP_X_PDD);
  1151.                         hdrPddDetails = normalizeX_(OPENSPCOOP1_HEADER_HTTP_X_PDD_DETAILS);
  1152.                     }
  1153.                     if(properties.containsKey(hdrPdd)==false) {
  1154.                         TransportUtils.setParameter(properties,hdrPdd,this.openspcoopProperties.getHttpServer());
  1155.                     }
  1156.                     if(this.openspcoopProperties.getHttpXPdDDetails()!=null && !"".equals(this.openspcoopProperties.getHttpXPdDDetails())){
  1157.                         if(properties.containsKey(hdrPddDetails)==false) {
  1158.                             TransportUtils.setParameter(properties,hdrPddDetails,this.openspcoopProperties.getHttpXPdDDetails());
  1159.                         }
  1160.                     }
  1161.                 }
  1162.                
  1163.                 boolean userAgent = this.keySetEnabled_HeaderIntegrazioneTrasporto.get(CostantiPdD.HEADER_INTEGRAZIONE_USER_AGENT);
  1164.                 if(userAgent) {
  1165.                     if(this.request) {
  1166.                         if(properties.containsKey(HttpConstants.USER_AGENT)==false) {
  1167.                             TransportUtils.setParameter(properties,HttpConstants.USER_AGENT,this.openspcoopProperties.getHttpUserAgent());
  1168.                         }
  1169.                     }
  1170.                     else {
  1171.                         if(properties.containsKey(HttpConstants.SERVER)==false) {
  1172.                             TransportUtils.setParameter(properties,HttpConstants.SERVER,this.openspcoopProperties.getHttpUserAgent());
  1173.                         }
  1174.                     }
  1175.                 }
  1176.                
  1177.                 if(this.openspcoop2 && this.keySetEnabled_HeaderIntegrazioneTrasporto.get(CostantiPdD.HEADER_INTEGRAZIONE_PROTOCOL_INFO)) {
  1178.                     if(protocolInfos!=null && protocolInfos.size()>0){
  1179.                        
  1180.                         String prefixProtocolInfo = this.keyValueIntegrazioneTrasporto.get(CostantiPdD.HEADER_INTEGRAZIONE_PROTOCOL_INFO);

  1181.                         Iterator<String> itProtocolInfos = protocolInfos.keySet().iterator();
  1182.                         while (itProtocolInfos.hasNext()) {
  1183.                             String name = (String) itProtocolInfos.next();
  1184.                             String value = protocolInfos.get(name);
  1185.                             String nameWithPrefix = (prefixProtocolInfo!=null) ? prefixProtocolInfo.trim()+name : name;
  1186.                             TransportUtils.setParameter(properties,normalizeX_(nameWithPrefix),value);
  1187.                         }
  1188.                     }
  1189.                 }
  1190.                
  1191.             }
  1192.         }catch(Exception e){
  1193.             throw new HeaderIntegrazioneException("UtilitiesIntegrazione, creazione delle proprieta' dell'header non riuscita: "+e.getMessage(),e);
  1194.         }
  1195.     }
  1196.    
  1197.    

  1198.     public void readHeader(OpenSPCoop2SoapMessage message,HeaderIntegrazione integrazione,
  1199.             String actorIntegrazione,
  1200.             String protocollo) throws HeaderIntegrazioneException{
  1201.        
  1202.        
  1203.         try{            
  1204.             if(actorIntegrazione==null)
  1205.                 throw new Exception("Actor non definito");
  1206.             SOAPHeader header = message.getSOAPHeader();
  1207.             if(header==null){
  1208.                 OpenSPCoop2Logger.getLoggerOpenSPCoopCore().debug("SOAPHeader non presente");
  1209.                 return;
  1210.             }
  1211.             SOAPHeaderElement headerElement = null;
  1212.             java.util.Iterator<?> it = header.examineAllHeaderElements();
  1213.             while( it.hasNext()  ){
  1214.                 // Test Header Element
  1215.                 headerElement = (SOAPHeaderElement) it.next();
  1216.                 //Controllo Actor
  1217.                 String actorCheck = SoapUtils.getSoapActor(headerElement, message.getMessageType());
  1218.                 if( actorIntegrazione.equals(actorCheck) ){
  1219.                     break;
  1220.                 }else{
  1221.                     headerElement = null;
  1222.                 }
  1223.             }
  1224.             if(headerElement==null){
  1225.                 OpenSPCoop2Logger.getLoggerOpenSPCoopCore().debug("Header di integrazione non presente");
  1226.                 return;
  1227.             }
  1228.            
  1229.             // validazione XSD
  1230.             if(MessageType.SOAP_11.equals(message.getMessageType())){
  1231.                 ValidatoreXSD validatoreXSD_soap11 = getValidatoreXSD(false, message.getFactory());
  1232.                 if(validatoreXSD_soap11==null)
  1233.                     throw new Exception("Validatore XSD (Soap11) non istanziato");
  1234.                 validatoreXSD_soap11.valida(new java.io.ByteArrayInputStream(message.getAsByte(headerElement, false)));
  1235.             }
  1236.             else if(MessageType.SOAP_12.equals(message.getMessageType())){
  1237.                 if(!this.openspcoop2) {
  1238.                     throw new HeaderIntegrazioneException("SOAP12 non supportato");
  1239.                 }
  1240.                 ValidatoreXSD validatoreXSD_soap12 = getValidatoreXSD(true, message.getFactory());
  1241.                 if(validatoreXSD_soap12==null)
  1242.                     throw new Exception("Validatore XSD (Soap12) non istanziato");
  1243.                 validatoreXSD_soap12.valida(new java.io.ByteArrayInputStream(message.getAsByte(headerElement, false)));
  1244.             }
  1245.             else{
  1246.                 throw MessageNotSupportedException.newMessageNotSupportedException(message.getMessageType());
  1247.             }

  1248.            
  1249.             // Ricerca tra gli attributi dell'header SOAP
  1250.             String tipoMittente = null;
  1251.             try{
  1252.                 if(this.keyReadEnabled_HeaderIntegrazioneSoap.get(CostantiPdD.HEADER_INTEGRAZIONE_TIPO_MITTENTE)) {
  1253.                     tipoMittente = headerElement.getAttribute((String)this.keyValueIntegrazioneSoap.get(CostantiPdD.HEADER_INTEGRAZIONE_TIPO_MITTENTE));
  1254.                     tipoMittente = normalizeOpenSPCoop2GovWay_tipoSoggetto(tipoMittente, protocollo);
  1255.                 }
  1256.             }catch(Exception e){}
  1257.             if(tipoMittente!=null && tipoMittente.compareTo("")!=0)
  1258.                 integrazione.getBusta().setTipoMittente(tipoMittente);
  1259.            
  1260.             String mittente = null;
  1261.             try{
  1262.                 if(this.keyReadEnabled_HeaderIntegrazioneSoap.get(CostantiPdD.HEADER_INTEGRAZIONE_MITTENTE)) {
  1263.                     mittente = headerElement.getAttribute((String)this.keyValueIntegrazioneSoap.get(CostantiPdD.HEADER_INTEGRAZIONE_MITTENTE));
  1264.                 }
  1265.             }catch(Exception e){}
  1266.             if(mittente!=null && mittente.compareTo("")!=0)
  1267.                 integrazione.getBusta().setMittente(mittente);
  1268.            
  1269.             String tipoDestinatario = null;
  1270.             try{
  1271.                 if(this.keyReadEnabled_HeaderIntegrazioneSoap.get(CostantiPdD.HEADER_INTEGRAZIONE_TIPO_DESTINATARIO)) {
  1272.                     tipoDestinatario = headerElement.getAttribute((String)this.keyValueIntegrazioneSoap.get(CostantiPdD.HEADER_INTEGRAZIONE_TIPO_DESTINATARIO));
  1273.                     tipoDestinatario = normalizeOpenSPCoop2GovWay_tipoSoggetto(tipoDestinatario, protocollo);
  1274.                 }
  1275.             }catch(Exception e){}
  1276.             if(tipoDestinatario!=null && tipoDestinatario.compareTo("")!=0)
  1277.                 integrazione.getBusta().setTipoDestinatario(tipoDestinatario);
  1278.            
  1279.             String destinatario = null;
  1280.             try{
  1281.                 if(this.keyReadEnabled_HeaderIntegrazioneSoap.get(CostantiPdD.HEADER_INTEGRAZIONE_DESTINATARIO)) {
  1282.                     destinatario = headerElement.getAttribute((String)this.keyValueIntegrazioneSoap.get(CostantiPdD.HEADER_INTEGRAZIONE_DESTINATARIO));
  1283.                 }
  1284.             }catch(Exception e){}
  1285.             if(destinatario!=null && destinatario.compareTo("")!=0)
  1286.                 integrazione.getBusta().setDestinatario(destinatario);

  1287.             String tipoServizio = null;
  1288.             try{
  1289.                 if(this.keyReadEnabled_HeaderIntegrazioneSoap.get(CostantiPdD.HEADER_INTEGRAZIONE_TIPO_SERVIZIO)) {
  1290.                     tipoServizio = headerElement.getAttribute((String)this.keyValueIntegrazioneSoap.get(CostantiPdD.HEADER_INTEGRAZIONE_TIPO_SERVIZIO));
  1291.                     tipoServizio = normalizeOpenSPCoop2GovWay_tipoServizio(tipoServizio, protocollo);
  1292.                 }
  1293.             }catch(Exception e){}
  1294.             if(tipoServizio!=null && tipoServizio.compareTo("")!=0)
  1295.                 integrazione.getBusta().setTipoServizio(tipoServizio);
  1296.            
  1297.             String servizio = null;
  1298.             try{
  1299.                 if(this.keyReadEnabled_HeaderIntegrazioneSoap.get(CostantiPdD.HEADER_INTEGRAZIONE_SERVIZIO)) {
  1300.                     servizio = headerElement.getAttribute((String)this.keyValueIntegrazioneSoap.get(CostantiPdD.HEADER_INTEGRAZIONE_SERVIZIO));
  1301.                 }
  1302.             }catch(Exception e){}
  1303.             if(servizio!=null && servizio.compareTo("")!=0)
  1304.                 integrazione.getBusta().setServizio(servizio);
  1305.            
  1306. //          String versioneServizio = null;
  1307. //          try{
  1308. //              if(this.keyReadEnabled_HeaderIntegrazioneSoap.get(CostantiPdD.HEADER_INTEGRAZIONE_VERSIONE_SERVIZIO)) {
  1309. //                  versioneServizio = headerElement.getAttribute((String)this.keyValueIntegrazioneSoap.get(CostantiPdD.HEADER_INTEGRAZIONE_VERSIONE_SERVIZIO));
  1310. //              }
  1311. //          }catch(Exception e){}
  1312. //          if(versioneServizio!=null && versioneServizio.compareTo("")!=0){
  1313. //              try{
  1314. //                  integrazione.getBusta().setVersioneServizio(Integer.parseInt(versioneServizio));
  1315. //              }catch(Exception e){
  1316. //                  throw new Exception("Formato versione ["+versioneServizio+"] non corretto: "+e.getMessage(),e);
  1317. //              }
  1318. //          }

  1319.             String azione= null;
  1320.             try{
  1321.                 if(this.keyReadEnabled_HeaderIntegrazioneSoap.get(CostantiPdD.HEADER_INTEGRAZIONE_AZIONE)) {
  1322.                     azione= headerElement.getAttribute((String)this.keyValueIntegrazioneSoap.get(CostantiPdD.HEADER_INTEGRAZIONE_AZIONE));
  1323.                 }
  1324.             }catch(Exception e){}
  1325.             if(azione!=null && azione.compareTo("")!=0)
  1326.                 integrazione.getBusta().setAzione(azione);

  1327.             String idBusta = null;
  1328.             try{
  1329.                 if(this.keyReadEnabled_HeaderIntegrazioneSoap.get(CostantiPdD.HEADER_INTEGRAZIONE_ID_MESSAGGIO)) {
  1330.                     idBusta = headerElement.getAttribute((String)this.keyValueIntegrazioneSoap.get(CostantiPdD.HEADER_INTEGRAZIONE_ID_MESSAGGIO));
  1331.                 }
  1332.             }catch(Exception e){}
  1333.             if(idBusta!=null && idBusta.compareTo("")!=0)
  1334.                 integrazione.getBusta().setID(idBusta);

  1335.             String riferimentoMessaggio = null;
  1336.             try{
  1337.                 if(this.keyReadEnabled_HeaderIntegrazioneSoap.get(CostantiPdD.HEADER_INTEGRAZIONE_RIFERIMENTO_MESSAGGIO)) {
  1338.                     riferimentoMessaggio = headerElement.getAttribute((String)this.keyValueIntegrazioneSoap.get(CostantiPdD.HEADER_INTEGRAZIONE_RIFERIMENTO_MESSAGGIO));
  1339.                 }
  1340.             }catch(Exception e){}
  1341.             if(riferimentoMessaggio!=null && riferimentoMessaggio.compareTo("")!=0)
  1342.                 integrazione.getBusta().setRiferimentoMessaggio(riferimentoMessaggio);

  1343.             String collaborazione = null;
  1344.             try{
  1345.                 if(this.keyReadEnabled_HeaderIntegrazioneSoap.get(CostantiPdD.HEADER_INTEGRAZIONE_COLLABORAZIONE)) {
  1346.                     collaborazione = headerElement.getAttribute((String)this.keyValueIntegrazioneSoap.get(CostantiPdD.HEADER_INTEGRAZIONE_COLLABORAZIONE));
  1347.                 }
  1348.             }catch(Exception e){}
  1349.             if(collaborazione!=null && collaborazione.compareTo("")!=0)
  1350.                 integrazione.getBusta().setIdCollaborazione(collaborazione);

  1351.             String idApplicativo = null;
  1352.             try{
  1353.                 if(this.keyReadEnabled_HeaderIntegrazioneSoap.get(CostantiPdD.HEADER_INTEGRAZIONE_ID_APPLICATIVO)) {
  1354.                     idApplicativo = headerElement.getAttribute((String)this.keyValueIntegrazioneSoap.get(CostantiPdD.HEADER_INTEGRAZIONE_ID_APPLICATIVO));
  1355.                 }
  1356.             }catch(Exception e){}
  1357.             if(idApplicativo!=null && idApplicativo.compareTo("")!=0)
  1358.                 integrazione.setIdApplicativo(idApplicativo);

  1359.             String sa = null;
  1360.             try{
  1361.                 if(this.keyReadEnabled_HeaderIntegrazioneSoap.get(CostantiPdD.HEADER_INTEGRAZIONE_SERVIZIO_APPLICATIVO)) {
  1362.                     sa = headerElement.getAttribute((String)this.keyValueIntegrazioneSoap.get(CostantiPdD.HEADER_INTEGRAZIONE_SERVIZIO_APPLICATIVO));
  1363.                 }
  1364.             }catch(Exception e){}
  1365.             if(sa!=null && sa.compareTo("")!=0)
  1366.                 integrazione.setServizioApplicativo(sa);
  1367.            
  1368.             if(this.openspcoop2) {
  1369.                 String idTransazione = null;
  1370.                 try{
  1371.                     if(this.keyReadEnabled_HeaderIntegrazioneSoap.get(CostantiPdD.HEADER_INTEGRAZIONE_ID_TRANSAZIONE)) {
  1372.                         idTransazione = headerElement.getAttribute((String)this.keyValueIntegrazioneSoap.get(CostantiPdD.HEADER_INTEGRAZIONE_ID_TRANSAZIONE));
  1373.                     }
  1374.                 }catch(Exception e){}
  1375.                 if(idTransazione!=null && idTransazione.compareTo("")!=0)
  1376.                     integrazione.setIdTransazione(idTransazione);
  1377.             }
  1378.            
  1379.         }catch(Exception e){
  1380.             throw new HeaderIntegrazioneException("UtilitiesIntegrazione, lettura dell'header soap non riuscita: "+e.getMessage(),e);
  1381.         }
  1382.     }

  1383.     public void updateHeader(OpenSPCoop2SoapMessage message,IDSoggetto soggettoFruitore,IDServizio idServizio,
  1384.             String idBusta,String servizioApplicativo,
  1385.             String correlazioneApplicativa,String riferimentoCorrelazioneApplicativaRichiesta, String idTransazione,
  1386.             String actorIntegrazione,String nomeElemento,String prefix,String namespace,
  1387.             String proprietaProtocolloNomeElemento,String proprietaProtocolloNomeTipoElemento,
  1388.             Map<String, String> protocolInfos,
  1389.             String protocollo) throws Exception{
  1390.         updateHeader(message, soggettoFruitore, idServizio, idBusta, null,
  1391.                 servizioApplicativo, correlazioneApplicativa, riferimentoCorrelazioneApplicativaRichiesta, idTransazione,
  1392.                 actorIntegrazione, nomeElemento, prefix, namespace,
  1393.                 proprietaProtocolloNomeElemento, proprietaProtocolloNomeTipoElemento, protocolInfos,
  1394.                 protocollo);
  1395.     }
  1396.    
  1397.     public void updateHeader(OpenSPCoop2SoapMessage message,IDSoggetto soggettoFruitore,IDServizio idServizio,
  1398.             String idBusta,String idBustaRisposta,String servizioApplicativo,
  1399.             String correlazioneApplicativa,String riferimentoCorrelazioneApplicativaRichiesta, String idTransazione,
  1400.             String actorIntegrazione,String nomeElemento,String prefix,String namespace,
  1401.             String proprietaProtocolloNomeElemento,String proprietaProtocolloNomeTipoElemento,
  1402.             Map<String, String> protocolInfos,
  1403.             String protocollo) throws Exception{
  1404.        
  1405.         HeaderIntegrazione integrazione = new HeaderIntegrazione(idTransazione);
  1406.         integrazione.setIdApplicativo(correlazioneApplicativa);
  1407.         integrazione.setServizioApplicativo(servizioApplicativo);
  1408.         HeaderIntegrazioneBusta busta = new HeaderIntegrazioneBusta();
  1409.         busta.setTipoMittente(soggettoFruitore.getTipo());
  1410.         busta.setMittente(soggettoFruitore.getNome());
  1411.         busta.setTipoDestinatario(idServizio.getSoggettoErogatore().getTipo());
  1412.         busta.setDestinatario(idServizio.getSoggettoErogatore().getNome());
  1413.         busta.setTipoServizio(idServizio.getTipo());
  1414.         busta.setServizio(idServizio.getNome());
  1415.         busta.setVersioneServizio(idServizio.getVersione());
  1416.         busta.setAzione(idServizio.getAzione());
  1417.         if(idBustaRisposta==null){
  1418.             busta.setID(idBusta);
  1419.         }
  1420.         else{
  1421.             busta.setID(idBustaRisposta);
  1422.             busta.setRiferimentoMessaggio(idBusta);
  1423.         }
  1424.         integrazione.setBusta(busta);
  1425.        
  1426.         this.updateHeader(message, integrazione, actorIntegrazione, nomeElemento, prefix, namespace,
  1427.                 proprietaProtocolloNomeElemento, proprietaProtocolloNomeTipoElemento, protocolInfos,
  1428.                 protocollo);
  1429.     }
  1430.        
  1431.     public void updateHeader(OpenSPCoop2SoapMessage message,HeaderIntegrazione integrazione,
  1432.             String actorIntegrazione,String nomeElemento,String prefix,String namespace,
  1433.             String proprietaProtocolloNomeElemento,String proprietaProtocolloNomeTipoElemento,
  1434.             Map<String, String> protocolInfos,
  1435.             String protocollo) throws Exception{
  1436.        
  1437.         if(actorIntegrazione==null)
  1438.             throw new Exception("Actor non definito");
  1439.         SOAPHeader header = message.getSOAPHeader();
  1440.         SOAPHeaderElement headerIntegrazione = null;
  1441.         if(header==null){
  1442.            
  1443.             // Creo soap header
  1444.             OpenSPCoop2Logger.getLoggerOpenSPCoopCore().debug("SOAPHeader non presente: add soapHeader");
  1445.             header = message.getSOAPPart().getEnvelope().addHeader();
  1446.            
  1447.         }else{

  1448.             // cerco soap di integrazione
  1449.             java.util.Iterator<?> it = header.examineAllHeaderElements();
  1450.             while( it.hasNext()  ){
  1451.                 // Test Header Element
  1452.                 headerIntegrazione = (SOAPHeaderElement) it.next();
  1453.                 //Controllo Actor
  1454.                 String actorCheck = SoapUtils.getSoapActor(headerIntegrazione, message.getMessageType());
  1455.                 if( actorIntegrazione.equals(actorCheck) ){
  1456.                     break;
  1457.                 }else{
  1458.                     headerIntegrazione = null;
  1459.                 }
  1460.             }
  1461.             if(headerIntegrazione==null){
  1462.                 OpenSPCoop2Logger.getLoggerOpenSPCoopCore().debug("Header di integrazione non presente, lo creo");
  1463.             }
  1464.         }

  1465.         List<SOAPElement> v = new ArrayList<SOAPElement>(); // mantengo eventuali message element presenti
  1466.         if(headerIntegrazione!=null){
  1467.            
  1468.             java.util.Iterator<?> it = headerIntegrazione.getChildElements();
  1469.             if(it.hasNext()){
  1470.                 SOAPElement tmp = (SOAPElement) it.next();
  1471.                 //System.out.println("CONSERVO MSG ELEMENT["+tmp.getLocalName()+"]");
  1472.                 v.add(tmp);
  1473.             }
  1474.              
  1475.             header.removeChild(headerIntegrazione);
  1476.         }
  1477.        
  1478.         // creo header da nuovo
  1479.         SOAPHeaderElement headerIntegrazioneNEW = this.buildHeader(integrazione, nomeElemento, prefix, namespace,
  1480.                 actorIntegrazione, message,
  1481.                 proprietaProtocolloNomeElemento, proprietaProtocolloNomeTipoElemento, protocolInfos,
  1482.                 protocollo);    
  1483.        
  1484.         // Riaggiungo eventuali elementi interni
  1485.         while(v.size()>0){
  1486.             SOAPElement tmp = v.remove(0);
  1487.             //System.out.println("RIAGGIUNGO MSG ELEMENT["+tmp.getLocalName()+"]");
  1488.             headerIntegrazioneNEW.addChildElement(tmp);
  1489.         }
  1490.        
  1491.         //System.out.println("OTTENGO ["+headerIntegrazioneNEW.getAsString()+"]");
  1492.        
  1493.         // aggiungo header element al SOAP Header
  1494.         //header.addChildElement(headerIntegrazioneNEW);
  1495.         message.addHeaderElement(header, headerIntegrazioneNEW);

  1496.     }
  1497.    
  1498.     public SOAPHeaderElement buildHeader(HeaderIntegrazione integrazione,String nomeElemento,
  1499.             String prefix,String namespace, String actor,
  1500.             OpenSPCoop2SoapMessage m,
  1501.             String proprietaProtocolloNomeElemento,String proprietaProtocolloNomeTipoElemento,
  1502.             Map<String, String> protocolInfos,
  1503.             String protocollo) throws HeaderIntegrazioneException{

  1504.         try{
  1505.             SOAPHeader soapHeader = m.getSOAPHeader();
  1506.             if(soapHeader==null){
  1507.                 soapHeader = m.getSOAPPart().getEnvelope().addHeader();
  1508.             }
  1509.             SOAPHeaderElement header = m.newSOAPHeaderElement(soapHeader, new QName(namespace,nomeElemento,prefix));

  1510.             header.setActor(actor);
  1511.             header.setMustUnderstand(false);
  1512.            
  1513.             setAttributes(integrazione,header,protocollo);
  1514.            
  1515.             if(this.openspcoop2 && this.keySetEnabled_HeaderIntegrazioneSoap.get(CostantiPdD.HEADER_INTEGRAZIONE_PROTOCOL_INFO)) {
  1516.                 if(protocolInfos!=null && protocolInfos.size()>0){
  1517.                    
  1518.                     String prefixProtocolInfo = this.keyValueIntegrazioneSoap.get(CostantiPdD.HEADER_INTEGRAZIONE_PROTOCOL_INFO);
  1519.                    
  1520.                     Iterator<String> itProtocolInfos = protocolInfos.keySet().iterator();
  1521.                     while (itProtocolInfos.hasNext()) {
  1522.                         String name = (String) itProtocolInfos.next();
  1523.                         String value = protocolInfos.get(name);
  1524.                         String nameWithPrefix = (prefixProtocolInfo!=null) ? prefixProtocolInfo.trim()+name : name;
  1525.                         SOAPElement element = header.addChildElement(new QName(namespace,proprietaProtocolloNomeElemento,prefix));
  1526.                         element.setTextContent(value);
  1527.                         @SuppressWarnings("unused")
  1528.                         SOAPElement attribute = element.addAttribute(new QName(proprietaProtocolloNomeTipoElemento),nameWithPrefix);
  1529.                     }
  1530.                 }
  1531.             }
  1532.            
  1533.             return header;

  1534.         }catch(Exception e){
  1535.             throw new HeaderIntegrazioneException("UtilitiesIntegrazione, creazione dell'header soap non riuscita: "+e.getMessage(),e);
  1536.         }
  1537.     }
  1538.    
  1539.    
  1540.     public void setAttributes(HeaderIntegrazione integrazione, SOAPHeaderElement header, String protocollo){
  1541.         if(integrazione.getBusta()!=null){

  1542.             if(integrazione.getBusta().getTipoMittente()!=null){
  1543.                 if(this.keySetEnabled_HeaderIntegrazioneSoap.get(CostantiPdD.HEADER_INTEGRAZIONE_TIPO_MITTENTE)) {
  1544.                     String tipo = integrazione.getBusta().getTipoMittente();
  1545.                     String normalized = normalizeGovWay2OpenSPCoop_tipoSoggetto(tipo, protocollo);
  1546.                     header.setAttribute((String)this.keyValueIntegrazioneSoap.get(CostantiPdD.HEADER_INTEGRAZIONE_TIPO_MITTENTE), normalized);
  1547.                 }
  1548.             }
  1549.             if(integrazione.getBusta().getMittente()!=null){
  1550.                 if(this.keySetEnabled_HeaderIntegrazioneSoap.get(CostantiPdD.HEADER_INTEGRAZIONE_MITTENTE)) {
  1551.                     header.setAttribute((String)this.keyValueIntegrazioneSoap.get(CostantiPdD.HEADER_INTEGRAZIONE_MITTENTE), integrazione.getBusta().getMittente());
  1552.                 }
  1553.             }

  1554.             if(integrazione.getBusta().getTipoDestinatario()!=null){
  1555.                 if(this.keySetEnabled_HeaderIntegrazioneSoap.get(CostantiPdD.HEADER_INTEGRAZIONE_TIPO_DESTINATARIO)) {
  1556.                     String tipo = integrazione.getBusta().getTipoDestinatario();
  1557.                     String normalized = normalizeGovWay2OpenSPCoop_tipoSoggetto(tipo, protocollo);
  1558.                     header.setAttribute((String)this.keyValueIntegrazioneSoap.get(CostantiPdD.HEADER_INTEGRAZIONE_TIPO_DESTINATARIO), normalized);
  1559.                 }
  1560.             }
  1561.             if(integrazione.getBusta().getDestinatario()!=null){
  1562.                 if(this.keySetEnabled_HeaderIntegrazioneSoap.get(CostantiPdD.HEADER_INTEGRAZIONE_DESTINATARIO)) {
  1563.                     header.setAttribute((String)this.keyValueIntegrazioneSoap.get(CostantiPdD.HEADER_INTEGRAZIONE_DESTINATARIO), integrazione.getBusta().getDestinatario());
  1564.                 }
  1565.             }

  1566.             if(integrazione.getBusta().getTipoServizio()!=null){
  1567.                 if(this.keySetEnabled_HeaderIntegrazioneSoap.get(CostantiPdD.HEADER_INTEGRAZIONE_TIPO_SERVIZIO)) {
  1568.                     String tipo = integrazione.getBusta().getTipoServizio();
  1569.                     String normalized = normalizeGovWay2OpenSPCoop_tipoServizio(tipo, protocollo);
  1570.                     header.setAttribute((String)this.keyValueIntegrazioneSoap.get(CostantiPdD.HEADER_INTEGRAZIONE_TIPO_SERVIZIO), normalized);
  1571.                 }
  1572.             }
  1573.             if(integrazione.getBusta().getServizio()!=null){
  1574.                 if(this.keySetEnabled_HeaderIntegrazioneSoap.get(CostantiPdD.HEADER_INTEGRAZIONE_SERVIZIO)) {
  1575.                     header.setAttribute((String)this.keyValueIntegrazioneSoap.get(CostantiPdD.HEADER_INTEGRAZIONE_SERVIZIO), integrazione.getBusta().getServizio());
  1576.                 }
  1577.             }
  1578. //          if(integrazione.getBusta().getVersioneServizio()!=null){
  1579. //              if(this.keySetEnabled_HeaderIntegrazioneSoap.get(CostantiPdD.HEADER_INTEGRAZIONE_VERSIONE_SERVIZIO)) {
  1580. //                  header.setAttribute((String)this.keyValueIntegrazioneSoap.get(CostantiPdD.HEADER_INTEGRAZIONE_VERSIONE_SERVIZIO), integrazione.getBusta().getVersioneServizio().intValue()+"");
  1581. //              }
  1582. //          }

  1583.             if(integrazione.getBusta().getAzione()!=null){
  1584.                 if(this.keySetEnabled_HeaderIntegrazioneSoap.get(CostantiPdD.HEADER_INTEGRAZIONE_AZIONE)) {
  1585.                     header.setAttribute((String)this.keyValueIntegrazioneSoap.get(CostantiPdD.HEADER_INTEGRAZIONE_AZIONE), integrazione.getBusta().getAzione());
  1586.                 }
  1587.             }

  1588.             if(integrazione.getBusta().getID()!=null){
  1589.                 if(this.keySetEnabled_HeaderIntegrazioneSoap.get(CostantiPdD.HEADER_INTEGRAZIONE_ID_MESSAGGIO)) {
  1590.                     header.setAttribute((String)this.keyValueIntegrazioneSoap.get(CostantiPdD.HEADER_INTEGRAZIONE_ID_MESSAGGIO), integrazione.getBusta().getID());
  1591.                 }
  1592.             }

  1593.             if(integrazione.getBusta().getRiferimentoMessaggio()!=null){
  1594.                 if(this.keySetEnabled_HeaderIntegrazioneSoap.get(CostantiPdD.HEADER_INTEGRAZIONE_RIFERIMENTO_MESSAGGIO)) {
  1595.                     header.setAttribute((String)this.keyValueIntegrazioneSoap.get(CostantiPdD.HEADER_INTEGRAZIONE_RIFERIMENTO_MESSAGGIO), integrazione.getBusta().getRiferimentoMessaggio());
  1596.                 }
  1597.             }

  1598.             if(integrazione.getBusta().getIdCollaborazione()!=null){
  1599.                 if(this.keySetEnabled_HeaderIntegrazioneSoap.get(CostantiPdD.HEADER_INTEGRAZIONE_COLLABORAZIONE)) {
  1600.                     header.setAttribute((String)this.keyValueIntegrazioneSoap.get(CostantiPdD.HEADER_INTEGRAZIONE_COLLABORAZIONE), integrazione.getBusta().getIdCollaborazione());
  1601.                 }
  1602.             }
  1603.         }

  1604.         if(integrazione.getIdApplicativo()!=null){
  1605.             if(this.keySetEnabled_HeaderIntegrazioneSoap.get(CostantiPdD.HEADER_INTEGRAZIONE_ID_APPLICATIVO)) {
  1606.                 header.setAttribute((String)this.keyValueIntegrazioneSoap.get(CostantiPdD.HEADER_INTEGRAZIONE_ID_APPLICATIVO), integrazione.getIdApplicativo());
  1607.             }
  1608.         }
  1609.        
  1610.         if(integrazione.getServizioApplicativo()!=null){
  1611.             if(this.keySetEnabled_HeaderIntegrazioneSoap.get(CostantiPdD.HEADER_INTEGRAZIONE_SERVIZIO_APPLICATIVO)) {
  1612.                 header.setAttribute((String)this.keyValueIntegrazioneSoap.get(CostantiPdD.HEADER_INTEGRAZIONE_SERVIZIO_APPLICATIVO), integrazione.getServizioApplicativo());
  1613.             }
  1614.         }
  1615.        
  1616.         if(this.openspcoop2 && integrazione.getIdTransazione()!=null){
  1617.             if(this.keySetEnabled_HeaderIntegrazioneSoap.get(CostantiPdD.HEADER_INTEGRAZIONE_ID_TRANSAZIONE)) {
  1618.                 header.setAttribute((String)this.keyValueIntegrazioneSoap.get(CostantiPdD.HEADER_INTEGRAZIONE_ID_TRANSAZIONE), integrazione.getIdTransazione());
  1619.             }
  1620.         }
  1621.        
  1622.         if(this.keySetEnabled_HeaderIntegrazioneSoap.get(CostantiPdD.HEADER_INTEGRAZIONE_INFO)) {
  1623.            
  1624.             if(this.openspcoop2) {
  1625.                 header.setAttribute(OPENSPCOOP2_HEADER_INTEGRAZIONE_SOAP_PDD_VERSION, this.openspcoopProperties.getHeaderIntegrazioneSOAPPdDVersione());
  1626.                 if(this.openspcoopProperties.getHeaderIntegrazioneSOAPPdDDetails()!=null && !"".equals(this.openspcoopProperties.getHeaderIntegrazioneSOAPPdDDetails())){
  1627.                     header.setAttribute(OPENSPCOOP2_HEADER_INTEGRAZIONE_SOAP_PDD_DETAILS, this.openspcoopProperties.getHeaderIntegrazioneSOAPPdDDetails());
  1628.                 }
  1629.             }
  1630.             else {
  1631.                 header.setAttribute(OPENSPCOOP1_HEADER_INTEGRAZIONE_SOAP_PDD_VERSION, this.openspcoopProperties.getHeaderIntegrazioneSOAPPdDVersione());
  1632.                 if(this.openspcoopProperties.getHeaderIntegrazioneSOAPPdDDetails()!=null && !"".equals(this.openspcoopProperties.getHeaderIntegrazioneSOAPPdDDetails())){
  1633.                     header.setAttribute(OPENSPCOOP1_HEADER_INTEGRAZIONE_SOAP_PDD_DETAILS, this.openspcoopProperties.getHeaderIntegrazioneSOAPPdDDetails());
  1634.                 }
  1635.             }
  1636.            
  1637.         }

  1638.     }
  1639.    
  1640.    
  1641.     public void deleteHeader(OpenSPCoop2SoapMessage message,String actorIntegrazione) throws HeaderIntegrazioneException{

  1642.         try{

  1643.             if(actorIntegrazione==null)
  1644.                 throw new Exception("Actor non definito");
  1645.             SOAPHeader header = message.getSOAPHeader();
  1646.             if(header==null){
  1647.                 OpenSPCoop2Logger.getLoggerOpenSPCoopCore().debug("SOAPHeader non presente");
  1648.                 return;
  1649.             }
  1650.             SOAPHeaderElement headerElement = null;
  1651.             java.util.Iterator<?> it = header.examineAllHeaderElements();
  1652.             while( it.hasNext()  ){
  1653.                 // Test Header Element
  1654.                 headerElement = (SOAPHeaderElement) it.next();
  1655.                 //Controllo Actor
  1656.                 String actorCheck = SoapUtils.getSoapActor(headerElement, message.getMessageType());
  1657.                 if( actorIntegrazione.equals(actorCheck) ){
  1658.                     break;
  1659.                 }else{
  1660.                     headerElement = null;
  1661.                 }
  1662.             }
  1663.             if(headerElement==null){
  1664.                 OpenSPCoop2Logger.getLoggerOpenSPCoopCore().debug("Header di integrazione non presente");
  1665.                 return;
  1666.             }
  1667.            
  1668.             header.removeChild(headerElement);
  1669.            
  1670.         }catch(Exception e){
  1671.             throw new HeaderIntegrazioneException("UtilitiesIntegrazione, eliminazione dell'header soap non riuscita: "+e.getMessage(),e);
  1672.         }
  1673.     }
  1674.    
  1675.     public static String getIdTransazione(PdDContext context){
  1676.         return UtilitiesIntegrazione.getIdTransazione(context);
  1677.     }
  1678. }