You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by drekbour <dr...@fastmail.fm> on 2010/12/30 17:29:24 UTC

ParameterHandler not invoked for Date parameter

There was a thread a while back on this
http://cxf.547215.n5.nabble.com/ParameterHandler-not-invoked-for-Date-parameter-tt2267734.html#a2839025

I copied the same handler code but the same issue doesn't seem to be
resolved
  @QueryParam("updated") Date updated
is not being picked up by 
<jaxrs:providers>
  <bean class="x.ISO8601TimestampParameterHandler" />
</jaxrs:providers>

The class signature is: public class ISO8601TimestampParameterHandler
implements ParameterHandler<Date> 

Of course the temporary (ugly) workaround is to take a string param then
run it through the same method in the server code but I'm sure we'd
rather not leave it like this.

Has anyone got a working example?

-- 
http://www.fastmail.fm - The way an email service should be


Re: ParameterHandler not invoked for Date parameter

Posted by Sergey Beryozkin <sb...@gmail.com>.
Hi

This has been fixed on the trunk, but what is also possible to do is to
register a custom
CXF JAX-RS RequestHandler filter (same way as the custom ExceptionMapper)
and have this filter replacing the value which is not recognized by the Date
constructor accepting String.

For ex, lets assume it's a query parameter.
So you can do

String query = message.get(Message.QUERY_STRING)

// replace it such that the default Date constructor works
query = replaceQueryStringAsNeeded(query);

message.put(Message.QUERY_STRING, query);

and then return 'null' from a handler to make sure the invocation is not
blocked.

If you have many query parameters then you can have a UriInfo instance
injected in the handler, use its getQueryParameters() which returns a map,
replace an individual parameter only and build a Message.QUERY_STRING from
this map.

You can deal similarly with matrix or header parameters - let me know please
if you need more info...

Cheers, Sergey

On Wed, Jan 12, 2011 at 8:54 PM, Sisyphus <in...@shaw.ca> wrote:

>
> Hi Sergey,
>
> I am wondering if there are any other elegant ways of managing a Date
> parameter given that the ParameterHandler does not currently work for this
> data type.
>
> The project I am working on currently uses String as the input type and
> then
> converts internally, but this is not an ideal solution.  Neither is
> creating
> our own wrapper data type.
>
> Look forward to your comments.
>
> Thanks, Ian
>
> --
> View this message in context:
> http://cxf.547215.n5.nabble.com/ParameterHandler-not-invoked-for-Date-parameter-tp3322606p3338853.html
> Sent from the cxf-user mailing list archive at Nabble.com.
>

Re: ParameterHandler not invoked for Date parameter

Posted by Sisyphus <in...@shaw.ca>.
Hi Sergey,

I am wondering if there are any other elegant ways of managing a Date
parameter given that the ParameterHandler does not currently work for this
data type.

The project I am working on currently uses String as the input type and then
converts internally, but this is not an ideal solution.  Neither is creating
our own wrapper data type.

Look forward to your comments.

Thanks, Ian

-- 
View this message in context: http://cxf.547215.n5.nabble.com/ParameterHandler-not-invoked-for-Date-parameter-tp3322606p3338853.html
Sent from the cxf-user mailing list archive at Nabble.com.

Re: ParameterHandler not invoked for Date parameter

Posted by Sergey Beryozkin <sb...@gmail.com>.
Hi

On Thu, Dec 30, 2010 at 4:46 PM, drekbour <dr...@fastmail.fm> wrote:

> Sorry for self-reply but I have checked the code (2.3.1) and this is
> because Date *does* have a String constructor - which fails to parse the
> provided input and errors out.



thanks for looking into it - it's helpful.


> If I have explicitly registered a
> handler for Date then either
> a) it should be attempted after the Date(String) before returning a
> failure
> b) it should be used in preference to the Date(String)
>
> I would think (b) is correct as there must be cases where users will
> want to override a default behaviour.
>
>
I probably agree. If the user registers a ParameterHandler which does
exactly what constructors or factory methods accepting Strings are supposed
to do then clearly a user is willing to affect the default behaviour.
However I might probably start first with optionally checking the handlers
in case of exceptions thrown from constructors like SomeType(String) or
SomeType.fromString()

thanks, Sergey


> On Thu, 30 Dec 2010 08:29 -0800, "drekbour" <dr...@fastmail.fm>
> wrote:
> > There was a thread a while back on this
> >
> http://cxf.547215.n5.nabble.com/ParameterHandler-not-invoked-for-Date-parameter-tt2267734.html#a2839025
> >
> > I copied the same handler code but the same issue doesn't seem to be
> > resolved
> >   @QueryParam("updated") Date updated
> > is not being picked up by
> > <jaxrs:providers>
> >   <bean class="x.ISO8601TimestampParameterHandler" />
> > </jaxrs:providers>
> >
> > The class signature is: public class ISO8601TimestampParameterHandler
> > implements ParameterHandler<Date>
> >
> > Of course the temporary (ugly) workaround is to take a string param then
> > run it through the same method in the server code but I'm sure we'd
> > rather not leave it like this.
> >
> > Has anyone got a working example?
> >
> > --
> > http://www.fastmail.fm - The way an email service should be
> >
> >
>
> --
> http://www.fastmail.fm - Send your email first class
>
>

Re: ParameterHandler not invoked for Date parameter

Posted by drekbour <dr...@fastmail.fm>.
Sorry for self-reply but I have checked the code (2.3.1) and this is
because Date *does* have a String constructor - which fails to parse the
provided input and errors out.  If I have explicitly registered a
handler for Date then either
a) it should be attempted after the Date(String) before returning a
failure
b) it should be used in preference to the Date(String)

I would think (b) is correct as there must be cases where users will
want to override a default behaviour.

On Thu, 30 Dec 2010 08:29 -0800, "drekbour" <dr...@fastmail.fm>
wrote:
> There was a thread a while back on this
> http://cxf.547215.n5.nabble.com/ParameterHandler-not-invoked-for-Date-parameter-tt2267734.html#a2839025
> 
> I copied the same handler code but the same issue doesn't seem to be
> resolved
>   @QueryParam("updated") Date updated
> is not being picked up by 
> <jaxrs:providers>
>   <bean class="x.ISO8601TimestampParameterHandler" />
> </jaxrs:providers>
> 
> The class signature is: public class ISO8601TimestampParameterHandler
> implements ParameterHandler<Date> 
> 
> Of course the temporary (ugly) workaround is to take a string param then
> run it through the same method in the server code but I'm sure we'd
> rather not leave it like this.
> 
> Has anyone got a working example?
> 
> -- 
> http://www.fastmail.fm - The way an email service should be
> 
> 

-- 
http://www.fastmail.fm - Send your email first class