ValidatoreErrori.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.basic.validator;

  21. import javax.xml.soap.SOAPFault;

  22. import org.openspcoop2.message.OpenSPCoop2Message;
  23. import org.openspcoop2.message.OpenSPCoop2SoapMessage;
  24. import org.openspcoop2.message.constants.ServiceBinding;
  25. import org.openspcoop2.protocol.basic.BasicStateComponentFactory;
  26. import org.openspcoop2.protocol.sdk.Busta;
  27. import org.openspcoop2.protocol.sdk.IProtocolFactory;
  28. import org.openspcoop2.protocol.sdk.ProtocolException;
  29. import org.openspcoop2.protocol.sdk.config.IProtocolVersionManager;
  30. import org.openspcoop2.protocol.sdk.config.ITraduttore;
  31. import org.openspcoop2.protocol.sdk.constants.MessaggiFaultErroreCooperazione;
  32. import org.openspcoop2.protocol.sdk.state.IState;
  33. import org.openspcoop2.protocol.sdk.validator.ProprietaValidazioneErrori;

  34. /**
  35.  * ValidatoreErrori
  36.  *
  37.  * @author Nardi Lorenzo (apoli@link.it)
  38.  * @author $Author$
  39.  * @version $Rev$, $Date$
  40.  *
  41.  */

  42. public class ValidatoreErrori extends BasicStateComponentFactory implements org.openspcoop2.protocol.sdk.validator.IValidatoreErrori {

  43.     private ITraduttore costanti;
  44.    
  45.     public ValidatoreErrori(IProtocolFactory<?> protocolFactory,IState state) throws ProtocolException{
  46.         super(protocolFactory, state);
  47.         this.costanti = protocolFactory.createTraduttore();
  48.     }
  49.    


  50.     @Override
  51.     public boolean isBustaErrore(Busta busta,OpenSPCoop2Message msg,ProprietaValidazioneErrori proprietaValidazioneErrori){
  52.        
  53.         boolean eccezioneProcessamento = false;
  54.         try{
  55.             if(msg!=null && ServiceBinding.SOAP.equals(msg.getServiceBinding())){
  56.                 OpenSPCoop2SoapMessage soapMessage = msg.castAsSoap();
  57.                 if(soapMessage.hasSOAPFault()){
  58.                     SOAPFault soapFault = soapMessage.getSOAPBody().getFault();
  59.                     String faultS = soapFault.getFaultString();
  60.                     if(faultS!=null)
  61.                         faultS = faultS.trim();
  62.                    
  63.                     eccezioneProcessamento = (this.costanti.toString( MessaggiFaultErroreCooperazione.FAULT_STRING_PROCESSAMENTO).equals(faultS))  || (this.costanti.toString(MessaggiFaultErroreCooperazione.FAULT_STRING_VALIDAZIONE).equals(faultS));
  64.                    
  65.                 }
  66.             }
  67.         }catch(Exception e){
  68.             this.log.error("Errore durante l'analisi per comprendere se un msg e' una busta Errore: "+e.getMessage(),e);
  69.         }
  70.                
  71.         if(eccezioneProcessamento){
  72.             return true;
  73.         }
  74.         else{
  75.             IProtocolVersionManager pManager = null;
  76.             try{
  77.                 pManager = this.protocolFactory.createProtocolVersionManager(proprietaValidazioneErrori.getVersioneProtocollo());
  78.             }catch(Exception e){
  79.                 this.log.error("Errore durante la createProtocolManager: "+e.getMessage(),e);
  80.             }
  81.            
  82.             if(
  83.                     (pManager!=null && pManager.isIgnoraEccezioniLivelloNonGrave())
  84.                     ||  
  85.                     proprietaValidazioneErrori.isIgnoraEccezioniNonGravi()
  86.                 ){
  87.                 if(  busta.containsEccezioniGravi() ){
  88.                     return true;
  89.                 }else{
  90.                     return false;
  91.                 }
  92.             }else{
  93.                 if(  busta.sizeListaEccezioni() > 0 ){
  94.                     return true;
  95.                 }else{
  96.                     return false;
  97.                 }
  98.             }
  99.         }
  100.     }
  101.    
  102.     @Override
  103.     public boolean isBustaErroreProcessamento(Busta busta,OpenSPCoop2Message msg,ProprietaValidazioneErrori proprietaValidazioneErrori){
  104.        
  105.         boolean eccezioneProcessamento = false;
  106.         try{
  107.             if(msg!=null && ServiceBinding.SOAP.equals(msg.getServiceBinding())){
  108.                 OpenSPCoop2SoapMessage soapMessage = msg.castAsSoap();
  109.                 if(soapMessage.hasSOAPFault()){
  110.                     SOAPFault soapFault = soapMessage.getSOAPBody().getFault();
  111.                     String faultS = soapFault.getFaultString();
  112.                     if(faultS!=null)
  113.                         faultS = faultS.trim();
  114.                    
  115.                     if( (this.costanti.toString(MessaggiFaultErroreCooperazione.FAULT_STRING_PROCESSAMENTO).equals(faultS))  ){
  116.                         eccezioneProcessamento = true;
  117.                     }
  118.                 }
  119.             }
  120.         }catch(Exception e){
  121.             this.log.error("Errore durante l'analisi per comprendere se un msg e' una busta Errore: "+e.getMessage(),e);
  122.         }
  123.        
  124.         return eccezioneProcessamento;
  125.     }
  126.    
  127.     @Override
  128.     public boolean isBustaErroreIntestazione(Busta busta,OpenSPCoop2Message msg,ProprietaValidazioneErrori proprietaValidazioneErrori){
  129.        
  130.         boolean eccezioneProcessamento = false;
  131.         try{
  132.             if(msg!=null && ServiceBinding.SOAP.equals(msg.getServiceBinding())){
  133.                 OpenSPCoop2SoapMessage soapMessage = msg.castAsSoap();
  134.                 if(soapMessage.hasSOAPFault()){
  135.                     SOAPFault soapFault = soapMessage.getSOAPBody().getFault();
  136.                     String faultS = soapFault.getFaultString();
  137.                     if(faultS!=null)
  138.                         faultS = faultS.trim();
  139.                    
  140.                     if( (this.costanti.toString(MessaggiFaultErroreCooperazione.FAULT_STRING_VALIDAZIONE).equals(faultS))  ){
  141.                         return true;
  142.                     }
  143.                    
  144.                     if( (this.costanti.toString(MessaggiFaultErroreCooperazione.FAULT_STRING_PROCESSAMENTO).equals(faultS))  ){
  145.                         eccezioneProcessamento = true;
  146.                     }
  147.                 }
  148.             }
  149.         }catch(Exception e){
  150.             this.log.error("Errore durante l'analisi per comprendere se un msg e' una busta Errore: "+e.getMessage(),e);
  151.         }
  152.                
  153.         if(eccezioneProcessamento){
  154.             return false;
  155.         }
  156.         else{
  157.             IProtocolVersionManager pManager = null;
  158.             try{
  159.                 pManager = this.protocolFactory.createProtocolVersionManager(proprietaValidazioneErrori.getVersioneProtocollo());
  160.             }catch(Exception e){
  161.                 this.log.error("Errore durante la createProtocolManager: "+e.getMessage(),e);
  162.             }
  163.            
  164.             if(
  165.                     (pManager!=null && pManager.isIgnoraEccezioniLivelloNonGrave())
  166.                     ||
  167.                     proprietaValidazioneErrori.isIgnoraEccezioniNonGravi()
  168.                 ){
  169.                 if(  busta.containsEccezioniGravi() ){
  170.                     return true;
  171.                 }else{
  172.                     return false;
  173.                 }
  174.             }else{
  175.                 if(  busta.sizeListaEccezioni() > 0 ){
  176.                     return true;
  177.                 }else{
  178.                     return false;
  179.                 }
  180.             }
  181.         }
  182.     }
  183. }