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