Announcement Announcement Module
No announcement yet.
SOAP Header - How to echo soap header payload from service request to response/fault Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • SOAP Header - How to echo soap header payload from service request to response/fault

    Hi, I am in the process of implementing a spring ws and have a few questions regarding the handling of SOAP headers.

    A few basic background regarding my current approach
    • My interceptor SoapHeaderInterceptor implements EndpointInterceptor
    • I have overriden the handleRequest, handleResponse and handleFault
    • Presently I am doing a ThreadLocal storage of the SoapHeader in my handleRequest and retrieve it in my handleResponse and handleFault.

    What I am observing when I run my service
    • I invoke SoapHeader header = ((SoapMessage) messageContext.getRequest()).getSoapHeader() to get the header in the handleRequest and handleResponse object. Based on the object id (address hash) it appears to be the same object. Is this the expected behavior - that the Soap Header instances will be the same in the handleRequest/handleResponse/handleFault methods?
    • If the above SoapHeader object is the same, I would expect any Soap Header attributes supplied in the service request to be implicitly be available in the SoapHeader of the response. Presently this is not the case.
    • Inspecting the header available in the handleResponse/handleFault methods through examinAllHeaderElements() shows the input soap header with the header payload present. But the service response and fault results do not show any of the Soap header attributes going back to the service client.

    My present need is to just echo back the SOAP Header block. How do I accomplish this? I am looking for some suggestions to steer me in the right direction.

    - Krishna

  • #2
    Folks, stepping through the debugger shows the header elements as being present, however what actually comes out in the soap envelope/header does not have any header attributes.

    public boolean handleFault(MessageContext messageContext, Object endpoint) throws Exception {
    SoapHeader header = ((SoapMessage) messageContext.getRequest()).getSoapHeader();
    for (Iterator<SoapHeaderElement> iterator = header.examineAllHeaderElements(); iterator.hasNext();) {
        		SoapHeaderElement headerElement = (SoapHeaderElement);
                    // the header has the elements from the incoming request's soap header
                    // I can add additional elements
    return true;
    It does not matter what I add or what is already present. The outgoing message's soap header section has none of the elements that I am seeing while I step through the handleResponse or handleFault methods.

    I am sure I am missing something very trivial or overlooking a detail. I would appreciate any suggestions that would steer me in the right direction.


    • #3
      From your post i understand that you are able to see the header values inside your handle fault and handle response methods. But you are not able to get the same in your actual response at the client side. correct?

      If yes, then I think that is because in your handle fault method above, you are always taking the header from the Request and not from the Fault or Response object.
      SoapHeader header = ((SoapMessage) messageContext.getRequest()).getSoapHeader();

      If your requirement is just to send the same request header values in your response also, then just store the request values using ThreadLocal storage and use it in your handleResponse and set it in the header response.


      • #4
        Mohan, sorry about the belated reply. I almost feel like a klutz for not spotting that :-). Appreciate the response. Sometimes an extra set of eyes does the trick.

        Thanks again.
        - K