Announcement Announcement Module
Collapse
No announcement yet.
Read SOAPHeader from AbstractJDomPayloadEndpoint Element Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Read SOAPHeader from AbstractJDomPayloadEndpoint Element

    I need to read the soap header from the incoming soap messages but i can't

    i'm using the AbstractJDomPayloadEndpoint and can't find any information to get this information. I've found an AbstractDomPayloadEndpoint post on spring forums but raises "type errors" on Eclipse

    The header i'm trying to read is called "ID"

    this is my non-working code

    Code:
    	protected String getID(Element rootElement){
    
    		String id = "";
    
    		try {
    			javax.xml.soap.SOAPMessage message = MessageFactory.newInstance().createMessage();
    			SOAPPart sp = message.getSOAPPart();
    			Node imported = sp.importNode((Node)rootElement, true);
    			javax.xml.soap.SOAPBody sb;
    			sb = message.getSOAPBody();
    			sb.appendChild((Node)imported);
    			id = message.getSOAPHeader().getFirstChild().getTextContent();
    		} catch (Exception e) {
    			// TODO Auto-generated catch block
    			e.printStackTrace();
    		}
    
    		return id;
    	}
    and this is de post i refer

    Code:
     Arjen Poutsma  Arjen Poutsma is offline
    Senior Member
    Spring Team
    	  	
    Join Date: Jul 2005
    Location: Rotterdam, the Netherlands
    Posts: 1,490
    Default
    Most SAAJ classes are actually subclasses of org.w3c.dom. For instance SOAPPart is a Document. So you could just do something like:
    
    Code:
    
    public Element invokeInternal(Element requestElement, Document doc) {
      SOAPMessage message = MessageFactory.newInstance().createMessage();
      SOAPPart sp = message.getSOAPPart();
      Element imported sp.importNode(requestElement, true);
      SOAPBody sb = message.getSOAPBody();
      sb.appendChild(imported);
    }
    have any body information about this?

  • #2
    Mate,
    The endpoint class you are using i.e. AbstractJDomPayloadEndpoint is only used to create payload endpoints.This means that you will only be able to access the SOAP body which contains request and response elements.A payload endpoint will not allow you to access elements like SOAP header.Now there are 2 solutions to your problem:

    1. If you want to access the SOAP header, then write an endpoint class by implementing
    MessageEndpoint interface.
    2. The other solution is to create a class ServiceInterceptor class which will implement the org.springframework.ws.server.endpoint.interceptor .EndpointInterceptorAdapter interface and override the method handleRequest () .By using the message context parameter in this method you should be able to extract the headers.Then later on you can create an object of ServiceInterceptor in the endpoint method invokeInternal() to intercept the SOAP request .You might have to look in the API/Reference doc to get familiar with the handleRequest method of EndpointInterceptorAdapter .

    I hope this helps.
    Cheers,
    Sushant

    Comment


    • #3
      THANKS!!!!!!! It helps a lot

      When I've finished this work i'll be back to post my code

      Comment


      • #4
        Solved

        This is the working code

        Code:
        package interceptors;
        
        import java.util.Iterator;
        
        import org.apache.axiom.soap.SOAPMessage;
        import org.springframework.ws.WebServiceMessage;
        import org.springframework.ws.context.MessageContext;
        import org.springframework.ws.server.endpoint.interceptor.EndpointInterceptorAdapter;
        import org.springframework.ws.soap.AbstractSoapMessage;
        import org.springframework.ws.soap.SoapEnvelope;
        import org.springframework.ws.soap.SoapHeader;
        import org.springframework.ws.soap.SoapHeaderElement;
        import org.springframework.ws.soap.axiom.AxiomSoapMessage;
        
        public class InterceptorTR069 extends EndpointInterceptorAdapter {
        
        	public boolean handleRequest(MessageContext messageContext, Object endpoint) throws Exception{
        
        		WebServiceMessage requestMessage = messageContext.getRequest();
        		AbstractSoapMessage abstractAxiomMessage = (AbstractSoapMessage) requestMessage;
        		AxiomSoapMessage axiomSoapMessage = (AxiomSoapMessage) abstractAxiomMessage;
        		SOAPMessage soapMessage = axiomSoapMessage.getAxiomMessage();
        
        		SoapEnvelope soapEnvelop = axiomSoapMessage.getEnvelope();
        		SoapHeader soapHeader = soapEnvelop.getHeader();
        		Iterator iterator = soapHeader.examineAllHeaderElements();
        		while (iterator.hasNext()) {
        			SoapHeaderElement element = (SoapHeaderElement) iterator.next();
        			String headerName = element.getName().getLocalPart();
        			String headerValue = element.getText();
        			System.out.println("Header: " + headerName + ", value: " + headerValue);
        		}
        
        		return true;
        	}
        
        }
        Output:

        10:43:05,730 INFO [STDOUT] Header: ID, value: 12345
        10:43:05,730 INFO [STDOUT] Header: HoldRequests, value: false
        10:43:05,788 INFO [STDOUT] GetRPCMethodsRequest ....

        Thank you for help!!!!!!

        Comment


        • #5
          Great Stuff mate, you got it through !!
          That's exactly what I explained in my sollution.Perfect !!
          Cheers,
          Sushant

          Comment


          • #6
            SoapHeader in Endpoint class

            Hi,

            I am unable to read SoapHeader value in my endpoint class.
            Please help

            Below thread has all teh details:
            http://forum.springsource.org/showth...Endpoint-class

            Thanks

            Comment

            Working...
            X