Results 1 to 6 of 6

Thread: Can a Spring Soap interceptor modify the contents of a message?

  1. #1

    Default Can a Spring Soap interceptor modify the contents of a message?

    I'm trying to write an interceptor for a web service that will modify the contents of the Soap message before is sent on to the endpoint. If a client sent a message where the value of some element is 1, I want to be able to alter that element to a 2 so that, when the message arrives at the endpoint, it looks as if the client submitted a 2 instead of a 1. I'm not sure if this is a difficult task which is elluding me, or an easy task which I am making harder than it needs to be.

    I have stepped through some of the Spring interceptors; but the validation and logging interceptors don't every alter the message that is in transit. The Wss4jSecurityInterceptor does add some properties to the MessageContext; but I haven't been able to leverage anything that it is doing. I have a shell of an interceptor; but nothing that is doing anything of any value.

    Code:
    	public boolean handleRequest(MessageContext messageContext, Object endpoint)
    			throws Exception {
    
    		SaajSoapMessage saajSoapMessage = (SaajSoapMessage) messageContext
    				.getRequest();
    		SOAPMessage soapMessage = saajSoapMessage.getSaajMessage();
    		SOAPBody soapBody = soapMessage.getSOAPBody();
    
    		return true;
    	}
    I was hoping there was a chance that soembody else had already solved this particular problem. Any insight would be appreciated. Thanks.

  2. #2
    Join Date
    Nov 2009
    Location
    Los Angeles, CA
    Posts
    3

    Default

    Not sure if you're still waiting for an answer to that question, but your problem is that you forgot to call
    Code:
    soapMessage.saveChanges()
    after you modified the message in your interceptor. If you don't, SAAJ will silently discard all your changes


    Code:
    	public boolean handleRequest(MessageContext messageContext, Object endpoint)
    			throws Exception {
    
    		SaajSoapMessage saajSoapMessage = (SaajSoapMessage) messageContext
    				.getRequest();
    		SOAPMessage soapMessage = saajSoapMessage.getSaajMessage();
    		SOAPBody soapBody = soapMessage.getSOAPBody();
                    
                    // message modifications here
    
                    // save changes to message
                    soapMessage.saveChanges();
    		return true;
    	}

  3. #3

    Default

    Quote Originally Posted by cwagner View Post
    Not sure if you're still waiting for an answer to that question, but your problem is that you forgot to call
    Oh. I hadn't seen that method. I was unable to figure out what I was doing wrong, and eventually ended up finding a different resolution to the problem set in front of me at that time. See the link below for details if interested.

    http://stackoverflow.com/questions/3...s-of-a-message

    If I find a few moments, I may circle back and see if that indeed is what I was looking for. And if not, I've still potentially learned something new. =)

    Thanks,
    -Dave

  4. #4
    Join Date
    Nov 2009
    Location
    Los Angeles, CA
    Posts
    3

    Smile

    Thanks for the thanks

    I found your post while looking for the solution to a slightly different problem -- I was trying to figure out how to use Spring-WS to talk to talk to a web service that expects several message parts, i.e. like so:

    Code:
    <SOAP-ENV:Body>
      <Element1>...</Element1>
      <Element2>...</Element2>
    </SOAP-ENV:Body>
    This seems to be impossible to produce using the hooks Spring-WS supplies, so I had to resort to using SAAJ to modify the message body directly. In other words, I used your interceptor stub (and added the saveChanges() call). Worked perfectly, so I thought I'd say thanks by answering your original question

  5. #5

    Default The same puzzled as you..

    This seems to be impossible to produce using the hooks Spring-WS supplies, so I had to resort to using SAAJ to modify the message body directly. In other words, I used your interceptor stub (and added the saveChanges() call). Worked perfectly, so I thought I'd say thanks by answering your original question

  6. #6
    Join Date
    Jan 2011
    Location
    Pittsburgh, PA, USA
    Posts
    11

    Question

    I have no clue on how to make changes to the SOAP content after this line.....

    Code:
    		
    SOAPBody soapBody = soapMessage.getSOAPBody();
    I do not understand which methos in SOAPBody will help me change the raw data.

    I appreciate an example. Thanks in advance.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •