Library

How to Access a Request Path Property at the Response Path

  • By Deepal Jayasingha
  • 3 Jul, 2007

To begin with, let's look at how we can share resources between the request and the response.

If we want to share resources between the request and the response, then the most suitable place is to store the property in the operation context. As we know, there are two different message contexts for the request and the response. If we store a property in the request message context, then it is slightly difficult to access it at the response path. Here's how we can achieve that.

Let's say we store a property called 'Foo' in the request message context. Then how do we access that at the response path? In the response path, we have direct access to the response message context.

  1. First we get the operation context from the response message context.
  2. OperationContext opCtx = responseMessageContext.getOperationContext();

  3. Next we get the request messageContext from the operationContext.
  4. MessageContext reqMessageContext = opCtx.getMessageContext(WSDLConstants.MESSAGE_LABEL_IN_VALUE);

  5. Then we get the request messageContext from the operationContext.
  6. reqMessageContext.getProperty("Foo");

For instance say that we store a property called "Bar" at the request path in the operation context as follows:

OperartionContext opCtx = reqMessageContext.getOperationContext();
opCtx.setProperty("Bar" , "Bar value");

Now we can access the property at the response as follows.

resMessageContext.getProperty("Bar");

If we want to share the resources among the messages, then we need to store the resources or the property in the ServiceContext or ServiceGroupContext.

 

Applies To

Apache Axis2/Java - any version