[jboss-user] [JBossWS] - Adding application specific properties to the MessageContext

kellenheller do-not-reply at jboss.com
Tue Jan 15 15:05:41 EST 2008


I'm trying to add application specific properties to the MessageContext to retrieve either in my service via WebServiceContext or in a SoapMessageHandler via messageContext.  

No matter how I try to retrieve them, the properties are always null:

Here's my test code:

        Service service = getWebService( ); //works fine
  |         HaloImpl endPoint = service.getPort( HaloImpl.class );    
  |         
  |         //setup custom properties in RequestContext
  |         BindingProvider bp = (BindingProvider) endPoint;
  |         bp.getRequestContext( );
  |         Map<String,Object> context = bp.getRequestContext( );
  |         context.put( "prop1", "value1");
  |         context.put( "prop2", "value2");
  |         
  |         return (HaloImpl) bp;

Then I call the endpoint service, no problem.

In the handler:


public class HaloHandler implements SOAPHandler<SOAPMessageContext>
  | {
  | 
  |     //@Override
  |     public boolean handleMessage( SOAPMessageContext msgContext )
  |     {
  | 
  |         try
  |         {
  |             String prop1 = (String) msgContext.get( "prop1" );
  |             String prop2 = (String) msgContext.get( "prop2" );        
  |         
  |         } catch( Exception e )
  |         {
  |             throw new RuntimeException( e );
  |         }
  | 
  |         return true;
  |     }

The handler is configured on the server side via the @HandlerChain annotation, and it is being executed.  However, prop1 and prop2 are always null, when they should have "value1" and "value2" respectively.  

I've tried adding the WebServiceContext in the web service impl class like so:

@Resource
  |     WebServiceContext ctx;
  | 
  |     public HaloImpl( )
  |     {
  | 
  |     }

and then accessing the properties in a method when a service method is called:

private void validateProperties( )
  |    {
  |         MessageContext msg = ctx.getMessageContext( );
  |         if (msg != null){
  | 
  |             String prop1 = (String) msg.get( "prop1" );
  |             String prop2 = (String) msg.get( "prop2" );
  |         }
  |     }


but again, the properties are null.

Am I missing a setting?  I've seen several examples in different implementations showing this is the way to access custom properties, but I can't seem to get this to work.

I am using Jboss 4.2.2 with the default jax-ws stack it came with in there ( v2.0.1.SP2 ).

Anybody have any ideas?  Thanks guys :)



View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4120208#4120208

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4120208



More information about the jboss-user mailing list