You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by huntc <hu...@mac.com> on 2010/08/08 00:27:30 UTC
ParameterHandler not invoked for Date parameter
Hi there,
I've created a parameter handler to translate ISO8601 time strings into Java
Date objects but the handler does not appear to be invoked (I get a "Class
java.util.Date can not be instantiated using a constructor with a single
String argument" error).
My handler looks like this:
public class ISO8601ParameterHandler implements ParameterHandler {
@Override
public Date fromString(String s) {
return null;
}
}
My service declaration looks like this:
@GET
@Path("/GPSTrackerCollection/gpsTrackers/GPSTracker/history")
public Response getHistory(
@DefaultValue("90.0") @QueryParam("id") double boundedByTopLat,
@DefaultValue("-180.0") @QueryParam("boundedByLeftLong") double
boundedByLeftLong,
@DefaultValue("-90.0") @QueryParam("boundedByBottomLat") double
boundedByBottomLat,
@DefaultValue("180.0") @QueryParam("boundedByRightLong") double
boundedByRightLong,
@DefaultValue("20090808T00:00:00Z") @QueryParam("startValidTime") Date
startValidTime,
@DefaultValue("20090808T00:00:00Z") @QueryParam("endValidTime") Date
endValidTime,
@DefaultValue("10") @QueryParam("numTimeSlices") int numTimeSlices) {
I register it as follows:
<cxf:rsServer id="rsServer"
address="http://localhost:${com.classactionpl.gpstrackerservices.httpPort}"
serviceClass="com.classactionpl.gpsTrackerReference.GPSTrackerCollectionService"
staticSubresourceResolution="true">
<cxf:providers>
<bean
class="com.classactionpl.gpsTrackerReference.GPSTrackerCollectionProvider">
<property name="gpsTrackerCollectionTransformer"
ref="gpsTrackerCollectionTransformer" />
</bean>
<bean
class="com.classactionpl.gpsTrackerReference.ISO8601ParameterHandler" />
</cxf:providers>
</cxf:rsServer>
Any ideas or suggestions on a better way to pass dates using REST?
Kind regards,
Christopher
--
View this message in context: http://cxf.547215.n5.nabble.com/ParameterHandler-not-invoked-for-Date-parameter-tp2267734p2267734.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
can you please confirm you have
"implements ParameterHandler<Date>" ?
thanks, Sergey
On Sat, Sep 11, 2010 at 4:47 PM, huntc <hu...@mac.com> wrote:
>
> Hi Sergey,
>
> Sorry for the delayed reply; just got around to trying this again with your
> recommendation.
>
> Unfortunately my handler is still not getting invoked. Here's its current
> declaration:
>
>
> /**
> * Converts ISO8601 parameters into date objects.
> *
> * @author huntc
> *
> */
> @Provider
> public class ISO8601TimestampParameterHandler implements ParameterHandler {
>
> /**
> * Cooerce an ISO8601 time string to a date object.
> *
> * @param s
> * the string to parse.
> * @return the date object or null if the string cannot be parsed.
> */
> @Override
> public Date fromString(String s) {
> SimpleDateFormat dateFormat = new SimpleDateFormat(
> "yyyy-MM-dd'T'HH:mm:ss'Z'", Locale.US);
> dateFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
> try {
> return new Date(dateFormat.parse(s).getTime());
> } catch (ParseException e) {
> return null;
> }
> }
> }
>
>
> Any more thoughts?
>
> Kind regards,
> Christopher
> --
> View this message in context:
> http://cxf.547215.n5.nabble.com/ParameterHandler-not-invoked-for-Date-parameter-tp2267734p2836108.html
> Sent from the cxf-user mailing list archive at Nabble.com.
>
Re: ParameterHandler not invoked for Date parameter
Posted by huntc <hu...@mac.com>.
Hi Sergey,
Sorry for the delayed reply; just got around to trying this again with your
recommendation.
Unfortunately my handler is still not getting invoked. Here's its current
declaration:
/**
* Converts ISO8601 parameters into date objects.
*
* @author huntc
*
*/
@Provider
public class ISO8601TimestampParameterHandler implements ParameterHandler {
/**
* Cooerce an ISO8601 time string to a date object.
*
* @param s
* the string to parse.
* @return the date object or null if the string cannot be parsed.
*/
@Override
public Date fromString(String s) {
SimpleDateFormat dateFormat = new SimpleDateFormat(
"yyyy-MM-dd'T'HH:mm:ss'Z'", Locale.US);
dateFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
try {
return new Date(dateFormat.parse(s).getTime());
} catch (ParseException e) {
return null;
}
}
}
Any more thoughts?
Kind regards,
Christopher
--
View this message in context: http://cxf.547215.n5.nabble.com/ParameterHandler-not-invoked-for-Date-parameter-tp2267734p2836108.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 Sat, Aug 7, 2010 at 11:27 PM, huntc <hu...@mac.com> wrote:
>
> Hi there,
>
> I've created a parameter handler to translate ISO8601 time strings into
> Java
> Date objects but the handler does not appear to be invoked (I get a "Class
> java.util.Date can not be instantiated using a constructor with a single
> String argument" error).
>
> My handler looks like this:
>
>
> public class ISO8601ParameterHandler implements ParameterHandler {
>
> @Override
> public Date fromString(String s) {
> return null;
> }
>
> }
>
>
I've just checked the code, you need to implement ParameterHandler<Date> -
can you try it please ? Also returning null will also currently result in
the runtime assuming no ParameterHandler has been found...
thanks, Sergey
>
> My service declaration looks like this:
>
>
> @GET
> @Path("/GPSTrackerCollection/gpsTrackers/GPSTracker/history")
> public Response getHistory(
> @DefaultValue("90.0") @QueryParam("id") double boundedByTopLat,
> @DefaultValue("-180.0") @QueryParam("boundedByLeftLong") double
> boundedByLeftLong,
> @DefaultValue("-90.0") @QueryParam("boundedByBottomLat") double
> boundedByBottomLat,
> @DefaultValue("180.0") @QueryParam("boundedByRightLong") double
> boundedByRightLong,
> @DefaultValue("20090808T00:00:00Z") @QueryParam("startValidTime") Date
> startValidTime,
> @DefaultValue("20090808T00:00:00Z") @QueryParam("endValidTime") Date
> endValidTime,
> @DefaultValue("10") @QueryParam("numTimeSlices") int numTimeSlices) {
>
>
> I register it as follows:
>
>
> <cxf:rsServer id="rsServer"
>
> address="http://localhost:
> ${com.classactionpl.gpstrackerservices.httpPort}"
>
>
> serviceClass="com.classactionpl.gpsTrackerReference.GPSTrackerCollectionService"
> staticSubresourceResolution="true">
> <cxf:providers>
> <bean
>
>
> class="com.classactionpl.gpsTrackerReference.GPSTrackerCollectionProvider">
> <property name="gpsTrackerCollectionTransformer"
> ref="gpsTrackerCollectionTransformer" />
> </bean>
> <bean
> class="com.classactionpl.gpsTrackerReference.ISO8601ParameterHandler" />
> </cxf:providers>
> </cxf:rsServer>
>
>
> Any ideas or suggestions on a better way to pass dates using REST?
>
> Kind regards,
> Christopher
> --
> View this message in context:
> http://cxf.547215.n5.nabble.com/ParameterHandler-not-invoked-for-Date-parameter-tp2267734p2267734.html
> Sent from the cxf-user mailing list archive at Nabble.com.
>