GestoreIntegrazionePDWSAddressing.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.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.logger.OpenSPCoop2Logger;
  30. import org.openspcoop2.utils.LoggerWrapperFactory;

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

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

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

  54.         try{
  55.             this.utilities = UtilitiesIntegrazioneWSAddressing.getInstance(this.log);
  56.         }catch(Exception e){
  57.             this.log.error("Errore durante l'inizializzazione delle UtilitiesIntegrazioneWSAddressing: "+e.getMessage(),e);
  58.         }
  59.     }
  60.    
  61.    
  62.     // IN - Request
  63.    
  64.     @Override
  65.     public void readInRequestHeader(HeaderIntegrazione integrazione,
  66.             InRequestPDMessage inRequestPDMessage) throws HeaderIntegrazioneException{
  67.         try{
  68.             OpenSPCoop2Message msg = inRequestPDMessage.getMessage();
  69.             if(ServiceBinding.SOAP.equals(msg.getServiceBinding())==false){
  70.                 throw new Exception("Non utilizzabile con un Service Binding Rest");
  71.             }
  72.             OpenSPCoop2SoapMessage soapMsg = msg.castAsSoap();
  73.            
  74.             this.utilities.readHeader(soapMsg, integrazione,
  75.                     UtilitiesIntegrazioneWSAddressing.INTERPRETA_COME_ID_APPLICATIVO,
  76.                     this.openspcoopProperties.getHeaderSoapActorIntegrazione()+"/wsa");
  77.         }catch(Exception e){
  78.             throw new HeaderIntegrazioneException("GestoreIntegrazionePDWSAddressing, "+e.getMessage(),e);
  79.         }
  80.     }

  81.     @Override
  82.     public void deleteInRequestHeader(InRequestPDMessage inRequestPDMessage) throws HeaderIntegrazioneException{
  83.         try{
  84.             OpenSPCoop2Message msg = inRequestPDMessage.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.utilities.deleteHeader(soapMsg,this.openspcoopProperties.getHeaderSoapActorIntegrazione()+"/wsa");
  91.         }catch(Exception e){
  92.             throw new HeaderIntegrazioneException("GestoreIntegrazionePDSoap, "+e.getMessage(),e);
  93.         }
  94.     }
  95.    
  96.     @Override
  97.     public void updateInRequestHeader(InRequestPDMessage inRequestPDMessage,IDServizio idServizio,
  98.             String idMessaggio,String servizioApplicativo,String correlazioneApplicativa) 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.utilities.updateHeader(soapMsg,
  107.                     inRequestPDMessage.getSoggettoPropeprietarioPortaDelegata(), idServizio, idMessaggio,
  108.                     servizioApplicativo, correlazioneApplicativa,
  109.                     UtilitiesIntegrazione.getIdTransazione(this.getPddContext()),
  110.                     this.openspcoopProperties.getHeaderSoapActorIntegrazione()+"/wsa");  // namespace
  111.         }catch(Exception e){
  112.             throw new HeaderIntegrazioneException("GestoreIntegrazionePDWSAddressing, "+e.getMessage(),e);
  113.         }
  114.     }

  115.    
  116.     // OUT - Request
  117.    
  118.     @Override
  119.     public void setOutRequestHeader(HeaderIntegrazione integrazione,
  120.             OutRequestPDMessage outRequestPDMessage) throws HeaderIntegrazioneException{
  121.    
  122.         // nop;
  123.        
  124.     }
  125.    
  126.     // IN - Response
  127.    
  128.     @Override
  129.     public void readInResponseHeader(HeaderIntegrazione integrazione,
  130.             InResponsePDMessage inResponsePDMessage) throws HeaderIntegrazioneException{
  131.         try{
  132.             OpenSPCoop2Message msg = inResponsePDMessage.getMessage();
  133.             if(ServiceBinding.SOAP.equals(msg.getServiceBinding())==false){
  134.                 throw new Exception("Non utilizzabile con un Service Binding Rest");
  135.             }
  136.             OpenSPCoop2SoapMessage soapMsg = msg.castAsSoap();
  137.            
  138.             this.utilities.readHeader(soapMsg, integrazione,
  139.                     UtilitiesIntegrazioneWSAddressing.INTERPRETA_COME_ID_BUSTA,
  140.                     this.openspcoopProperties.getHeaderSoapActorIntegrazione()+"/wsa");
  141.         }catch(Exception e){
  142.             throw new HeaderIntegrazioneException("GestoreIntegrazionePDWSAddressing, "+e.getMessage(),e);
  143.         }
  144.     }
  145.    
  146.     @Override
  147.     public void deleteInResponseHeader(InResponsePDMessage inResponsePDMessage) throws HeaderIntegrazioneException{
  148.         try{
  149.             OpenSPCoop2Message msg = inResponsePDMessage.getMessage();
  150.             if(ServiceBinding.SOAP.equals(msg.getServiceBinding())==false){
  151.                 throw new Exception("Non utilizzabile con un Service Binding Rest");
  152.             }
  153.             OpenSPCoop2SoapMessage soapMsg = msg.castAsSoap();
  154.            
  155.             this.utilities.deleteHeader(soapMsg,this.openspcoopProperties.getHeaderSoapActorIntegrazione()+"/wsa");
  156.         }catch(Exception e){
  157.             throw new HeaderIntegrazioneException("GestoreIntegrazionePDSoap, "+e.getMessage(),e);
  158.         }
  159.     }
  160.    
  161.     @Override
  162.     public void updateInResponseHeader(InResponsePDMessage inResponsePDMessage,
  163.             String idMessageRequest,String idMessageResponse,String servizioApplicativo,String correlazioneApplicativa,String riferimentoCorrelazioneApplicativaRichiesta) throws HeaderIntegrazioneException{
  164.         try{
  165.             OpenSPCoop2Message msg = inResponsePDMessage.getMessage();
  166.             if(ServiceBinding.SOAP.equals(msg.getServiceBinding())==false){
  167.                 throw new Exception("Non utilizzabile con un Service Binding Rest");
  168.             }
  169.             OpenSPCoop2SoapMessage soapMsg = msg.castAsSoap();
  170.            
  171.             this.utilities.updateHeader(soapMsg,
  172.                     inResponsePDMessage.getSoggettoMittente(),
  173.                     inResponsePDMessage.getServizio(),
  174.                     idMessageRequest,  idMessageResponse,
  175.                     servizioApplicativo, correlazioneApplicativa, this.openspcoopProperties.getHeaderSoapActorIntegrazione()+"/wsa");  // namespace
  176.         }catch(Exception e){
  177.             throw new HeaderIntegrazioneException("GestoreIntegrazionePDWSAddressing, "+e.getMessage(),e);
  178.         }
  179.     }
  180.    
  181.    
  182.    
  183.     // OUT - Response
  184.    
  185.     @Override
  186.     public void setOutResponseHeader(HeaderIntegrazione integrazione,
  187.             OutResponsePDMessage outResponsePDMessage) throws HeaderIntegrazioneException{
  188.        
  189.         try{
  190.            
  191.             OpenSPCoop2Message msg = outResponsePDMessage.getMessage();
  192.             if(ServiceBinding.SOAP.equals(msg.getServiceBinding())==false){
  193.                 throw new Exception("Non utilizzabile con un Service Binding Rest");
  194.             }
  195.             OpenSPCoop2SoapMessage soapMsg = msg.castAsSoap();
  196.            
  197.             if(soapMsg.getSOAPHeader() == null){
  198.                 soapMsg.getSOAPPart().getEnvelope().addHeader();
  199.             }
  200.            
  201.             if(integrazione.getBusta()!=null){
  202.                
  203.                 HeaderIntegrazioneBusta hBusta = integrazione.getBusta();
  204.                    
  205.                 if(hBusta.getDestinatario()!=null && hBusta.getServizio()!=null){
  206.                    
  207.                     // To
  208.                     SOAPHeaderElement wsaTO = UtilitiesIntegrazioneWSAddressing.buildWSATo(soapMsg,this.openspcoopProperties.getHeaderSoapActorIntegrazione()+"/wsa",
  209.                             hBusta.getTipoDestinatario(),hBusta.getDestinatario(),
  210.                             hBusta.getTipoServizio(), hBusta.getServizio(), hBusta.getVersioneServizio());
  211.                     soapMsg.addHeaderElement(soapMsg.getSOAPHeader(), wsaTO);
  212.                    
  213.                     // Action
  214.                     if(hBusta.getAzione()!=null){
  215.                         SOAPHeaderElement wsaAction = UtilitiesIntegrazioneWSAddressing.buildWSAAction(soapMsg,this.openspcoopProperties.getHeaderSoapActorIntegrazione()+"/wsa",
  216.                                 hBusta.getTipoDestinatario(),hBusta.getDestinatario(),
  217.                                 hBusta.getTipoServizio(), hBusta.getServizio(), hBusta.getVersioneServizio(), hBusta.getAzione());
  218.                         soapMsg.addHeaderElement(soapMsg.getSOAPHeader(), wsaAction);
  219.                     }
  220.                 }
  221.                
  222.                 if(hBusta.getMittente()!=null){
  223.                     SOAPHeaderElement wsaFROM = UtilitiesIntegrazioneWSAddressing.buildWSAFrom(soapMsg,this.openspcoopProperties.getHeaderSoapActorIntegrazione()+"/wsa",integrazione.getServizioApplicativo(),hBusta.getTipoMittente(),hBusta.getMittente());
  224.                     soapMsg.addHeaderElement(soapMsg.getSOAPHeader(), wsaFROM);
  225.                 }
  226.                    
  227.                 if(hBusta.getID()!=null){
  228.                     SOAPHeaderElement wsaID = UtilitiesIntegrazioneWSAddressing.buildWSAID(soapMsg,this.openspcoopProperties.getHeaderSoapActorIntegrazione()+"/wsa",hBusta.getID());
  229.                     soapMsg.addHeaderElement(soapMsg.getSOAPHeader(), wsaID);
  230.                 }
  231.                
  232.                 if(hBusta.getRiferimentoMessaggio()!=null || hBusta.getIdCollaborazione()!=null){
  233.                     String rif = hBusta.getRiferimentoMessaggio();
  234.                     if(rif==null){
  235.                         rif = hBusta.getIdCollaborazione();
  236.                     }
  237.                     SOAPHeaderElement wsaRelatesTo = UtilitiesIntegrazioneWSAddressing.buildWSARelatesTo(soapMsg,this.openspcoopProperties.getHeaderSoapActorIntegrazione()+"/wsa",rif);
  238.                     soapMsg.addHeaderElement(soapMsg.getSOAPHeader(), wsaRelatesTo);
  239.                 }
  240.             }
  241.            
  242.         }catch(Exception e){
  243.             throw new HeaderIntegrazioneException("GestoreIntegrazionePDWSAddressing, "+e.getMessage(),e);
  244.         }
  245.        
  246.     }
  247.    

  248. }