ValidatoreMessaggiApplicativiRest.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;

  21. import java.io.ByteArrayOutputStream;
  22. import java.io.InputStream;
  23. import java.util.ArrayList;
  24. import java.util.HashMap;
  25. import java.util.List;
  26. import java.util.Map;

  27. import org.apache.cxf.common.util.StringUtils;
  28. import org.openspcoop2.core.config.Proprieta;
  29. import org.openspcoop2.core.id.IDServizio;
  30. import org.openspcoop2.core.registry.AccordoServizioParteComune;
  31. import org.openspcoop2.core.registry.AccordoServizioParteSpecifica;
  32. import org.openspcoop2.core.registry.constants.FormatoSpecifica;
  33. import org.openspcoop2.core.registry.driver.AccordoServizioUtils;
  34. import org.openspcoop2.core.registry.driver.DriverRegistroServiziException;
  35. import org.openspcoop2.core.registry.driver.DriverRegistroServiziNotFound;
  36. import org.openspcoop2.core.registry.driver.IDAccordoFactory;
  37. import org.openspcoop2.core.registry.rest.AccordoServizioWrapper;
  38. import org.openspcoop2.message.OpenSPCoop2Message;
  39. import org.openspcoop2.message.OpenSPCoop2RestJsonMessage;
  40. import org.openspcoop2.message.OpenSPCoop2RestMessage;
  41. import org.openspcoop2.message.OpenSPCoop2RestXmlMessage;
  42. import org.openspcoop2.message.constants.MessageRole;
  43. import org.openspcoop2.message.constants.MessageType;
  44. import org.openspcoop2.message.constants.ServiceBinding;
  45. import org.openspcoop2.message.exception.MessageException;
  46. import org.openspcoop2.message.exception.MessageNotSupportedException;
  47. import org.openspcoop2.message.rest.RestUtilities;
  48. import org.openspcoop2.message.xml.MessageXMLUtils;
  49. import org.openspcoop2.pdd.config.CostantiProprieta;
  50. import org.openspcoop2.pdd.config.OpenSPCoop2Properties;
  51. import org.openspcoop2.pdd.logger.OpenSPCoop2Logger;
  52. import org.openspcoop2.protocol.registry.RegistroServiziManager;
  53. import org.openspcoop2.protocol.sdk.IProtocolFactory;
  54. import org.openspcoop2.protocol.sdk.constants.CodiceErroreIntegrazione;
  55. import org.openspcoop2.protocol.sdk.constants.ErroriIntegrazione;
  56. import org.openspcoop2.protocol.sdk.constants.InformationApiSource;
  57. import org.openspcoop2.protocol.sdk.constants.IntegrationFunctionError;
  58. import org.openspcoop2.protocol.sdk.state.RequestInfo;
  59. import org.openspcoop2.protocol.utils.ErroriProperties;
  60. import org.openspcoop2.protocol.utils.PorteNamingUtils;
  61. import org.openspcoop2.utils.UtilsException;
  62. import org.openspcoop2.utils.json.JSONUtils;
  63. import org.openspcoop2.utils.json.YAMLUtils;
  64. import org.openspcoop2.utils.openapi.OpenapiApi;
  65. import org.openspcoop2.utils.openapi.UniqueInterfaceGenerator;
  66. import org.openspcoop2.utils.openapi.UniqueInterfaceGeneratorConfig;
  67. import org.openspcoop2.utils.openapi.validator.OpenAPILibrary;
  68. import org.openspcoop2.utils.openapi.validator.OpenapiApiValidatorConfig;
  69. import org.openspcoop2.utils.openapi.validator.OpenapiLibraryValidatorConfig;
  70. import org.openspcoop2.utils.rest.ApiFactory;
  71. import org.openspcoop2.utils.rest.ApiFormats;
  72. import org.openspcoop2.utils.rest.ApiReaderConfig;
  73. import org.openspcoop2.utils.rest.ApiValidatorConfig;
  74. import org.openspcoop2.utils.rest.IApiReader;
  75. import org.openspcoop2.utils.rest.IApiValidator;
  76. import org.openspcoop2.utils.rest.api.Api;
  77. import org.openspcoop2.utils.rest.api.ApiSchema;
  78. import org.openspcoop2.utils.rest.api.ApiSchemaType;
  79. import org.openspcoop2.utils.rest.entity.BinaryHttpRequestEntity;
  80. import org.openspcoop2.utils.rest.entity.BinaryHttpResponseEntity;
  81. import org.openspcoop2.utils.rest.entity.Cookie;
  82. import org.openspcoop2.utils.rest.entity.ElementHttpRequestEntity;
  83. import org.openspcoop2.utils.rest.entity.ElementHttpResponseEntity;
  84. import org.openspcoop2.utils.rest.entity.HttpBaseRequestEntity;
  85. import org.openspcoop2.utils.rest.entity.HttpBaseResponseEntity;
  86. import org.openspcoop2.utils.rest.entity.InputStreamHttpRequestEntity;
  87. import org.openspcoop2.utils.rest.entity.InputStreamHttpResponseEntity;
  88. import org.openspcoop2.utils.rest.entity.TextHttpRequestEntity;
  89. import org.openspcoop2.utils.rest.entity.TextHttpResponseEntity;
  90. import org.openspcoop2.utils.transport.http.ContentTypeUtilities;
  91. import org.openspcoop2.utils.transport.http.HttpRequestMethod;
  92. import org.openspcoop2.utils.wsdl.WSDLException;
  93. import org.openspcoop2.utils.xml.AbstractValidatoreXSD;
  94. import org.openspcoop2.utils.xml.ValidatoreXSD;
  95. import org.slf4j.Logger;
  96. import org.w3c.dom.Element;


  97. /**
  98.  * Classe utilizzata per validare i messaggi applicativi.
  99.  *
  100.  * @author Poli Andrea (apoli@link.it)
  101.  * @author Lezza Aldo (lezza@openspcoop.org)
  102.  * @author Lorenzo Nardi (nardi@link.it)
  103.  * @author $Author$
  104.  * @version $Rev$, $Date$
  105.  */

  106. public class ValidatoreMessaggiApplicativiRest {

  107.     /** Registro dei Servizi */
  108.     private RegistroServiziManager registroServiziManager;

  109.     /** SOAPEnvelope */
  110.     private OpenSPCoop2Message message;
  111.     /** Associato al servizio */
  112.     private org.openspcoop2.core.registry.rest.AccordoServizioWrapper accordoServizioWrapper = null;
  113.     /** Logger */
  114.     private Logger logger = null;
  115.     /** ProtocolFactory */
  116.     private IProtocolFactory<?> protocolFactory;
  117.     /** PddContext */
  118.     private PdDContext pddContext;
  119.     /** RequestInfo */
  120.     private RequestInfo requestInfo;
  121.     /** UseInterface */
  122.     private boolean useInterface;
  123.     /** OpenApi4j config */
  124.     private OpenapiLibraryValidatorConfig configOpenApiValidator;
  125.     /** OpenSPCoop2Properties */
  126.     private OpenSPCoop2Properties op2Properties = OpenSPCoop2Properties.getInstance();
  127.     /** Buffer */
  128.     private boolean bufferMessage_readOnly = true;
  129.    
  130.    

  131.    
  132.     /* ------ Costruttore -------------- */
  133.     public ValidatoreMessaggiApplicativiRest(RegistroServiziManager registro,IDServizio idServizio,
  134.             OpenSPCoop2Message message,boolean readInterfaceAccordoServizio, List<Proprieta> proprieta,
  135.             IProtocolFactory<?> protocolFactory, PdDContext pddContext)throws ValidatoreMessaggiApplicativiException{
  136.        
  137.         if(registro==null){
  138.             ValidatoreMessaggiApplicativiException ex
  139.             = new ValidatoreMessaggiApplicativiException("Reader del Registro dei Servizi non fornito");
  140.             ex.setErrore(ErroriIntegrazione.ERRORE_5XX_GENERICO_PROCESSAMENTO_MESSAGGIO.get5XX_ErroreProcessamento(CodiceErroreIntegrazione.CODICE_531_VALIDAZIONE_TRAMITE_INTERFACCIA_FALLITA));
  141.             throw ex;
  142.         }
  143.        
  144.         if(idServizio==null || idServizio.getSoggettoErogatore()==null || idServizio.getTipo()==null || idServizio.getNome()==null || idServizio.getVersione()==null ||
  145.                 idServizio.getSoggettoErogatore().getTipo()==null || idServizio.getSoggettoErogatore().getNome()==null){
  146.             ValidatoreMessaggiApplicativiException ex
  147.             = new ValidatoreMessaggiApplicativiException("ID del servizio da validare, non fornito");
  148.             ex.setErrore(ErroriIntegrazione.ERRORE_5XX_GENERICO_PROCESSAMENTO_MESSAGGIO.get5XX_ErroreProcessamento(CodiceErroreIntegrazione.CODICE_531_VALIDAZIONE_TRAMITE_INTERFACCIA_FALLITA));
  149.             throw ex;
  150.         }
  151.        
  152.         this.message = message;

  153.         this.registroServiziManager = registro;
  154.        
  155.         this.logger = OpenSPCoop2Logger.getLoggerOpenSPCoopCore();
  156.        
  157.         this.protocolFactory = protocolFactory;
  158.        
  159.         this.pddContext = pddContext;
  160.        
  161.         if(this.pddContext!=null && this.pddContext.containsKey(org.openspcoop2.core.constants.Costanti.REQUEST_INFO)) {
  162.             this.requestInfo = (RequestInfo) this.pddContext.getObject(org.openspcoop2.core.constants.Costanti.REQUEST_INFO);
  163.         }
  164.        
  165.         try{
  166.             this.useInterface = readInterfaceAccordoServizio;
  167.            
  168.             boolean processIncludeForOpenApi = true;
  169.             this.configOpenApiValidator = new OpenapiLibraryValidatorConfig();
  170.             this.configOpenApiValidator.setOpenApiLibrary(this.op2Properties.getValidazioneContenutiApplicativiOpenApiLibrary());
  171.             if(OpenAPILibrary.openapi4j.equals(this.configOpenApiValidator.getOpenApiLibrary()) ||
  172.                     OpenAPILibrary.swagger_request_validator.equals(this.configOpenApiValidator.getOpenApiLibrary())) {
  173.                 this.configOpenApiValidator.setMergeAPISpec(this.op2Properties.isValidazioneContenutiApplicativiOpenApiMergeAPISpec());
  174.                 this.configOpenApiValidator.setValidateAPISpec(this.op2Properties.isValidazioneContenutiApplicativiOpenApiValidateAPISpec());
  175.                 this.configOpenApiValidator.setValidateRequestPath(this.op2Properties.isValidazioneContenutiApplicativiOpenApiValidateRequestPath());
  176.                 this.configOpenApiValidator.setValidateRequestQuery(this.op2Properties.isValidazioneContenutiApplicativiOpenApiValidateRequestQuery());
  177.                 this.configOpenApiValidator.setValidateRequestUnexpectedQueryParam(this.op2Properties.isValidazioneContenutiApplicativiOpenApiValidateRequestUnexpectedQueryParam());
  178.                 this.configOpenApiValidator.setValidateRequestHeaders(this.op2Properties.isValidazioneContenutiApplicativiOpenApiValidateRequestHeaders());
  179.                 this.configOpenApiValidator.setValidateRequestCookie(this.op2Properties.isValidazioneContenutiApplicativiOpenApiValidateRequestCookie());
  180.                 this.configOpenApiValidator.setValidateRequestBody(this.op2Properties.isValidazioneContenutiApplicativiOpenApiValidateRequestBody());
  181.                 this.configOpenApiValidator.setValidateResponseHeaders(this.op2Properties.isValidazioneContenutiApplicativiOpenApiValidateResponseHeaders());
  182.                 this.configOpenApiValidator.setValidateResponseBody(this.op2Properties.isValidazioneContenutiApplicativiOpenApiValidateResponseBody());
  183.                 this.configOpenApiValidator.setValidateWildcardSubtypeAsJson(this.op2Properties.isValidazioneContenutiApplicativiOpenApiValidateWildcardSubtypeAsJson());
  184.                 this.configOpenApiValidator.setValidateMultipartOptimization(this.op2Properties.isValidazioneContenutiApplicativiOpenApiValidateMultipartOptimization());
  185.                 this.configOpenApiValidator.setSwaggerRequestValidator_InjectingAdditionalPropertiesFalse(this.op2Properties.isValidazioneContenutiApplicativiOpenApiSwaggerRequestValidatorInjectingAdditionalPropertiesFalse());
  186.                 this.configOpenApiValidator.setSwaggerRequestValidator_ResolveFullyApiSpec(this.op2Properties.isValidazioneContenutiApplicativiOpenApiSwaggerRequestValidatorResolveFullyApiSpec());
  187.             }
  188.            
  189.             updateOpenapiValidatorConfig(proprieta, this.configOpenApiValidator); // aggiorno anche se utilizzarlo o meno
  190.                        
  191.             if(OpenAPILibrary.openapi4j.equals(this.configOpenApiValidator.getOpenApiLibrary()) ||
  192.                     OpenAPILibrary.swagger_request_validator.equals(this.configOpenApiValidator.getOpenApiLibrary())) {
  193.                 processIncludeForOpenApi = false;
  194.             }
  195.            
  196.             this.bufferMessage_readOnly = OpenSPCoop2Properties.getInstance().isValidazioneContenutiApplicativiBufferContentRead();
  197.             if(proprieta!=null && !proprieta.isEmpty()) {
  198.                 boolean defaultBehaviour = this.bufferMessage_readOnly;
  199.                 this.bufferMessage_readOnly = ValidatoreMessaggiApplicativiRest.readBooleanValueWithDefault(proprieta, CostantiProprieta.VALIDAZIONE_CONTENUTI_PROPERTY_NAME_BUFFER_ENABLED, defaultBehaviour);
  200.             }
  201.            
  202.             if(readInterfaceAccordoServizio){
  203.                 this.accordoServizioWrapper = this.registroServiziManager.getRestAccordoServizio(idServizio,InformationApiSource.SPECIFIC,true,processIncludeForOpenApi,false, this.requestInfo);
  204.             }else{
  205.                 this.accordoServizioWrapper = this.registroServiziManager.getRestAccordoServizio(idServizio,InformationApiSource.REGISTRY,true,processIncludeForOpenApi,true, this.requestInfo);
  206.             }
  207.         }catch(DriverRegistroServiziNotFound e){
  208.             this.logger.error("Riscontrato errore durante la ricerca del formato di specifica che definisce l'accordo di servizio: "+e.getMessage(),e);
  209.             ValidatoreMessaggiApplicativiException ex
  210.             = new ValidatoreMessaggiApplicativiException("Riscontrato errore durante la ricerca del formato di specifica: "+e.getMessage(),e);
  211.             ex.setErrore(ErroriIntegrazione.ERRORE_405_SERVIZIO_NON_TROVATO.getErroreIntegrazione());
  212.             throw ex;
  213.         }catch(DriverRegistroServiziException e){
  214.            
  215.             FormatoSpecifica formatoSpecifica = null;
  216.             try {
  217.                 AccordoServizioParteSpecifica asps = this.registroServiziManager.getAccordoServizioParteSpecifica(idServizio, null, false, this.requestInfo);
  218.                 AccordoServizioParteComune apc = this.registroServiziManager.getAccordoServizioParteComune(IDAccordoFactory.getInstance().getIDAccordoFromUri(asps.getAccordoServizioParteComune()), null, false, false, this.requestInfo);
  219.                 formatoSpecifica = apc.getFormatoSpecifica();
  220.             }catch(Exception eIgnore) {}
  221.            
  222.             this.logger.error("Riscontrato errore durante l'inizializzazione: "+e.getMessage(),e);
  223.             ValidatoreMessaggiApplicativiException ex
  224.                 = new ValidatoreMessaggiApplicativiException("Riscontrato errore durante l'inizializzazione: "+e.getMessage(),e);
  225.             if(e.getMessage()!=null && formatoSpecifica!=null){
  226.                 ex.setErrore(ErroriIntegrazione.ERRORE_417_COSTRUZIONE_VALIDATORE_TRAMITE_INTERFACCIA_FALLITA.getErrore417_CostruzioneValidatoreTramiteInterfacciaFallita(formatoSpecifica.getValue()));
  227.                 throw ex;
  228.             }else{
  229.                 ex.setErrore(ErroriIntegrazione.ERRORE_5XX_GENERICO_PROCESSAMENTO_MESSAGGIO.get5XX_ErroreProcessamento(CodiceErroreIntegrazione.CODICE_530_COSTRUZIONE_INTERFACCIA_FALLITA));
  230.                 throw ex;
  231.             }
  232.         }
  233.        

  234.     }
  235.    
  236.    
  237.    
  238.    
  239.    
  240.    
  241.    
  242.     /* ----------- INTERFACCE ---------------- */
  243.     public AccordoServizioWrapper getAccordoServizioWrapper() {
  244.         return this.accordoServizioWrapper;
  245.     }
  246.    
  247.    
  248.    
  249.    
  250.    
  251.    
  252.    
  253.    
  254.    
  255.     /* -------------- VALIDAZIONE XSD --------------------- */
  256.    
  257.     public void validateWithSchemiXSD(boolean isRichiesta) throws ValidatoreMessaggiApplicativiException{
  258.        
  259.         if(ServiceBinding.SOAP.equals(this.message.getServiceBinding())){
  260.             throw new ValidatoreMessaggiApplicativiException("Tipo di validazione non supportata con Service Binding SOAP");
  261.         }
  262.         if(!MessageType.XML.equals(this.message.getMessageType())){
  263.             throw new ValidatoreMessaggiApplicativiException("Tipo di validazione non supportata con Service Binding REST e MessageType '"+this.message.getMessageType()+"'");
  264.         }
  265.        
  266.         try{
  267.             if(this.message.castAsRest().hasContent()==false) {
  268.                 return;
  269.             }
  270.         }catch(Exception e){
  271.             this.logger.error("Riscontrato errore durante il controllo del messaggio: "+e.getMessage(),e);
  272.             ValidatoreMessaggiApplicativiException ex
  273.                 = new ValidatoreMessaggiApplicativiException("Riscontrato errore durante l'inizializzazione: "+e.getMessage(),e);
  274.             ex.setErrore(ErroriIntegrazione.ERRORE_5XX_GENERICO_PROCESSAMENTO_MESSAGGIO.get5XX_ErroreProcessamento(CodiceErroreIntegrazione.CODICE_530_COSTRUZIONE_INTERFACCIA_FALLITA));
  275.             throw ex;
  276.         }
  277.        
  278.         AbstractValidatoreXSD validatoreBodyApplicativo = null;
  279.         try{
  280.            
  281.             AccordoServizioUtils accordoServizioUtils = new AccordoServizioUtils(this.message.getFactory(), this.logger);
  282.             boolean fromBytes = this.accordoServizioWrapper.isRegistroServiziDB();
  283.             javax.xml.validation.Schema schema = accordoServizioUtils.buildSchema(this.accordoServizioWrapper.getAccordoServizio(), fromBytes);
  284.            
  285.             try{
  286.                 if(schema!=null){
  287.                     validatoreBodyApplicativo = new ValidatoreXSD(schema);
  288.                 }else{
  289.                     throw new Exception("Schema non costruito?");
  290.                 }
  291.             }catch(Exception e){
  292.                 throw new WSDLException("Riscontrato errore durante la costruzione del validatore XSD per il contenuto applicativo: "+e.getMessage(),e);
  293.             }
  294.            
  295.         }catch(Exception e){
  296.             this.logger.error("validateWithSchemiXSD failed: "+e.getMessage(),e);
  297.             ValidatoreMessaggiApplicativiException ex
  298.                 = new ValidatoreMessaggiApplicativiException(e.getMessage(),e);
  299.             ex.setErrore(ErroriIntegrazione.ERRORE_417_COSTRUZIONE_VALIDATORE_TRAMITE_INTERFACCIA_FALLITA.getErrore417_CostruzioneValidatoreTramiteInterfacciaFallita(CostantiPdD.SCHEMA_XSD));
  300.             throw ex;
  301.         }
  302.        
  303.        
  304.         try {
  305.             String idTransazione = null;
  306.             if(this.pddContext!=null) {
  307.                 idTransazione = (String)this.pddContext.getObject(org.openspcoop2.core.constants.Costanti.ID_TRANSAZIONE);
  308.             }
  309.            
  310.             OpenSPCoop2RestXmlMessage xmlMsg = this.message.castAsRestXml();
  311.             Element content = xmlMsg.getContent(this.bufferMessage_readOnly, idTransazione);                        
  312.             validatoreBodyApplicativo.valida(content);
  313.            
  314.         }catch(Exception e){
  315.             ValidatoreMessaggiApplicativiException ex
  316.                 = new ValidatoreMessaggiApplicativiException(e.getMessage(),e);
  317.            
  318.             String messaggioErrore = e.getMessage();
  319.             boolean overwriteMessageError = false;
  320.             try {
  321.                 messaggioErrore = ErroriProperties.getInstance(this.logger).getGenericDetails_noWrap(isRichiesta ? IntegrationFunctionError.INVALID_REQUEST_CONTENT : IntegrationFunctionError.INVALID_RESPONSE_CONTENT);
  322.                 messaggioErrore = messaggioErrore+": "+e.getMessage();
  323.                 overwriteMessageError = true;
  324.             }catch(Exception excp) {}
  325.            
  326.             if(isRichiesta){
  327.                 ex.setErrore(ErroriIntegrazione.ERRORE_418_VALIDAZIONE_RICHIESTA_TRAMITE_INTERFACCIA_FALLITA.getErrore418_ValidazioneRichiestaTramiteInterfacciaFallita(CostantiPdD.SCHEMA_XSD, messaggioErrore, overwriteMessageError));
  328.             }else{
  329.                 ex.setErrore(ErroriIntegrazione.ERRORE_419_VALIDAZIONE_RISPOSTA_TRAMITE_INTERFACCIA_FALLITA.getErrore419_ValidazioneRispostaTramiteInterfacciaFallita(CostantiPdD.SCHEMA_XSD, messaggioErrore, overwriteMessageError));
  330.             }
  331.             throw ex;
  332.         }
  333.        
  334.     }

  335.    
  336.    
  337.    
  338.    
  339.     /* -------------- VALIDAZIONE Interface --------------------- */
  340.    
  341.     public void validateRequestWithInterface(boolean portaApplicativa) throws ValidatoreMessaggiApplicativiException {
  342.         this.validateWithInterface(true, portaApplicativa, null);
  343.     }
  344.     public void validateResponseWithInterface(OpenSPCoop2Message requestMessage, boolean portaApplicativa) throws ValidatoreMessaggiApplicativiException {
  345.         this.validateWithInterface(false, portaApplicativa, requestMessage);
  346.     }
  347.     private void validateWithInterface(boolean isRichiesta, boolean portaApplicativa, OpenSPCoop2Message requestMessage) throws ValidatoreMessaggiApplicativiException {
  348.        
  349.         if(ServiceBinding.SOAP.equals(this.message.getServiceBinding())){
  350.             throw new ValidatoreMessaggiApplicativiException("Tipo di validazione non supportata con Service Binding SOAP");
  351.         }
  352.        
  353.         String interfaceType = null;
  354.         ApiFormats format = null;
  355.         ApiValidatorConfig validatorConfig = null;
  356.         OpenAPILibrary openApiLibrary = null;
  357.         Api api = this.accordoServizioWrapper.getApi();
  358.         switch (this.accordoServizioWrapper.getAccordoServizio().getFormatoSpecifica()) {
  359.         case WADL:
  360.             interfaceType = "Interfaccia WADL";
  361.             format=ApiFormats.WADL;
  362.             validatorConfig = new ApiValidatorConfig();
  363.             break;
  364.         case SWAGGER_2:
  365.             interfaceType = "Interfaccia Swagger 2";
  366.             format=ApiFormats.SWAGGER_2;
  367.             validatorConfig = new OpenapiApiValidatorConfig();
  368.             ((OpenapiApiValidatorConfig)validatorConfig).setJsonValidatorAPI(this.op2Properties.getValidazioneContenutiApplicativiOpenApiJsonValidator());
  369.             if(this.useInterface && this.configOpenApiValidator!=null) {
  370.                 openApiLibrary = this.configOpenApiValidator.getOpenApiLibrary();
  371.                 if(OpenAPILibrary.swagger_request_validator.equals(openApiLibrary)) {
  372.                     ((OpenapiApiValidatorConfig)validatorConfig).setOpenApiValidatorConfig(this.configOpenApiValidator);
  373.                     if(this.configOpenApiValidator.isMergeAPISpec()) {
  374.                         // forzo a false, la funzionalità di merge non supporta swagger
  375.                         this.configOpenApiValidator.setMergeAPISpec(false);
  376.                     }
  377.                     /*if(this.configOpenApiValidator.isMergeAPISpec() && api instanceof OpenapiApi) {
  378.                         OpenapiApi openapi = (OpenapiApi) api;
  379.                         if(openapi.getValidationStructure()==null) {
  380.                             api = this.mergeApiSpec(openapi, this.accordoServizioWrapper);
  381.                         }
  382.                     }*/
  383.                 }
  384.             }
  385.             break;
  386.         case OPEN_API_3:
  387.             interfaceType = "Interfaccia OpenAPI 3";
  388.             format=ApiFormats.OPEN_API_3;
  389.             validatorConfig = new OpenapiApiValidatorConfig();
  390.             ((OpenapiApiValidatorConfig)validatorConfig).setJsonValidatorAPI(this.op2Properties.getValidazioneContenutiApplicativiOpenApiJsonValidator());
  391.             if(this.useInterface && this.configOpenApiValidator!=null) {
  392.                 openApiLibrary = this.configOpenApiValidator.getOpenApiLibrary();
  393.                 if(OpenAPILibrary.openapi4j.equals(openApiLibrary) || OpenAPILibrary.swagger_request_validator.equals(openApiLibrary)) {
  394.                     ((OpenapiApiValidatorConfig)validatorConfig).setOpenApiValidatorConfig(this.configOpenApiValidator);
  395.                     if(this.configOpenApiValidator.isMergeAPISpec() && api instanceof OpenapiApi) {
  396.                         OpenapiApi openapi = (OpenapiApi) api;
  397.                         if(openapi.getValidationStructure()==null) {
  398.                             api = this.mergeApiSpec(openapi, this.accordoServizioWrapper);
  399.                         }
  400.                     }
  401.                 }
  402.             }
  403.             break;
  404.         default:
  405.             // altre interfacce non supportate per rest
  406.             throw new ValidatoreMessaggiApplicativiException("Tipo di interfaccia ["+this.accordoServizioWrapper.getAccordoServizio().getFormatoSpecifica()+"] non supportata");
  407.         }
  408.        
  409.         IApiValidator apiValidator = null;
  410.         try {
  411.             apiValidator = ApiFactory.newApiValidator(format);
  412.             validatorConfig.setXmlUtils(MessageXMLUtils.getInstance(this.message.getFactory()));
  413.             validatorConfig.setVerbose(this.op2Properties.isValidazioneContenutiApplicativiDebug());
  414.             validatorConfig.setPolicyAdditionalProperties(this.op2Properties.getValidazioneContenutiApplicativiJsonPolicyAdditionalProperties());
  415.             apiValidator.init(this.logger, api, validatorConfig);
  416.         }catch(Exception e){
  417.             this.logger.error("validateWithInterface failed: "+e.getMessage(),e);
  418.             ValidatoreMessaggiApplicativiException ex
  419.                 = new ValidatoreMessaggiApplicativiException(e.getMessage(),e);
  420.             ex.setErrore(ErroriIntegrazione.ERRORE_417_COSTRUZIONE_VALIDATORE_TRAMITE_INTERFACCIA_FALLITA.getErrore417_CostruzioneValidatoreTramiteInterfacciaFallita(interfaceType));
  421.             throw ex;
  422.         }
  423.            
  424.         InputStream isContent = null;
  425.         try{
  426.             org.openspcoop2.utils.transport.TransportRequestContext transportContext = null;
  427.             if(isRichiesta) {
  428.                 transportContext = this.message.getTransportRequestContext();
  429.             }
  430.             else {
  431.                 transportContext = requestMessage.getTransportRequestContext();
  432.             }
  433.             String normalizedInterfaceName = null;
  434.             try {
  435.                 String interfaceName = null;
  436.                 if(this.pddContext!=null && this.pddContext.containsKey(CostantiPdD.NOME_PORTA_INVOCATA)) {
  437.                     interfaceName = (String) this.pddContext.getObject(CostantiPdD.NOME_PORTA_INVOCATA);
  438.                 }
  439.                 else {
  440.                     interfaceName = transportContext.getInterfaceName();
  441.                 }
  442.                 if(transportContext.getInterfaceName()!=null) {
  443.                     PorteNamingUtils namingUtils = new PorteNamingUtils(this.protocolFactory);
  444.                     if(portaApplicativa){
  445.                         normalizedInterfaceName = namingUtils.normalizePA(interfaceName);
  446.                     }
  447.                     else {
  448.                         normalizedInterfaceName = namingUtils.normalizePD(interfaceName);
  449.                     }
  450.                 }
  451.             }catch(Exception e) {
  452.                 throw new DriverRegistroServiziException(e.getMessage(),e);
  453.             }
  454.             String path = RestUtilities.getUrlWithoutInterface(transportContext, normalizedInterfaceName);
  455.             HttpRequestMethod httpMethod = HttpRequestMethod.valueOf(transportContext.getRequestType());
  456.            
  457.             String idTransazione = null;
  458.             if(this.pddContext!=null) {
  459.                 idTransazione = (String)this.pddContext.getObject(org.openspcoop2.core.constants.Costanti.ID_TRANSAZIONE);
  460.             }
  461.            
  462.             if(isRichiesta) {
  463.                 HttpBaseRequestEntity<?> httpRequest = null;
  464.                 switch (this.message.getMessageType()) {
  465.                 case XML:
  466.                     httpRequest = new ElementHttpRequestEntity();
  467.                     if(this.message.castAsRest().hasContent()) {
  468.                        
  469.                         // serve anche in opeanpi4j per bufferizzare la richiesta
  470.                         OpenSPCoop2RestXmlMessage xmlMsg = this.message.castAsRestXml();
  471.                         Element contentXml = xmlMsg.getContent(this.bufferMessage_readOnly, idTransazione);
  472.                        
  473.                         if(OpenAPILibrary.openapi4j.equals(openApiLibrary) || OpenAPILibrary.swagger_request_validator.equals(openApiLibrary)) {
  474.                             httpRequest = new BinaryHttpRequestEntity();
  475.                             ByteArrayOutputStream bout = new ByteArrayOutputStream();
  476.                             this.message.writeTo(bout, false);
  477.                             bout.flush();
  478.                             bout.close();
  479.                             ((BinaryHttpRequestEntity)httpRequest).setContent(bout.toByteArray());
  480.                         }
  481.                         else {
  482.                             ((ElementHttpRequestEntity)httpRequest).setContent(contentXml);
  483.                         }
  484.                     }
  485.                     break;
  486.                 case JSON:
  487.                     httpRequest = new TextHttpRequestEntity();
  488.                     if(this.message.castAsRest().hasContent()) {
  489.                         OpenSPCoop2RestJsonMessage jsonMsg = this.message.castAsRestJson();
  490.                         String contentString = jsonMsg.getContent(this.bufferMessage_readOnly, idTransazione);                      
  491.                         ((TextHttpRequestEntity)httpRequest).setContent(contentString);
  492.                     }
  493.                     break;
  494.                 case BINARY:
  495.                 case MIME_MULTIPART:
  496.                     OpenSPCoop2RestMessage<?> restMsg = this.message.castAsRest();
  497.                     if(restMsg.hasContent()) {
  498.                         boolean lazy = restMsg.setInputStreamLazyBuffer(idTransazione); // bufferizzazione lazy
  499.                         InputStream isLazyContent = lazy ? restMsg.getInputStream() : null;
  500.                         if(isLazyContent!=null) {
  501.                             // isContent verra' chiuso sotto nel finally, mentre il lazy no
  502.                             httpRequest = new InputStreamHttpRequestEntity();
  503.                             ((InputStreamHttpRequestEntity)httpRequest).setContent(isLazyContent);
  504.                         }
  505.                         else {
  506.                             restMsg.initContent(this.bufferMessage_readOnly, idTransazione); // bufferizzo
  507.                             isContent = restMsg.getInputStreamFromContentBuffer();
  508.                             if(isContent!=null) {
  509.                                 httpRequest = new InputStreamHttpRequestEntity();
  510.                                 ((InputStreamHttpRequestEntity)httpRequest).setContent(isContent);
  511.                             }
  512.                             else {
  513.                                 httpRequest = new BinaryHttpRequestEntity();
  514.                                 ByteArrayOutputStream bout = new ByteArrayOutputStream();
  515.                                 this.message.writeTo(bout, false);
  516.                                 bout.flush();
  517.                                 bout.close();
  518.                                 ((BinaryHttpRequestEntity)httpRequest).setContent(bout.toByteArray());
  519.                             }
  520.                         }
  521.                     }
  522.                     else {
  523.                         httpRequest = new BinaryHttpRequestEntity();
  524.                     }
  525.                     break;
  526.                 default:
  527.                     break;
  528.                 }
  529.                 if(httpRequest==null) {
  530.                     throw new Exception("HttpRequest undefined");
  531.                 }
  532.                 httpRequest.setContentType(this.message.getContentType());
  533.                 httpRequest.setHeaders(this.message.getTransportRequestContext().getHeaders());
  534.                 httpRequest.setParameters(this.message.getTransportRequestContext().getParameters());
  535.                 Map<String,String> mapCookies = this.message.getTransportRequestContext().getCookiesValue();
  536.                 if(mapCookies!=null && !mapCookies.isEmpty()) {
  537.                     for (String name : mapCookies.keySet()) {
  538.                         String value = mapCookies.get(name);
  539.                         Cookie cookie = new Cookie(name, value);
  540.                         if(httpRequest.getCookies()==null) {
  541.                             httpRequest.setCookies(new ArrayList<Cookie>());
  542.                         }
  543.                         httpRequest.getCookies().add(cookie);
  544.                     }
  545.                 }
  546.                 httpRequest.setUrl(path);
  547.                 httpRequest.setMethod(httpMethod);
  548.                 apiValidator.validate(httpRequest);
  549.             }
  550.             else {
  551.                 HttpBaseResponseEntity<?> httpResponse = null;
  552.                 switch (this.message.getMessageType()) {
  553.                 case XML:
  554.                     httpResponse = new ElementHttpResponseEntity();
  555.                     if(this.message.castAsRest().hasContent()) {

  556.                         // serve anche in opeanpi4j per bufferizzare la richiesta
  557.                         OpenSPCoop2RestXmlMessage xmlMsg = this.message.castAsRestXml();
  558.                         Element contentXml = xmlMsg.getContent(this.bufferMessage_readOnly, idTransazione);
  559.                        
  560.                         if(OpenAPILibrary.openapi4j.equals(openApiLibrary) || OpenAPILibrary.swagger_request_validator.equals(openApiLibrary)) {
  561.                             httpResponse = new BinaryHttpResponseEntity();
  562.                             ByteArrayOutputStream bout = new ByteArrayOutputStream();
  563.                             this.message.writeTo(bout, false);
  564.                             bout.flush();
  565.                             bout.close();
  566.                             ((BinaryHttpResponseEntity)httpResponse).setContent(bout.toByteArray());
  567.                         }
  568.                         else {
  569.                             ((ElementHttpResponseEntity)httpResponse).setContent(contentXml);
  570.                         }
  571.                     }
  572.                     break;
  573.                 case JSON:
  574.                     httpResponse = new TextHttpResponseEntity();
  575.                     if(this.message.castAsRest().hasContent()) {
  576.                         OpenSPCoop2RestJsonMessage jsonMsg = this.message.castAsRestJson();
  577.                         String contentString = jsonMsg.getContent(this.bufferMessage_readOnly, idTransazione);                      
  578.                         ((TextHttpResponseEntity)httpResponse).setContent(contentString);
  579.                     }
  580.                     break;
  581.                 case BINARY:
  582.                 case MIME_MULTIPART:
  583.                     OpenSPCoop2RestMessage<?> restMsg = this.message.castAsRest();
  584.                     if(restMsg.hasContent()) {
  585.                         boolean lazy = restMsg.setInputStreamLazyBuffer(idTransazione); // bufferizzazione lazy
  586.                         InputStream isLazyContent = lazy ? restMsg.getInputStream() : null;
  587.                         if(isLazyContent!=null) {
  588.                             // isContent verra' chiuso sotto nel finally, mentre il lazy no
  589.                             httpResponse = new InputStreamHttpResponseEntity();
  590.                             ((InputStreamHttpResponseEntity)httpResponse).setContent(isLazyContent);
  591.                         }
  592.                         else {
  593.                             restMsg.initContent(this.bufferMessage_readOnly, idTransazione); // bufferizzo
  594.                             isContent = restMsg.getInputStreamFromContentBuffer();
  595.                             if(isContent!=null) {
  596.                                 httpResponse = new InputStreamHttpResponseEntity();
  597.                                 ((InputStreamHttpResponseEntity)httpResponse).setContent(isContent);
  598.                             }
  599.                             else {
  600.                                 httpResponse = new BinaryHttpResponseEntity();
  601.                                 ByteArrayOutputStream bout = new ByteArrayOutputStream();
  602.                                 this.message.writeTo(bout, false);
  603.                                 bout.flush();
  604.                                 bout.close();
  605.                                 ((BinaryHttpResponseEntity)httpResponse).setContent(bout.toByteArray());
  606.                             }
  607.                         }
  608.                     }
  609.                     else {
  610.                         httpResponse = new BinaryHttpResponseEntity();
  611.                     }
  612.                     break;
  613.                 default:
  614.                     break;
  615.                 }
  616.                 if(httpResponse==null) {
  617.                     throw new Exception("httpResponse undefined");
  618.                 }
  619.                 httpResponse.setContentType(this.message.getContentType());
  620.                 httpResponse.setHeaders(this.message.getTransportResponseContext().getHeaders());
  621.                 httpResponse.setUrl(path);
  622.                 httpResponse.setMethod(httpMethod);
  623.                 httpResponse.setStatus(Integer.parseInt(this.message.getTransportResponseContext().getCodiceTrasporto()));
  624.                 apiValidator.validate(httpResponse);
  625.             }
  626.            
  627.         }catch(Throwable e ){ // WSDLValidatorException
  628.             ValidatoreMessaggiApplicativiException ex
  629.                 = new ValidatoreMessaggiApplicativiException(e.getMessage(),e);
  630.            
  631.             String messaggioErrore = e.getMessage();
  632.             boolean overwriteMessageError = false;
  633.             try {
  634.                 messaggioErrore = ErroriProperties.getInstance(this.logger).getGenericDetails_noWrap(isRichiesta ? IntegrationFunctionError.INVALID_REQUEST_CONTENT : IntegrationFunctionError.INVALID_RESPONSE_CONTENT);
  635.                 messaggioErrore = messaggioErrore+": "+e.getMessage();
  636.                 overwriteMessageError = true;
  637.             }catch(Exception excp) {}
  638.            
  639.             if(isRichiesta){
  640.                 ex.setErrore(ErroriIntegrazione.ERRORE_418_VALIDAZIONE_RICHIESTA_TRAMITE_INTERFACCIA_FALLITA.getErrore418_ValidazioneRichiestaTramiteInterfacciaFallita(interfaceType,messaggioErrore, overwriteMessageError));
  641.             }else{
  642.                 ex.setErrore(ErroriIntegrazione.ERRORE_419_VALIDAZIONE_RISPOSTA_TRAMITE_INTERFACCIA_FALLITA.getErrore419_ValidazioneRispostaTramiteInterfacciaFallita(interfaceType, messaggioErrore, overwriteMessageError));
  643.             }
  644.             throw ex;
  645.         }finally {
  646.             try {
  647.                 apiValidator.close(this.logger, this.accordoServizioWrapper.getApi(), validatorConfig);
  648.             }catch(Throwable e){
  649.                 this.logger.error("validateWithInterface close error: "+e.getMessage(),e);
  650.             }
  651.             try {
  652.                 if(isContent!=null) {
  653.                     isContent.close();
  654.                     isContent = null;
  655.                 }
  656.             }catch(Throwable t) {}
  657.         }
  658.        
  659.     }
  660.    
  661.     private Api mergeApiSpec(OpenapiApi api, org.openspcoop2.core.registry.rest.AccordoServizioWrapper accordoServizioWrapper) {
  662.        
  663.         YAMLUtils yamlUtils = YAMLUtils.getInstance();
  664.         JSONUtils jsonUtils = JSONUtils.getInstance();
  665.                                
  666.         Map<String, String> attachments = new HashMap<>();
  667.         if(api.getSchemas()!=null && api.getSchemas().size()>0) {

  668.             for (ApiSchema apiSchema : api.getSchemas()) {
  669.            
  670.                 if(!ApiSchemaType.JSON.equals(apiSchema.getType()) && !ApiSchemaType.YAML.equals(apiSchema.getType())) {
  671.                     continue;
  672.                 }
  673.                 byte [] schema = apiSchema.getContent();
  674.                 if(ApiSchemaType.JSON.equals(apiSchema.getType())) {
  675.                     if(jsonUtils.isJson(schema)) {
  676.                         attachments.put(apiSchema.getName(), new String(apiSchema.getContent()));
  677.                     }
  678.                 }
  679.                 else {
  680.                     if(yamlUtils.isYaml(schema)) {
  681.                         attachments.put(apiSchema.getName(), new String(apiSchema.getContent()));
  682.                     }
  683.                 }
  684.                
  685.             }
  686.         }
  687.        
  688.         if(attachments.isEmpty()) {
  689.             return api; // non vi sono attachments da aggiungere
  690.         }
  691.        
  692.         String apiRaw = api.getApiRaw();
  693.         boolean apiRawIsYaml = yamlUtils.isYaml(apiRaw);
  694.                                    
  695.         UniqueInterfaceGeneratorConfig configUniqueInterfaceGeneratorConfig = new UniqueInterfaceGeneratorConfig();
  696.         configUniqueInterfaceGeneratorConfig.setFormat(ApiFormats.OPEN_API_3);
  697.         configUniqueInterfaceGeneratorConfig.setYaml(apiRawIsYaml);
  698.         configUniqueInterfaceGeneratorConfig.setMaster(apiRaw);
  699.         configUniqueInterfaceGeneratorConfig.setAttachments(attachments);
  700.         try {
  701.             String apiMerged = UniqueInterfaceGenerator.generate(configUniqueInterfaceGeneratorConfig, null, null, true, this.logger);
  702.             if(apiMerged==null) {
  703.                 throw new Exception("empty ApiSpec");
  704.             }
  705.            
  706.             IApiReader apiReader = ApiFactory.newApiReader(ApiFormats.OPEN_API_3);
  707.             ApiReaderConfig config = new ApiReaderConfig();
  708.             config.setProcessInclude(false);
  709.             config.setProcessInlineSchema(true);
  710.             apiReader.init(this.logger, apiMerged, config);
  711.             Api apiMergedObject = apiReader.read();
  712.             if(apiMergedObject==null) {
  713.                 throw new Exception("empty ApiSpec after read");
  714.             }
  715.             accordoServizioWrapper.updateApi(apiMergedObject);
  716.             return apiMergedObject;
  717.         }catch(Throwable t) {
  718.             this.logger.error("Merge API Spec failed: "+t.getMessage(),t);
  719.             return api; // torno al metodo tradizionale utilizzando l'api non merged
  720.         }

  721.     }
  722.    
  723.     private void updateOpenapiValidatorConfig(List<Proprieta> proprieta, OpenapiLibraryValidatorConfig configOpenApi4j) {
  724.         if(proprieta==null || proprieta.isEmpty()) {
  725.             return;
  726.         }
  727.        
  728.         String useOpenApi4j = ValidatoreMessaggiApplicativiRest.readValue(proprieta, CostantiProprieta.VALIDAZIONE_CONTENUTI_PROPERTY_NAME_OPENAPI4J_ENABLED);
  729.         boolean openApi4jForceDisabled = false;
  730.         if(useOpenApi4j!=null && !StringUtils.isEmpty(useOpenApi4j)) {
  731.             if(CostantiProprieta.VALIDAZIONE_CONTENUTI_PROPERTY_VALUE_OPENAPI4J_ENABLED.equals(useOpenApi4j.trim())) {
  732.                 configOpenApi4j.setOpenApiLibrary(OpenAPILibrary.openapi4j);
  733.             }
  734.             else if(CostantiProprieta.VALIDAZIONE_CONTENUTI_PROPERTY_VALUE_OPENAPI4J_DISABLED.equals(useOpenApi4j.trim())) {
  735.                 openApi4jForceDisabled = true;
  736.             }
  737.         }
  738.         String useSwaggerRequestValidator = ValidatoreMessaggiApplicativiRest.readValue(proprieta, CostantiProprieta.VALIDAZIONE_CONTENUTI_PROPERTY_NAME_SWAGGER_REQUEST_VALIDATOR_ENABLED);
  739.         boolean swaggerRequestValidatorForceDisabled = false;
  740.         if(useSwaggerRequestValidator!=null && !StringUtils.isEmpty(useSwaggerRequestValidator)) {
  741.             if(CostantiProprieta.VALIDAZIONE_CONTENUTI_PROPERTY_VALUE_SWAGGER_REQUEST_VALIDATOR_ENABLED.equals(useSwaggerRequestValidator.trim())) {
  742.                 configOpenApi4j.setOpenApiLibrary(OpenAPILibrary.swagger_request_validator);
  743.             }
  744.             else if(CostantiProprieta.VALIDAZIONE_CONTENUTI_PROPERTY_VALUE_SWAGGER_REQUEST_VALIDATOR_DISABLED.equals(useSwaggerRequestValidator.trim())) {
  745.                 swaggerRequestValidatorForceDisabled = true;
  746.             }
  747.         }
  748.        
  749.         if(openApi4jForceDisabled && swaggerRequestValidatorForceDisabled) {
  750.             configOpenApi4j.setOpenApiLibrary(OpenAPILibrary.json_schema);
  751.         }
  752.        
  753.         if(!OpenAPILibrary.openapi4j.equals(configOpenApi4j.getOpenApiLibrary()) && !OpenAPILibrary.swagger_request_validator.equals(configOpenApi4j.getOpenApiLibrary())) {
  754.             return;
  755.         }
  756.         boolean openapi4j = OpenAPILibrary.openapi4j.equals(configOpenApi4j.getOpenApiLibrary());
  757.         String enabled = openapi4j ? CostantiProprieta.VALIDAZIONE_CONTENUTI_PROPERTY_VALUE_OPENAPI4J_ENABLED : CostantiProprieta.VALIDAZIONE_CONTENUTI_PROPERTY_VALUE_SWAGGER_REQUEST_VALIDATOR_ENABLED;
  758.         String disabled = openapi4j ? CostantiProprieta.VALIDAZIONE_CONTENUTI_PROPERTY_VALUE_OPENAPI4J_DISABLED : CostantiProprieta.VALIDAZIONE_CONTENUTI_PROPERTY_VALUE_SWAGGER_REQUEST_VALIDATOR_DISABLED;
  759.        
  760.         String mergeAPISpec = ValidatoreMessaggiApplicativiRest.readValue(proprieta,
  761.                 openapi4j ? CostantiProprieta.VALIDAZIONE_CONTENUTI_PROPERTY_NAME_OPENAPI4J_MERGE_API_SPEC : CostantiProprieta.VALIDAZIONE_CONTENUTI_PROPERTY_NAME_SWAGGER_REQUEST_VALIDATOR_MERGE_API_SPEC);
  762.         if(mergeAPISpec==null || StringUtils.isEmpty(mergeAPISpec)) {
  763.             mergeAPISpec = ValidatoreMessaggiApplicativiRest.readValue(proprieta, CostantiProprieta.VALIDAZIONE_CONTENUTI_PROPERTY_NAME_COMMONS_MERGE_API_SPEC);
  764.         }
  765.         if(mergeAPISpec!=null && !StringUtils.isEmpty(mergeAPISpec)) {
  766.             if(enabled.equals(mergeAPISpec.trim())) {
  767.                 configOpenApi4j.setMergeAPISpec(true);
  768.             }
  769.             else if(disabled.equals(mergeAPISpec.trim())) {
  770.                 configOpenApi4j.setMergeAPISpec(false);
  771.             }
  772.         }
  773.        
  774.         String validateAPISpec = ValidatoreMessaggiApplicativiRest.readValue(proprieta,
  775.                 openapi4j ? CostantiProprieta.VALIDAZIONE_CONTENUTI_PROPERTY_NAME_OPENAPI4J_VALIDATE_API_SPEC : CostantiProprieta.VALIDAZIONE_CONTENUTI_PROPERTY_NAME_SWAGGER_REQUEST_VALIDATOR_VALIDATE_API_SPEC);
  776.         if(validateAPISpec==null || StringUtils.isEmpty(validateAPISpec)) {
  777.             validateAPISpec = ValidatoreMessaggiApplicativiRest.readValue(proprieta, CostantiProprieta.VALIDAZIONE_CONTENUTI_PROPERTY_NAME_COMMONS_VALIDATE_API_SPEC);
  778.         }
  779.         if(validateAPISpec!=null && !StringUtils.isEmpty(validateAPISpec)) {
  780.             if(enabled.equals(validateAPISpec.trim())) {
  781.                 configOpenApi4j.setValidateAPISpec(true);
  782.             }
  783.             else if(disabled.equals(validateAPISpec.trim())) {
  784.                 configOpenApi4j.setValidateAPISpec(false);
  785.             }
  786.         }
  787.        
  788.         String validateRequestPath = ValidatoreMessaggiApplicativiRest.readValue(proprieta,
  789.                 openapi4j ? CostantiProprieta.VALIDAZIONE_CONTENUTI_PROPERTY_NAME_OPENAPI4J_VALIDATE_REQUEST_PATH : CostantiProprieta.VALIDAZIONE_CONTENUTI_PROPERTY_NAME_SWAGGER_REQUEST_VALIDATOR_VALIDATE_REQUEST_PATH);
  790.         if(validateRequestPath==null || StringUtils.isEmpty(validateRequestPath)) {
  791.             validateRequestPath = ValidatoreMessaggiApplicativiRest.readValue(proprieta, CostantiProprieta.VALIDAZIONE_CONTENUTI_PROPERTY_NAME_COMMONS_VALIDATE_REQUEST_PATH);
  792.         }
  793.         if(validateRequestPath!=null && !StringUtils.isEmpty(validateRequestPath)) {
  794.             if(enabled.equals(validateRequestPath.trim())) {
  795.                 configOpenApi4j.setValidateRequestPath(true);
  796.             }
  797.             else if(disabled.equals(validateRequestPath.trim())) {
  798.                 configOpenApi4j.setValidateRequestPath(false);
  799.             }
  800.         }
  801.        
  802.         String validateRequestQuery = ValidatoreMessaggiApplicativiRest.readValue(proprieta,
  803.                 openapi4j ? CostantiProprieta.VALIDAZIONE_CONTENUTI_PROPERTY_NAME_OPENAPI4J_VALIDATE_REQUEST_QUERY : CostantiProprieta.VALIDAZIONE_CONTENUTI_PROPERTY_NAME_SWAGGER_REQUEST_VALIDATOR_VALIDATE_REQUEST_QUERY);
  804.         if(validateRequestQuery==null || StringUtils.isEmpty(validateRequestQuery)) {
  805.             validateRequestQuery = ValidatoreMessaggiApplicativiRest.readValue(proprieta, CostantiProprieta.VALIDAZIONE_CONTENUTI_PROPERTY_NAME_COMMONS_VALIDATE_REQUEST_QUERY);
  806.         }
  807.         if(validateRequestQuery!=null && !StringUtils.isEmpty(validateRequestQuery)) {
  808.             if(enabled.equals(validateRequestQuery.trim())) {
  809.                 configOpenApi4j.setValidateRequestQuery(true);
  810.             }
  811.             else if(disabled.equals(validateRequestQuery.trim())) {
  812.                 configOpenApi4j.setValidateRequestQuery(false);
  813.             }
  814.         }
  815.        
  816.         String validateRequestQueryUnexpectedQueryParam = ValidatoreMessaggiApplicativiRest.readValue(proprieta,
  817.                 openapi4j ? CostantiProprieta.VALIDAZIONE_CONTENUTI_PROPERTY_NAME_OPENAPI4J_VALIDATE_REQUEST_UNEXPECTED_QUERY_PARAM : CostantiProprieta.VALIDAZIONE_CONTENUTI_PROPERTY_NAME_SWAGGER_REQUEST_VALIDATOR_VALIDATE_REQUEST_UNEXPECTED_QUERY_PARAM);
  818.         if(validateRequestQueryUnexpectedQueryParam==null || StringUtils.isEmpty(validateRequestQueryUnexpectedQueryParam)) {
  819.             validateRequestQueryUnexpectedQueryParam = ValidatoreMessaggiApplicativiRest.readValue(proprieta, CostantiProprieta.VALIDAZIONE_CONTENUTI_PROPERTY_NAME_COMMONS_VALIDATE_REQUEST_UNEXPECTED_QUERY_PARAM);
  820.         }
  821.         if(validateRequestQueryUnexpectedQueryParam!=null && !StringUtils.isEmpty(validateRequestQueryUnexpectedQueryParam)) {
  822.             if(enabled.equals(validateRequestQueryUnexpectedQueryParam.trim())) {
  823.                 configOpenApi4j.setValidateRequestUnexpectedQueryParam(true);
  824.             }
  825.             else if(disabled.equals(validateRequestQueryUnexpectedQueryParam.trim())) {
  826.                 configOpenApi4j.setValidateRequestUnexpectedQueryParam(false);
  827.             }
  828.         }
  829.        
  830.         String validateRequestHeaders = ValidatoreMessaggiApplicativiRest.readValue(proprieta,
  831.                 openapi4j ? CostantiProprieta.VALIDAZIONE_CONTENUTI_PROPERTY_NAME_OPENAPI4J_VALIDATE_REQUEST_HEADERS : CostantiProprieta.VALIDAZIONE_CONTENUTI_PROPERTY_NAME_SWAGGER_REQUEST_VALIDATOR_VALIDATE_REQUEST_HEADERS);
  832.         if(validateRequestHeaders==null || StringUtils.isEmpty(validateRequestHeaders)) {
  833.             validateRequestHeaders = ValidatoreMessaggiApplicativiRest.readValue(proprieta, CostantiProprieta.VALIDAZIONE_CONTENUTI_PROPERTY_NAME_COMMONS_VALIDATE_REQUEST_HEADERS);
  834.         }
  835.         if(validateRequestHeaders!=null && !StringUtils.isEmpty(validateRequestHeaders)) {
  836.             if(enabled.equals(validateRequestHeaders.trim())) {
  837.                 configOpenApi4j.setValidateRequestHeaders(true);
  838.             }
  839.             else if(disabled.equals(validateRequestHeaders.trim())) {
  840.                 configOpenApi4j.setValidateRequestHeaders(false);
  841.             }
  842.         }
  843.        
  844.         String validateRequestCookie = ValidatoreMessaggiApplicativiRest.readValue(proprieta,
  845.                 openapi4j ? CostantiProprieta.VALIDAZIONE_CONTENUTI_PROPERTY_NAME_OPENAPI4J_VALIDATE_REQUEST_COOKIES : CostantiProprieta.VALIDAZIONE_CONTENUTI_PROPERTY_NAME_SWAGGER_REQUEST_VALIDATOR_VALIDATE_REQUEST_COOKIES);
  846.         if(validateRequestCookie==null || StringUtils.isEmpty(validateRequestCookie)) {
  847.             validateRequestCookie = ValidatoreMessaggiApplicativiRest.readValue(proprieta, CostantiProprieta.VALIDAZIONE_CONTENUTI_PROPERTY_NAME_COMMONS_VALIDATE_REQUEST_COOKIES);
  848.         }
  849.         if(validateRequestCookie!=null && !StringUtils.isEmpty(validateRequestCookie)) {
  850.             if(enabled.equals(validateRequestCookie.trim())) {
  851.                 configOpenApi4j.setValidateRequestCookie(true);
  852.             }
  853.             else if(disabled.equals(validateRequestCookie.trim())) {
  854.                 configOpenApi4j.setValidateRequestCookie(false);
  855.             }
  856.         }
  857.        
  858.         String validateRequestBody = ValidatoreMessaggiApplicativiRest.readValue(proprieta,
  859.                 openapi4j ? CostantiProprieta.VALIDAZIONE_CONTENUTI_PROPERTY_NAME_OPENAPI4J_VALIDATE_REQUEST_BODY : CostantiProprieta.VALIDAZIONE_CONTENUTI_PROPERTY_NAME_SWAGGER_REQUEST_VALIDATOR_VALIDATE_REQUEST_BODY);
  860.         if(validateRequestBody==null || StringUtils.isEmpty(validateRequestBody)) {
  861.             validateRequestBody = ValidatoreMessaggiApplicativiRest.readValue(proprieta, CostantiProprieta.VALIDAZIONE_CONTENUTI_PROPERTY_NAME_COMMONS_VALIDATE_REQUEST_BODY);
  862.         }
  863.         if(validateRequestBody!=null && !StringUtils.isEmpty(validateRequestBody)) {
  864.             if(enabled.equals(validateRequestBody.trim())) {
  865.                 configOpenApi4j.setValidateRequestBody(true);
  866.             }
  867.             else if(disabled.equals(validateRequestBody.trim())) {
  868.                 configOpenApi4j.setValidateRequestBody(false);
  869.             }
  870.         }
  871.        
  872.         String validateResponseHeaders = ValidatoreMessaggiApplicativiRest.readValue(proprieta,
  873.                 openapi4j ? CostantiProprieta.VALIDAZIONE_CONTENUTI_PROPERTY_NAME_OPENAPI4J_VALIDATE_RESPONSE_HEADERS : CostantiProprieta.VALIDAZIONE_CONTENUTI_PROPERTY_NAME_SWAGGER_REQUEST_VALIDATOR_VALIDATE_RESPONSE_HEADERS);
  874.         if(validateResponseHeaders==null || StringUtils.isEmpty(validateResponseHeaders)) {
  875.             validateResponseHeaders = ValidatoreMessaggiApplicativiRest.readValue(proprieta, CostantiProprieta.VALIDAZIONE_CONTENUTI_PROPERTY_NAME_COMMONS_VALIDATE_RESPONSE_HEADERS);
  876.         }
  877.         if(validateResponseHeaders!=null && !StringUtils.isEmpty(validateResponseHeaders)) {
  878.             if(enabled.equals(validateResponseHeaders.trim())) {
  879.                 configOpenApi4j.setValidateResponseHeaders(true);
  880.             }
  881.             else if(disabled.equals(validateResponseHeaders.trim())) {
  882.                 configOpenApi4j.setValidateResponseHeaders(false);
  883.             }
  884.         }
  885.        
  886.         String validateResponseBody = ValidatoreMessaggiApplicativiRest.readValue(proprieta,
  887.                 openapi4j ? CostantiProprieta.VALIDAZIONE_CONTENUTI_PROPERTY_NAME_OPENAPI4J_VALIDATE_RESPONSE_BODY : CostantiProprieta.VALIDAZIONE_CONTENUTI_PROPERTY_NAME_SWAGGER_REQUEST_VALIDATOR_VALIDATE_RESPONSE_BODY);
  888.         if(validateResponseBody==null || StringUtils.isEmpty(validateResponseBody)) {
  889.             validateResponseBody = ValidatoreMessaggiApplicativiRest.readValue(proprieta, CostantiProprieta.VALIDAZIONE_CONTENUTI_PROPERTY_NAME_COMMONS_VALIDATE_RESPONSE_BODY);
  890.         }
  891.         if(validateResponseBody!=null && !StringUtils.isEmpty(validateResponseBody)) {
  892.             if(enabled.equals(validateResponseBody.trim())) {
  893.                 configOpenApi4j.setValidateResponseBody(true);
  894.             }
  895.             else if(disabled.equals(validateResponseBody.trim())) {
  896.                 configOpenApi4j.setValidateResponseBody(false);
  897.             }
  898.         }
  899.        
  900.         String validateWildcardSubtypeAsJson = ValidatoreMessaggiApplicativiRest.readValue(proprieta,
  901.                 openapi4j ? CostantiProprieta.VALIDAZIONE_CONTENUTI_PROPERTY_NAME_OPENAPI4J_VALIDATE_WILDCARD_SUBTYPE_AS_JSON : CostantiProprieta.VALIDAZIONE_CONTENUTI_PROPERTY_NAME_SWAGGER_REQUEST_VALIDATOR_VALIDATE_WILDCARD_SUBTYPE_AS_JSON);
  902.         if(validateWildcardSubtypeAsJson==null || StringUtils.isEmpty(validateWildcardSubtypeAsJson)) {
  903.             validateWildcardSubtypeAsJson = ValidatoreMessaggiApplicativiRest.readValue(proprieta, CostantiProprieta.VALIDAZIONE_CONTENUTI_PROPERTY_NAME_COMMONS_VALIDATE_WILDCARD_SUBTYPE_AS_JSON);
  904.         }
  905.         if(validateWildcardSubtypeAsJson!=null && !StringUtils.isEmpty(validateWildcardSubtypeAsJson)) {
  906.             if(enabled.equals(validateWildcardSubtypeAsJson.trim())) {
  907.                 configOpenApi4j.setValidateWildcardSubtypeAsJson(true);
  908.             }
  909.             else if(disabled.equals(validateWildcardSubtypeAsJson.trim())) {
  910.                 configOpenApi4j.setValidateWildcardSubtypeAsJson(false);
  911.             }
  912.         }
  913.        
  914.         if(openapi4j) {
  915.             String validateMultipartOptimization = ValidatoreMessaggiApplicativiRest.readValue(proprieta,
  916.                     //openapi4j ? CostantiProprieta.VALIDAZIONE_CONTENUTI_PROPERTY_NAME_OPENAPI4J_VALIDATE_MULTIPART_OPTIMIZATION : CostantiProprieta.VALIDAZIONE_CONTENUTI_PROPERTY_NAME_SWAGGER_REQUEST_VALIDATOR_VALIDATE_MULTIPART_OPTIMIZATION);
  917.                     CostantiProprieta.VALIDAZIONE_CONTENUTI_PROPERTY_NAME_OPENAPI4J_VALIDATE_MULTIPART_OPTIMIZATION);
  918.             if(validateMultipartOptimization==null || StringUtils.isEmpty(validateMultipartOptimization)) {
  919.                 validateMultipartOptimization = ValidatoreMessaggiApplicativiRest.readValue(proprieta, CostantiProprieta.VALIDAZIONE_CONTENUTI_PROPERTY_NAME_COMMONS_VALIDATE_MULTIPART_OPTIMIZATION);
  920.             }
  921.             if(validateMultipartOptimization!=null && !StringUtils.isEmpty(validateMultipartOptimization)) {
  922.                 if(enabled.equals(validateMultipartOptimization.trim())) {
  923.                     configOpenApi4j.setValidateMultipartOptimization(true);
  924.                 }
  925.                 else if(disabled.equals(validateMultipartOptimization.trim())) {
  926.                     configOpenApi4j.setValidateMultipartOptimization(false);
  927.                 }
  928.             }
  929.         }
  930.        
  931.         if(!openapi4j) {
  932.             String injectingAdditionalPropertiesFalse = ValidatoreMessaggiApplicativiRest.readValue(proprieta, CostantiProprieta.VALIDAZIONE_CONTENUTI_PROPERTY_NAME_SWAGGER_REQUEST_VALIDATOR_INJECTING_ADDITIONAL_PROPERTIES_FALSE);
  933.             if(injectingAdditionalPropertiesFalse!=null && !StringUtils.isEmpty(injectingAdditionalPropertiesFalse)) {
  934.                 if(enabled.equals(injectingAdditionalPropertiesFalse.trim())) {
  935.                     configOpenApi4j.setSwaggerRequestValidator_InjectingAdditionalPropertiesFalse(true);
  936.                 }
  937.                 else if(disabled.equals(injectingAdditionalPropertiesFalse.trim())) {
  938.                     configOpenApi4j.setSwaggerRequestValidator_InjectingAdditionalPropertiesFalse(false);
  939.                 }
  940.             }
  941.            
  942.             String resolveFullyApiSpec = ValidatoreMessaggiApplicativiRest.readValue(proprieta, CostantiProprieta.VALIDAZIONE_CONTENUTI_PROPERTY_NAME_SWAGGER_REQUEST_VALIDATOR_RESOLVE_FULLY_API_SPEC);
  943.             if(resolveFullyApiSpec!=null && !StringUtils.isEmpty(resolveFullyApiSpec)) {
  944.                 if(enabled.equals(resolveFullyApiSpec.trim())) {
  945.                     configOpenApi4j.setSwaggerRequestValidator_ResolveFullyApiSpec(true);
  946.                 }
  947.                 else if(disabled.equals(resolveFullyApiSpec.trim())) {
  948.                     configOpenApi4j.setSwaggerRequestValidator_ResolveFullyApiSpec(false);
  949.                 }
  950.             }
  951.         }
  952.        
  953.     }
  954.     protected static String readValue(List<Proprieta> proprieta, String nome) {
  955.         if(proprieta==null || proprieta.isEmpty()) {
  956.             return null;
  957.         }
  958.         for (Proprieta proprietaCheck : proprieta) {
  959.             if(nome.equalsIgnoreCase(proprietaCheck.getNome())) {
  960.                 return proprietaCheck.getValore();
  961.             }
  962.         }
  963.         return null;
  964.     }
  965.     public static boolean readBooleanValueWithDefault(List<Proprieta> proprieta, String nome, boolean defaultValue) {
  966.         String valueS = ValidatoreMessaggiApplicativiRest.readValue(proprieta, nome);
  967.         if(valueS!=null && !StringUtils.isEmpty(valueS)) {
  968.             if(CostantiProprieta.VALIDAZIONE_CONTENUTI_PROPERTY_VALUE_ENABLED.equals(valueS.trim())) {
  969.                 return true;
  970.             }
  971.             else if(CostantiProprieta.VALIDAZIONE_CONTENUTI_PROPERTY_VALUE_DISABLED.equals(valueS.trim())) {
  972.                 return false;
  973.             }
  974.         }
  975.         return defaultValue;
  976.     }
  977.    
  978.     public static boolean isValidazioneAbilitata(Logger log, List<Proprieta> proprieta, OpenSPCoop2Message responseMessage, int codiceRitornato) throws UtilsException, MessageException, MessageNotSupportedException {
  979.        
  980.         OpenSPCoop2RestMessage<?> restMsg = responseMessage.castAsRest();
  981.        
  982.         // Controllo se validare risposte vuote
  983.         boolean defaultValidateEmptyResponse = true; // default. devo controllare gli header etc...
  984.         boolean validateEmptyResponse = readBooleanValueWithDefault(proprieta, CostantiProprieta.VALIDAZIONE_CONTENUTI_PROPERTY_NAME_REST_EMPTY_RESPONSE_ENABLED, defaultValidateEmptyResponse);
  985.         if(!validateEmptyResponse) {
  986.             boolean hasContent = restMsg.hasContent();
  987.             if(!hasContent) {
  988.                 return false;
  989.             }
  990.         }
  991.        
  992.         // Controllo se validare i fault generati da govway prima di arrivare alla validazione.
  993.         // Sono errori interni che potrebbero non essere definiti nell'interfaccia.
  994.         // per default questa validazione è disabilitata
  995.         boolean defaultValidateGovwayFault = false;
  996.         boolean validateGovwayFault = readBooleanValueWithDefault(proprieta, CostantiProprieta.VALIDAZIONE_CONTENUTI_PROPERTY_NAME_REST_FAULT_GOVWAY_ENABLED, defaultValidateGovwayFault);
  997.         if(!validateGovwayFault) {
  998.             boolean isFaultGovway = MessageRole.FAULT.equals(responseMessage.getMessageRole());
  999.             if(isFaultGovway) {
  1000.                 return false;
  1001.             }
  1002.         }
  1003.        
  1004.         // Controllo se validare problem detail
  1005.         boolean defaultValidateProblemDetail = true; // dovrebbero far parte dell'interfaccia essendo generati dal server o dalla controparte (non sono fault generati da govway)
  1006.         boolean validateProblemDetail = readBooleanValueWithDefault(proprieta, CostantiProprieta.VALIDAZIONE_CONTENUTI_PROPERTY_NAME_REST_PROBLEM_DETAIL_ENABLED, defaultValidateProblemDetail);
  1007.         if(!validateProblemDetail &&
  1008.             restMsg.isProblemDetailsForHttpApis_RFC7807()) {
  1009.             return false;
  1010.         }
  1011.        
  1012.         // Controllo se validare solo determinati codici http
  1013.         String valueS = ValidatoreMessaggiApplicativiRest.readValue(proprieta, CostantiProprieta.VALIDAZIONE_CONTENUTI_PROPERTY_NAME_REST_RETURN_CODE_LIST_ENABLED);
  1014.         if(valueS!=null && !StringUtils.isEmpty(valueS)) {
  1015.            
  1016.             boolean defaultNot = false;
  1017.             boolean not = readBooleanValueWithDefault(proprieta, CostantiProprieta.VALIDAZIONE_CONTENUTI_PROPERTY_NAME_REST_RETURN_CODE_NOT, defaultNot);
  1018.            
  1019.             List<String> codici = new ArrayList<>();
  1020.             if(valueS.contains(CostantiProprieta.VALIDAZIONE_CONTENUTI_PROPERTY_NAME_REST_RETURN_CODE_LIST_SEPARATOR)) {
  1021.                 String [] tmp = valueS.split(CostantiProprieta.VALIDAZIONE_CONTENUTI_PROPERTY_NAME_REST_RETURN_CODE_LIST_SEPARATOR);
  1022.                 if(tmp!=null && tmp.length>0) {
  1023.                     for (String s : tmp) {
  1024.                         codici.add(s.trim());
  1025.                     }
  1026.                 }
  1027.             }
  1028.             else {
  1029.                 codici.add(valueS.trim());
  1030.             }
  1031.             if(codici!=null && !codici.isEmpty()) {
  1032.                
  1033.                 boolean match = false;
  1034.                
  1035.                 for (String codice : codici) {
  1036.                     if(codice.contains(CostantiProprieta.VALIDAZIONE_CONTENUTI_PROPERTY_NAME_REST_RETURN_CODE_LIST_INTERVAL_SEPARATOR)) {
  1037.                         String [] tmp = codice.split(CostantiProprieta.VALIDAZIONE_CONTENUTI_PROPERTY_NAME_REST_RETURN_CODE_LIST_INTERVAL_SEPARATOR);
  1038.                         if(tmp==null || tmp.length!=2) {
  1039.                             throw new UtilsException("Codice '"+codice+"' indicato nella proprietà '"+CostantiProprieta.VALIDAZIONE_CONTENUTI_PROPERTY_NAME_REST_RETURN_CODE_LIST_SEPARATOR+"' possiede un formato errato; atteso: codiceMin-codiceMax");
  1040.                         }
  1041.                         String codiceMin = tmp[0];
  1042.                         String codiceMax = tmp[1];
  1043.                         if(codiceMin==null || StringUtils.isEmpty(codiceMin.trim())) {
  1044.                             throw new UtilsException("Codice '"+codice+"' indicato nella proprietà '"+CostantiProprieta.VALIDAZIONE_CONTENUTI_PROPERTY_NAME_REST_RETURN_CODE_LIST_SEPARATOR+"' possiede un formato errato (intervallo minimo non definito); atteso: codiceMin-codiceMax");
  1045.                         }
  1046.                         if(codiceMax==null || StringUtils.isEmpty(codiceMax.trim())) {
  1047.                             throw new UtilsException("Codice '"+codice+"' indicato nella proprietà '"+CostantiProprieta.VALIDAZIONE_CONTENUTI_PROPERTY_NAME_REST_RETURN_CODE_LIST_SEPARATOR+"' possiede un formato errato (intervallo massimo non definito); atteso: codiceMin-codiceMax");
  1048.                         }
  1049.                         codiceMin = codiceMin.trim();
  1050.                         codiceMax = codiceMax.trim();
  1051.                         int codiceMinInt = -1;
  1052.                         try {
  1053.                             codiceMinInt = Integer.valueOf(codiceMin);
  1054.                         }catch(Exception e) {
  1055.                             throw new UtilsException("Codice '"+codice+"' indicato nella proprietà '"+CostantiProprieta.VALIDAZIONE_CONTENUTI_PROPERTY_NAME_REST_RETURN_CODE_LIST_SEPARATOR+"' contiene un intervallo minimo '"+codiceMin+"' che non è un numero intero");
  1056.                         }
  1057.                         int codiceMaxInt = -1;
  1058.                         try {
  1059.                             codiceMaxInt = Integer.valueOf(codiceMax);
  1060.                         }catch(Exception e) {
  1061.                             throw new UtilsException("Codice '"+codice+"' indicato nella proprietà '"+CostantiProprieta.VALIDAZIONE_CONTENUTI_PROPERTY_NAME_REST_RETURN_CODE_LIST_SEPARATOR+"' contiene un intervallo massimo '"+codiceMax+"' che non è un numero intero");
  1062.                         }
  1063.                         if(codiceMaxInt<=codiceMinInt) {
  1064.                             throw new UtilsException("Codice '"+codice+"' indicato nella proprietà '"+CostantiProprieta.VALIDAZIONE_CONTENUTI_PROPERTY_NAME_REST_RETURN_CODE_LIST_SEPARATOR+"' contiene un intervallo massimo '"+codiceMax+"' minore o uguale all'intervallo minimo '"+codiceMin+"'");
  1065.                         }
  1066.                         if( (codiceMinInt <= codiceRitornato) && (codiceRitornato <= codiceMaxInt)) {
  1067.                             match = true;
  1068.                             break;
  1069.                         }
  1070.                     }
  1071.                     else {
  1072.                         try {
  1073.                             int codiceInt = Integer.parseInt(codice);
  1074.                             if(codiceInt == codiceRitornato) {
  1075.                                 match = true;
  1076.                                 break;
  1077.                             }
  1078.                         }catch(Exception e) {
  1079.                             throw new UtilsException("Codice '"+codice+"' indicato nella proprietà '"+CostantiProprieta.VALIDAZIONE_CONTENUTI_PROPERTY_NAME_REST_RETURN_CODE_LIST_SEPARATOR+"' non è un numero intero");
  1080.                         }
  1081.                     }
  1082.                 }
  1083.                
  1084.                 if(match) {
  1085.                     return !not ;
  1086.                 }
  1087.                 else {
  1088.                     return not;
  1089.                 }
  1090.             }
  1091.         }
  1092.        
  1093.        
  1094.         // Controllo se validare solo determinati content-type
  1095.         valueS = ValidatoreMessaggiApplicativiRest.readValue(proprieta, CostantiProprieta.VALIDAZIONE_CONTENUTI_PROPERTY_NAME_REST_CONTENT_TYPE_LIST_ENABLED);
  1096.         if(valueS!=null && !StringUtils.isEmpty(valueS)) {
  1097.            
  1098.             boolean defaultNot = false;
  1099.             boolean not = readBooleanValueWithDefault(proprieta, CostantiProprieta.VALIDAZIONE_CONTENUTI_PROPERTY_NAME_REST_CONTENT_TYPE_NOT, defaultNot);
  1100.            
  1101.             List<String> contentTypes = new ArrayList<>();
  1102.             if(valueS.contains(CostantiProprieta.VALIDAZIONE_CONTENUTI_PROPERTY_NAME_REST_CONTENT_TYPE_LIST_SEPARATOR)) {
  1103.                 String [] tmp = valueS.split(CostantiProprieta.VALIDAZIONE_CONTENUTI_PROPERTY_NAME_REST_CONTENT_TYPE_LIST_SEPARATOR);
  1104.                 if(tmp!=null && tmp.length>0) {
  1105.                     for (String s : tmp) {
  1106.                         contentTypes.add(s.trim());
  1107.                     }
  1108.                 }
  1109.             }
  1110.             else {
  1111.                 contentTypes.add(valueS.trim());
  1112.             }
  1113.             if(contentTypes!=null && !contentTypes.isEmpty()) {
  1114.                
  1115.                 String contentTypeRisposta = responseMessage.getContentType();
  1116.                                
  1117.                 if(ContentTypeUtilities.isMatch(log, contentTypeRisposta, contentTypes)) {
  1118.                     return !not ;
  1119.                 }
  1120.                 else {              
  1121.                     return not;
  1122.                 }
  1123.             }
  1124.         }
  1125.        
  1126.        
  1127.         return true;
  1128.        
  1129.     }
  1130.    
  1131. }