Page 2 of 3 FirstFirst 123 LastLast
Results 11 to 20 of 26

Thread: How do I extract information from a soap header and pass it to the endpoint

  1. #11
    Join Date
    Jul 2005
    Location
    Rotterdam, the Netherlands
    Posts
    1,562

    Default

    I'l think about it. One of the possibilities is to do it similar to Spring-MVC's new @Controller and @RequestMapping style. Basically, you would be able to define a WebServiceMessage or MethodContext parameter, and it will be injected by Spring-WS.
    Arjen Poutsma

    Spring Web Services Dev Lead
    Please read the FAQ

  2. #12
    Join Date
    Jan 2008
    Posts
    13

    Default How to set variables from the interceptor into the endpoint

    I am trying to solve the same problem mentioned in this thread. From what I have understood so far, if i need to view the SOAP header I would have to define a custom interceptor which would read the message context. This context can then be set into the end point.

    My question is how do i set a variable in the endpoint from the interceptor. Is it something I would do using the spring configuration files or do I have to programatically do it.

    Any help on this would be appreciated.

    Irfan

  3. #13
    Join Date
    May 2007
    Posts
    19

    Default JIRA Created Yet

    Hi Arjen,

    Did you happen to create a JIRA for this issue?

    I think is a common problem - Passing Data from the interceptor to the endpoint and the other way round without loosing the flexibility to use @Endpoint or any other DOM/Marshalling based endpoint.

    Implementing MessageEndpoint which handles messages individually can lead to a inflated code base for large projects.

    Using the threadlocal approach is something i can live with but would prefer if the Spring Wiz Team did us a favor

    Thanks
    Last edited by Rahul Mishra; Mar 12th, 2008 at 12:41 PM.

  4. #14
    Join Date
    Feb 2007
    Posts
    20

    Default

    Why not simply inject a "request" scoped bean in an Interceptor and in the Endpoint?
    The interceptor will extract the infos from the SOAP Header and put them in the bean and then the Endpoint will be able to read them.
    If you are using a custom Soap Header you can also unmarshal it in the Interceptor to a java Object.

  5. #15
    Join Date
    Mar 2008
    Posts
    11

    Default

    How does injecting a request scoped bean into the interceptor and the endpoint work, with regards to this article: http://static.springframework.org/sp...ot-interaction

    Did I read this wrong or is this saying that you won't necessarily get a new instance of the request scoped bean?

  6. #16
    Join Date
    Feb 2007
    Posts
    20

    Default

    As stated in the Spring Reference guide you mention:
    "the Spring container will create a brand new instance of the.... bean using the '...' bean definition for each and every HTTP request".

    Where did you read about a different behaviour?

    You have only to pay attention to not reassign the variable, referring to the bean, in your code but only change its internal state to pass information from interceptor to endpoint.

  7. #17
    Join Date
    Mar 2008
    Posts
    11

    Default

    Never mind I must have been reading the wrong section.

    Thanks Lucian.

  8. #18
    Join Date
    Jul 2005
    Location
    Rotterdam, the Netherlands
    Posts
    1,562

    Default

    Quote Originally Posted by Rahul Mishra View Post
    Did you happen to create a JIRA for this issue?
    No I didn't do that yet, so please go ahead and do it .

    Injecting various objects as method parameters (such as MessageContext, and maybe others), is a major feature, and therefore not something I can do in the 1.5 timeline though. It will be something for the next major release.
    Arjen Poutsma

    Spring Web Services Dev Lead
    Please read the FAQ

  9. #19
    Join Date
    Feb 2007
    Posts
    20

    Default

    I can't understand why open a JIRA issue for something that can be already done as required by Rahul Mishra.
    I explain how:

    1)I define a request scoped bean both in the interceptor and in the endpoint that can be also an AbstractMarshallingPayloadEndpoint with automatic marshalling/unmarshalling of SOAP body
    2)In the interceptor I read the SOAP Header and can Unmarshal it to a object using Jibx , JAXB or what I want es:
    Code:
    	public boolean handleRequest(MessageContext messageContext, Object endpoint)
    			throws Exception {
        	System.out.println("Interceptor invocato ");
    	    AxiomSoapMessage axiomMsg = (AxiomSoapMessage)messageContext.getRequest();
    	    SOAPEnvelope axiomEnvelope = axiomMsg.getAxiomMessage().getSOAPEnvelope();
    	    SOAPHeader header=axiomEnvelope.getHeader();
    	    QName elementQName = new QName( "http://www.openspcoop.org/integrazione","integrazione");
    	    OMElement element=null;
    	    if (header!=null)
    	    	element=header.getFirstChildWithName(elementQName);
        
    	    if (element!=null)
    	    {
    	    	IUnmarshallingContext ctx = BindingDirectory.getFactory(IntegrazioneImpl.class).createUnmarshallingContext();
    	    	Integrazione appo = (Integrazione) ctx.unmarshalDocument(new StringReader(element.toString()));
         //integra is my request scoped bean
         integra.setInte(appo);
    	    }
    		return true;
    	}
    3)In the endpoint in the variable referring to the request scoped bean I have the info of the SOAP header.

    With client interceptor this works also for Web Services clients If I need.

  10. #20
    Join Date
    Apr 2009
    Posts
    14

    Default

    Hi luciano61,

    I am not sure how to unmarshall soap header elements can you explain it a bit. I a, trying to get a particular soap header element named session. after that i want to unmarshall it using jaxb. but not exaxtly sure how to do it. Here what my interceptor code looks like
    Code:
    	public boolean handleRequest(MessageContext messageContext, Object endpoint)
    			throws Exception {
    		System.out.println("Intercepted");
    		SoapHeader soapHeader = ((SaajSoapMessage) messageContext.getRequest()).getEnvelope().getHeader();
    		
    		Iterator i = soapHeader.examineAllHeaderElements();
    		SessionHeader sessionHeader = null 
    		for (Iterator iterator = soapHeader.examineAllHeaderElements(); iterator.hasNext();) {
    			SoapHeaderElement headerElement = (SoapHeaderElement) iterator.next();
    			if(headerElement.getName().getLocalPart().equals("session")){
    // i want to unmarshall this element into Session Header. 
    
    }
    }
    }

    Secondly can you please provide configuration settings for the code provided in ur last post especially for the request scope bean and its injection in other beans.

    thanks,
    Muein
    Last edited by mmuzamil; May 15th, 2009 at 05:41 AM.

Posting Permissions

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