You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by srinivas thallapalli <sr...@gmail.com> on 2013/03/08 15:23:13 UTC
dateTime usage in CXf Restful service
Hello,
Can anybody please explain, how I can use dateTime datatype as parameter in
restful services?
Thanks
--
View this message in context: http://cxf.547215.n5.nabble.com/dateTime-usage-in-CXf-Restful-service-tp5724306.html
Sent from the cxf-user mailing list archive at Nabble.com.
Re: dateTime usage in CXf Restful service
Posted by srinivas thallapalli <sr...@gmail.com>.
Thanks Sergey.
Now I changed my client code to use URI with String time and converting to
java.util.Date with ParameterHandler and it all works fine.
Thanks once again!! :)
--
View this message in context: http://cxf.547215.n5.nabble.com/dateTime-usage-in-CXf-Restful-service-tp5724306p5724605.html
Sent from the cxf-user mailing list archive at Nabble.com.
Re: dateTime usage in CXf Restful service
Posted by Sergey Beryozkin <sb...@gmail.com>.
On 14/03/13 13:56, srinivas thallapalli wrote:
> Hi Sergey,
>
> I have created a ParameterHandler for java.util.Date type as follows
>
> import java.util.Date;
>
> import org.apache.cxf.jaxrs.ext.ParameterHandler;
>
> public class DateTypeHandler implements ParameterHandler<Date>{
>
> @Override
> public Date fromString(String arg0) {
> // TODO Auto-generated method stub
>
> System.out.println("From DateTypeHandler.fromString() "+ arg0);
> return new Date(arg0);
> }
>
> }
>
> For testing purpose, i have registered this date handler with server and
> client using setProviders()
>
> Server Code:
>
>
> JAXRSServerFactoryBean restServer = new
> JAXRSServerFactoryBean();
> restServer.setResourceClasses(Student.class);
> restServer.setServiceBean(studentService);
> list providers = new ArrayList();
> providers.add(new DateTypeHandler());
> restServer.setProviders(providers);
> restServer.setAddress("http://localhost:9000/");
>
> ClientCode:
>
> List providers = new ArrayList();
> providers.add(new DateTypeHandler());
> WebClient client4 =
> WebClient.create("http://localhost:9000/students", providers);
>
> Client4.path("/date/").accept(MediaType.APPLICATION_OCTET_STREAM).
> type(MediaType.APPLICATION_OCTET_STREAM);
> Date date = new Date();
> System.out.println(" The date sent from client is " + date);
> client4.post(date);
>
> But still I am getting the exception as follows
>
> ... 5 more
> Caused by: org.apache.cxf.jaxrs.client.ClientWebApplicationException: .No
> message body writer has been found for class : class java.util.Date,
> ContentType : application/octet-stream.
> at
> org.apache.cxf.jaxrs.client.AbstractClient.reportMessageHandlerProblem(AbstractClient.java:596)
> at
> org.apache.cxf.jaxrs.client.AbstractClient.writeBody(AbstractClient.java:403)
> at
> org.apache.cxf.jaxrs.client.WebClient$BodyWriter.handleMessage(WebClient.java:878)
> ... 7 more
>
>
Looks like you are posting Date as a body, but you said earlier that you
actually have to get it passed as part of request URI ?
If you actually do need to pass it within the message body, then simply
convert it to String and post it, do not have to deal with the providers
at all, same on the server side, just type String in the signature
Cheers, Sergey
> Am I missing anything? Thanks for the help.
>
>
>
>
>
> --
> View this message in context: http://cxf.547215.n5.nabble.com/dateTime-usage-in-CXf-Restful-service-tp5724306p5724568.html
> Sent from the cxf-user mailing list archive at Nabble.com.
--
Sergey Beryozkin
Talend Community Coders
http://coders.talend.com/
Blog: http://sberyozkin.blogspot.com
Re: dateTime usage in CXf Restful service
Posted by srinivas thallapalli <sr...@gmail.com>.
Hi Sergey,
I have created a ParameterHandler for java.util.Date type as follows
import java.util.Date;
import org.apache.cxf.jaxrs.ext.ParameterHandler;
public class DateTypeHandler implements ParameterHandler<Date>{
@Override
public Date fromString(String arg0) {
// TODO Auto-generated method stub
System.out.println("From DateTypeHandler.fromString() "+ arg0);
return new Date(arg0);
}
}
For testing purpose, i have registered this date handler with server and
client using setProviders()
Server Code:
JAXRSServerFactoryBean restServer = new
JAXRSServerFactoryBean();
restServer.setResourceClasses(Student.class);
restServer.setServiceBean(studentService);
list providers = new ArrayList();
providers.add(new DateTypeHandler());
restServer.setProviders(providers);
restServer.setAddress("http://localhost:9000/");
ClientCode:
List providers = new ArrayList();
providers.add(new DateTypeHandler());
WebClient client4 =
WebClient.create("http://localhost:9000/students", providers);
Client4.path("/date/").accept(MediaType.APPLICATION_OCTET_STREAM).
type(MediaType.APPLICATION_OCTET_STREAM);
Date date = new Date();
System.out.println(" The date sent from client is " + date);
client4.post(date);
But still I am getting the exception as follows
... 5 more
Caused by: org.apache.cxf.jaxrs.client.ClientWebApplicationException: .No
message body writer has been found for class : class java.util.Date,
ContentType : application/octet-stream.
at
org.apache.cxf.jaxrs.client.AbstractClient.reportMessageHandlerProblem(AbstractClient.java:596)
at
org.apache.cxf.jaxrs.client.AbstractClient.writeBody(AbstractClient.java:403)
at
org.apache.cxf.jaxrs.client.WebClient$BodyWriter.handleMessage(WebClient.java:878)
... 7 more
Am I missing anything? Thanks for the help.
--
View this message in context: http://cxf.547215.n5.nabble.com/dateTime-usage-in-CXf-Restful-service-tp5724306p5724568.html
Sent from the cxf-user mailing list archive at Nabble.com.
Re: dateTime usage in CXf Restful service
Posted by Sergey Beryozkin <sb...@gmail.com>.
On 14/03/13 10:32, srinivas thallapalli wrote:
> Yes, We want to pass the date from URI, let's PathParam.
>
> Thanks
>
In this case, as I suggested earlier, use CXF ParameterHandler, or just
pass it as a String to the method and parse it manually inside the method
Sergey
>
>
> --
> View this message in context: http://cxf.547215.n5.nabble.com/dateTime-usage-in-CXf-Restful-service-tp5724306p5724543.html
> Sent from the cxf-user mailing list archive at Nabble.com.
Re: dateTime usage in CXf Restful service
Posted by srinivas thallapalli <sr...@gmail.com>.
Yes, We want to pass the date from URI, let's PathParam.
Thanks
--
View this message in context: http://cxf.547215.n5.nabble.com/dateTime-usage-in-CXf-Restful-service-tp5724306p5724543.html
Sent from the cxf-user mailing list archive at Nabble.com.
Re: dateTime usage in CXf Restful service
Posted by Sergey Beryozkin <sb...@gmail.com>.
Hi
On 13/03/13 06:40, srinivas thallapalli wrote:
> Hi Sergey,
>
> I wrote Message Body Reader and Writer providers for java.util.Date type and
> observered that providers works with streams, But in this case how the how
> .Net client can call this service? does the CXF takes care of the streams
> interoperability issues?.
>
How is that Date representation is passed from a .NET client ? Is it
part of the request URI, which is what I thought ?
Cheers, Sergey
> Thanks
>
>
>
> --
> View this message in context: http://cxf.547215.n5.nabble.com/dateTime-usage-in-CXf-Restful-service-tp5724306p5724487.html
> Sent from the cxf-user mailing list archive at Nabble.com.
Re: dateTime usage in CXf Restful service
Posted by srinivas thallapalli <sr...@gmail.com>.
Hi Sergey,
I wrote Message Body Reader and Writer providers for java.util.Date type and
observered that providers works with streams, But in this case how the how
.Net client can call this service? does the CXF takes care of the streams
interoperability issues?.
Thanks
--
View this message in context: http://cxf.547215.n5.nabble.com/dateTime-usage-in-CXf-Restful-service-tp5724306p5724487.html
Sent from the cxf-user mailing list archive at Nabble.com.
Re: dateTime usage in CXf Restful service
Posted by Sergey Beryozkin <sb...@gmail.com>.
On 09/03/13 08:25, srinivas thallapalli wrote:
> Thanks Sergey..
>
>
> Could you please provide links for examples of both ParameterHandler and
> ParameterConverter.
>
See a basic example at the end of
http://svn.apache.org/repos/asf/cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/JAXRSUtilsTest.java
Cheers, Sergey
> Thanks
>
>
>
> --
> View this message in context: http://cxf.547215.n5.nabble.com/dateTime-usage-in-CXf-Restful-service-tp5724306p5724329.html
> Sent from the cxf-user mailing list archive at Nabble.com.
--
Sergey Beryozkin
Talend Community Coders
http://coders.talend.com/
Blog: http://sberyozkin.blogspot.com
Re: dateTime usage in CXf Restful service
Posted by srinivas thallapalli <sr...@gmail.com>.
Thanks Sergey..
Could you please provide links for examples of both ParameterHandler and
ParameterConverter.
Thanks
--
View this message in context: http://cxf.547215.n5.nabble.com/dateTime-usage-in-CXf-Restful-service-tp5724306p5724329.html
Sent from the cxf-user mailing list archive at Nabble.com.
Re: dateTime usage in CXf Restful service
Posted by Sergey Beryozkin <sb...@gmail.com>.
Hi
On 08/03/13 14:23, srinivas thallapalli wrote:
> Hello,
>
> Can anybody please explain, how I can use dateTime datatype as parameter in
> restful services?
Register CXF ParameterHandler as jaxrs:provider or if you on CXF 2.7.x
then JAX-RS 2.0 ParameterConverter
Cheers, Sergey
>
> Thanks
>
>
>
> --
> View this message in context: http://cxf.547215.n5.nabble.com/dateTime-usage-in-CXf-Restful-service-tp5724306.html
> Sent from the cxf-user mailing list archive at Nabble.com.