Explicit Request Contexts
Request contexts allow a client to send additional data to the server without having to include this data as input parameters in the operation’s Slice definition. They provide a lightweight mechanism for passing metadata alongside normal request arguments.
The Ice context demo provides a complete example of using request context in Java.
Using the Slice greeter definitions once again:
module VisitorCenter
{
interface Greeter
{
string greet(string name);
}
}
A client application can set a request context to send additional metadata:
// We request a French greeting by setting the context parameter.
String greeting = greeter.greet(name, Map.of("language", "fr"));
On the server side, the request context is available through the ctx member of the com.zeroc.Ice.Current parameter:
public String greet(String name, Current current) {
// We retrieve the value for the language entry in the context.
String language = current.ctx.getOrDefault("language", "");
...
}