访问调用语言环境和时区
执行此任务以访问调用国际化上下文的元素。
开始之前
应用程序组件首先必须解析对 InvocationInternationalization 对象的引用,然后将它绑定到国际化上下文 API 的 InvocationInternationalization 接口。
关于此任务
servlet 服务或 Enterprise JavaBeans (EJB) 业务方法的每个远程调用都有一个与运行该调用的线程关联的调用国际化上下文。调用上下文是 servlet 和业务方法实现运行所在的国际化上下文;国际化服务和中间件将在后续调用中传播它。此任务还适用于 Web Service 客户机程序。
过程
示例
在以下代码示例中,语言环境 (en,GB) 和简单时区 (GMT) 在对 myBusinessMethod 方法的调用中进行透明传播。服务器端应用程序组件(如 myEjb)可以使用 InvocationInternationalization 接口来获取这些上下文元素。
...
//--------------------------------------------------------------------
// Set the invocation context under which the business method or
// servlet will run 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();
在 CMI 应用程序组件中,Internationalization 和 InvocationInternationalization 接口在语义上是等效的。您可以使用这两个接口中的任何一个来获取与组件运行所在的线程关联的上下文。例如,这两个接口都可以用于获取传播到 servlet doPost 服务方法的语言环境列表。