You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by Coder One <co...@yahoo.com> on 2008/06/13 08:32:41 UTC
Rest Service & Locale
My REST calls need to deal with locale. What's the recommended way to obtain a locale setting from the client?
Thanks,
Re: Rest Service & Loc
Posted by Benson Margulies <bi...@gmail.com>.
Users often find themselves using a browser which sends accept-language
headers which do not actually reflect their preferences. This is why web
sites are in the habit of offering an explicit UI (often a set of flags) for
the purpose.
My day job has a large aspect of I18N consulting (see www.basistech.com) so
I know a bit about this.
Re: Rest Service & Loca
Posted by Coder One <co...@yahoo.com>.
The client software can always specify locale using Accept-Language esp. if the transport is HTTP...where user makes the locale choice can be made moot.
--- On Fri, 6/13/08, Benson Margulies <bi...@gmail.com> wrote:
> From: Benson Margulies <bi...@gmail.com>
> Subject: Re: Rest Service & Loca
> To: users@cxf.apache.org, coder_lol@yahoo.com
> Date: Friday, June 13, 2008, 7:06 PM
> Just using accept-language is asking for trouble. Not
> everyone wants to see
> the language their browser is configured to return. Best to
> have explicit
> UI.
Re: Rest Service & Loca
Posted by Benson Margulies <bi...@gmail.com>.
Just using accept-language is asking for trouble. Not everyone wants to see
the language their browser is configured to return. Best to have explicit
UI.
Re: Rest Service & Local
Posted by Coder One <co...@yahoo.com>.
This looks great. I was heading down the @Context WebServiceContext but I do like the headers.getLanguage() call...
Thanks...
--- On Fri, 6/13/08, Sergey Beryozkin <se...@iona.com> wrote:
> From: Sergey Beryozkin <se...@iona.com>
> Subject: Re: Rest Service & Local
> To: users@cxf.apache.org, coder_lol@yahoo.com
> Date: Friday, June 13, 2008, 10:00 AM
> With JAX-RS you can inject
>
> @Contex HttpHeaders headers
>
> as a parameter and then do headers.getLanguage()
>
> assuming you're using Accept-Language parameter
>
> Alternatively, if you have a request Accept header set like
> this :
>
> Accept : application/json;charset=value1
>
> then you can do
>
> List<MediaType> types =
> headers.getAcceptableMediaTypes();
>
> and then for every MediaType you can do
>
> type.getParameter("charset")
>
>
> Cheers, Sergey
>
>
> ----- Original Message -----
> From: "Benson Margulies"
> <bi...@gmail.com>
> To: <us...@cxf.apache.org>;
> <co...@yahoo.com>
> Sent: Friday, June 13, 2008 12:19 PM
> Subject: Re: Rest Service & Local
>
>
> > Add it as a parameter.
> >
> > On Fri, Jun 13, 2008 at 2:32 AM, Coder One
> <co...@yahoo.com> wrote:
> >
> >> My REST calls need to deal with locale.
> What's the recommended way to
> >> obtain a locale setting from the client?
> >>
> >> Thanks,
> >>
> >>
> >>
> >>
> >>
> >>
> >>
> >
>
> ----------------------------
> IONA Technologies PLC (registered in Ireland)
> Registered Number: 171387
> Registered Address: The IONA Building, Shelbourne Road,
> Dublin 4, Ireland
Re: Rest Service & Local
Posted by Sergey Beryozkin <se...@iona.com>.
My apologies for the confusion, HttpHeadersImpl,getLanguage() does indeed return the value of the Content-Language header, the
latest version of HttpHeaders (starting from 0.8 api) actually has the method you're suggesting [1].
So looks like the simpliest way with 0.6 api to get to the Accept-Language is to do
@HeaderParam("Accept-Language") String headerValue
in a method signature and then do the custom processing of this value,
or may be do something like
@Context HttpHeaders headers
and then
List<String> values = headers.getRequestHeaders().get("Accept-Language");
Cheers, Sergey
[1] https://jsr311.dev.java.net/nonav/releases/0.8/index.html
----- Original Message -----
From: "Coder One" <co...@yahoo.com>
To: <us...@cxf.apache.org>
Sent: Friday, June 13, 2008 11:45 PM
Subject: Re: Rest Service & Local
> It seems like the CXF HttpHeadersImpl actually returns Content-Language and not Accept-Language.
>
> This seems like an standard JAX-RS API miss. If the response needs to be formatted by a locale, the rest code needs to extract
> and parses accept-language by itself.
>
----------------------------
IONA Technologies PLC (registered in Ireland)
Registered Number: 171387
Registered Address: The IONA Building, Shelbourne Road, Dublin 4, Ireland
Re: Rest Service & Local
Posted by Coder One <co...@yahoo.com>.
It seems like the CXF HttpHeadersImpl actually returns Content-Language and not Accept-Language.
This seems like an standard JAX-RS API miss. If the response needs to be formatted by a locale, the rest code needs to extract and parses accept-language by itself.
--- On Fri, 6/13/08, Coder One <co...@yahoo.com> wrote:
> From: Coder One <co...@yahoo.com>
> Subject: Re: Rest Service & Local
> To: users@cxf.apache.org
> Date: Friday, June 13, 2008, 3:03 PM
> It's interesting to note that per HTTP, Accept-Language
> lists a set of language with a "preference"
> value.
>
> I wonder why the standard API does not do a String[]
> headers.getLanguages() with the array sorted by order of
> language preference...
>
> Thanks...
>
> --- On Fri, 6/13/08, Sergey Beryozkin
> <se...@iona.com> wrote:
>
> > From: Sergey Beryozkin
> <se...@iona.com>
> > Subject: Re: Rest Service & Local
> > To: users@cxf.apache.org, coder_lol@yahoo.com
> > Date: Friday, June 13, 2008, 10:00 AM
> > With JAX-RS you can inject
> >
> > @Contex HttpHeaders headers
> >
> > as a parameter and then do headers.getLanguage()
> >
> > assuming you're using Accept-Language parameter
> >
> > Alternatively, if you have a request Accept header set
> like
> > this :
> >
> > Accept : application/json;charset=value1
> >
> > then you can do
> >
> > List<MediaType> types =
> > headers.getAcceptableMediaTypes();
> >
> > and then for every MediaType you can do
> >
> > type.getParameter("charset")
> >
> >
> > Cheers, Sergey
> >
> >
> > ----- Original Message -----
> > From: "Benson Margulies"
> > <bi...@gmail.com>
> > To: <us...@cxf.apache.org>;
> > <co...@yahoo.com>
> > Sent: Friday, June 13, 2008 12:19 PM
> > Subject: Re: Rest Service & Local
> >
> >
> > > Add it as a parameter.
> > >
> > > On Fri, Jun 13, 2008 at 2:32 AM, Coder One
> > <co...@yahoo.com> wrote:
> > >
> > >> My REST calls need to deal with locale.
> > What's the recommended way to
> > >> obtain a locale setting from the client?
> > >>
> > >> Thanks,
> > >>
> > >>
> > >>
> > >>
> > >>
> > >>
> > >>
> > >
> >
> > ----------------------------
> > IONA Technologies PLC (registered in Ireland)
> > Registered Number: 171387
> > Registered Address: The IONA Building, Shelbourne
> Road,
> > Dublin 4, Ireland
Re: Rest Service & Local
Posted by Coder One <co...@yahoo.com>.
It's interesting to note that per HTTP, Accept-Language lists a set of language with a "preference" value.
I wonder why the standard API does not do a String[] headers.getLanguages() with the array sorted by order of language preference...
Thanks...
--- On Fri, 6/13/08, Sergey Beryozkin <se...@iona.com> wrote:
> From: Sergey Beryozkin <se...@iona.com>
> Subject: Re: Rest Service & Local
> To: users@cxf.apache.org, coder_lol@yahoo.com
> Date: Friday, June 13, 2008, 10:00 AM
> With JAX-RS you can inject
>
> @Contex HttpHeaders headers
>
> as a parameter and then do headers.getLanguage()
>
> assuming you're using Accept-Language parameter
>
> Alternatively, if you have a request Accept header set like
> this :
>
> Accept : application/json;charset=value1
>
> then you can do
>
> List<MediaType> types =
> headers.getAcceptableMediaTypes();
>
> and then for every MediaType you can do
>
> type.getParameter("charset")
>
>
> Cheers, Sergey
>
>
> ----- Original Message -----
> From: "Benson Margulies"
> <bi...@gmail.com>
> To: <us...@cxf.apache.org>;
> <co...@yahoo.com>
> Sent: Friday, June 13, 2008 12:19 PM
> Subject: Re: Rest Service & Local
>
>
> > Add it as a parameter.
> >
> > On Fri, Jun 13, 2008 at 2:32 AM, Coder One
> <co...@yahoo.com> wrote:
> >
> >> My REST calls need to deal with locale.
> What's the recommended way to
> >> obtain a locale setting from the client?
> >>
> >> Thanks,
> >>
> >>
> >>
> >>
> >>
> >>
> >>
> >
>
> ----------------------------
> IONA Technologies PLC (registered in Ireland)
> Registered Number: 171387
> Registered Address: The IONA Building, Shelbourne Road,
> Dublin 4, Ireland
Re: Rest Service & Local
Posted by Sergey Beryozkin <se...@iona.com>.
With JAX-RS you can inject
@Contex HttpHeaders headers
as a parameter and then do headers.getLanguage()
assuming you're using Accept-Language parameter
Alternatively, if you have a request Accept header set like this :
Accept : application/json;charset=value1
then you can do
List<MediaType> types = headers.getAcceptableMediaTypes();
and then for every MediaType you can do
type.getParameter("charset")
Cheers, Sergey
----- Original Message -----
From: "Benson Margulies" <bi...@gmail.com>
To: <us...@cxf.apache.org>; <co...@yahoo.com>
Sent: Friday, June 13, 2008 12:19 PM
Subject: Re: Rest Service & Local
> Add it as a parameter.
>
> On Fri, Jun 13, 2008 at 2:32 AM, Coder One <co...@yahoo.com> wrote:
>
>> My REST calls need to deal with locale. What's the recommended way to
>> obtain a locale setting from the client?
>>
>> Thanks,
>>
>>
>>
>>
>>
>>
>>
>
----------------------------
IONA Technologies PLC (registered in Ireland)
Registered Number: 171387
Registered Address: The IONA Building, Shelbourne Road, Dublin 4, Ireland
Re: Rest Service & Local
Posted by Benson Margulies <bi...@gmail.com>.
Add it as a parameter.
On Fri, Jun 13, 2008 at 2:32 AM, Coder One <co...@yahoo.com> wrote:
> My REST calls need to deal with locale. What's the recommended way to
> obtain a locale setting from the client?
>
> Thanks,
>
>
>
>
>
>
>