[Version 5.0.2 and later]Accessing invocation locales and time zone

Before you begin

An application component must first resolve a reference to the InvocationInternationalization object and then bind it to the InvocationInternationalization interface of the internationalization context API.

Why and when to perform this task

Every remote invocation of a servlet service or EJB business method has an invocation internationalization context associated with the thread running that invocation. Invocation context is the internationalization context under which servlet and business method implementations execute; it is propagated on subsequent invocations by the internationalization service and middleware. Perform the following task to access elements of the invocation internationalization context.

[Version 5.0.2 and later]This task also applies to Web services clients and stateless session beans enabled for Web services.

Steps for this task

  1. Obtain the desired invocation context elements.
    java.util.Locale myLocale;
    try {
      myLocale = invocationI18n.getLocale();
    }
    catch (IllegalStateException ise) {
      // The invocation context is unavailable; 
      // is the service started and enabled?  
    }
    ...
    

    The InvocationInternationalization interface contains the following methods to both get and set invocation internationalization context elements:

    • Locale [] getLocales(). Returns the list of invocation locales associated with the current thread.
    • Locale getLocale(). Returns the first in the list of invocation locales associated with the current thread.
    • TimeZone getTimeZone(). Returns the invocation SimpleTimeZone associated with the current thread.
    • setLocales(Locale []). Sets the list of invocation locales associated with the current thread to the supplied list.
    • setLocale(Locale). Sets the list of invocation locales associated with the current thread to a list containing the supplied locale.
    • setTimeZone(TimeZone). Sets the invocation time zone associated with the current thread to the supplied SimpleTimeZone.
    • setTimeZone(String). Sets invocation time zone associated with the current thread to a SimpleTimeZone having the supplied ID.

    The InvocationInternalization interface allows read and write access to invocation internationalization context within application components. However, according to internationalization context management policies, only components configured to manage internationalization context (AMI components) have write access to invocation internationalization context elements. Calls to set invocation context elements within CMI application components result in a java.lang.IllegalStateException. Any differences in how application components can use InvocationInternationalization methods are explained in Internationalization context.

  2. Use the invocation context elements to localize a computation under a locale or time zone of the invoking process.
    DateFormat df = DateFormat.getDateInstance(myLocale);
      String localizedDate = df.getDateInstance().format(aDateInstance);
      ...

Example

In the following code example, locale (en,GB) and simple time zone (GMT) transparently propagate on the call to the myBusinessMethod() method. Server-side application components, such as myEjb, can use the InvocationInternationalization interface to obtain these context elements.

...
//--------------------------------------------------------------------
// Set the invocation context under which the business method or 
// servlet will execute and propagate on subsequent remote business 
// method invocations.
//--------------------------------------------------------------------
try {
  invocationI18n.setLocale(new Locale("en", "GB"));
  invocationI18n.setTimeZone(SimpleTimeZone.getTimeZone("GMT"));
}
catch (IllegalStateException ise) {
  // Is the component CMI; is the service started and enabled?  
}
myEjb.myBusinessMethod();

Within CMI application components, the Internationalization and InvocationInternationalization interfaces are semantically equivalent, and either of these interfaces can be used to obtain the context associated with the thread on which that component is running. For instance, both interfaces can be used to obtain the list of locales propagated to the servlet doPost() service method.


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



Searchable topic ID:   tin_accessinvoctz
Last updated: Jun 21, 2007 8:07:48 PM CDT    WebSphere Business Integration Server Foundation, Version 5.0.2
http://publib.boulder.ibm.com/infocenter/wasinfo/index.jsp?topic=/com.ibm.wasee.doc/info/ee/i18n/tasks/tin_accessinvoctz.html

Library | Support | Terms of Use | Feedback