SPCoopValidatoreErrori.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.spcoop.validator;

  21. import javax.xml.soap.SOAPFault;

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

  33. /**
  34.  * Classe che implementa, in base al protocollo SPCoop, l'interfaccia {@link org.openspcoop2.protocol.sdk.validator.IValidatoreErrori}
  35.  *
  36.  * @author Poli Andrea (apoli@link.it)
  37.  * @author $Author$
  38.  * @version $Rev$, $Date$
  39.  */
  40. public class SPCoopValidatoreErrori extends BasicStateComponentFactory implements IValidatoreErrori {

  41.     /**
  42.      * Costruttore.
  43.      *
  44.      * @param protocolFactory ProtocolFactory
  45.      * @throws ProtocolException
  46.      *
  47.      */
  48.     public SPCoopValidatoreErrori(IProtocolFactory<?> protocolFactory,IState state) throws ProtocolException{
  49.         super(protocolFactory,state);
  50.     }
  51.    


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