AbstractGestoreIntegrazionePDSoapBC.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.slf4j.Logger;
  23. import org.openspcoop2.core.id.IDServizio;
  24. import org.openspcoop2.message.OpenSPCoop2Message;
  25. import org.openspcoop2.message.OpenSPCoop2SoapMessage;
  26. import org.openspcoop2.message.constants.ServiceBinding;
  27. import org.openspcoop2.pdd.config.OpenSPCoop2Properties;
  28. import org.openspcoop2.pdd.core.AbstractCore;
  29. import org.openspcoop2.pdd.core.integrazione.HeaderIntegrazione;
  30. import org.openspcoop2.pdd.core.integrazione.HeaderIntegrazioneException;
  31. import org.openspcoop2.pdd.core.integrazione.IGestoreIntegrazionePDSoap;
  32. import org.openspcoop2.pdd.core.integrazione.InRequestPDMessage;
  33. import org.openspcoop2.pdd.core.integrazione.InResponsePDMessage;
  34. import org.openspcoop2.pdd.core.integrazione.OutRequestPDMessage;
  35. import org.openspcoop2.pdd.core.integrazione.OutResponsePDMessage;
  36. import org.openspcoop2.pdd.logger.OpenSPCoop2Logger;
  37. import org.openspcoop2.protocol.sdk.constants.TipoIntegrazione;
  38. import org.openspcoop2.utils.LoggerWrapperFactory;

  39. /**
  40.  * Classe utilizzata per la ricezione di informazioni di integrazione
  41.  * dai servizi applicativi verso la porta di dominio.
  42.  *
  43.  * @author Poli Andrea (apoli@link.it)
  44.  * @author Lorenzo Nardi (nardi@link.it)
  45.  * @author $Author$
  46.  * @version $Rev$, $Date$
  47.  */
  48. public abstract class AbstractGestoreIntegrazionePDSoapBC extends AbstractCore implements IGestoreIntegrazionePDSoap{

  49.     /** Utility per l'integrazione */
  50.     UtilitiesIntegrazioneBC utilitiesRequestBC = null;
  51.     UtilitiesIntegrazioneBC utilitiesResponseBC = null;

  52.     /** OpenSPCoopProperties */
  53.     OpenSPCoop2Properties openspcoopProperties = OpenSPCoop2Properties.getInstance();
  54.    
  55.     /** Logger utilizzato per debug. */
  56.     private Logger log = null;

  57.     protected boolean openspcoop2;
  58.    
  59.     public AbstractGestoreIntegrazionePDSoapBC(boolean openspcoop2){
  60.         this.log = OpenSPCoop2Logger.getLoggerOpenSPCoopCore();
  61.         this.openspcoop2 = openspcoop2;
  62.         if(this.log==null){
  63.             this.log = LoggerWrapperFactory.getLogger(AbstractGestoreIntegrazionePDSoapBC.class);
  64.         }
  65.         try{
  66.             this.utilitiesRequestBC = UtilitiesIntegrazioneBC.getInstancePDRequest(this.log, openspcoop2, false);
  67.             this.utilitiesResponseBC = UtilitiesIntegrazioneBC.getInstancePDResponse(this.log, openspcoop2, false);
  68.         }catch(Exception e){
  69.             this.log.error("Errore durante l'inizializzazione delle UtilitiesIntegrazione: "+e.getMessage(),e);
  70.         }
  71.     }
  72.    
  73.     // IN - Request
  74.    
  75.     @Override
  76.     public void readInRequestHeader(HeaderIntegrazione integrazione,
  77.             InRequestPDMessage inRequestPDMessage) throws HeaderIntegrazioneException{
  78.         try{
  79.             OpenSPCoop2Message msg = inRequestPDMessage.getMessage();
  80.             if(ServiceBinding.SOAP.equals(msg.getServiceBinding())==false){
  81.                 throw new Exception("Non utilizzabile con un Service Binding Rest");
  82.             }
  83.             OpenSPCoop2SoapMessage soapMsg = msg.castAsSoap();
  84.            
  85.             String protocollo = this.getProtocolFactory()!=null ? this.getProtocolFactory().getProtocol() : null;
  86.            
  87.             this.utilitiesRequestBC.readHeader(soapMsg, integrazione,
  88.                     this.openspcoop2 ?
  89.                             this.openspcoopProperties.getHeaderSoapActorIntegrazione_backwardCompatibility_openspcoop2() :
  90.                             this.openspcoopProperties.getHeaderSoapActorIntegrazione_backwardCompatibility_openspcoop1(),
  91.                             protocollo);
  92.         }catch(Exception e){
  93.             throw new HeaderIntegrazioneException("GestoreIntegrazionePDSoap, "+e.getMessage(),e);
  94.         }
  95.     }  
  96.    
  97.     @Override
  98.     public void deleteInRequestHeader(InRequestPDMessage inRequestPDMessage) throws HeaderIntegrazioneException{
  99.         try{
  100.             OpenSPCoop2Message msg = inRequestPDMessage.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.utilitiesRequestBC.deleteHeader(soapMsg,
  107.                     this.openspcoop2 ?
  108.                             this.openspcoopProperties.getHeaderSoapActorIntegrazione_backwardCompatibility_openspcoop2() :
  109.                             this.openspcoopProperties.getHeaderSoapActorIntegrazione_backwardCompatibility_openspcoop1());
  110.         }catch(Exception e){
  111.             throw new HeaderIntegrazioneException("GestoreIntegrazionePDSoap, "+e.getMessage(),e);
  112.         }
  113.     }

  114.    
  115.     @Override
  116.     public void updateInRequestHeader(InRequestPDMessage inRequestPDMessage,
  117.             IDServizio idServizio,
  118.             String idMessaggio,String servizioApplicativo,String correlazioneApplicativa) throws HeaderIntegrazioneException{
  119.         try{
  120.             OpenSPCoop2Message msg = inRequestPDMessage.getMessage();
  121.             if(ServiceBinding.SOAP.equals(msg.getServiceBinding())==false){
  122.                 throw new Exception("Non utilizzabile con un Service Binding Rest");
  123.             }
  124.             OpenSPCoop2SoapMessage soapMsg = msg.castAsSoap();
  125.            
  126.             String protocollo = this.getProtocolFactory()!=null ? this.getProtocolFactory().getProtocol() : null;
  127.            
  128.             this.utilitiesRequestBC.updateHeader(soapMsg,
  129.                     inRequestPDMessage.getSoggettoPropeprietarioPortaDelegata(), idServizio, 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(inRequestPDMessage.getBustaRichiesta(), true, TipoIntegrazione.SOAP),
  151.                     protocollo
  152.                     );  
  153.         }catch(Exception e){
  154.             throw new HeaderIntegrazioneException("GestoreIntegrazionePDSoap, "+e.getMessage(),e);
  155.         }
  156.     }

  157.    
  158.     // OUT - Request
  159.    
  160.     @Override
  161.     public void setOutRequestHeader(HeaderIntegrazione integrazione,
  162.             OutRequestPDMessage outRequestPDMessage) throws HeaderIntegrazioneException{
  163.    
  164.         // nop;
  165.        
  166.     }
  167.    
  168.    
  169.     // IN - Response
  170.    
  171.     @Override
  172.     public void readInResponseHeader(HeaderIntegrazione integrazione,
  173.             InResponsePDMessage inResponsePDMessage) throws HeaderIntegrazioneException{
  174.         try{
  175.             OpenSPCoop2Message msg = inResponsePDMessage.getMessage();
  176.             if(ServiceBinding.SOAP.equals(msg.getServiceBinding())==false){
  177.                 throw new Exception("Non utilizzabile con un Service Binding Rest");
  178.             }
  179.             OpenSPCoop2SoapMessage soapMsg = msg.castAsSoap();
  180.            
  181.             String protocollo = this.getProtocolFactory()!=null ? this.getProtocolFactory().getProtocol() : null;
  182.            
  183.             this.utilitiesResponseBC.readHeader(soapMsg, integrazione,this.openspcoop2 ?
  184.                             this.openspcoopProperties.getHeaderSoapActorIntegrazione_backwardCompatibility_openspcoop2() :
  185.                             this.openspcoopProperties.getHeaderSoapActorIntegrazione_backwardCompatibility_openspcoop1(),
  186.                             protocollo);
  187.         }catch(Exception e){
  188.             throw new HeaderIntegrazioneException("GestoreIntegrazionePDSoap, "+e.getMessage(),e);
  189.         }
  190.     }
  191.    
  192.     @Override
  193.     public void deleteInResponseHeader(InResponsePDMessage inResponsePDMessage) throws HeaderIntegrazioneException{
  194.         try{
  195.             OpenSPCoop2Message msg = inResponsePDMessage.getMessage();
  196.             if(ServiceBinding.SOAP.equals(msg.getServiceBinding())==false){
  197.                 throw new Exception("Non utilizzabile con un Service Binding Rest");
  198.             }
  199.             OpenSPCoop2SoapMessage soapMsg = msg.castAsSoap();
  200.            
  201.             this.utilitiesResponseBC.deleteHeader(soapMsg,this.openspcoop2 ?
  202.                             this.openspcoopProperties.getHeaderSoapActorIntegrazione_backwardCompatibility_openspcoop2() :
  203.                             this.openspcoopProperties.getHeaderSoapActorIntegrazione_backwardCompatibility_openspcoop1());
  204.         }catch(Exception e){
  205.             throw new HeaderIntegrazioneException("GestoreIntegrazionePDSoap, "+e.getMessage(),e);
  206.         }
  207.     }
  208.    
  209.     @Override
  210.     public void updateInResponseHeader(InResponsePDMessage inResponsePDMessage,
  211.             String idMessageRequest,String idMessageResponse,String servizioApplicativo,String correlazioneApplicativa,String riferimentoCorrelazioneApplicativaRichiesta) throws HeaderIntegrazioneException{
  212.         try{
  213.             OpenSPCoop2Message msg = inResponsePDMessage.getMessage();
  214.             if(ServiceBinding.SOAP.equals(msg.getServiceBinding())==false){
  215.                 throw new Exception("Non utilizzabile con un Service Binding Rest");
  216.             }
  217.             OpenSPCoop2SoapMessage soapMsg = msg.castAsSoap();
  218.            
  219.             String protocollo = this.getProtocolFactory()!=null ? this.getProtocolFactory().getProtocol() : null;
  220.            
  221.             this.utilitiesResponseBC.updateHeader(soapMsg,
  222.                     inResponsePDMessage.getSoggettoMittente(),
  223.                     inResponsePDMessage.getServizio(), idMessageRequest, idMessageResponse,
  224.                     servizioApplicativo, correlazioneApplicativa, riferimentoCorrelazioneApplicativaRichiesta,
  225.                     this.openspcoop2 ?
  226.                             this.openspcoopProperties.getHeaderSoapActorIntegrazione_backwardCompatibility_openspcoop2() :
  227.                             this.openspcoopProperties.getHeaderSoapActorIntegrazione_backwardCompatibility_openspcoop1(),  // actor
  228.                     this.openspcoop2 ?
  229.                             this.openspcoopProperties.getHeaderSoapNameIntegrazione_backwardCompatibility_openspcoop2() :
  230.                             this.openspcoopProperties.getHeaderSoapNameIntegrazione_backwardCompatibility_openspcoop1(),  // header name
  231.                     this.openspcoop2 ?
  232.                             this.openspcoopProperties.getHeaderSoapPrefixIntegrazione_backwardCompatibility_openspcoop2() :
  233.                             this.openspcoopProperties.getHeaderSoapPrefixIntegrazione_backwardCompatibility_openspcoop1(),  // prefix
  234.                     this.openspcoop2 ?
  235.                             this.openspcoopProperties.getHeaderSoapActorIntegrazione_backwardCompatibility_openspcoop2() :
  236.                             this.openspcoopProperties.getHeaderSoapActorIntegrazione_backwardCompatibility_openspcoop1(),  // namespace
  237.                     this.openspcoop2 ?
  238.                             this.openspcoopProperties.getHeaderSoapExtProtocolInfoNomeElementoIntegrazione_backwardCompatibility_openspcoop2() :
  239.                             this.openspcoopProperties.getHeaderSoapExtProtocolInfoNomeElementoIntegrazione_backwardCompatibility_openspcoop1()  , // nomeElemento ExtInfoProtocol
  240.                     this.openspcoop2 ?
  241.                             this.openspcoopProperties.getHeaderSoapExtProtocolInfoNomeAttributoIntegrazione_backwardCompatibility_openspcoop2() :
  242.                             this.openspcoopProperties.getHeaderSoapExtProtocolInfoNomeAttributoIntegrazione_backwardCompatibility_openspcoop1() , // nomeAttributo ExtInfoProtocol
  243.                     this.getProtocolFactory().createProtocolManager().buildIntegrationProperties(inResponsePDMessage.getBustaRichiesta(), false, TipoIntegrazione.SOAP),
  244.                     protocollo
  245.                 );
  246.         }catch(Exception e){
  247.             throw new HeaderIntegrazioneException("GestoreIntegrazionePDSoap, "+e.getMessage(),e);
  248.         }
  249.     }
  250.    
  251.     // OUT - Response
  252.    
  253.     @Override
  254.     public void setOutResponseHeader(HeaderIntegrazione integrazione,
  255.             OutResponsePDMessage outResponsePDMessage) throws HeaderIntegrazioneException{
  256.        
  257.         try{
  258.             OpenSPCoop2Message msg = outResponsePDMessage.getMessage();
  259.             if(ServiceBinding.SOAP.equals(msg.getServiceBinding())==false){
  260.                 throw new Exception("Non utilizzabile con un Service Binding Rest");
  261.             }
  262.             OpenSPCoop2SoapMessage soapMsg = msg.castAsSoap();
  263.            
  264.             String protocollo = this.getProtocolFactory()!=null ? this.getProtocolFactory().getProtocol() : null;
  265.            
  266.             SOAPHeaderElement header = this.utilitiesResponseBC.buildHeader(integrazione,
  267.                     this.openspcoop2 ?
  268.                             this.openspcoopProperties.getHeaderSoapNameIntegrazione_backwardCompatibility_openspcoop2() :
  269.                             this.openspcoopProperties.getHeaderSoapNameIntegrazione_backwardCompatibility_openspcoop1(), // header name
  270.                     this.openspcoop2 ?
  271.                             this.openspcoopProperties.getHeaderSoapPrefixIntegrazione_backwardCompatibility_openspcoop2() :
  272.                             this.openspcoopProperties.getHeaderSoapPrefixIntegrazione_backwardCompatibility_openspcoop1(), // prefix
  273.                     this.openspcoop2 ?
  274.                             this.openspcoopProperties.getHeaderSoapActorIntegrazione_backwardCompatibility_openspcoop2() :
  275.                             this.openspcoopProperties.getHeaderSoapActorIntegrazione_backwardCompatibility_openspcoop1(), // namespace
  276.                     this.openspcoop2 ?
  277.                             this.openspcoopProperties.getHeaderSoapActorIntegrazione_backwardCompatibility_openspcoop2() :
  278.                             this.openspcoopProperties.getHeaderSoapActorIntegrazione_backwardCompatibility_openspcoop1(), // actor
  279.                     soapMsg,
  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(outResponsePDMessage.getBustaRichiesta(), false, TipoIntegrazione.SOAP),
  287.                     protocollo
  288.                 );
  289.             //System.out.println((new org.openspcoop.dao.message.OpenSPCoopMessageFactory().createMessage().getAsString(header)));
  290.             if(soapMsg.getSOAPHeader() == null){
  291.                 soapMsg.getSOAPPart().getEnvelope().addHeader();
  292.             }
  293.             //outResponsePDMessage.getMessage().getSOAPHeader().addChildElement(header);
  294.             soapMsg.addHeaderElement(soapMsg.getSOAPHeader(), header);
  295.            
  296.         }catch(Exception e){
  297.             throw new HeaderIntegrazioneException("GestoreIntegrazionePDSoap, "+e.getMessage(),e);
  298.         }
  299.        
  300.     }
  301. }