Use the internationalization context API

 

Before you begin

EJB client applications, servlets, and enterprise beans can programmatically obtain and manage internationalization context using the internationalization context API. For Web service client applications, you use the API to obtain and manage internationalization context in the same manner as for EJB clients.

The java.util and com.ibm.websphere.i18n.context packages contain all of the classes necessary to use the internationalization service within an EJB application. Classes specific to the internationalization service reside in the install_root/lib/i18nctx.jar file. Before compiling application components that import internationalization service classes, add the i18nctx.jar file to your CLASSPATH setting.

 

Procedure

  1. Gain access to the internationalization context API.

    Resolve internationalization context API references once over the life cycle of an application component, within the initialization method of that component (for example, within the init method of servlets, or within the SetXxxContext method of enterprise beans). For Web service client programs, resolve a reference to the internationalization context API during initialization. For stateless session beans enabled for Web services, resolve the reference in the setSessionContext method.

  2. Access caller locales and time zones.

    Every remote invocation of an application component has an associated caller internationalization context associated with the thread that is running that invocation. A caller context is propagated by the internationalization service and middleware to the target of a request, such as an EJB business method or servlet service method. This task also applies to Web service client programs.

  3. Access invocation locales and time zones.

    Every remote invocation of a servlet service or EJB business method has an invocation internationalization context associated with the thread that is running that invocation. Invocation context is the internationalization context under which servlet and business method implementations run; it is propagated on subsequent invocations by the internationalization service and middleware. This task also applies to Web service client programs.

 

Result

The resulting components are said to use application-managed internationalization (AMI). For more information about AMI, see Internationalization context: Management policies.

 

Example

Each supported application component uses the internationalization context API differently. Three code examples are provided that illustrate how to use the API within each component type. Differences in API usage, as well as other coding tips, are noted in comments that precede the relevant statement blocks.

 

See also


Gaining access to the internationalization context API
Accessing caller locales and time zones
Accessing invocation locales and time zones
Example: Internationalization context in an EJB client program
Example: Internationalization context in a servlet
Example: Internationalization context in a session bean
Internationalization context API: Programming reference

 

See Also


Internationalization context: Management policies