Skip to main content
August 4, 2008
Answered

SetLocale no effect in event gateway

  • August 4, 2008
  • 3 replies
  • 2417 views
SetLocale() is ignored when a CFC is called through an event gateway. SetLocale() works fine when called through an ordinary HTTP request. When called through the gateway the locale is always set as default locale that the server JVM instance was installed with.

Does anybody have a workaround for this?
We use MX7.

Here is some example code if you want to test:
<cfset message = StructNew()>
<cfset message.method = "onTest">
<cfset pushQueue = SendGatewayMessage("LocaleTest",message)>

Create a gateway "LocaleTest" pointing to "LocaleText.cfc" which looks like this:
<cfcomponent>

<cffunction name="onTest" output="no">
<cfargument name="CFEvent" type="struct" required="yes">

<!--- choose a different locale then your server default --->
<cfset SetLocale("en_GB")>
<cffile action="append" file="c:\temp.log" output="#GetLocale()#">

</cffunction>

</cfcomponent>

You can find the output in c:{temp.log, you will see it doesnt take the locale set by SetLocale()
This topic has been closed for replies.
Correct answer Newsgroup_User
Leo_CF wrote:
> SetLocale() is ignored when a CFC is called through an event gateway.
> SetLocale() works fine when called through an ordinary HTTP request. When
> called through the gateway the locale is always set as default locale that the
> server JVM instance was installed with.

ok, i can confirm for asynch gateways.

> Does anybody have a workaround for this?

not sure i'd class this as a "workaround" as it's pretty drastic & i have not
tested for any side effects but this "works":

<cfscript>
locale=createObject("java","java.util.Locale");
thisLocale=locale.init("th","TH");
originalLocale=locale.getDefault();
locale.setDefault(thisLocale);
</cfscript>

<!--- note that cflog doesn't do unicode --->
<cflog text="#getLocale()# ::: #LSdateFormat(now(),'FULL')#" file="localeTest">

<cfscript>
// return to original locale
locale.setDefault(originalLocale);
</cfscript>

3 replies

Inspiring
August 7, 2008
the cf team's been made aware of this & they've found the problem already. i don't have a timeline but it *will* get fixed.


btw don't forget to var scope that locale stuff.
Newsgroup_UserCorrect answer
Inspiring
August 6, 2008
Leo_CF wrote:
> SetLocale() is ignored when a CFC is called through an event gateway.
> SetLocale() works fine when called through an ordinary HTTP request. When
> called through the gateway the locale is always set as default locale that the
> server JVM instance was installed with.

ok, i can confirm for asynch gateways.

> Does anybody have a workaround for this?

not sure i'd class this as a "workaround" as it's pretty drastic & i have not
tested for any side effects but this "works":

<cfscript>
locale=createObject("java","java.util.Locale");
thisLocale=locale.init("th","TH");
originalLocale=locale.getDefault();
locale.setDefault(thisLocale);
</cfscript>

<!--- note that cflog doesn't do unicode --->
<cflog text="#getLocale()# ::: #LSdateFormat(now(),'FULL')#" file="localeTest">

<cfscript>
// return to original locale
locale.setDefault(originalLocale);
</cfscript>
August 6, 2008
Thanks Paul, that works! I will do some extra testing to look for any side-effects
Inspiring
August 6, 2008
Leo_CF wrote:
> SetLocale() is ignored when a CFC is called through an event gateway.
> SetLocale() works fine when called through an ordinary HTTP request. When
> called through the gateway the locale is always set as default locale that the
> server JVM instance was installed with.

what kind of gateway?