GestoreIntegrazionePASoap.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 javax.xml.soap.SOAPHeaderElement;

  22. import org.openspcoop2.message.OpenSPCoop2Message;
  23. import org.openspcoop2.message.OpenSPCoop2SoapMessage;
  24. import org.openspcoop2.message.constants.ServiceBinding;
  25. import org.openspcoop2.pdd.config.OpenSPCoop2Properties;
  26. import org.openspcoop2.pdd.core.AbstractCore;
  27. import org.openspcoop2.pdd.logger.OpenSPCoop2Logger;
  28. import org.openspcoop2.protocol.sdk.constants.TipoIntegrazione;
  29. import org.openspcoop2.utils.LoggerWrapperFactory;
  30. import org.slf4j.Logger;


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

  40.     /** Utility per l'integrazione */
  41.     UtilitiesIntegrazione utilitiesRequest = null;
  42.     UtilitiesIntegrazione utilitiesResponse = null;
  43.    
  44.     /** OpenSPCoopProperties */
  45.     OpenSPCoop2Properties openspcoopProperties = OpenSPCoop2Properties.getInstance();
  46.    
  47.     /** Logger utilizzato per debug. */
  48.     private Logger log = null;

  49.    
  50.     public GestoreIntegrazionePASoap(){
  51.         this.log = OpenSPCoop2Logger.getLoggerOpenSPCoopCore();
  52.         if(this.log==null){
  53.             this.log = LoggerWrapperFactory.getLogger(GestoreIntegrazionePASoap.class);
  54.         }
  55.         try{
  56.             this.utilitiesRequest = UtilitiesIntegrazione.getInstancePARequest(this.log);
  57.             this.utilitiesResponse = UtilitiesIntegrazione.getInstancePAResponse(this.log);
  58.         }catch(Exception e){
  59.             this.log.error("Errore durante l'inizializzazione delle UtilitiesIntegrazione: "+e.getMessage(),e);
  60.         }
  61.     }
  62.    
  63.     // IN - Request
  64.    
  65.     @Override
  66.     public void readInRequestHeader(HeaderIntegrazione integrazione,
  67.             InRequestPAMessage inRequestPAMessage) throws HeaderIntegrazioneException{
  68.         try{
  69.             OpenSPCoop2Message msg = inRequestPAMessage.getMessage();
  70.             if(ServiceBinding.SOAP.equals(msg.getServiceBinding())==false){
  71.                 throw new Exception("Non utilizzabile con un Service Binding Rest");
  72.             }
  73.             OpenSPCoop2SoapMessage soapMsg = msg.castAsSoap();
  74.            
  75.             this.utilitiesRequest.readHeader(soapMsg, integrazione, this.openspcoopProperties.getHeaderSoapActorIntegrazione());
  76.         }catch(Exception e){
  77.             throw new HeaderIntegrazioneException("GestoreIntegrazionePASoap, "+e.getMessage(),e);
  78.         }
  79.     }
  80.    
  81.     @Override
  82.     public void deleteInRequestHeader(InRequestPAMessage inRequestPAMessage) throws HeaderIntegrazioneException{
  83.         try{
  84.             OpenSPCoop2Message msg = inRequestPAMessage.getMessage();
  85.             if(ServiceBinding.SOAP.equals(msg.getServiceBinding())==false){
  86.                 throw new Exception("Non utilizzabile con un Service Binding Rest");
  87.             }
  88.             OpenSPCoop2SoapMessage soapMsg = msg.castAsSoap();
  89.            
  90.             this.utilitiesRequest.deleteHeader(soapMsg,this.openspcoopProperties.getHeaderSoapActorIntegrazione());
  91.         }catch(Exception e){
  92.             throw new HeaderIntegrazioneException("GestoreIntegrazionePASoap, "+e.getMessage(),e);
  93.         }
  94.     }
  95.    
  96.     @Override
  97.     public void updateInRequestHeader(InRequestPAMessage inRequestPAMessage,
  98.             String idMessaggio,String servizioApplicativo,String correlazioneApplicativa) throws HeaderIntegrazioneException{
  99.         try{
  100.             OpenSPCoop2Message msg = inRequestPAMessage.getMessage();
  101.             if(ServiceBinding.SOAP.equals(msg.getServiceBinding())==false){
  102.                 throw new Exception("Non utilizzabile con un Service Binding Rest");
  103.             }
  104.             OpenSPCoop2SoapMessage soapMsg = msg.castAsSoap();
  105.            
  106.             this.utilitiesRequest.updateHeader(soapMsg,
  107.                     inRequestPAMessage.getSoggettoMittente(),
  108.                     inRequestPAMessage.getServizio(),
  109.                     idMessaggio,
  110.                     servizioApplicativo, correlazioneApplicativa, null,
  111.                     UtilitiesIntegrazione.getIdTransazione(this.getPddContext()),
  112.                     this.openspcoopProperties.getHeaderSoapActorIntegrazione(),  // actor
  113.                     this.openspcoopProperties.getHeaderSoapNameIntegrazione(),  // header name
  114.                     this.openspcoopProperties.getHeaderSoapPrefixIntegrazione(),  // prefix
  115.                     this.openspcoopProperties.getHeaderSoapActorIntegrazione(),  // namespace
  116.                     this.openspcoopProperties.getHeaderSoapExtProtocolInfoNomeElementoIntegrazione(), // nomeElemento ExtInfoProtocol
  117.                     this.openspcoopProperties.getHeaderSoapExtProtocolInfoNomeAttributoIntegrazione(), // nomeAttributo ExtInfoProtocol
  118.                     this.getProtocolFactory().createProtocolManager().buildIntegrationProperties(inRequestPAMessage.getBustaRichiesta(), true, TipoIntegrazione.SOAP)
  119.                 );
  120.         }catch(Exception e){
  121.             throw new HeaderIntegrazioneException("GestoreIntegrazionePASoap, "+e.getMessage(),e);
  122.         }
  123.     }
  124.    
  125.    
  126.     // OUT - Request
  127.    
  128.     @Override
  129.     public void setOutRequestHeader(HeaderIntegrazione integrazione,
  130.             OutRequestPAMessage outRequestPAMessage) throws HeaderIntegrazioneException{
  131.         try{
  132.            
  133.             OpenSPCoop2Message msg = outRequestPAMessage.getMessage();
  134.             if(ServiceBinding.SOAP.equals(msg.getServiceBinding())==false){
  135.                 throw new Exception("Non utilizzabile con un Service Binding Rest");
  136.             }
  137.             OpenSPCoop2SoapMessage soapMsg = msg.castAsSoap();
  138.            
  139.             SOAPHeaderElement header = this.utilitiesRequest.buildHeader(integrazione,
  140.                     this.openspcoopProperties.getHeaderSoapNameIntegrazione(), // header name
  141.                     this.openspcoopProperties.getHeaderSoapPrefixIntegrazione(), // prefix
  142.                     this.openspcoopProperties.getHeaderSoapActorIntegrazione(), // namespace
  143.                     this.openspcoopProperties.getHeaderSoapActorIntegrazione(), // actor
  144.                     soapMsg,
  145.                     this.openspcoopProperties.getHeaderSoapExtProtocolInfoNomeElementoIntegrazione(), // nomeElemento ExtInfoProtocol
  146.                     this.openspcoopProperties.getHeaderSoapExtProtocolInfoNomeAttributoIntegrazione(), // nomeAttributo ExtInfoProtocol
  147.                     this.getProtocolFactory().createProtocolManager().buildIntegrationProperties(outRequestPAMessage.getBustaRichiesta(), true, TipoIntegrazione.SOAP)
  148.                 );
  149.                        
  150.             if(soapMsg.getSOAPHeader() == null){
  151.                 soapMsg.getSOAPPart().getEnvelope().addHeader();
  152.             }
  153.             soapMsg.addHeaderElement(soapMsg.getSOAPHeader(), header);
  154.            
  155.         }catch(Exception e){
  156.             throw new HeaderIntegrazioneException("GestoreIntegrazionePASoap, "+e.getMessage(),e);
  157.         }
  158.     }
  159.    
  160.    
  161.     // IN - Response
  162.        
  163.     @Override
  164.     public void readInResponseHeader(HeaderIntegrazione integrazione,
  165.             InResponsePAMessage inResponsePAMessage) throws HeaderIntegrazioneException{
  166.         try{
  167.             OpenSPCoop2Message msg = inResponsePAMessage.getMessage();
  168.             if(ServiceBinding.SOAP.equals(msg.getServiceBinding())==false){
  169.                 throw new Exception("Non utilizzabile con un Service Binding Rest");
  170.             }
  171.             OpenSPCoop2SoapMessage soapMsg = msg.castAsSoap();
  172.            
  173.             this.utilitiesResponse.readHeader(soapMsg, integrazione, this.openspcoopProperties.getHeaderSoapActorIntegrazione());
  174.         }catch(Exception e){
  175.             throw new HeaderIntegrazioneException("GestoreIntegrazionePASoap, "+e.getMessage(),e);
  176.         }
  177.     }
  178.    
  179.     @Override
  180.     public void deleteInResponseHeader(InResponsePAMessage inResponsePAMessage) throws HeaderIntegrazioneException{
  181.         try{
  182.             OpenSPCoop2Message msg = inResponsePAMessage.getMessage();
  183.             if(ServiceBinding.SOAP.equals(msg.getServiceBinding())==false){
  184.                 throw new Exception("Non utilizzabile con un Service Binding Rest");
  185.             }
  186.             OpenSPCoop2SoapMessage soapMsg = msg.castAsSoap();
  187.            
  188.             this.utilitiesResponse.deleteHeader(soapMsg,this.openspcoopProperties.getHeaderSoapActorIntegrazione());
  189.         }catch(Exception e){
  190.             throw new HeaderIntegrazioneException("GestoreIntegrazionePASoap, "+e.getMessage(),e);
  191.         }
  192.     }
  193.        
  194.     @Override
  195.     public void updateInResponseHeader(InResponsePAMessage inResponsePAMessage,
  196.             String idMessaggioRichiesta,String idMessaggioRisposta,String servizioApplicativo,String correlazioneApplicativa,String riferimentoCorrelazioneApplicativaRichiesta) throws HeaderIntegrazioneException{
  197.         try{
  198.             OpenSPCoop2Message msg = inResponsePAMessage.getMessage();
  199.             if(ServiceBinding.SOAP.equals(msg.getServiceBinding())==false){
  200.                 throw new Exception("Non utilizzabile con un Service Binding Rest");
  201.             }
  202.             OpenSPCoop2SoapMessage soapMsg = msg.castAsSoap();
  203.            
  204.             this.utilitiesResponse.updateHeader(soapMsg,
  205.                     inResponsePAMessage.getSoggettoMittente(),
  206.                     inResponsePAMessage.getServizio(),
  207.                     idMessaggioRichiesta, idMessaggioRisposta,
  208.                     servizioApplicativo, correlazioneApplicativa, riferimentoCorrelazioneApplicativaRichiesta,
  209.                     this.openspcoopProperties.getHeaderSoapActorIntegrazione(),  // actor
  210.                     this.openspcoopProperties.getHeaderSoapNameIntegrazione(),  // header name
  211.                     this.openspcoopProperties.getHeaderSoapPrefixIntegrazione(),  // prefix
  212.                     this.openspcoopProperties.getHeaderSoapActorIntegrazione(),  // namespace
  213.                     this.openspcoopProperties.getHeaderSoapExtProtocolInfoNomeElementoIntegrazione(), // nomeElemento ExtInfoProtocol
  214.                     this.openspcoopProperties.getHeaderSoapExtProtocolInfoNomeAttributoIntegrazione(), // nomeAttributo ExtInfoProtocol
  215.                     this.getProtocolFactory().createProtocolManager().buildIntegrationProperties(inResponsePAMessage.getBustaRichiesta(), false, TipoIntegrazione.SOAP)
  216.                 );
  217.         }catch(Exception e){
  218.             throw new HeaderIntegrazioneException("GestoreIntegrazionePASoap, "+e.getMessage(),e);
  219.         }
  220.     }
  221.        
  222.     // OUT - Response
  223.    
  224.     @Override
  225.     public void setOutResponseHeader(HeaderIntegrazione integrazione,
  226.             OutResponsePAMessage outResponsePAMessage) throws HeaderIntegrazioneException{
  227.        
  228.         // nop;
  229.        
  230.     }
  231. }