Version 9.6
 —  Virtualized Services in CentraSite Control  —

Using Context Variables in Virtualized Services

Mediator provides predefined context variables, and you can declare your own custom context variables. You can use both predefined and custom context variables when you configure various processing steps of a virtualized service. Specifically, you can use them:

This section discusses:


The Predefined Context Variables

You can use the predefined context variables listed below. Any context variable state defined during the inbound request processing steps will still be available during the outbound response processing steps.

Notes:

  1. To set, get or remove the predefined context variables, use The API for Context Variables provided by Mediator.
  2. You do not need to declare the predefined context variables. If you attempt to declare an existing predefined context variable, an error will occur.
Context Variable Display Name Context Variable Name Description
Average Response AVG_SUCCESS_TIME The average amount of time it took the service to complete all invocations in the current interval. This is measured from the moment Mediator receives the request until the moment it returns the response to the caller.

Note:
By default, Average Response Time does not include metrics for failed invocations. You can include metrics for failed invocations by setting the pg.PgMetricsFormatter.includeFaults parameter to true. For details, see the section Advanced Settings in the document Administering webMethods Mediator.

Client IP Address INBOUND_IP The IP address used to send the request to Mediator.
Consumer CONSUMER_APPLICATION The name of the consumer application accessing the service, if known.
Fault Count INTERVAL_FAULT_COUNT The number of service faults for the interval.
Inbound Content Type MESSAGE_TYPE A Content-Type defined in axis2.xml for a message formatter. This value must be a key in the axis2 message formatters list, since it is used to control message serialization. (The valid choices are defined as attributes of <messageFormatters/> group in the Integration Server's axis2.xml configuration.)
Inbound HTTP Method INBOUND_HTTP_METHOD The HTTP method used by the client to send the request (GET, POST, PUT, DELETE, Use Context Variable).
Inbound Protocol INBOUND_PROTOCOL The protocol (HTTP or HTTPS) of the request.
Maximum Response SLOWEST_SUCCESS_INVOKE Maximum Response Time.

Note:
By default, Maximum Response Time does not include metrics for failed invocations. You can include metrics for failed invocations by setting the pg.PgMetricsFormatter.includeFaults parameter to true. For details, see the section Advanced Settings in the document Administering webMethods Mediator.

Mediator Host Name MEDIATOR_HOSTNAME Mediator host name.
Mediator IP Address MEDIATOR_IP Mediator IP address.
Mediator Target Name TARGET_NAME Mediator target name.
Minimum Response FASTEST_SUCCESS_INVOKE Minimum Response Time.

Note:
By default, Minimum Response Time does not include metrics for failed invocations. You can include metrics for failed invocations by setting the pg.PgMetricsFormatter.includeFaults parameter to true. For details, see Advanced Settings in the document Administering webMethods Mediator.

Outbound HTTP Method ROUTING_METHOD The HTTP method to be sent to the native service if the inbound HTTP method is custom. Otherwise, this value will be null. For more information, see Changing the HTTP Method of a REST or XML Request.
Success Count INTERVAL_SUCCESS_COUNT The number of success counts for a given service.
Total Count INTERVAL_TOTAL_COUNT The total number of counts for a given service.
Virtual Service Name SERVICE_NAME Virtual service name.
N/A BUILDER_TYPE A Content Type defined in axis2.xml for a message builder. This value must be a key in the axis2 message builders list, since it is used to control building of native service response messages. (The valid choices are defined as attributes of <messageBuilders/> group in the Integration Server's axis2.xml configuration.)
N/A INBOUND_REQUEST_URI

A partial reference to a virtual service (for HTTP/HTTPS only). The protocol, host and port are not part of the value. For example, if the following virtual service is invoked:

http://mcusawco:5555/ws/TC1

then the expected value of this variable would be /ws/TC1.

For a REST or XML service, the URL might also include query string parameters. For example, if the following virtual service is invoked:

http://mcusawco:5555/ws/cars?vin=1234

the expected value of this variable would be /ws/cars?vin1234.

This is useful to know because by the time you are able to access the request inside of Mediator, the REST request would contain a top-level element that looks like this:

<vin>1234</vin>

So it is not obvious from an XSLT expression or a webMethods IS service callout what part of a REST request came in as a query parameter.

Therefore, using this variable along with INBOUND_HTTP_METHOD and INBOUND_PROTOCOL, you can determine the exact entry point URI that was used when a virtual service was invoked.

N/A NATIVE_PROVIDER_ERROR The reason returned by the native service provider in the case where it produced a SOAP fault. This will not contain Mediator-hosted errors such as security policy enforcement errors. This variable will only contain the "reason" text wrapped in a SOAP fault.

Note:
When you are using this variable in a custom SOAP fault message that you are specifying in the Response Processing Step, note the following. If a request is denied due to security policy enforcement, the fault handler variable $ERROR_MESSAGE variable would contain a native service provider error message or other error messages that result from enforced security assertions. However, $NATIVE_PROVIDER_ERROR will be null in this case. For information about $ERROR_MESSAGE, see The Response Processing Step.

N/A OPERATION The virtual service operation selected to execute a request.
N/A PROTOCOL_HEADERS Contains a map of key-value pairs in the request, where the values are typed as strings. To get/set this variable, see pub.mediator.ctxvar:getContextVariable.
N/A SOAP_HEADERS (For use in webMethods IS services only.) Contains an array of the SOAP header elements in the request. To get/set this variable, see pub.mediator.ctxvar:getContextVariable.
N/A USER The value defined for the Integration Server session executing the request message. If the request is not authenticated, it will use a default unprivileged account. Otherwise, it will set the Integration Server session to the user credentials used for transport security. Also, if credentials were included for message based security (e.g., an X509 token was included and this certificate was mapped to an Integration Server user), then this information would override any transport security (e.g., basic authentication).

Note:
When you use predefined context variables in a custom error message in The Response Processing Step, note the following:

Top of page

The API for Context Variables

Mediator provides an API that you can use to:

Mediator provides the following Java services, which are defined in the class ISMediatorRuntimeFacade.java:

The following sample flow services are described in this section as well:

pub.mediator.ctxvar:getContextVariable

Use this Java service to retrieve a context variable’s value and assign it to a pipeline variable. All parameter names are case-sensitive.

Parameter Pipeline Type Data Type Description Examples
MessageContext in Object ref This object is inserted into the pipeline by Mediator. N/A
varName in String Context variable name (predefined or custom). PROTOCOL_HEADERS
SOAP_HEADERS
mx:CUSTOM_VAR
serValue out Object ref Java.io.serializable value. (Usually a string).  

Notes on Getting and Setting the PROTOCOL_HEADERS and SOAP_HEADERS Variables

All context variable values are typed as either "string" or "int" except for the predefined context variables PROTOCOL_HEADERS and SOAP_HEADERS, which are of the type "IData". You can set/get values for PROTOCOL_HEADERS and SOAP_HEADERS in one of two ways:

pub.mediator.ctxvar:setContextVariable

Use this Java service to set a value on a context variable. The pipeline variable containing the context variable value should be an object reference that implements java.io.Serializable. All parameter names are case-sensitive.

Parameter Pipeline Type Data Type Description Examples
MessageContext in Object ref This object is inserted into the pipeline by Mediator. N/A
varName in String Context variable name (predefined or custom). PROTOCOL_HEADERS
SOAP_HEADERS
mx:CUSTOM_VAR
serValue in Object ref Java.io.serializable value. (Usually a string).  

pub.mediator.ctxvar:declareContextVariable

Use this Java service to declare a custom context variable. All custom-defined context variables must be declared in a custom namespace that is identified by using the prefix mx (e.g., mx:CUSTOM_VARIABLE). All parameter names are case-sensitive.

Note:
It is not legal to use this service to declare the predefined context variables; you can only declare custom variables.

Parameter Pipeline Type Data Type Description
ctxVar in Object ref The document type defining the context variable object. Use the ctxVar Document Type provided in the Java service pub.mediator.ctxvar:ctxVar and map it to this input variable. Define the name (for example, mx:CUSTOM_VARIABLE), the schema_type (string or int), and isReadOnly (true or false).
ctxVar out Object ref The set Context variable document type.
varNameQ out Object ref javax.xml.namespace.QName value. The QName of the variable.

Note the following:

pub.mediator.ctxvar:removeContextVariable

Use this Java service to remove a custom context variable from a request/response session. All parameter names are case-sensitive.

Notes:

  1. It is not legal to use this service to remove any predefined context variables; you can only remove custom variables.
  2. Attempting to remove a non-existent context variable will not result in an error.
Parameter Pipeline Type Data Type Description Examples
MessageContext in Object ref This object is inserted into the pipeline by Mediator. N/A
varName in String Custom context variable name. mx:CUSTOM_VAR

Sample Flow Service: Getting a Context Variable Value

This flow service gets the value of a custom context variable from a request. The service declares a context variable using the name defined in the pipeline variable customName ( i.e., mx:COMP_TEST). It is hard-coded to store the predefined context variable SERVICE_NAME in this custom context variable name.

Step 1. Setting varName and customName

graphics/scrn_CtxVar01.png

In this flow service, the following pipeline variables that are hard-coded as follows:

Step 2. Calling the pub.mediator.ctxvar:getContextVariable service

graphics/scrn_CtxVar02.png

The call to pub.mediator.ctxvar:getContextVariable looks up the context variable value for the "Pipeline In" variable varName and sets the Serializable value in the output pipeline variable named serValue.

Step 3. Calling the pub.mediator.ctxvar:declareContextVariable service

graphics/scrn_CtxVar03.png

The call to pub.mediator.ctxvar:declareContextVariable takes the serialized value we looked up for varName and assigns it to a newly declared custom context variable named ctxVar.

Step 4. Calling the pub.mediator.ctxvar:setContextVariable service

graphics/scrn_CtxVar04.png

The call to pub.mediator.ctxvar:setContextVariable sets the context variable value back into MessageContext so it will be available for the rest of the service invocation steps.

Sample Flow Service: Setting a Context Variable Value

This flow service sets the value of a custom context variable to be used in a response.

This flow service declares a pipeline variable named customName, which is set to the value mx:COMP_TEST.

This flow service will retrieve the context variable for customName and create an element for its context variable value in the response message return to the consumer.

Step 1. Declaring customName

graphics/scrn_CtxVar05.png

We define the customName variable value to be mx:COMP_TEST so we can use this variable to lookup the custom variable name that was seeded in the previous example.

Step 2. Setting customName to mx:COMP_TEST

graphics/scrn_CtxVar06.png

Clicking on the customName pipeline variable will display the name.

Step 3. Displaying the value of customName

graphics/scrn_CtxVar07.png

The call to pub.mediator.ctxvar:getContextVariable retrieves the value of the custom context variable from the context variable map.

Step 4. Calling meditor.ctxvar:getContextVariable

graphics/scrn_CtxVar08.png

This is just a sample Java service that takes the context variable and creates a top-level element in the response message using the same name and value.

Step 5. Sample service using the context variable

graphics/scrn_CtxVar09.png

Top of page