GestoreIntegrazionePAWSAddressingWithResponseOut.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.openspcoop2.message.OpenSPCoop2Message;
  23. import org.openspcoop2.message.OpenSPCoop2SoapMessage;
  24. import org.openspcoop2.message.constants.ServiceBinding;


  25. /**
  26.  * Classe utilizzata per la spedizione di informazioni di integrazione
  27.  * dalla porta di dominio verso i servizi applicativi.
  28.  *
  29.  * @author Poli Andrea (apoli@link.it)
  30.  * @author $Author$
  31.  * @version $Rev$, $Date$
  32.  */
  33. public class GestoreIntegrazionePAWSAddressingWithResponseOut extends GestoreIntegrazionePAWSAddressing{

  34.     @Override
  35.     public void setOutResponseHeader(HeaderIntegrazione integrazione,
  36.             OutResponsePAMessage outResponsePAMessage) throws HeaderIntegrazioneException{
  37.        
  38.         try{
  39.             OpenSPCoop2Message msg = outResponsePAMessage.getMessage();
  40.             if(ServiceBinding.SOAP.equals(msg.getServiceBinding())==false){
  41.                 throw new Exception("Non utilizzabile con un Service Binding Rest");
  42.             }
  43.             OpenSPCoop2SoapMessage soapMsg = msg.castAsSoap();
  44.            
  45.             if(soapMsg.getSOAPHeader() == null){
  46.                 soapMsg.getSOAPPart().getEnvelope().addHeader();
  47.             }
  48.            
  49.             if(integrazione.getBusta()!=null){
  50.                
  51.                 HeaderIntegrazioneBusta hBusta = integrazione.getBusta();
  52.                    
  53.                 if(hBusta.getDestinatario()!=null && hBusta.getServizio()!=null){
  54.                    
  55.                     // To
  56.                     SOAPHeaderElement wsaTO = UtilitiesIntegrazioneWSAddressing.buildWSATo(soapMsg,this.openspcoopProperties.getHeaderSoapActorIntegrazione()+"/wsa",
  57.                             hBusta.getTipoDestinatario(),hBusta.getDestinatario(),
  58.                             hBusta.getTipoServizio(), hBusta.getServizio(), hBusta.getVersioneServizio());
  59.                     soapMsg.addHeaderElement(soapMsg.getSOAPHeader(), wsaTO);
  60.                    
  61.                     // Action
  62.                     if(hBusta.getAzione()!=null){
  63.                         SOAPHeaderElement wsaAction = UtilitiesIntegrazioneWSAddressing.buildWSAAction(soapMsg,this.openspcoopProperties.getHeaderSoapActorIntegrazione()+"/wsa",
  64.                                 hBusta.getTipoDestinatario(),hBusta.getDestinatario(),
  65.                                 hBusta.getTipoServizio(), hBusta.getServizio(), hBusta.getVersioneServizio(), hBusta.getAzione());
  66.                         soapMsg.addHeaderElement(soapMsg.getSOAPHeader(), wsaAction);
  67.                     }
  68.                 }
  69.                
  70.                 if(hBusta.getMittente()!=null){
  71.                     SOAPHeaderElement wsaFROM = UtilitiesIntegrazioneWSAddressing.buildWSAFrom(soapMsg,this.openspcoopProperties.getHeaderSoapActorIntegrazione()+"/wsa",integrazione.getServizioApplicativo(),hBusta.getTipoMittente(),hBusta.getMittente());
  72.                     soapMsg.addHeaderElement(soapMsg.getSOAPHeader(), wsaFROM);
  73.                 }
  74.                    
  75.                 if(hBusta.getID()!=null){
  76.                     SOAPHeaderElement wsaID = UtilitiesIntegrazioneWSAddressing.buildWSAID(soapMsg,this.openspcoopProperties.getHeaderSoapActorIntegrazione()+"/wsa",hBusta.getID());
  77.                     soapMsg.addHeaderElement(soapMsg.getSOAPHeader(), wsaID);
  78.                 }
  79.                
  80.                 if(hBusta.getRiferimentoMessaggio()!=null || hBusta.getIdCollaborazione()!=null){
  81.                     String rif = hBusta.getRiferimentoMessaggio();
  82.                     if(rif==null){
  83.                         rif = hBusta.getIdCollaborazione();
  84.                     }
  85.                     SOAPHeaderElement wsaRelatesTo = UtilitiesIntegrazioneWSAddressing.buildWSARelatesTo(soapMsg,this.openspcoopProperties.getHeaderSoapActorIntegrazione()+"/wsa",rif);
  86.                     soapMsg.addHeaderElement(soapMsg.getSOAPHeader(), wsaRelatesTo);
  87.                 }
  88.             }
  89.            
  90.         }catch(Exception e){
  91.             throw new HeaderIntegrazioneException("GestoreIntegrazionePASoap, "+e.getMessage(),e);
  92.         }
  93.        
  94.     }
  95. }