AbstractGestoreIntegrazionePASoapBC.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 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.core.integrazione.HeaderIntegrazione;
  28. import org.openspcoop2.pdd.core.integrazione.HeaderIntegrazioneException;
  29. import org.openspcoop2.pdd.core.integrazione.IGestoreIntegrazionePASoap;
  30. import org.openspcoop2.pdd.core.integrazione.InRequestPAMessage;
  31. import org.openspcoop2.pdd.core.integrazione.InResponsePAMessage;
  32. import org.openspcoop2.pdd.core.integrazione.OutRequestPAMessage;
  33. import org.openspcoop2.pdd.core.integrazione.OutResponsePAMessage;
  34. import org.openspcoop2.pdd.logger.OpenSPCoop2Logger;
  35. import org.openspcoop2.protocol.sdk.constants.TipoIntegrazione;
  36. import org.openspcoop2.utils.LoggerWrapperFactory;
  37. import org.slf4j.Logger;


  38. /**
  39.  * Classe utilizzata per la spedizione di informazioni di integrazione
  40.  * dalla porta di dominio verso i servizi applicativi.
  41.  *
  42.  * @author Poli Andrea (apoli@link.it)
  43.  * @author $Author$
  44.  * @version $Rev$, $Date$
  45.  */
  46. public abstract class AbstractGestoreIntegrazionePASoapBC extends AbstractCore implements IGestoreIntegrazionePASoap{

  47.     /** Utility per l'integrazione */
  48.     protected UtilitiesIntegrazioneBC utilitiesRequestBC = null;
  49.     protected UtilitiesIntegrazioneBC utilitiesResponseBC = null;
  50.    
  51.     /** OpenSPCoopProperties */
  52.     protected OpenSPCoop2Properties openspcoopProperties = OpenSPCoop2Properties.getInstance();
  53.    
  54.     /** Logger utilizzato per debug. */
  55.     private Logger log = null;

  56.     protected boolean openspcoop2;
  57.    
  58.     public AbstractGestoreIntegrazionePASoapBC(boolean openspcoop2){
  59.         this.log = OpenSPCoop2Logger.getLoggerOpenSPCoopCore();
  60.         this.openspcoop2 = openspcoop2;
  61.         if(this.log==null){
  62.             this.log = LoggerWrapperFactory.getLogger(AbstractGestoreIntegrazionePASoapBC.class);
  63.         }
  64.         try{
  65.             this.utilitiesRequestBC = UtilitiesIntegrazioneBC.getInstancePARequest(this.log, openspcoop2, false);
  66.             this.utilitiesResponseBC = UtilitiesIntegrazioneBC.getInstancePAResponse(this.log, openspcoop2, false);
  67.         }catch(Exception e){
  68.             this.log.error("Errore durante l'inizializzazione delle UtilitiesIntegrazione: "+e.getMessage(),e);
  69.         }
  70.     }
  71.    
  72.     // IN - Request
  73.    
  74.     @Override
  75.     public void readInRequestHeader(HeaderIntegrazione integrazione,
  76.             InRequestPAMessage inRequestPAMessage) throws HeaderIntegrazioneException{
  77.         try{
  78.             OpenSPCoop2Message msg = inRequestPAMessage.getMessage();
  79.             if(ServiceBinding.SOAP.equals(msg.getServiceBinding())==false){
  80.                 throw new Exception("Non utilizzabile con un Service Binding Rest");
  81.             }
  82.             OpenSPCoop2SoapMessage soapMsg = msg.castAsSoap();
  83.            
  84.             String protocollo = this.getProtocolFactory()!=null ? this.getProtocolFactory().getProtocol() : null;
  85.            
  86.             this.utilitiesRequestBC.readHeader(soapMsg, integrazione,
  87.                     this.openspcoop2 ?
  88.                             this.openspcoopProperties.getHeaderSoapActorIntegrazione_backwardCompatibility_openspcoop2() :
  89.                             this.openspcoopProperties.getHeaderSoapActorIntegrazione_backwardCompatibility_openspcoop1(),
  90.                             protocollo);
  91.         }catch(Exception e){
  92.             throw new HeaderIntegrazioneException("GestoreIntegrazionePASoap, "+e.getMessage(),e);
  93.         }
  94.     }
  95.    
  96.     @Override
  97.     public void deleteInRequestHeader(InRequestPAMessage inRequestPAMessage) throws HeaderIntegrazioneException{
  98.         try{
  99.             OpenSPCoop2Message msg = inRequestPAMessage.getMessage();
  100.             if(ServiceBinding.SOAP.equals(msg.getServiceBinding())==false){
  101.                 throw new Exception("Non utilizzabile con un Service Binding Rest");
  102.             }
  103.             OpenSPCoop2SoapMessage soapMsg = msg.castAsSoap();
  104.            
  105.             this.utilitiesRequestBC.deleteHeader(soapMsg,
  106.                     this.openspcoop2 ?
  107.                             this.openspcoopProperties.getHeaderSoapActorIntegrazione_backwardCompatibility_openspcoop2() :
  108.                             this.openspcoopProperties.getHeaderSoapActorIntegrazione_backwardCompatibility_openspcoop1());
  109.         }catch(Exception e){
  110.             throw new HeaderIntegrazioneException("GestoreIntegrazionePASoap, "+e.getMessage(),e);
  111.         }
  112.     }
  113.    
  114.     @Override
  115.     public void updateInRequestHeader(InRequestPAMessage inRequestPAMessage,
  116.             String idMessaggio,String servizioApplicativo,String correlazioneApplicativa) throws HeaderIntegrazioneException{
  117.         try{
  118.             OpenSPCoop2Message msg = inRequestPAMessage.getMessage();
  119.             if(ServiceBinding.SOAP.equals(msg.getServiceBinding())==false){
  120.                 throw new Exception("Non utilizzabile con un Service Binding Rest");
  121.             }
  122.             OpenSPCoop2SoapMessage soapMsg = msg.castAsSoap();
  123.            
  124.             String protocollo = this.getProtocolFactory()!=null ? this.getProtocolFactory().getProtocol() : null;
  125.            
  126.             this.utilitiesRequestBC.updateHeader(soapMsg,
  127.                     inRequestPAMessage.getSoggettoMittente(),
  128.                     inRequestPAMessage.getServizio(),
  129.                     idMessaggio,
  130.                     servizioApplicativo, correlazioneApplicativa, null,
  131.                     UtilitiesIntegrazioneBC.getIdTransazione(this.getPddContext()),
  132.                     this.openspcoop2 ?
  133.                             this.openspcoopProperties.getHeaderSoapActorIntegrazione_backwardCompatibility_openspcoop2() :
  134.                             this.openspcoopProperties.getHeaderSoapActorIntegrazione_backwardCompatibility_openspcoop1(),  // actor
  135.                     this.openspcoop2 ?
  136.                             this.openspcoopProperties.getHeaderSoapNameIntegrazione_backwardCompatibility_openspcoop2() :
  137.                             this.openspcoopProperties.getHeaderSoapNameIntegrazione_backwardCompatibility_openspcoop1() ,  // header name
  138.                     this.openspcoop2 ?
  139.                             this.openspcoopProperties.getHeaderSoapPrefixIntegrazione_backwardCompatibility_openspcoop2() :
  140.                             this.openspcoopProperties.getHeaderSoapPrefixIntegrazione_backwardCompatibility_openspcoop1()   ,  // prefix
  141.                     this.openspcoop2 ?
  142.                             this.openspcoopProperties.getHeaderSoapActorIntegrazione_backwardCompatibility_openspcoop2() :
  143.                             this.openspcoopProperties.getHeaderSoapActorIntegrazione_backwardCompatibility_openspcoop1(),  // namespace
  144.                     this.openspcoop2 ?
  145.                             this.openspcoopProperties.getHeaderSoapExtProtocolInfoNomeElementoIntegrazione_backwardCompatibility_openspcoop2() :
  146.                             this.openspcoopProperties.getHeaderSoapExtProtocolInfoNomeElementoIntegrazione_backwardCompatibility_openspcoop1()  , // nomeElemento ExtInfoProtocol
  147.                     this.openspcoop2 ?
  148.                             this.openspcoopProperties.getHeaderSoapExtProtocolInfoNomeAttributoIntegrazione_backwardCompatibility_openspcoop2() :
  149.                             this.openspcoopProperties.getHeaderSoapExtProtocolInfoNomeAttributoIntegrazione_backwardCompatibility_openspcoop1() , // nomeAttributo ExtInfoProtocol
  150.                     this.getProtocolFactory().createProtocolManager().buildIntegrationProperties(inRequestPAMessage.getBustaRichiesta(), true, TipoIntegrazione.SOAP),
  151.                     protocollo
  152.                 );
  153.         }catch(Exception e){
  154.             throw new HeaderIntegrazioneException("GestoreIntegrazionePASoap, "+e.getMessage(),e);
  155.         }
  156.     }
  157.    
  158.    
  159.     // OUT - Request
  160.    
  161.     @Override
  162.     public void setOutRequestHeader(HeaderIntegrazione integrazione,
  163.             OutRequestPAMessage outRequestPAMessage) throws HeaderIntegrazioneException{
  164.         try{
  165.            
  166.             OpenSPCoop2Message msg = outRequestPAMessage.getMessage();
  167.             if(ServiceBinding.SOAP.equals(msg.getServiceBinding())==false){
  168.                 throw new Exception("Non utilizzabile con un Service Binding Rest");
  169.             }
  170.             OpenSPCoop2SoapMessage soapMsg = msg.castAsSoap();
  171.            
  172.             String protocollo = this.getProtocolFactory()!=null ? this.getProtocolFactory().getProtocol() : null;
  173.            
  174.             SOAPHeaderElement header = this.utilitiesRequestBC.buildHeader(integrazione,
  175.                     this.openspcoop2 ?
  176.                             this.openspcoopProperties.getHeaderSoapNameIntegrazione_backwardCompatibility_openspcoop2() :
  177.                             this.openspcoopProperties.getHeaderSoapNameIntegrazione_backwardCompatibility_openspcoop1() ,  // header name
  178.                     this.openspcoop2 ?
  179.                             this.openspcoopProperties.getHeaderSoapPrefixIntegrazione_backwardCompatibility_openspcoop2() :
  180.                             this.openspcoopProperties.getHeaderSoapPrefixIntegrazione_backwardCompatibility_openspcoop1()   ,  // prefix
  181.                     this.openspcoop2 ?
  182.                             this.openspcoopProperties.getHeaderSoapActorIntegrazione_backwardCompatibility_openspcoop2() :
  183.                             this.openspcoopProperties.getHeaderSoapActorIntegrazione_backwardCompatibility_openspcoop1(),  // namespace
  184.                     this.openspcoop2 ?
  185.                             this.openspcoopProperties.getHeaderSoapActorIntegrazione_backwardCompatibility_openspcoop2() :
  186.                             this.openspcoopProperties.getHeaderSoapActorIntegrazione_backwardCompatibility_openspcoop1(),  // actor
  187.                     soapMsg,
  188.                     this.openspcoop2 ?
  189.                             this.openspcoopProperties.getHeaderSoapExtProtocolInfoNomeElementoIntegrazione_backwardCompatibility_openspcoop2() :
  190.                             this.openspcoopProperties.getHeaderSoapExtProtocolInfoNomeElementoIntegrazione_backwardCompatibility_openspcoop1()  , // nomeElemento ExtInfoProtocol
  191.                     this.openspcoop2 ?
  192.                             this.openspcoopProperties.getHeaderSoapExtProtocolInfoNomeAttributoIntegrazione_backwardCompatibility_openspcoop2() :
  193.                             this.openspcoopProperties.getHeaderSoapExtProtocolInfoNomeAttributoIntegrazione_backwardCompatibility_openspcoop1() , // nomeAttributo ExtInfoProtocol
  194.                     this.getProtocolFactory().createProtocolManager().buildIntegrationProperties(outRequestPAMessage.getBustaRichiesta(), true, TipoIntegrazione.SOAP),
  195.                     protocollo
  196.                 );
  197.                        
  198.             if(soapMsg.getSOAPHeader() == null){
  199.                 soapMsg.getSOAPPart().getEnvelope().addHeader();
  200.             }
  201.             soapMsg.addHeaderElement(soapMsg.getSOAPHeader(), header);
  202.            
  203.         }catch(Exception e){
  204.             throw new HeaderIntegrazioneException("GestoreIntegrazionePASoap, "+e.getMessage(),e);
  205.         }
  206.     }
  207.    
  208.    
  209.     // IN - Response
  210.        
  211.     @Override
  212.     public void readInResponseHeader(HeaderIntegrazione integrazione,
  213.             InResponsePAMessage inResponsePAMessage) throws HeaderIntegrazioneException{
  214.         try{
  215.             OpenSPCoop2Message msg = inResponsePAMessage.getMessage();
  216.             if(ServiceBinding.SOAP.equals(msg.getServiceBinding())==false){
  217.                 throw new Exception("Non utilizzabile con un Service Binding Rest");
  218.             }
  219.             OpenSPCoop2SoapMessage soapMsg = msg.castAsSoap();
  220.            
  221.             String protocollo = this.getProtocolFactory()!=null ? this.getProtocolFactory().getProtocol() : null;
  222.            
  223.             this.utilitiesResponseBC.readHeader(soapMsg, integrazione,
  224.                     this.openspcoop2 ?
  225.                             this.openspcoopProperties.getHeaderSoapActorIntegrazione_backwardCompatibility_openspcoop2() :
  226.                             this.openspcoopProperties.getHeaderSoapActorIntegrazione_backwardCompatibility_openspcoop1(),
  227.                             protocollo);
  228.         }catch(Exception e){
  229.             throw new HeaderIntegrazioneException("GestoreIntegrazionePASoap, "+e.getMessage(),e);
  230.         }
  231.     }
  232.    
  233.     @Override
  234.     public void deleteInResponseHeader(InResponsePAMessage inResponsePAMessage) throws HeaderIntegrazioneException{
  235.         try{
  236.             OpenSPCoop2Message msg = inResponsePAMessage.getMessage();
  237.             if(ServiceBinding.SOAP.equals(msg.getServiceBinding())==false){
  238.                 throw new Exception("Non utilizzabile con un Service Binding Rest");
  239.             }
  240.             OpenSPCoop2SoapMessage soapMsg = msg.castAsSoap();
  241.            
  242.             this.utilitiesResponseBC.deleteHeader(soapMsg,
  243.                     this.openspcoop2 ?
  244.                             this.openspcoopProperties.getHeaderSoapActorIntegrazione_backwardCompatibility_openspcoop2() :
  245.                             this.openspcoopProperties.getHeaderSoapActorIntegrazione_backwardCompatibility_openspcoop1());
  246.         }catch(Exception e){
  247.             throw new HeaderIntegrazioneException("GestoreIntegrazionePASoap, "+e.getMessage(),e);
  248.         }
  249.     }
  250.        
  251.     @Override
  252.     public void updateInResponseHeader(InResponsePAMessage inResponsePAMessage,
  253.             String idMessaggioRichiesta,String idMessaggioRisposta,String servizioApplicativo,String correlazioneApplicativa,String riferimentoCorrelazioneApplicativaRichiesta) throws HeaderIntegrazioneException{
  254.         try{
  255.             OpenSPCoop2Message msg = inResponsePAMessage.getMessage();
  256.             if(ServiceBinding.SOAP.equals(msg.getServiceBinding())==false){
  257.                 throw new Exception("Non utilizzabile con un Service Binding Rest");
  258.             }
  259.             OpenSPCoop2SoapMessage soapMsg = msg.castAsSoap();
  260.            
  261.             String protocollo = this.getProtocolFactory()!=null ? this.getProtocolFactory().getProtocol() : null;
  262.            
  263.             this.utilitiesResponseBC.updateHeader(soapMsg,
  264.                     inResponsePAMessage.getSoggettoMittente(),
  265.                     inResponsePAMessage.getServizio(),
  266.                     idMessaggioRichiesta, idMessaggioRisposta,
  267.                     servizioApplicativo, correlazioneApplicativa, riferimentoCorrelazioneApplicativaRichiesta,
  268.                     this.openspcoop2 ?
  269.                             this.openspcoopProperties.getHeaderSoapActorIntegrazione_backwardCompatibility_openspcoop2() :
  270.                             this.openspcoopProperties.getHeaderSoapActorIntegrazione_backwardCompatibility_openspcoop1(),  // actor
  271.                     this.openspcoop2 ?
  272.                             this.openspcoopProperties.getHeaderSoapNameIntegrazione_backwardCompatibility_openspcoop2() :
  273.                             this.openspcoopProperties.getHeaderSoapNameIntegrazione_backwardCompatibility_openspcoop1() ,  // header name
  274.                     this.openspcoop2 ?
  275.                             this.openspcoopProperties.getHeaderSoapPrefixIntegrazione_backwardCompatibility_openspcoop2() :
  276.                             this.openspcoopProperties.getHeaderSoapPrefixIntegrazione_backwardCompatibility_openspcoop1()   ,  // prefix
  277.                     this.openspcoop2 ?
  278.                             this.openspcoopProperties.getHeaderSoapActorIntegrazione_backwardCompatibility_openspcoop2() :
  279.                             this.openspcoopProperties.getHeaderSoapActorIntegrazione_backwardCompatibility_openspcoop1(),  // namespace
  280.                     this.openspcoop2 ?
  281.                             this.openspcoopProperties.getHeaderSoapExtProtocolInfoNomeElementoIntegrazione_backwardCompatibility_openspcoop2() :
  282.                             this.openspcoopProperties.getHeaderSoapExtProtocolInfoNomeElementoIntegrazione_backwardCompatibility_openspcoop1()  , // nomeElemento ExtInfoProtocol
  283.                     this.openspcoop2 ?
  284.                             this.openspcoopProperties.getHeaderSoapExtProtocolInfoNomeAttributoIntegrazione_backwardCompatibility_openspcoop2() :
  285.                             this.openspcoopProperties.getHeaderSoapExtProtocolInfoNomeAttributoIntegrazione_backwardCompatibility_openspcoop1() , // nomeAttributo ExtInfoProtocol
  286.                     this.getProtocolFactory().createProtocolManager().buildIntegrationProperties(inResponsePAMessage.getBustaRichiesta(), false, TipoIntegrazione.SOAP),
  287.                     protocollo
  288.                 );
  289.         }catch(Exception e){
  290.             throw new HeaderIntegrazioneException("GestoreIntegrazionePASoap, "+e.getMessage(),e);
  291.         }
  292.     }
  293.        
  294.     // OUT - Response
  295.    
  296.     @Override
  297.     public void setOutResponseHeader(HeaderIntegrazione integrazione,
  298.             OutResponsePAMessage outResponsePAMessage) throws HeaderIntegrazioneException{
  299.        
  300.         // nop;
  301.        
  302.     }
  303. }