GestoreIntegrazionePAWSAddressing.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.slf4j.Logger;
  23. import org.openspcoop2.message.OpenSPCoop2Message;
  24. import org.openspcoop2.message.OpenSPCoop2SoapMessage;
  25. import org.openspcoop2.message.constants.ServiceBinding;
  26. import org.openspcoop2.pdd.config.OpenSPCoop2Properties;
  27. import org.openspcoop2.pdd.core.AbstractCore;
  28. import org.openspcoop2.pdd.logger.OpenSPCoop2Logger;
  29. import org.openspcoop2.utils.LoggerWrapperFactory;


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

  39.     /** Utility per l'integrazione */
  40.     UtilitiesIntegrazioneWSAddressing utilities = null;
  41.    
  42.     /** OpenSPCoopProperties */
  43.     OpenSPCoop2Properties openspcoopProperties = OpenSPCoop2Properties.getInstance();
  44.    
  45.     /** Logger utilizzato per debug. */
  46.     private Logger log = null;

  47.    
  48.     public GestoreIntegrazionePAWSAddressing(){
  49.         this.log = OpenSPCoop2Logger.getLoggerOpenSPCoopCore();
  50.         if(this.log==null){
  51.             this.log = LoggerWrapperFactory.getLogger(GestoreIntegrazionePAWSAddressing.class);
  52.         }

  53.         try{
  54.             this.utilities = UtilitiesIntegrazioneWSAddressing.getInstance(this.log);
  55.         }catch(Exception e){
  56.             this.log.error("Errore durante l'inizializzazione delle UtilitiesIntegrazioneWSAddressing: "+e.getMessage(),e);
  57.         }
  58.     }
  59.    
  60.    
  61.     // IN - Request
  62.    
  63.     @Override
  64.     public void readInRequestHeader(HeaderIntegrazione integrazione,
  65.             InRequestPAMessage inRequestPAMessage) throws HeaderIntegrazioneException{
  66.         try{
  67.             OpenSPCoop2Message msg = inRequestPAMessage.getMessage();
  68.             if(ServiceBinding.SOAP.equals(msg.getServiceBinding())==false){
  69.                 throw new Exception("Non utilizzabile con un Service Binding Rest");
  70.             }
  71.             OpenSPCoop2SoapMessage soapMsg = msg.castAsSoap();
  72.            
  73.             this.utilities.readHeader(soapMsg, integrazione, UtilitiesIntegrazioneWSAddressing.INTERPRETA_COME_ID_BUSTA, this.openspcoopProperties.getHeaderSoapActorIntegrazione()+"/wsa");
  74.         }catch(Exception e){
  75.             throw new HeaderIntegrazioneException("GestoreIntegrazionePASoap, "+e.getMessage(),e);
  76.         }
  77.     }
  78.    
  79.     @Override
  80.     public void deleteInRequestHeader(InRequestPAMessage inRequestPAMessage) throws HeaderIntegrazioneException{
  81.         try{
  82.             OpenSPCoop2Message msg = inRequestPAMessage.getMessage();
  83.             if(ServiceBinding.SOAP.equals(msg.getServiceBinding())==false){
  84.                 throw new Exception("Non utilizzabile con un Service Binding Rest");
  85.             }
  86.             OpenSPCoop2SoapMessage soapMsg = msg.castAsSoap();
  87.            
  88.             this.utilities.deleteHeader(soapMsg, this.openspcoopProperties.getHeaderSoapActorIntegrazione()+"/wsa");
  89.         }catch(Exception e){
  90.             throw new HeaderIntegrazioneException("GestoreIntegrazionePASoap, "+e.getMessage(),e);
  91.         }
  92.     }
  93.    
  94.     @Override
  95.     public void updateInRequestHeader(InRequestPAMessage inRequestPAMessage,
  96.             String idMessaggio,String servizioApplicativo,String correlazioneApplicativa) throws HeaderIntegrazioneException{
  97.         try{
  98.             OpenSPCoop2Message msg = inRequestPAMessage.getMessage();
  99.             if(ServiceBinding.SOAP.equals(msg.getServiceBinding())==false){
  100.                 throw new Exception("Non utilizzabile con un Service Binding Rest");
  101.             }
  102.             OpenSPCoop2SoapMessage soapMsg = msg.castAsSoap();
  103.            
  104.             this.utilities.updateHeader(soapMsg,
  105.                     inRequestPAMessage.getSoggettoMittente(),
  106.                     inRequestPAMessage.getServizio(),
  107.                     idMessaggio, servizioApplicativo, correlazioneApplicativa,
  108.                     UtilitiesIntegrazione.getIdTransazione(this.getPddContext()),
  109.                     this.openspcoopProperties.getHeaderSoapActorIntegrazione()+"/wsa");
  110.         }catch(Exception e){
  111.             throw new HeaderIntegrazioneException("GestoreIntegrazionePASoap, "+e.getMessage(),e);
  112.         }
  113.     }
  114.    
  115.    
  116.     // OUT - Request
  117.    
  118.     @Override
  119.     public void setOutRequestHeader(HeaderIntegrazione integrazione,
  120.             OutRequestPAMessage outRequestPAMessage) throws HeaderIntegrazioneException{
  121.         try{
  122.             OpenSPCoop2Message msg = outRequestPAMessage.getMessage();
  123.             if(ServiceBinding.SOAP.equals(msg.getServiceBinding())==false){
  124.                 throw new Exception("Non utilizzabile con un Service Binding Rest");
  125.             }
  126.             OpenSPCoop2SoapMessage soapMsg = msg.castAsSoap();
  127.            
  128.             if(soapMsg.getSOAPHeader() == null){
  129.                 soapMsg.getSOAPPart().getEnvelope().addHeader();
  130.             }
  131.            
  132.             if(integrazione.getBusta()!=null){
  133.                
  134.                 HeaderIntegrazioneBusta hBusta = integrazione.getBusta();
  135.                    
  136.                 if(hBusta.getDestinatario()!=null && hBusta.getServizio()!=null){
  137.                    
  138.                     // To
  139.                     SOAPHeaderElement wsaTO = UtilitiesIntegrazioneWSAddressing.buildWSATo(soapMsg,this.openspcoopProperties.getHeaderSoapActorIntegrazione()+"/wsa",
  140.                             hBusta.getTipoDestinatario(),hBusta.getDestinatario(),
  141.                             hBusta.getTipoServizio(), hBusta.getServizio(), hBusta.getVersioneServizio());
  142.                     soapMsg.addHeaderElement(soapMsg.getSOAPHeader(), wsaTO);
  143.                                        
  144.                     // Action
  145.                     if(hBusta.getAzione()!=null){
  146.                         SOAPHeaderElement wsaAction = UtilitiesIntegrazioneWSAddressing.buildWSAAction(soapMsg,this.openspcoopProperties.getHeaderSoapActorIntegrazione()+"/wsa",
  147.                                 hBusta.getTipoDestinatario(),hBusta.getDestinatario(),
  148.                                 hBusta.getTipoServizio(), hBusta.getServizio(),hBusta.getVersioneServizio(), hBusta.getAzione());
  149.                         soapMsg.addHeaderElement(soapMsg.getSOAPHeader(), wsaAction);
  150.                     }
  151.                 }
  152.                
  153.                 if(hBusta.getMittente()!=null){
  154.                     SOAPHeaderElement wsaFROM = UtilitiesIntegrazioneWSAddressing.buildWSAFrom(soapMsg,this.openspcoopProperties.getHeaderSoapActorIntegrazione()+"/wsa",integrazione.getServizioApplicativo(),hBusta.getTipoMittente(),hBusta.getMittente());
  155.                     soapMsg.addHeaderElement(soapMsg.getSOAPHeader(), wsaFROM);
  156.                 }
  157.                    
  158.                 if(hBusta.getID()!=null){
  159.                     SOAPHeaderElement wsaID = UtilitiesIntegrazioneWSAddressing.buildWSAID(soapMsg,this.openspcoopProperties.getHeaderSoapActorIntegrazione()+"/wsa",hBusta.getID());
  160.                     soapMsg.addHeaderElement(soapMsg.getSOAPHeader(), wsaID);
  161.                 }
  162.                
  163.                 if(hBusta.getRiferimentoMessaggio()!=null || hBusta.getIdCollaborazione()!=null){
  164.                     String rif = hBusta.getRiferimentoMessaggio();
  165.                     if(rif==null){
  166.                         rif = hBusta.getIdCollaborazione();
  167.                     }
  168.                     SOAPHeaderElement wsaRelatesTo = UtilitiesIntegrazioneWSAddressing.buildWSARelatesTo(soapMsg,this.openspcoopProperties.getHeaderSoapActorIntegrazione()+"/wsa",rif);
  169.                     soapMsg.addHeaderElement(soapMsg.getSOAPHeader(), wsaRelatesTo);
  170.                 }
  171.             }
  172.            
  173.         }catch(Exception e){
  174.             throw new HeaderIntegrazioneException("GestoreIntegrazionePASoap, "+e.getMessage(),e);
  175.         }
  176.     }

  177.    
  178.     // IN - Response
  179.    
  180.     @Override
  181.     public void readInResponseHeader(HeaderIntegrazione integrazione,
  182.             InResponsePAMessage inResponsePAMessage) throws HeaderIntegrazioneException{
  183.         try{
  184.             OpenSPCoop2Message msg = inResponsePAMessage.getMessage();
  185.             if(ServiceBinding.SOAP.equals(msg.getServiceBinding())==false){
  186.                 throw new Exception("Non utilizzabile con un Service Binding Rest");
  187.             }
  188.             OpenSPCoop2SoapMessage soapMsg = msg.castAsSoap();
  189.            
  190.             this.utilities.readHeader(soapMsg, integrazione, UtilitiesIntegrazioneWSAddressing.INTERPRETA_COME_ID_APPLICATIVO, this.openspcoopProperties.getHeaderSoapActorIntegrazione()+"/wsa");
  191.         }catch(Exception e){
  192.             throw new HeaderIntegrazioneException("GestoreIntegrazionePASoap, "+e.getMessage(),e);
  193.         }
  194.     }
  195.    
  196.     @Override
  197.     public void deleteInResponseHeader(InResponsePAMessage inResponsePAMessage) throws HeaderIntegrazioneException{
  198.         try{
  199.             OpenSPCoop2Message msg = inResponsePAMessage.getMessage();
  200.             if(ServiceBinding.SOAP.equals(msg.getServiceBinding())==false){
  201.                 throw new Exception("Non utilizzabile con un Service Binding Rest");
  202.             }
  203.             OpenSPCoop2SoapMessage soapMsg = msg.castAsSoap();
  204.            
  205.             this.utilities.deleteHeader(soapMsg, this.openspcoopProperties.getHeaderSoapActorIntegrazione()+"/wsa");
  206.         }catch(Exception e){
  207.             throw new HeaderIntegrazioneException("GestoreIntegrazionePASoap, "+e.getMessage(),e);
  208.         }
  209.     }
  210.    
  211.     @Override
  212.     public void updateInResponseHeader(InResponsePAMessage inResponsePAMessage,
  213.             String idMessageRequest,String idMessageResponse,String servizioApplicativo,String correlazioneApplicativa,String riferimentoCorrelazioneApplicativaRichiesta) 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.             this.utilities.updateHeader(soapMsg,
  222.                     inResponsePAMessage.getSoggettoMittente(),
  223.                     inResponsePAMessage.getServizio(),
  224.                     idMessageRequest, idMessageResponse, servizioApplicativo, correlazioneApplicativa, this.openspcoopProperties.getHeaderSoapActorIntegrazione()+"/wsa");
  225.         }catch(Exception e){
  226.             throw new HeaderIntegrazioneException("GestoreIntegrazionePASoap, "+e.getMessage(),e);
  227.         }
  228.     }
  229.    
  230.     // OUT - Response
  231.        
  232.     @Override
  233.     public void setOutResponseHeader(HeaderIntegrazione integrazione,
  234.             OutResponsePAMessage outResponsePAMessage) throws HeaderIntegrazioneException{
  235.        
  236.         // nop;
  237.        
  238.     }
  239. }