Announcement Announcement Module
Collapse
No announcement yet.
How do I get hold of the SOAP Header Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    try threAD http://forum.springframework.org/showthread.php?t=61501

    Comment


    • #3
      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?

      Comment


      • #4
        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

        Comment

        Working...
        X