On 14/12/11 18:44, Guy Pardon wrote:
My mistake,
Tried again and somehow it worked where it didn't before. Not sure what I did
wrong, sorry.
no problems, thanks for trying it,
Sergey
Guy
On 12-dec-2011, at 11:20, Sergey Beryozkin wrote:
Hi Guy
On 11/12/11 08:57, Guy Pardon wrote:
Hi,
I am trying to define a custom hypermedia model (cf REST in Practice) as the
return type of my REST service.
With MIME type "application/json" this works, but with type
"application/vnd.example-com.foo+json" (which is what I want) this fails, however.
Calling the service URL gives:
"org.apache.cxf.jaxrs.interceptor.JAXRSOutInterceptor writeResponseErrorMessage
WARNING: No message body writer has been found for response class ListResult."
My service method:
@GET
@Path("list")
@Produces("application/vnd.example-com.foo+json")
public ListResult retrieveList() {
return new ListResult();
}
My configuration code looks like this:
JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
JSONProvider prov = new JSONProvider();
// setting custom mime types does not seem to work?
List<String> mimeTypes = new ArrayList<String>();
mimeTypes.add("application/vnd.example-com.foo+json");
mimeTypes.add("application/json");
prov.setProduceMediaTypes(mimeTypes);
// following is regular CXF config as usual
prov.setDropRootElement(true);
sf.setProvider(prov);
sf.setResourceClasses(ListService.class);
sf.setResourceProvider(ListService.class,
new SingletonResourceProvider(new ListService()));
sf.setAddress("http://localhost:9000/");
sf.create();
Did I miss anything? I am using CXF 2.4.1...
I've updated one of the existing tests on the trunk and it works fine for me,
here is a trace:
----------------------------
ID: 1
Address: http://localhost:9000/the/bookstore/books/123
Http-Method: GET
Content-Type: */*
Headers: {Accept=[application/vnd.example-com.foo+json],
accept-encoding=[gzip;q=1.0, identity; q=0.5, *;q=0], Cache-Control=[no-cache],
connection=[keep-alive], content-type=[*/*], Host=[localhost:9000],
Pragma=[no-cache], User-Agent=[Java/1.6.0_26]}
--------------------------------------
12-Dec-2011 10:15:28 org.apache.cxf.interceptor.LoggingOutInterceptor
INFO: Outbound Message
---------------------------
ID: 1
Response-Code: 200
Content-Type: application/vnd.example-com.foo+json
Headers: {Date=[Mon, 12 Dec 2011 10:15:28 GMT]}
Payload: {"Book":{"id":123,"name":"CXF in Action"}}
I set produceMediaTypes on JSONProvider (from Spring),
can you confirm please
Accept: application/vnd.example-com.foo+json
is set on the wire, LoggingInInterceptor can help
Cheers, Sergey
Thanks
Guy