Add Soap message header for your endpoint from XwsSecurityInterceptor

When a soap message request come to our server spring validate usernametoken from our soapheader.But later If you want this header from endpoint you cannot get this(reason is unknown probably spring remove this security header when authentication validation completed).We can use this soap header from our endpoint by custom our XwsSecurityInterceptor class for example we can create a CustomXwsSecurityInterceptor class and override validateMessage method like this

****************************************************************************
public class CustomXwsSecurityInterceptor extends XwsSecurityInterceptor {



    protected void validateMessage(org.springframework.ws.soap.SoapMessage soapMessage, org.springframework.ws.context.MessageContext messageContext) throws org.springframework.ws.soap.security.WsSecurityValidationException {

        logger.info(SaajUtils.getSoapEnvelope((SaajSoapMessage) soapMessage));

        messageContext.setProperty("somePropertyNameFromHeader",somevalueFromHeader);
        super.validateMessage(soapMessage,messageContext);

    }

}
*************************************************************************

now you can goto your endpoint and write a code to access soap header like this
SomeType soapMessage = messageContext.getProperty("somePropertyName"); 
from this soapMessage you can get your header elements. This is only for solving my purpose.There may be other way to solve this situation.

Thanks


Reactions

Post a Comment

0 Comments