Search code examples
propertieswso2session-managementwso2-esb

how to set a property globally in wso2 ESB


I am trying to figure out how to implement session management in wso2 esb.So i have written a class mediator which generates session_ID that i want to store.For storing the session id I am using following code as:

org.apache.axis2.context.ServiceContext serviceContext = org.apache.axis2.context.MessageContext
            .getCurrentMessageContext().getServiceContext();
serviceContext.setProperty("SessionIDGlobal", uuid);

But while running it in my esb's proxy it throws null pointer exception at getCurrentMessageContext part.I have followed another approach where-in i am storing the sessionID in property mediator and tried to get its value but when i click postRequest operation after generateSessionID operation from try-it. all the property gets reset and my sessionID property gives me null value. What should i do to rectify this problem? Is there any alternate way?


Solution

  • You have to create servicecontext like this;

    ConfigurationContext cfgCtx =(((Axis2MessageContext) synCtx).getAxis2MessageContext(). getConfigurationContext();
    
    cfgCtx.getOperationContext().getServiceContext();