ErroriProperties.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.protocol.utils;

  21. import java.util.Enumeration;
  22. import java.util.Properties;
  23. import java.util.concurrent.ConcurrentHashMap;

  24. import org.openspcoop2.message.constants.IntegrationError;
  25. import org.openspcoop2.protocol.sdk.ProtocolException;
  26. import org.openspcoop2.protocol.sdk.constants.CostantiProtocollo;
  27. import org.openspcoop2.protocol.sdk.constants.IntegrationFunctionError;
  28. import org.openspcoop2.utils.LoggerWrapperFactory;
  29. import org.openspcoop2.utils.resources.Loader;
  30. import org.slf4j.Logger;

  31. /**
  32.  * Classe che gestisce il file di properties 'errori.properties'
  33.  *
  34.  * @author Poli Andrea (apoli@link.it)
  35.  * @author $Author$
  36.  * @version $Rev$, $Date$
  37.  */
  38. public class ErroriProperties {

  39.     // 400
  40.     private static boolean FORCE_SPECIFIC_ERROR_TYPE_FOR_INTERNAL_BAD_REQUEST = false;
  41.     // 502
  42.     private static boolean FORCE_SPECIFIC_ERROR_TYPE_FOR_BAD_RESPONSE = false;
  43.     private static boolean FORCE_SPECIFIC_ERROR_TYPE_FOR_INTERNAL_RESPONSE_ERROR = false;
  44.     // 503
  45.     private static boolean FORCE_SPECIFIC_ERROR_TYPE_FOR_INTERNAL_ERROR = false;

  46.     // 400
  47.     public static boolean isFORCE_SPECIFIC_ERROR_TYPE_FOR_INTERNAL_BAD_REQUEST() {
  48.         return FORCE_SPECIFIC_ERROR_TYPE_FOR_INTERNAL_BAD_REQUEST;
  49.     }
  50.     public static void setFORCE_SPECIFIC_ERROR_TYPE_FOR_INTERNAL_BAD_REQUEST(
  51.             boolean fORCE_SPECIFIC_ERROR_TYPE_FOR_INTERNAL_BAD_REQUEST,
  52.             String confDir,Logger log,Loader loader) throws ProtocolException {
  53.         FORCE_SPECIFIC_ERROR_TYPE_FOR_INTERNAL_BAD_REQUEST = fORCE_SPECIFIC_ERROR_TYPE_FOR_INTERNAL_BAD_REQUEST;
  54.         reInit(confDir, log, loader);
  55.     }
  56.    
  57.     public static boolean isFORCE_SPECIFIC_ERROR_TYPE_FOR_BAD_RESPONSE() {
  58.         return FORCE_SPECIFIC_ERROR_TYPE_FOR_BAD_RESPONSE;
  59.     }
  60.     public static void setFORCE_SPECIFIC_ERROR_TYPE_FOR_BAD_RESPONSE(
  61.             boolean fORCE_SPECIFIC_ERROR_TYPE_FOR_BAD_RESPONSE,
  62.             String confDir,Logger log,Loader loader) throws ProtocolException {
  63.         FORCE_SPECIFIC_ERROR_TYPE_FOR_BAD_RESPONSE = fORCE_SPECIFIC_ERROR_TYPE_FOR_BAD_RESPONSE;
  64.         reInit(confDir, log, loader);
  65.     }

  66.     public static boolean isFORCE_SPECIFIC_ERROR_TYPE_FOR_INTERNAL_RESPONSE_ERROR() {
  67.         return FORCE_SPECIFIC_ERROR_TYPE_FOR_INTERNAL_RESPONSE_ERROR;
  68.     }
  69.     public static void setFORCE_SPECIFIC_ERROR_TYPE_FOR_INTERNAL_RESPONSE_ERROR(
  70.             boolean fORCE_SPECIFIC_ERROR_TYPE_FOR_INTERNAL_RESPONSE_ERROR,
  71.             String confDir,Logger log,Loader loader) throws ProtocolException {
  72.         FORCE_SPECIFIC_ERROR_TYPE_FOR_INTERNAL_RESPONSE_ERROR = fORCE_SPECIFIC_ERROR_TYPE_FOR_INTERNAL_RESPONSE_ERROR;
  73.         reInit(confDir, log, loader);
  74.     }

  75.     public static boolean isFORCE_SPECIFIC_ERROR_TYPE_FOR_INTERNAL_ERROR() {
  76.         return FORCE_SPECIFIC_ERROR_TYPE_FOR_INTERNAL_ERROR;
  77.     }
  78.     public static void setFORCE_SPECIFIC_ERROR_TYPE_FOR_INTERNAL_ERROR(
  79.             boolean fORCE_SPECIFIC_ERROR_TYPE_FOR_INTERNAL_ERROR,
  80.             String confDir,Logger log,Loader loader) throws ProtocolException {
  81.         FORCE_SPECIFIC_ERROR_TYPE_FOR_INTERNAL_ERROR = fORCE_SPECIFIC_ERROR_TYPE_FOR_INTERNAL_ERROR;
  82.         reInit(confDir, log, loader);
  83.     }
  84.    
  85.     private static synchronized void reInit(String confDir,Logger log,Loader loader) throws ProtocolException {
  86.         ErroriProperties erroriPropertiesNew = new ErroriProperties(confDir, log);
  87.         erroriPropertiesNew.validaConfigurazione(loader);
  88.         ErroriProperties.erroriProperties = erroriPropertiesNew; // switch
  89.     }
  90.    
  91.    
  92.     /** Logger utilizzato per errori eventuali. */
  93.     private Logger log = null;


  94.     /** Copia Statica */
  95.     private static ErroriProperties erroriProperties = null;

  96.     /* ********  F I E L D S  P R I V A T I  ******** */

  97.     /** Reader delle proprieta' impostate nel file 'errori.properties' */
  98.     private ErroriInstanceProperties reader;


  99.    


  100.     /* ********  C O S T R U T T O R E  ******** */

  101.     /**
  102.      * Viene chiamato in causa per istanziare il properties reader
  103.      *
  104.      *
  105.      */
  106.     private ErroriProperties(String confDir,Logger log) throws ProtocolException{

  107.         if(log != null)
  108.             this.log = log;
  109.         else
  110.             this.log = LoggerWrapperFactory.getLogger(ErroriProperties.class);

  111.         /* ---- Lettura del cammino del file di configurazione ---- */

  112.         Properties propertiesReader = new Properties();
  113.         java.io.InputStream properties = null;
  114.         try{  
  115.             properties = ErroriProperties.class.getResourceAsStream("/org/openspcoop2/protocol/utils/errori.properties");
  116.             if(properties==null){
  117.                 throw new Exception("File '/org/openspcoop2/protocol/utils/errori.properties' not found");
  118.             }
  119.             propertiesReader.load(properties);
  120.         }catch(Exception e) {
  121.             this.log.error("Riscontrato errore durante la lettura del file 'org/openspcoop2/protocol/utils/errori.properties': "+e.getMessage());
  122.             throw new ProtocolException("ErroriProperties initialize error: "+e.getMessage(),e);
  123.         }finally{
  124.             try{
  125.                 if(properties!=null)
  126.                     properties.close();
  127.             }catch(Throwable er){
  128.                 // close
  129.             }
  130.         }
  131.         try{
  132.             this.reader = new ErroriInstanceProperties(confDir, propertiesReader, this.log);
  133.         }catch(Exception e){
  134.             throw new ProtocolException(e.getMessage(),e);
  135.         }

  136.     }

  137.     /**
  138.      * Il Metodo si occupa di inizializzare il propertiesReader
  139.      *
  140.      *
  141.      */
  142.     public static synchronized void initialize(String confDir,Logger log,Loader loader) throws ProtocolException{

  143.         if(ErroriProperties.erroriProperties==null){
  144.            
  145.             ErroriProperties.erroriProperties = new ErroriProperties(confDir, log);
  146.             erroriProperties.validaConfigurazione(loader);
  147.                        
  148.         }

  149.     }

  150.     /**
  151.      * Ritorna l'istanza di questa classe
  152.      *
  153.      * @return Istanza di OpenSPCoopProperties
  154.      * @throws Exception
  155.      *
  156.      */
  157.     public static ErroriProperties getInstance(Logger log) throws ProtocolException{

  158.         if(ErroriProperties.erroriProperties==null) {
  159.             // spotbugs warning 'SING_SINGLETON_GETTER_NOT_SYNCHRONIZED': l'istanza viene creata allo startup
  160.             synchronized (ErroriProperties.class) {
  161.                 throw new ProtocolException("ErroriProperties not initialized (use init method in factory)");
  162.             }
  163.         }

  164.         return ErroriProperties.erroriProperties;
  165.     }




  166.     public void validaConfigurazione(Loader loader) throws ProtocolException  {
  167.         try{  
  168.            
  169.             getPrefixWebSite();
  170.            
  171.             getPrefixWebSiteErrorPage();
  172.            
  173.             initMapWrapped();
  174.            
  175.             IntegrationFunctionError [] lista = IntegrationFunctionError.values();
  176.             for (IntegrationFunctionError integrationFunctionError : lista) {
  177.                
  178.                 getIntegrationError(integrationFunctionError);
  179.                
  180.                 getErrorType(integrationFunctionError);

  181.                 getGenericDetails(integrationFunctionError);
  182.                
  183.                 isForceGenericDetails(integrationFunctionError);
  184.                
  185.                 getWebSite(integrationFunctionError);
  186.                
  187.             }
  188.            
  189.            
  190.         }catch(java.lang.Exception e) {
  191.             String msg = "Riscontrato errore durante la validazione della proprieta' degli errori, "+e.getMessage();
  192.             this.log.error(msg,e);
  193.             throw new ProtocolException(msg,e);
  194.         }
  195.     }

  196.    
  197.    
  198.     /* **** CONVERTER **** */

  199.     private Boolean typeEnabled = null;
  200.     public boolean isTypeEnabled() throws ProtocolException {
  201.         if(this.typeEnabled==null) {
  202.             this.initTypeEnabled();
  203.         }
  204.         return this.typeEnabled;
  205.     }
  206.     private synchronized void initTypeEnabled() throws ProtocolException {
  207.         if(this.typeEnabled==null) {
  208.             this.typeEnabled = getBooleanProperty("type.enabled");
  209.         }
  210.     }
  211.    
  212.    
  213.    
  214.    
  215.     private String webSite = null;
  216.     public String getPrefixWebSite() throws ProtocolException {
  217.         if(this.webSite==null) {
  218.             this.initPrefixWebSite();
  219.         }
  220.         return this.webSite;
  221.     }
  222.     private synchronized void initPrefixWebSite() throws ProtocolException {
  223.         if(this.webSite==null) {
  224.             this.webSite = getProperty("webSite");
  225.             if(this.webSite.endsWith("/")) {
  226.                 this.webSite = this.webSite.substring(0, this.webSite.length()-1);
  227.             }
  228.         }
  229.     }
  230.    
  231.    

  232.     private String webSiteErrorPage = null;
  233.     public String getPrefixWebSiteErrorPage() throws ProtocolException {
  234.         if(this.webSiteErrorPage==null) {
  235.             this.initPrefixWebSiteErrorPage();
  236.         }
  237.         return this.webSiteErrorPage;
  238.     }
  239.     private synchronized void initPrefixWebSiteErrorPage() throws ProtocolException {
  240.         if(this.webSiteErrorPage==null) {
  241.             this.webSiteErrorPage = getProperty("webSite.errorPage");
  242.         }
  243.     }
  244.    
  245.    
  246.    
  247.     private ConcurrentHashMap<IntegrationFunctionError,Boolean> mapWrapped= null;
  248.     public Boolean isWrapped(IntegrationFunctionError functionError) throws ProtocolException {
  249.         if(this.mapWrapped==null){
  250.             this.initMapWrapped();
  251.         }
  252.         return this.mapWrapped.get(functionError);
  253.     }
  254.     private synchronized void initMapWrapped() throws ProtocolException {
  255.         if(this.mapWrapped==null){
  256.             this.mapWrapped = new ConcurrentHashMap<IntegrationFunctionError, Boolean>();
  257.             IntegrationFunctionError [] lista = IntegrationFunctionError.wrappedValues();
  258.             for (IntegrationFunctionError integrationFunctionError : lista) {
  259.                
  260.                 String pName = integrationFunctionError.name()+".enabled";
  261.                 try{
  262.                     Boolean p = null;
  263.                     if(IntegrationFunctionError.WRAP_400_INTERNAL_BAD_REQUEST.equals(integrationFunctionError)){
  264.                         if(FORCE_SPECIFIC_ERROR_TYPE_FOR_INTERNAL_BAD_REQUEST) {
  265.                             p = false;
  266.                         }
  267.                         else {
  268.                             p = getBooleanProperty(pName);
  269.                         }
  270.                     }
  271.                     else if(IntegrationFunctionError.WRAP_502_BAD_RESPONSE.equals(integrationFunctionError)){
  272.                         if(FORCE_SPECIFIC_ERROR_TYPE_FOR_BAD_RESPONSE) {
  273.                             p = false;
  274.                         }
  275.                         else {
  276.                             p = getBooleanProperty(pName);
  277.                         }
  278.                     }
  279.                     else if(IntegrationFunctionError.WRAP_502_INTERNAL_RESPONSE_ERROR.equals(integrationFunctionError)){
  280.                         if(FORCE_SPECIFIC_ERROR_TYPE_FOR_INTERNAL_RESPONSE_ERROR) {
  281.                             p = false;
  282.                         }
  283.                         else {
  284.                             p = getBooleanProperty(pName);
  285.                         }
  286.                     }
  287.                     else if(IntegrationFunctionError.WRAP_503_INTERNAL_ERROR.equals(integrationFunctionError)){
  288.                         if(FORCE_SPECIFIC_ERROR_TYPE_FOR_INTERNAL_ERROR) {
  289.                             p = false;
  290.                         }
  291.                         else {
  292.                             p = getBooleanProperty(pName);
  293.                         }
  294.                     }
  295.                     else {
  296.                         // caso non esistente
  297.                         p = getBooleanProperty(pName);
  298.                     }
  299.                     this.mapWrapped.put(integrationFunctionError, p);
  300.                 }catch(Exception e){
  301.                     throw new ProtocolException("Errore durante la gestione del codice ["+integrationFunctionError.name()+"]: "+e.getMessage(),e);
  302.                 }
  303.             }
  304.         }
  305.     }
  306.    
  307.    
  308.    
  309.    
  310.    
  311.     private ConcurrentHashMap<IntegrationFunctionError,IntegrationError> mapIntegrationError= null;
  312.     private ConcurrentHashMap<IntegrationFunctionError,IntegrationError> mapIntegrationError_noWrap= null;
  313.     public IntegrationError getIntegrationError(IntegrationFunctionError functionError) throws ProtocolException {
  314.         if(this.mapIntegrationError==null){
  315.             this.initMapIntegrationError();
  316.         }
  317.         return this.mapIntegrationError.get(functionError);
  318.     }
  319.     public IntegrationError getIntegrationError_noWrap(IntegrationFunctionError functionError) throws ProtocolException {
  320.         if(this.mapIntegrationError_noWrap==null){
  321.             this.initMapIntegrationError();
  322.         }
  323.         return this.mapIntegrationError_noWrap.get(functionError);
  324.     }
  325.     private synchronized void initMapIntegrationError() throws ProtocolException {
  326.         if(this.mapIntegrationError==null){
  327.             this.mapIntegrationError = new ConcurrentHashMap<IntegrationFunctionError, IntegrationError>();
  328.             this.mapIntegrationError_noWrap = new ConcurrentHashMap<IntegrationFunctionError, IntegrationError>();
  329.             IntegrationFunctionError [] lista = IntegrationFunctionError.values();
  330.             for (IntegrationFunctionError integrationFunctionError : lista) {
  331.                 String pName = integrationFunctionError.name()+".errorCode";
  332.                 try{
  333.                     String p = getProperty(pName);
  334.                     IntegrationError integrationError = IntegrationError.valueOf(p);
  335.                     IntegrationError integrationError_noWrap = IntegrationError.valueOf(p);
  336.                    
  337.                     if(integrationFunctionError.isWrapBadRequest()) {
  338.                         if(isWrapped(IntegrationFunctionError.WRAP_400_INTERNAL_BAD_REQUEST)) {
  339.                             String pWrappedName = IntegrationFunctionError.WRAP_400_INTERNAL_BAD_REQUEST.name()+".errorCode";
  340.                             p = getProperty(pWrappedName);
  341.                             integrationError = IntegrationError.valueOf(p);
  342.                         }
  343.                     }
  344.                     else if(integrationFunctionError.isWrapBadResponse(integrationError)) {
  345.                         if(isWrapped(IntegrationFunctionError.WRAP_502_BAD_RESPONSE)) {
  346.                             String pWrappedName = IntegrationFunctionError.WRAP_502_BAD_RESPONSE.name()+".errorCode";
  347.                             p = getProperty(pWrappedName);
  348.                             integrationError = IntegrationError.valueOf(p);
  349.                         }
  350.                     }
  351.                     else if(integrationFunctionError.isWrapInternalResponseError(integrationError)) {
  352.                         if(isWrapped(IntegrationFunctionError.WRAP_502_INTERNAL_RESPONSE_ERROR)) {
  353.                             String pWrappedName = IntegrationFunctionError.WRAP_502_INTERNAL_RESPONSE_ERROR.name()+".errorCode";
  354.                             p = getProperty(pWrappedName);
  355.                             integrationError = IntegrationError.valueOf(p);
  356.                         }
  357.                     }
  358.                     else if(integrationFunctionError.isWrapInternalError()) {
  359.                         if(isWrapped(IntegrationFunctionError.WRAP_503_INTERNAL_ERROR)) {
  360.                             String pWrappedName = IntegrationFunctionError.WRAP_503_INTERNAL_ERROR.name()+".errorCode";
  361.                             p = getProperty(pWrappedName);
  362.                             integrationError = IntegrationError.valueOf(p);
  363.                         }
  364.                     }
  365.                    
  366.                     this.mapIntegrationError.put(integrationFunctionError, integrationError);
  367.                     this.mapIntegrationError_noWrap.put(integrationFunctionError, integrationError_noWrap);
  368.                    
  369.                 }catch(Exception e){
  370.                     throw new ProtocolException("Errore durante la gestione del codice ["+integrationFunctionError.name()+"]: "+e.getMessage(),e);
  371.                 }
  372.             }
  373.         }
  374.     }
  375.    
  376.    
  377.    
  378.     private ConcurrentHashMap<IntegrationFunctionError,String> mapErrorType= null;
  379.     private ConcurrentHashMap<IntegrationFunctionError,String> mapErrorType_noWrap= null;
  380.     public String getErrorType(IntegrationFunctionError functionError) throws ProtocolException {
  381.         if(this.mapErrorType==null){
  382.             this.initMapErrorType();
  383.         }
  384.         return this.mapErrorType.get(functionError);
  385.     }
  386.     public String getErrorType_noWrap(IntegrationFunctionError functionError) throws ProtocolException {
  387.         if(this.mapErrorType_noWrap==null){
  388.             this.initMapErrorType();
  389.         }
  390.         return this.mapErrorType_noWrap.get(functionError);
  391.     }
  392.     public IntegrationFunctionError convertToIntegrationFunctionError(String errorType) throws ProtocolException {
  393.         return this._convertToIntegrationFunctionError(errorType);
  394.     }
  395.     private IntegrationFunctionError _convertToIntegrationFunctionError(String errorType) throws ProtocolException {
  396.         if(this.mapErrorType==null){
  397.             this.initMapErrorType();
  398.         }
  399.         Enumeration<IntegrationFunctionError> en = this.mapErrorType.keys();
  400.         while (en.hasMoreElements()) {
  401.             IntegrationFunctionError integrationFunctionError = (IntegrationFunctionError) en.nextElement();
  402.             String type = this.mapErrorType.get(integrationFunctionError);
  403.             if(type.equals(errorType)) {
  404.                 return integrationFunctionError;
  405.             }
  406.         }
  407.         throw new ProtocolException("GovWayErrorType '"+errorType+"' unknown");
  408.     }
  409.     public IntegrationFunctionError convertToIntegrationFunctionError_noWrap(String errorType) throws ProtocolException {
  410.         return this._convertToIntegrationFunctionError_noWrap(errorType);
  411.     }
  412.     private IntegrationFunctionError _convertToIntegrationFunctionError_noWrap(String errorType) throws ProtocolException {
  413.         if(this.mapErrorType_noWrap==null){
  414.             this.initMapErrorType();
  415.         }
  416.         Enumeration<IntegrationFunctionError> en = this.mapErrorType_noWrap.keys();
  417.         while (en.hasMoreElements()) {
  418.             IntegrationFunctionError integrationFunctionError = (IntegrationFunctionError) en.nextElement();
  419.             String type = this.mapErrorType_noWrap.get(integrationFunctionError);
  420.             if(type.equals(errorType)) {
  421.                 return integrationFunctionError;
  422.             }
  423.         }
  424.         throw new ProtocolException("GovWayErrorType '"+errorType+"' unknown");
  425.     }
  426.     private synchronized void initMapErrorType() throws ProtocolException {
  427.         if(this.mapErrorType==null){
  428.             this.mapErrorType = new ConcurrentHashMap<IntegrationFunctionError, String>();
  429.             this.mapErrorType_noWrap = new ConcurrentHashMap<IntegrationFunctionError, String>();
  430.             IntegrationFunctionError [] lista = IntegrationFunctionError.values();
  431.             for (IntegrationFunctionError integrationFunctionError : lista) {
  432.                 String pName = integrationFunctionError.name()+".errorType";
  433.                 try{
  434.                     String p = getProperty(pName);
  435.                     String p_noWrap = p;
  436.                    
  437.                     IntegrationError integrationError = this.mapIntegrationError_noWrap.get(integrationFunctionError);
  438.                    
  439.                     if(integrationFunctionError.isWrapBadRequest()) {
  440.                         if(isWrapped(IntegrationFunctionError.WRAP_400_INTERNAL_BAD_REQUEST)) {
  441.                             String pWrappedName = IntegrationFunctionError.WRAP_400_INTERNAL_BAD_REQUEST.name()+".errorType";
  442.                             p = getProperty(pWrappedName);
  443.                         }
  444.                     }
  445.                     else if(integrationFunctionError.isWrapBadResponse(integrationError)) {
  446.                         if(isWrapped(IntegrationFunctionError.WRAP_502_BAD_RESPONSE)) {
  447.                             String pWrappedName = IntegrationFunctionError.WRAP_502_BAD_RESPONSE.name()+".errorType";
  448.                             p = getProperty(pWrappedName);
  449.                         }
  450.                     }
  451.                     else if(integrationFunctionError.isWrapInternalResponseError(integrationError)) {
  452.                         if(isWrapped(IntegrationFunctionError.WRAP_502_INTERNAL_RESPONSE_ERROR)) {
  453.                             String pWrappedName = IntegrationFunctionError.WRAP_502_INTERNAL_RESPONSE_ERROR.name()+".errorType";
  454.                             p = getProperty(pWrappedName);
  455.                         }
  456.                     }
  457.                     else if(integrationFunctionError.isWrapInternalError()) {
  458.                         if(isWrapped(IntegrationFunctionError.WRAP_503_INTERNAL_ERROR)) {
  459.                             String pWrappedName = IntegrationFunctionError.WRAP_503_INTERNAL_ERROR.name()+".errorType";
  460.                             p = getProperty(pWrappedName);
  461.                         }
  462.                     }              
  463.                    
  464.                     this.mapErrorType.put(integrationFunctionError, p);
  465.                     this.mapErrorType_noWrap.put(integrationFunctionError, p_noWrap);
  466.                 }catch(Exception e){
  467.                     throw new ProtocolException("Errore durante la gestione del codice ["+integrationFunctionError.name()+"]: "+e.getMessage(),e);
  468.                 }
  469.             }
  470.         }
  471.     }
  472.    
  473.    
  474.    
  475.     private ConcurrentHashMap<IntegrationFunctionError,String> mapWebSite= null;
  476.     private ConcurrentHashMap<IntegrationFunctionError,String> mapWebSite_noWrap= null;
  477.     public String getWebSite(IntegrationFunctionError functionError) throws ProtocolException {
  478.         if(this.mapWebSite==null){
  479.             this.initMapWebSite();
  480.         }
  481.         return this.mapWebSite.get(functionError);
  482.     }
  483.     public String getWebSite_noWrap(IntegrationFunctionError functionError) throws ProtocolException {
  484.         if(this.mapWebSite_noWrap==null){
  485.             this.initMapWebSite();
  486.         }
  487.         return this.mapWebSite_noWrap.get(functionError);
  488.     }
  489.     private synchronized void initMapWebSite() throws ProtocolException {
  490.         if(this.mapWebSite==null){
  491.             this.mapWebSite = new ConcurrentHashMap<IntegrationFunctionError, String>();
  492.             this.mapWebSite_noWrap = new ConcurrentHashMap<IntegrationFunctionError, String>();
  493.             IntegrationFunctionError [] lista = IntegrationFunctionError.values();
  494.             for (IntegrationFunctionError integrationFunctionError : lista) {
  495.                 String pName = integrationFunctionError.name()+".webSite";
  496.                 try{
  497.                     String p = getOptionalProperty(pName);
  498.                     String p_noWrap = p;
  499.                    
  500.                     IntegrationError integrationError = this.mapIntegrationError_noWrap.get(integrationFunctionError);
  501.                     IntegrationError integrationError_noWrap = integrationError;
  502.                    
  503.                     String integrationType = this.getErrorType(integrationFunctionError);
  504.                     String integrationType_noWrap = integrationType;                
  505.                    
  506.                     if(integrationFunctionError.isWrapBadRequest()) {
  507.                         if(isWrapped(IntegrationFunctionError.WRAP_400_INTERNAL_BAD_REQUEST)) {
  508.                             String pWrappedName = IntegrationFunctionError.WRAP_400_INTERNAL_BAD_REQUEST.name()+".webSite";
  509.                             p = getOptionalProperty(pWrappedName);
  510.                             integrationError = this.getIntegrationError(IntegrationFunctionError.WRAP_400_INTERNAL_BAD_REQUEST);
  511.                             integrationType = this.getErrorType(IntegrationFunctionError.WRAP_400_INTERNAL_BAD_REQUEST);
  512.                         }
  513.                     }
  514.                     else if(integrationFunctionError.isWrapBadResponse(integrationError)) {
  515.                         if(isWrapped(IntegrationFunctionError.WRAP_502_BAD_RESPONSE)) {
  516.                             String pWrappedName = IntegrationFunctionError.WRAP_502_BAD_RESPONSE.name()+".webSite";
  517.                             p = getOptionalProperty(pWrappedName);
  518.                             integrationError = this.getIntegrationError(IntegrationFunctionError.WRAP_502_BAD_RESPONSE);
  519.                             integrationType = this.getErrorType(IntegrationFunctionError.WRAP_502_BAD_RESPONSE);
  520.                         }
  521.                     }
  522.                     else if(integrationFunctionError.isWrapInternalResponseError(integrationError)) {
  523.                         if(isWrapped(IntegrationFunctionError.WRAP_502_INTERNAL_RESPONSE_ERROR)) {
  524.                             String pWrappedName = IntegrationFunctionError.WRAP_502_INTERNAL_RESPONSE_ERROR.name()+".webSite";
  525.                             p = getOptionalProperty(pWrappedName);
  526.                             integrationError = this.getIntegrationError(IntegrationFunctionError.WRAP_502_INTERNAL_RESPONSE_ERROR);
  527.                             integrationType = this.getErrorType(IntegrationFunctionError.WRAP_502_INTERNAL_RESPONSE_ERROR);
  528.                         }
  529.                     }
  530.                     else if(integrationFunctionError.isWrapInternalError()) {
  531.                         if(isWrapped(IntegrationFunctionError.WRAP_503_INTERNAL_ERROR)) {
  532.                             String pWrappedName = IntegrationFunctionError.WRAP_503_INTERNAL_ERROR.name()+".webSite";
  533.                             p = getOptionalProperty(pWrappedName);
  534.                             integrationError = this.getIntegrationError(IntegrationFunctionError.WRAP_503_INTERNAL_ERROR);
  535.                             integrationType = this.getErrorType(IntegrationFunctionError.WRAP_503_INTERNAL_ERROR);
  536.                         }
  537.                     }
  538.                    
  539.                     String site = this.getSite(p, integrationError, integrationType);
  540.                     this.mapWebSite.put(integrationFunctionError, site);
  541.                        
  542.                     String site_noWrap = this.getSite(p_noWrap, integrationError_noWrap, integrationType_noWrap);
  543.                     this.mapWebSite_noWrap.put(integrationFunctionError, site_noWrap);
  544.                    
  545.                 }catch(Exception e){
  546.                     throw new ProtocolException("Errore durante la gestione del codice ["+integrationFunctionError.name()+"]: "+e.getMessage(),e);
  547.                 }
  548.             }
  549.         }
  550.     }
  551.     private String getSite(String p, IntegrationError integrationError, String integrationType) {
  552.                
  553.         String site = null;
  554.         if(p!=null) {
  555.             if(p.startsWith("http://") || p.startsWith("https://")) {
  556.                 return p;
  557.             }
  558.             else {
  559.                 if(p.startsWith("/")) {
  560.                     site = this.webSite + p;
  561.                 }
  562.                 else {
  563.                     site = this.webSite + "/" + p;
  564.                 }
  565.             }
  566.         }
  567.         else {
  568.             if(this.webSiteErrorPage.startsWith("/")) {
  569.                 site = this.webSite + this.webSiteErrorPage;
  570.             }
  571.             else {
  572.                 site = this.webSite + "/" + this.webSiteErrorPage;
  573.             }
  574.         }
  575.            
  576.         while(site.contains(CostantiProtocollo.OPENSPCOOP2_ERRORI_TEMPLATE_HTTP_CODE)) {
  577.             switch (integrationError) {
  578.             case BAD_REQUEST:
  579.                 site = site.replace(CostantiProtocollo.OPENSPCOOP2_ERRORI_TEMPLATE_HTTP_CODE, "400");
  580.                 break;
  581.             case AUTHENTICATION:
  582.                 site = site.replace(CostantiProtocollo.OPENSPCOOP2_ERRORI_TEMPLATE_HTTP_CODE, "401");
  583.                 break;
  584.             case AUTHORIZATION:
  585.                 site = site.replace(CostantiProtocollo.OPENSPCOOP2_ERRORI_TEMPLATE_HTTP_CODE, "403");
  586.                 break;
  587.             case NOT_FOUND:
  588.                 site = site.replace(CostantiProtocollo.OPENSPCOOP2_ERRORI_TEMPLATE_HTTP_CODE, "404");
  589.                 break;
  590.             case CONFLICT:
  591.                 site = site.replace(CostantiProtocollo.OPENSPCOOP2_ERRORI_TEMPLATE_HTTP_CODE, "409");
  592.                 break;
  593.             case REQUEST_TOO_LARGE:
  594.                 site = site.replace(CostantiProtocollo.OPENSPCOOP2_ERRORI_TEMPLATE_HTTP_CODE, "413");
  595.                 break;
  596.             case LIMIT_EXCEEDED:
  597.             case TOO_MANY_REQUESTS:
  598.                 site = site.replace(CostantiProtocollo.OPENSPCOOP2_ERRORI_TEMPLATE_HTTP_CODE, "429");
  599.                 break;
  600.             case BAD_RESPONSE:
  601.             case INTERNAL_RESPONSE_ERROR:
  602.                 site = site.replace(CostantiProtocollo.OPENSPCOOP2_ERRORI_TEMPLATE_HTTP_CODE, "502");
  603.                 break;
  604.             case SERVICE_UNAVAILABLE:
  605.             case INTERNAL_REQUEST_ERROR:
  606.                 site = site.replace(CostantiProtocollo.OPENSPCOOP2_ERRORI_TEMPLATE_HTTP_CODE, "503");
  607.                 break;
  608.             case ENDPOINT_REQUEST_TIMED_OUT:
  609.                 site = site.replace(CostantiProtocollo.OPENSPCOOP2_ERRORI_TEMPLATE_HTTP_CODE, "504");
  610.                 break;
  611.             case DEFAULT:
  612.                 site = site.replace(CostantiProtocollo.OPENSPCOOP2_ERRORI_TEMPLATE_HTTP_CODE, "503");
  613.                 break;
  614.             }  
  615.         }
  616.        
  617.         while(site.contains(CostantiProtocollo.OPENSPCOOP2_ERRORI_TEMPLATE_ERROR_CODE)) {
  618.             site = site.replace(CostantiProtocollo.OPENSPCOOP2_ERRORI_TEMPLATE_ERROR_CODE, integrationError.name());
  619.         }
  620.        
  621.         while(site.contains(CostantiProtocollo.OPENSPCOOP2_ERRORI_TEMPLATE_ERROR_TYPE)) {
  622.             site = site.replace(CostantiProtocollo.OPENSPCOOP2_ERRORI_TEMPLATE_ERROR_TYPE, integrationType);
  623.         }
  624.        
  625.         return site;
  626.     }
  627.    
  628.    
  629.     private ConcurrentHashMap<IntegrationFunctionError,String> mapGenericDetails= null;
  630.     private ConcurrentHashMap<IntegrationFunctionError,String> mapGenericDetails_noWrap= null;
  631.     public String getGenericDetails(IntegrationFunctionError functionError) throws ProtocolException {
  632.         if(this.mapGenericDetails==null){
  633.             this.initMapGenericDetails();
  634.         }
  635.         return this.mapGenericDetails.get(functionError);
  636.     }
  637.     public String getGenericDetails_noWrap(IntegrationFunctionError functionError) throws ProtocolException {
  638.         if(this.mapGenericDetails_noWrap==null){
  639.             this.initMapGenericDetails();
  640.         }
  641.         return this.mapGenericDetails_noWrap.get(functionError);
  642.     }
  643.     private synchronized void initMapGenericDetails() throws ProtocolException {
  644.         if(this.mapGenericDetails==null){
  645.             this.mapGenericDetails = new ConcurrentHashMap<IntegrationFunctionError, String>();
  646.             this.mapGenericDetails_noWrap = new ConcurrentHashMap<IntegrationFunctionError, String>();
  647.             IntegrationFunctionError [] lista = IntegrationFunctionError.values();
  648.             for (IntegrationFunctionError integrationFunctionError : lista) {
  649.                 String pName = integrationFunctionError.name()+".genericDetails";
  650.                 try{
  651.                     String p = getProperty(pName);
  652.                     String p_noWrap = p;
  653.                    
  654.                     IntegrationError integrationError = this.mapIntegrationError_noWrap.get(integrationFunctionError);
  655.                    
  656.                     if(integrationFunctionError.isWrapBadRequest()) {
  657.                         if(isWrapped(IntegrationFunctionError.WRAP_400_INTERNAL_BAD_REQUEST)) {
  658.                             String pWrappedName = IntegrationFunctionError.WRAP_400_INTERNAL_BAD_REQUEST.name()+".genericDetails";
  659.                             p = getProperty(pWrappedName);
  660.                         }
  661.                     }
  662.                     else if(integrationFunctionError.isWrapBadResponse(integrationError)) {
  663.                         if(isWrapped(IntegrationFunctionError.WRAP_502_BAD_RESPONSE)) {
  664.                             String pWrappedName = IntegrationFunctionError.WRAP_502_BAD_RESPONSE.name()+".genericDetails";
  665.                             p = getProperty(pWrappedName);
  666.                         }
  667.                     }
  668.                     else if(integrationFunctionError.isWrapInternalResponseError(integrationError)) {
  669.                         if(isWrapped(IntegrationFunctionError.WRAP_502_INTERNAL_RESPONSE_ERROR)) {
  670.                             String pWrappedName = IntegrationFunctionError.WRAP_502_INTERNAL_RESPONSE_ERROR.name()+".genericDetails";
  671.                             p = getProperty(pWrappedName);
  672.                         }
  673.                     }
  674.                     else if(integrationFunctionError.isWrapInternalError()) {
  675.                         if(isWrapped(IntegrationFunctionError.WRAP_503_INTERNAL_ERROR)) {
  676.                             String pWrappedName = IntegrationFunctionError.WRAP_503_INTERNAL_ERROR.name()+".genericDetails";
  677.                             p = getProperty(pWrappedName);
  678.                         }
  679.                     }      
  680.                    
  681.                     this.mapGenericDetails.put(integrationFunctionError, p);
  682.                     this.mapGenericDetails_noWrap.put(integrationFunctionError, p_noWrap);
  683.                 }catch(Exception e){
  684.                     throw new ProtocolException("Errore durante la gestione del codice ["+integrationFunctionError.name()+"]: "+e.getMessage(),e);
  685.                 }
  686.             }
  687.         }
  688.     }
  689.    
  690.    
  691.     private ConcurrentHashMap<IntegrationFunctionError,Boolean> mapIsGenericDetails= null;
  692.     private ConcurrentHashMap<IntegrationFunctionError,Boolean> mapIsGenericDetails_noWrap= null;
  693.     public Boolean isForceGenericDetails(IntegrationFunctionError functionError) throws ProtocolException {
  694.         if(this.mapIsGenericDetails==null){
  695.             this.initMapIsGenericDetails();
  696.         }
  697.         return this.mapIsGenericDetails.get(functionError);
  698.     }
  699.     public Boolean isForceGenericDetails_noWrap(IntegrationFunctionError functionError) throws ProtocolException {
  700.         if(this.mapIsGenericDetails_noWrap==null){
  701.             this.initMapIsGenericDetails();
  702.         }
  703.         return this.mapIsGenericDetails_noWrap.get(functionError);
  704.     }
  705.     private synchronized void initMapIsGenericDetails() throws ProtocolException {
  706.         if(this.mapIsGenericDetails==null){
  707.             this.mapIsGenericDetails = new ConcurrentHashMap<IntegrationFunctionError, Boolean>();
  708.             this.mapIsGenericDetails_noWrap = new ConcurrentHashMap<IntegrationFunctionError, Boolean>();
  709.             IntegrationFunctionError [] lista = IntegrationFunctionError.values();
  710.             for (IntegrationFunctionError integrationFunctionError : lista) {
  711.                 String pName = integrationFunctionError.name()+".forceGenericDetails";
  712.                 try{
  713.                     Boolean p = getBooleanProperty(pName);
  714.                     Boolean p_noWrap = p;
  715.                    
  716.                     IntegrationError integrationError = this.mapIntegrationError_noWrap.get(integrationFunctionError);
  717.                    
  718.                     if(integrationFunctionError.isWrapBadRequest()) {
  719.                         if(isWrapped(IntegrationFunctionError.WRAP_400_INTERNAL_BAD_REQUEST)) {
  720.                             String pWrappedName = IntegrationFunctionError.WRAP_400_INTERNAL_BAD_REQUEST.name()+".forceGenericDetails";
  721.                             p = getBooleanProperty(pWrappedName);
  722.                         }
  723.                     }
  724.                     else if(integrationFunctionError.isWrapBadResponse(integrationError)) {
  725.                         if(isWrapped(IntegrationFunctionError.WRAP_502_BAD_RESPONSE)) {
  726.                             String pWrappedName = IntegrationFunctionError.WRAP_502_BAD_RESPONSE.name()+".forceGenericDetails";
  727.                             p = getBooleanProperty(pWrappedName);
  728.                         }
  729.                     }
  730.                     else if(integrationFunctionError.isWrapInternalResponseError(integrationError)) {
  731.                         if(isWrapped(IntegrationFunctionError.WRAP_502_INTERNAL_RESPONSE_ERROR)) {
  732.                             String pWrappedName = IntegrationFunctionError.WRAP_502_INTERNAL_RESPONSE_ERROR.name()+".forceGenericDetails";
  733.                             p = getBooleanProperty(pWrappedName);
  734.                         }
  735.                     }
  736.                     else if(integrationFunctionError.isWrapInternalError()) {
  737.                         if(isWrapped(IntegrationFunctionError.WRAP_503_INTERNAL_ERROR)) {
  738.                             String pWrappedName = IntegrationFunctionError.WRAP_503_INTERNAL_ERROR.name()+".forceGenericDetails";
  739.                             p = getBooleanProperty(pWrappedName);
  740.                         }
  741.                     }  
  742.                    
  743.                     this.mapIsGenericDetails.put(integrationFunctionError, p);
  744.                     this.mapIsGenericDetails_noWrap.put(integrationFunctionError, p_noWrap);
  745.                 }catch(Exception e){
  746.                     throw new ProtocolException("Errore durante la gestione del codice ["+integrationFunctionError.name()+"]: "+e.getMessage(),e);
  747.                 }
  748.             }
  749.         }
  750.     }

  751.    


  752.    
  753.    
  754.     /* ******* UTILITIES ********* */
  755.    
  756.     public String getProperty(String property) throws ProtocolException {
  757.         try{
  758.             String name = null;
  759.             name = this.reader.getValueConvertEnvProperties(property);
  760.             if(name==null)
  761.                 throw new Exception("proprieta non definita");
  762.             return name.trim();
  763.         }catch(java.lang.Exception e) {
  764.             String msg = "Riscontrato errore durante la lettura della proprieta' '"+property+"': "+e.getMessage();
  765.             this.log.error(msg,e);
  766.             throw new ProtocolException(msg,e);
  767.         }      
  768.     }
  769.    
  770.     public String getOptionalProperty(String property) throws ProtocolException {
  771.         try{
  772.             String name = null;
  773.             name = this.reader.getValueConvertEnvProperties(property);
  774.             if(name==null)
  775.                 return null;
  776.             return name.trim();
  777.         }catch(java.lang.Exception e) {
  778.             String msg = "Riscontrato errore durante la lettura della proprieta' '"+property+"': "+e.getMessage();
  779.             this.log.error(msg,e);
  780.             throw new ProtocolException(msg,e);
  781.         }      
  782.     }
  783.    
  784.     public Boolean getBooleanProperty(String property) throws ProtocolException {
  785.         try{
  786.             String name = null;
  787.             name = this.reader.getValueConvertEnvProperties(property);
  788.             if(name==null)
  789.                 throw new Exception("proprieta non definita");
  790.             return Boolean.parseBoolean(name.trim());
  791.         }catch(java.lang.Exception e) {
  792.             String msg = "Riscontrato errore durante la lettura della proprieta' '"+property+"': "+e.getMessage();
  793.             this.log.error(msg,e);
  794.             throw new ProtocolException(msg,e);
  795.         }      
  796.     }
  797.    
  798. }