Skip to main content
Skip table of contents

Per-Proxy Request Contexts

Instead of passing a context explicitly with an invocation, you can also use a per-proxy context. Per-proxy contexts allow you to set a context on a particular proxy once and, thereafter, whenever you use that proxy to invoke an operation, the previously-set context is sent with each invocation.

Configuring a Per-Proxy Request Context Programmatically

The proxy methods ice_context and ice_getContext set and retrieve the context, respectively. ice_context creates a new proxy that stores the given context. Calling ice_getContext returns the stored context, or an empty dictionary if no per-proxy context has been configured for the proxy.

TYPESCRIPT
// setting the context on the proxy.
const greeterEs = greeter.ice_context(new Map([["language", "es"]]));

This example shows how to configure a request context on a proxy. Once set, the request context is automatically included with every request sent through that proxy. An explicit request context provided at the time of an invocation always takes precedence over the proxy’s configured context.

Configuring a Per-Proxy Request Context using Properties

You can also configure a context with proxy properties when you use the communicator method propertyToProxy.

We can configure a context for this proxy using the following properties:

CODE
GreeterProxy=person:greeter:tcp -h localhost -p 4061
GreeterProxy.Context.language=es

The Context property has the form name.Context.key=value, where key and value can be any legal property symbols.

The proxy returned by propertyToProxy already contains the context key/value pairs specified in the configuration properties. To make any modifications to the context at run time, you'll need to retrieve the proxy's context dictionary using ice_getContext, modify the dictionary as necessary, and finally obtain a new proxy by calling ice_context, as we described above.

See Also
JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.