AbstractGestoreIntegrazionePATrasportoBC.java

  1. /*
  2.  * GovWay - A customizable API Gateway
  3.  * https://govway.org
  4.  *
  5.  * Copyright (c) 2005-2025 Link.it srl (https://link.it).
  6.  *
  7.  * This program is free software: you can redistribute it and/or modify
  8.  * it under the terms of the GNU General Public License version 3, as published by
  9.  * the Free Software Foundation.
  10.  *
  11.  * This program is distributed in the hope that it will be useful,
  12.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.  * GNU General Public License for more details.
  15.  *
  16.  * You should have received a copy of the GNU General Public License
  17.  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  18.  *
  19.  */

  20. package org.openspcoop2.pdd.core.integrazione.backward_compatibility;

  21. import org.slf4j.Logger;
  22. import org.openspcoop2.pdd.core.AbstractCore;
  23. import org.openspcoop2.pdd.core.integrazione.HeaderIntegrazione;
  24. import org.openspcoop2.pdd.core.integrazione.HeaderIntegrazioneException;
  25. import org.openspcoop2.pdd.core.integrazione.IGestoreIntegrazionePA;
  26. import org.openspcoop2.pdd.core.integrazione.InRequestPAMessage;
  27. import org.openspcoop2.pdd.core.integrazione.InResponsePAMessage;
  28. import org.openspcoop2.pdd.core.integrazione.OutRequestPAMessage;
  29. import org.openspcoop2.pdd.core.integrazione.OutResponsePAMessage;
  30. import org.openspcoop2.pdd.logger.OpenSPCoop2Logger;
  31. import org.openspcoop2.protocol.sdk.constants.TipoIntegrazione;
  32. import org.openspcoop2.utils.LoggerWrapperFactory;



  33. /**
  34.  * Classe utilizzata per la spedizione di informazioni di integrazione
  35.  * dalla porta di dominio verso i servizi applicativi.
  36.  *
  37.  * @author Poli Andrea (apoli@link.it)
  38.  * @author $Author$
  39.  * @version $Rev$, $Date$
  40.  */
  41. public abstract class AbstractGestoreIntegrazionePATrasportoBC extends AbstractCore implements IGestoreIntegrazionePA{

  42.     /** Utility per l'integrazione */
  43.     UtilitiesIntegrazioneBC utilitiesRequestBC = null;
  44.     UtilitiesIntegrazioneBC utilitiesResponseBC = null;
  45.    
  46.     /** Logger utilizzato per debug. */
  47.     private Logger log = null;
  48.    
  49.     public AbstractGestoreIntegrazionePATrasportoBC(boolean openspcoop2, boolean x_prefix){
  50.         this.log = OpenSPCoop2Logger.getLoggerOpenSPCoopCore();
  51.         if(this.log==null){
  52.             this.log = LoggerWrapperFactory.getLogger(AbstractGestoreIntegrazionePATrasportoBC.class);
  53.         }
  54.         try{
  55.             this.utilitiesRequestBC = UtilitiesIntegrazioneBC.getInstancePARequest(this.log, openspcoop2, x_prefix);
  56.             this.utilitiesResponseBC = UtilitiesIntegrazioneBC.getInstancePAResponse(this.log, openspcoop2, x_prefix);
  57.         }catch(Exception e){
  58.             this.log.error("Errore durante l'inizializzazione delle UtilitiesIntegrazione: "+e.getMessage(),e);
  59.         }
  60.     }
  61.    
  62.    
  63.     // IN - Request
  64.    
  65.     @Override
  66.     public void readInRequestHeader(HeaderIntegrazione integrazione,
  67.             InRequestPAMessage inRequestPAMessage) throws HeaderIntegrazioneException {
  68.         try{
  69.             String protocollo = this.getProtocolFactory()!=null ? this.getProtocolFactory().getProtocol() : null;
  70.            
  71.             this.utilitiesRequestBC.readTransportProperties(inRequestPAMessage.getUrlProtocolContext().getHeaders(),
  72.                     integrazione,
  73.                     protocollo);
  74.         }catch(Exception e){
  75.             throw new HeaderIntegrazioneException("GestoreIntegrazionePATrasporto, "+e.getMessage(),e);
  76.         }
  77.     }
  78.    
  79.     // OUT - Request
  80.    
  81.     @Override
  82.     public void setOutRequestHeader(HeaderIntegrazione integrazione,
  83.             OutRequestPAMessage outRequestPAMessage) throws HeaderIntegrazioneException{
  84.         try{
  85.             String protocollo = this.getProtocolFactory()!=null ? this.getProtocolFactory().getProtocol() : null;
  86.            
  87.             this.utilitiesRequestBC.setTransportProperties(integrazione, outRequestPAMessage.getHeaders(),
  88.                     this.getProtocolFactory().createProtocolManager().buildIntegrationProperties(outRequestPAMessage.getBustaRichiesta(), true, TipoIntegrazione.TRASPORTO),
  89.                     protocollo);
  90.         }catch(Exception e){
  91.             throw new HeaderIntegrazioneException("GestoreIntegrazionePATrasporto, "+e.getMessage(),e);
  92.         }
  93.     }
  94.    
  95.     // IN - Response
  96.    
  97.     @Override
  98.     public void readInResponseHeader(HeaderIntegrazione integrazione,
  99.             InResponsePAMessage inResponsePAMessage) throws HeaderIntegrazioneException{
  100.         try{
  101.             String protocollo = this.getProtocolFactory()!=null ? this.getProtocolFactory().getProtocol() : null;
  102.            
  103.             this.utilitiesResponseBC.readTransportProperties(inResponsePAMessage.getHeaders(), integrazione,
  104.                     protocollo);
  105.         }catch(Exception e){
  106.             throw new HeaderIntegrazioneException("GestoreIntegrazionePATrasporto, "+e.getMessage(),e);
  107.         }
  108.     }
  109.        
  110.     // OUT - Response

  111.     @Override
  112.     public void setOutResponseHeader(HeaderIntegrazione integrazione,
  113.             OutResponsePAMessage outResponsePAMessage) throws HeaderIntegrazioneException{
  114.        
  115.         try{
  116.             String protocollo = this.getProtocolFactory()!=null ? this.getProtocolFactory().getProtocol() : null;
  117.            
  118.             // Vogliamo aggiungere solo informazioni sulla Pdd nella risposta verso la porta mittente.
  119.             // Per questo non forniamo integrazione.
  120.             // Per il protocollo trasparente vien apoosta definita la classe WithResponseOut che estende questa,
  121.             // ridefinisce questo metodo e fornisce anche integrazione.
  122.             this.utilitiesResponseBC.setTransportProperties(null, outResponsePAMessage.getHeaders(),
  123.                     this.getProtocolFactory().createProtocolManager().buildIntegrationProperties(outResponsePAMessage.getBustaRichiesta(), false, TipoIntegrazione.TRASPORTO),
  124.                     protocollo);
  125.         }catch(Exception e){
  126.             throw new HeaderIntegrazioneException("GestoreIntegrazionePATrasporto, "+e.getMessage(),e);
  127.         }
  128.        
  129.     }
  130. }