1 Reply Latest reply on Jul 15, 2010 11:23 AM by mesanchez

    Is there a way to access the information send in the SOAPHeader within an endpoint EJB?

    mesanchez

      I have installed JBoss6.0.0M3 which deploys woth JBossws3.3.0.

      I am trying to see if it is possible to access the information passed as part of the SOAP header within the endpoint EJB. I have been able to use handlers to manipulate the SOAP Message, but I am not able to find information regarding access from the EJB.

      There are some pages that indicate that this is possible using the SessionContext. The handlers set some attributes that are later accessed from the EJB, this would work but  I do not find any code that I could use as a reference. Any ideas? Code examples?

       

      This is the code I found but it has problems:

       

      public class MyMessageHandler extends 
                     javax.xml.rpc.handler.GenericHandler { 
         public boolean handleRequest(MessageContext mc) {
                SOAPMessage msg = ((SOAPMessageContext)mc).getMessage() ;
                SOAPPart sp = msg.getSOAPPart();
                SOAPEnvelope se = sp.getEnvelope();
                SOAPHeader header = se.getHeader();
                SOAPBody body = se.getBody();             
                if (header == null) {
                     // raise error
                }
                for (Iterator iter = header.getChildElements(); 
                                    iter.hasNext();) {
                     SOAPElement element = (SOAPElement) iter.next();
                     if (element.getElementName().getLocalName()
                               .equals("PriorityProcessing")) {
                          mc.setProperty("PriorityProcessing", 
                               element.getValue());
                     }
                }
           ...
           return true;
      }
      

      Code Example 8.6 Passing Context Information from Handler to Endpoint

       

      Then, you can get access to MessageContext in the endpoint that receives the request. For an EJB service endpoint, MessageContext is available with the bean'sSessionContext. Code Example 8.7 shows the enterprise bean code for the endpoint.

      public class EndpointBean implements SessionBean {
           private SessionContext sc;     
           public void businessMethod() {
                MessageContext msgc= sc.getMessageContext();
                String s = (String)msgc.getProperty("PriorityProcessing");
                Boolean priority = new Boolean(s);
                ...
           }       
           public void setSessionContext(SessionContext sc) {
                this.sc = sc;
           }
           ...
      }
      

      Code Example 8.7 Endpoint Receiving Context Information from a Handler

       

      When I do this SessionContext object is null

       

      Thanks,

         Maria