Enterprise JavaBeans (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.
Before you begin
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.
Procedure
- 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.
- 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 Enterprise JavaBeans (EJB) business method or servlet service method.
This task also applies to Web service client programs.
- Access invocation
locales and time zones.
Every remote invocation of a servlet service
or Enterprise JavaBeans (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.
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.