Results 1 to 4 of 4

Thread: How do I get hold of the SOAP Header

  1. #1

    Default How do I get hold of the SOAP Header

    I currently have an endpoint that extends AbstractJDomPayloadEndpoint and deals with my request/response just fine.
    However, I have just been asked to use a session ID, which is stored on the SOAP Header, for my logging and exception handling.
    With my current configuration how to I get access to the SOAP Header???

    Code:
    public class AppStatusEndpoint extends AbstractJDomPayloadEndpoint
    Code:
    <bean class="org.springframework.ws.server.endpoint.mapping.PayloadRootQNameEndpointMapping">
       <property name="mappings">
          <props>
             <prop key="{/schema/appstatus/tIsApplicationEnabledV1C}IsApplicationEnabledRequest">AppStatusServiceEndpoint</prop>
          </props>
       </property>
       <!--And a log file interceptor-->
       <property name="interceptors">
          <bean class="org.springframework.ws.server.endpoint.interceptor.PayloadLoggingInterceptor"/>
       </property>
    </bean>
    I did try and implement MessageEndpoint in my endpoint class but I wasn't quite sure how to get the request processed and the response returned once I had retrieved the session ID from the SOAP header?

    Any ideas?

  2. #2
    Join Date
    Dec 2005
    Posts
    24

  3. #3

    Default

    Thanks for your reply 'sroach' but I have to say I still don't know how I would get hold of my SOAP Header element?

    If I have a request like this
    Code:
    <soapenv:Envelope xmlns:soapenv="//schemas.xmlsoap.org/soap/envelope/" xmlns:tis="//schema/appstatus/tIsApplicationEnabledV1C">
       <soapenv:Header>
    	<SessionID>123456</SessionID>
       </soapenv:Header>
    ....
    </soapenv:Envelope>
    How do I get hold of the SessionID?

  4. #4
    Join Date
    Apr 2009
    Posts
    14

    Thumbs up

    I believe you have already solved this issue, but for the reference of others, you can implement an interceptor to intercept the soap request and can access Soap Headers from there.

    Configuration
    Code:
    <bean class="org.springframework.ws.server.endpoint.mapping.PayloadRootAnnotationMethodEndpointMapping">
    		<property name="interceptors">
    			<list>
    				<ref bean="soapHeaderInterceptor" />
    			</list>
    		</property>
    	</bean>
    <bean id="soapHeaderInterceptor" class="sample.HeaderItemInceptionInterceptor" />
    Here HeaderItemInceptionInterceptor has implemented EndpointInterceptor
    interface. You can override its handle request method to access Soap Header.

    Code:
    public boolean handleRequest(MessageContext messageContext, Object endpoint)
    			throws Exception {
    		System.out.println("Intercepted");
    		SoapHeader header = ((SoapMessage)messageContext.getRequest()).getSoapHeader();
    		Iterator i = header.examineAllHeaderElements();
    		for (Iterator iterator = header.examineAllHeaderElements(); iterator.hasNext();) {
    			SoapHeaderElement headerElement = (SoapHeaderElement) iterator.next();
    			if(headerElement.getName().getLocalPart().equals("SessionId")){
    				String sessionId = headerElement.getText();
    // You can take any decission here based on session id. You can generate soap fault here if session is not valid by throwing an exception.
    			}
    		}
    		return true;
    	}
    I hope it will help.

    Cheers
    Muein

Posting Permissions

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