OpenSPCoop2SoapMessageCore.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.message.soap;

  21. import javax.xml.soap.MimeHeaders;
  22. import javax.xml.soap.SOAPMessage;

  23. import org.openspcoop2.message.constants.Costanti;
  24. import org.openspcoop2.message.constants.MessageType;
  25. import org.openspcoop2.message.context.MessageContext;
  26. import org.openspcoop2.message.context.Soap;
  27. import org.openspcoop2.message.exception.MessageException;
  28. import org.openspcoop2.message.exception.MessageNotSupportedException;

  29. /**
  30.  * OpenSPCoop2SoapMessageCore
  31.  *
  32.  * @author Andrea Poli (apoli@link.it)
  33.  * @author $Author$
  34.  * @version $Rev$, $Date$
  35.  */
  36. public class OpenSPCoop2SoapMessageCore {

  37.     /* SOAPAction */
  38.     public String soapAction;
  39.    
  40.     /* boolean throwExceptionIfFoundMoreSecurityHeader */
  41.     public boolean throwExceptionIfFoundMoreSecurityHeader = true; // se esistono due header con stesso actor e role viene normalmente lanciata una eccezione

  42.    
  43.     public void copyInstanceFieldValueTo(OpenSPCoop2SoapMessageCore core) {
  44.         core.soapAction = this.soapAction;
  45.         core.throwExceptionIfFoundMoreSecurityHeader = this.throwExceptionIfFoundMoreSecurityHeader;
  46.     }
  47.    
  48.     /* Copy Resources to another instance */
  49.    
  50.     public MessageContext serializeResourcesTo(MessageContext messageContext) throws MessageException{
  51.         Soap soap = new Soap();
  52.         soap.setSoapAction(this.soapAction);
  53.         messageContext.setSoap(soap);
  54.         return messageContext;
  55.     }
  56.    
  57.     public void readResourcesFrom(MessageContext messageContext) throws MessageException{
  58.        
  59.         if(messageContext.getSoap()!=null) {
  60.            
  61.             /* SOAPAction */
  62.             if(messageContext.getSoap().getSoapAction()!=null) {
  63.                 this.soapAction = messageContext.getSoap().getSoapAction();
  64.             }
  65.         }
  66.     }
  67.    
  68.    
  69.     /* Elementi SOAP */
  70.    
  71.     public SOAPMessage getSOAPMessage(SOAPMessage soapMessage, MessageType messageType) throws MessageException,MessageNotSupportedException{
  72.         try{
  73.             if(soapMessage!=null){
  74.                 soapMessage.setProperty(Costanti.SOAP_MESSAGE_PROPERTY_MESSAGE_TYPE, messageType);
  75.                
  76.                 if(MessageType.SOAP_11.equals(messageType)) {
  77.                     MimeHeaders mhs = soapMessage.getMimeHeaders();
  78.                     mhs.removeHeader(Costanti.SOAP11_MANDATORY_HEADER_HTTP_SOAP_ACTION);
  79.                     mhs.addHeader(Costanti.SOAP11_MANDATORY_HEADER_HTTP_SOAP_ACTION, this.getSoapAction());
  80.                 }
  81.             }
  82.             return soapMessage;
  83.         }
  84.         catch(Exception e){
  85.             throw new MessageException(e.getMessage(),e);
  86.         }
  87.     }
  88.    

  89.     /* SOAPAction */
  90.    
  91.     public String getSoapAction(){
  92.         return this.soapAction;
  93.     }
  94.    
  95.     public void setSoapAction(String soapAction){
  96.         this.soapAction = soapAction;
  97.     }
  98.    
  99.        
  100.    
  101.     /* WSSecurity */
  102.    
  103.     public boolean isThrowExceptionIfFoundMoreSecurityHeader() {
  104.         return this.throwExceptionIfFoundMoreSecurityHeader;
  105.     }

  106.     public void setThrowExceptionIfFoundMoreSecurityHeader(boolean throwExceptionIfFoundMoreSecurityHeader) {
  107.         this.throwExceptionIfFoundMoreSecurityHeader = throwExceptionIfFoundMoreSecurityHeader;
  108.     }
  109. }