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.
- First we get the operation context from the response message context.
- Next we get the request messageContext from the operationContext.
- Then we get the request messageContext from the operationContext.
OperationContext opCtx = responseMessageContext.getOperationContext();
MessageContext reqMessageContext = opCtx.getMessageContext(WSDLConstants.MESSAGE_LABEL_IN_VALUE);
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.
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.
Apache Axis2/Java - any version