GestoreIntegrazionePDSoap.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.protocol.sdk.constants.TipoIntegrazione;
  31. import org.openspcoop2.utils.LoggerWrapperFactory;

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

  42.     /** Utility per l'integrazione */
  43.     UtilitiesIntegrazione utilitiesRequest = null;
  44.     UtilitiesIntegrazione utilitiesResponse = null;

  45.     /** OpenSPCoopProperties */
  46.     OpenSPCoop2Properties openspcoopProperties = OpenSPCoop2Properties.getInstance();
  47.    
  48.     /** Logger utilizzato per debug. */
  49.     private Logger log = null;

  50.    
  51.     public GestoreIntegrazionePDSoap(){
  52.         this.log = OpenSPCoop2Logger.getLoggerOpenSPCoopCore();
  53.         if(this.log==null){
  54.             this.log = LoggerWrapperFactory.getLogger(GestoreIntegrazionePDSoap.class);
  55.         }
  56.         try{
  57.             this.utilitiesRequest = UtilitiesIntegrazione.getInstancePDRequest(this.log);
  58.             this.utilitiesResponse = UtilitiesIntegrazione.getInstancePDResponse(this.log);
  59.         }catch(Exception e){
  60.             this.log.error("Errore durante l'inizializzazione delle UtilitiesIntegrazione: "+e.getMessage(),e);
  61.         }
  62.     }
  63.    
  64.     // IN - Request
  65.    
  66.     @Override
  67.     public void readInRequestHeader(HeaderIntegrazione integrazione,
  68.             InRequestPDMessage inRequestPDMessage) throws HeaderIntegrazioneException{
  69.         try{
  70.             OpenSPCoop2Message msg = inRequestPDMessage.getMessage();
  71.             if(ServiceBinding.SOAP.equals(msg.getServiceBinding())==false){
  72.                 throw new Exception("Non utilizzabile con un Service Binding Rest");
  73.             }
  74.             OpenSPCoop2SoapMessage soapMsg = msg.castAsSoap();
  75.            
  76.             this.utilitiesRequest.readHeader(soapMsg, integrazione,this.openspcoopProperties.getHeaderSoapActorIntegrazione());
  77.         }catch(Exception e){
  78.             throw new HeaderIntegrazioneException("GestoreIntegrazionePDSoap, "+e.getMessage(),e);
  79.         }
  80.     }  
  81.    
  82.     @Override
  83.     public void deleteInRequestHeader(InRequestPDMessage inRequestPDMessage) throws HeaderIntegrazioneException{
  84.         try{
  85.             OpenSPCoop2Message msg = inRequestPDMessage.getMessage();
  86.             if(ServiceBinding.SOAP.equals(msg.getServiceBinding())==false){
  87.                 throw new Exception("Non utilizzabile con un Service Binding Rest");
  88.             }
  89.             OpenSPCoop2SoapMessage soapMsg = msg.castAsSoap();
  90.            
  91.             this.utilitiesRequest.deleteHeader(soapMsg,this.openspcoopProperties.getHeaderSoapActorIntegrazione());
  92.         }catch(Exception e){
  93.             throw new HeaderIntegrazioneException("GestoreIntegrazionePDSoap, "+e.getMessage(),e);
  94.         }
  95.     }

  96.    
  97.     @Override
  98.     public void updateInRequestHeader(InRequestPDMessage inRequestPDMessage,
  99.             IDServizio idServizio,
  100.             String idMessaggio,String servizioApplicativo,String correlazioneApplicativa) throws HeaderIntegrazioneException{
  101.         try{
  102.             OpenSPCoop2Message msg = inRequestPDMessage.getMessage();
  103.             if(ServiceBinding.SOAP.equals(msg.getServiceBinding())==false){
  104.                 throw new Exception("Non utilizzabile con un Service Binding Rest");
  105.             }
  106.             OpenSPCoop2SoapMessage soapMsg = msg.castAsSoap();
  107.            
  108.             this.utilitiesRequest.updateHeader(soapMsg,
  109.                     inRequestPDMessage.getSoggettoPropeprietarioPortaDelegata(), idServizio, 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(inRequestPDMessage.getBustaRichiesta(), true, TipoIntegrazione.SOAP)
  119.                 );  
  120.         }catch(Exception e){
  121.             throw new HeaderIntegrazioneException("GestoreIntegrazionePDSoap, "+e.getMessage(),e);
  122.         }
  123.     }

  124.    
  125.     // OUT - Request
  126.    
  127.     @Override
  128.     public void setOutRequestHeader(HeaderIntegrazione integrazione,
  129.             OutRequestPDMessage outRequestPDMessage) throws HeaderIntegrazioneException{
  130.    
  131.         // nop;
  132.        
  133.     }
  134.    
  135.    
  136.     // IN - Response
  137.    
  138.     @Override
  139.     public void readInResponseHeader(HeaderIntegrazione integrazione,
  140.             InResponsePDMessage inResponsePDMessage) throws HeaderIntegrazioneException{
  141.         try{
  142.             OpenSPCoop2Message msg = inResponsePDMessage.getMessage();
  143.             if(ServiceBinding.SOAP.equals(msg.getServiceBinding())==false){
  144.                 throw new Exception("Non utilizzabile con un Service Binding Rest");
  145.             }
  146.             OpenSPCoop2SoapMessage soapMsg = msg.castAsSoap();
  147.            
  148.             this.utilitiesResponse.readHeader(soapMsg, integrazione,this.openspcoopProperties.getHeaderSoapActorIntegrazione());
  149.         }catch(Exception e){
  150.             throw new HeaderIntegrazioneException("GestoreIntegrazionePDSoap, "+e.getMessage(),e);
  151.         }
  152.     }
  153.    
  154.     @Override
  155.     public void deleteInResponseHeader(InResponsePDMessage inResponsePDMessage) throws HeaderIntegrazioneException{
  156.         try{
  157.             OpenSPCoop2Message msg = inResponsePDMessage.getMessage();
  158.             if(ServiceBinding.SOAP.equals(msg.getServiceBinding())==false){
  159.                 throw new Exception("Non utilizzabile con un Service Binding Rest");
  160.             }
  161.             OpenSPCoop2SoapMessage soapMsg = msg.castAsSoap();
  162.            
  163.             this.utilitiesResponse.deleteHeader(soapMsg,this.openspcoopProperties.getHeaderSoapActorIntegrazione());
  164.         }catch(Exception e){
  165.             throw new HeaderIntegrazioneException("GestoreIntegrazionePDSoap, "+e.getMessage(),e);
  166.         }
  167.     }
  168.    
  169.     @Override
  170.     public void updateInResponseHeader(InResponsePDMessage inResponsePDMessage,
  171.             String idMessageRequest,String idMessageResponse,String servizioApplicativo,String correlazioneApplicativa,String riferimentoCorrelazioneApplicativaRichiesta) throws HeaderIntegrazioneException{
  172.         try{
  173.             OpenSPCoop2Message msg = inResponsePDMessage.getMessage();
  174.             if(ServiceBinding.SOAP.equals(msg.getServiceBinding())==false){
  175.                 throw new Exception("Non utilizzabile con un Service Binding Rest");
  176.             }
  177.             OpenSPCoop2SoapMessage soapMsg = msg.castAsSoap();
  178.            
  179.             this.utilitiesResponse.updateHeader(soapMsg,
  180.                     inResponsePDMessage.getSoggettoMittente(),
  181.                     inResponsePDMessage.getServizio(), idMessageRequest, idMessageResponse,
  182.                     servizioApplicativo, correlazioneApplicativa, riferimentoCorrelazioneApplicativaRichiesta,
  183.                     this.openspcoopProperties.getHeaderSoapActorIntegrazione(),  // actor
  184.                     this.openspcoopProperties.getHeaderSoapNameIntegrazione(),  // header name
  185.                     this.openspcoopProperties.getHeaderSoapPrefixIntegrazione(),  // prefix
  186.                     this.openspcoopProperties.getHeaderSoapActorIntegrazione(),  // namespace
  187.                     this.openspcoopProperties.getHeaderSoapExtProtocolInfoNomeElementoIntegrazione(), // nomeElemento ExtInfoProtocol
  188.                     this.openspcoopProperties.getHeaderSoapExtProtocolInfoNomeAttributoIntegrazione(), // nomeAttributo ExtInfoProtocol
  189.                     this.getProtocolFactory().createProtocolManager().buildIntegrationProperties(inResponsePDMessage.getBustaRichiesta(), false, TipoIntegrazione.SOAP)
  190.                 );
  191.         }catch(Exception e){
  192.             throw new HeaderIntegrazioneException("GestoreIntegrazionePDSoap, "+e.getMessage(),e);
  193.         }
  194.     }
  195.    
  196.     // OUT - Response
  197.    
  198.     @Override
  199.     public void setOutResponseHeader(HeaderIntegrazione integrazione,
  200.             OutResponsePDMessage outResponsePDMessage) throws HeaderIntegrazioneException{
  201.        
  202.         try{
  203.             OpenSPCoop2Message msg = outResponsePDMessage.getMessage();
  204.             if(ServiceBinding.SOAP.equals(msg.getServiceBinding())==false){
  205.                 throw new Exception("Non utilizzabile con un Service Binding Rest");
  206.             }
  207.             OpenSPCoop2SoapMessage soapMsg = msg.castAsSoap();
  208.            
  209.             SOAPHeaderElement header = this.utilitiesResponse.buildHeader(integrazione,
  210.                     this.openspcoopProperties.getHeaderSoapNameIntegrazione(), // header name
  211.                     this.openspcoopProperties.getHeaderSoapPrefixIntegrazione(), // prefix
  212.                     this.openspcoopProperties.getHeaderSoapActorIntegrazione(), // namespace
  213.                     this.openspcoopProperties.getHeaderSoapActorIntegrazione(), // actor
  214.                     soapMsg,
  215.                     this.openspcoopProperties.getHeaderSoapExtProtocolInfoNomeElementoIntegrazione(), // nomeElemento ExtInfoProtocol
  216.                     this.openspcoopProperties.getHeaderSoapExtProtocolInfoNomeAttributoIntegrazione(), // nomeAttributo ExtInfoProtocol
  217.                     this.getProtocolFactory().createProtocolManager().buildIntegrationProperties(outResponsePDMessage.getBustaRichiesta(), false, TipoIntegrazione.SOAP)
  218.                 );
  219.             //System.out.println((new org.openspcoop.dao.message.OpenSPCoopMessageFactory().createMessage().getAsString(header)));
  220.             if(soapMsg.getSOAPHeader() == null){
  221.                 soapMsg.getSOAPPart().getEnvelope().addHeader();
  222.             }
  223.             //outResponsePDMessage.getMessage().getSOAPHeader().addChildElement(header);
  224.             soapMsg.addHeaderElement(soapMsg.getSOAPHeader(), header);
  225.            
  226.         }catch(Exception e){
  227.             throw new HeaderIntegrazioneException("GestoreIntegrazionePDSoap, "+e.getMessage(),e);
  228.         }
  229.        
  230.     }
  231. }