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

  21. import org.slf4j.Logger;
  22. import org.openspcoop2.pdd.core.AbstractCore;
  23. import org.openspcoop2.pdd.logger.OpenSPCoop2Logger;
  24. import org.openspcoop2.protocol.sdk.constants.TipoIntegrazione;
  25. import org.openspcoop2.utils.LoggerWrapperFactory;



  26. /**
  27.  * Classe utilizzata per la spedizione di informazioni di integrazione
  28.  * dalla porta di dominio verso i servizi applicativi.
  29.  *
  30.  * @author Poli Andrea (apoli@link.it)
  31.  * @author $Author$
  32.  * @version $Rev$, $Date$
  33.  */
  34. public class GestoreIntegrazionePATrasporto extends AbstractCore implements IGestoreIntegrazionePA{

  35.     /** Utility per l'integrazione */
  36.     UtilitiesIntegrazione utilitiesRequest = null;
  37.     UtilitiesIntegrazione utilitiesResponse = null;
  38.    
  39.     /** Logger utilizzato per debug. */
  40.     private Logger log = null;
  41.    
  42.     public GestoreIntegrazionePATrasporto(){
  43.         this.log = OpenSPCoop2Logger.getLoggerOpenSPCoopCore();
  44.         if(this.log==null){
  45.             this.log = LoggerWrapperFactory.getLogger(GestoreIntegrazionePATrasporto.class);
  46.         }
  47.         try{
  48.             this.utilitiesRequest = UtilitiesIntegrazione.getInstancePARequest(this.log);
  49.             this.utilitiesResponse = UtilitiesIntegrazione.getInstancePAResponse(this.log);
  50.         }catch(Exception e){
  51.             this.log.error("Errore durante l'inizializzazione delle UtilitiesIntegrazione: "+e.getMessage(),e);
  52.         }
  53.     }
  54.    
  55.    
  56.     // IN - Request
  57.    
  58.     @Override
  59.     public void readInRequestHeader(HeaderIntegrazione integrazione,
  60.             InRequestPAMessage inRequestPAMessage) throws HeaderIntegrazioneException {
  61.         try{
  62.             this.utilitiesRequest.readTransportProperties(inRequestPAMessage.getUrlProtocolContext().getHeaders(),
  63.                     integrazione);
  64.         }catch(Exception e){
  65.             throw new HeaderIntegrazioneException("GestoreIntegrazionePATrasporto, "+e.getMessage(),e);
  66.         }
  67.     }
  68.    
  69.     // OUT - Request
  70.    
  71.     @Override
  72.     public void setOutRequestHeader(HeaderIntegrazione integrazione,
  73.             OutRequestPAMessage outRequestPAMessage) throws HeaderIntegrazioneException{
  74.         try{
  75.             this.utilitiesRequest.setTransportProperties(integrazione, outRequestPAMessage.getHeaders(),
  76.                     this.getProtocolFactory().createProtocolManager().buildIntegrationProperties(outRequestPAMessage.getBustaRichiesta(), true, TipoIntegrazione.TRASPORTO));
  77.         }catch(Exception e){
  78.             throw new HeaderIntegrazioneException("GestoreIntegrazionePATrasporto, "+e.getMessage(),e);
  79.         }
  80.     }
  81.    
  82.     // IN - Response
  83.    
  84.     @Override
  85.     public void readInResponseHeader(HeaderIntegrazione integrazione,
  86.             InResponsePAMessage inResponsePAMessage) throws HeaderIntegrazioneException{
  87.         try{
  88.             this.utilitiesResponse.readTransportProperties(inResponsePAMessage.getHeaders(), integrazione);
  89.         }catch(Exception e){
  90.             throw new HeaderIntegrazioneException("GestoreIntegrazionePATrasporto, "+e.getMessage(),e);
  91.         }
  92.     }
  93.        
  94.     // OUT - Response

  95.     @Override
  96.     public void setOutResponseHeader(HeaderIntegrazione integrazione,
  97.             OutResponsePAMessage outResponsePAMessage) throws HeaderIntegrazioneException{
  98.        
  99.         try{
  100.             // Vogliamo aggiungere solo informazioni sulla Pdd nella risposta verso la porta mittente.
  101.             // Per questo non forniamo integrazione.
  102.             // Per il protocollo trasparente vien apoosta definita la classe WithResponseOut che estende questa,
  103.             // ridefinisce questo metodo e fornisce anche integrazione.
  104.             this.utilitiesResponse.setTransportProperties(null, outResponsePAMessage.getHeaders(),
  105.                     this.getProtocolFactory().createProtocolManager().buildIntegrationProperties(outResponsePAMessage.getBustaRichiesta(), false, TipoIntegrazione.TRASPORTO));
  106.         }catch(Exception e){
  107.             throw new HeaderIntegrazioneException("GestoreIntegrazionePATrasporto, "+e.getMessage(),e);
  108.         }
  109.        
  110.     }
  111. }