JAX-RS offers a great way to specify content types in @Produces, and the structure will automatically determine the best content type from the client HTTP Acceptheader and, miraculously, it even converts your object to this type (for example, XML using JAXB or JSON using Jackson) when returning information to the caller.
My (working) client, as clients often do, simplified the work by asking me to specify the type of content with an extension in the URL, for example. api/widgets.json. This will make me have different methods getWidgetsXXX(), one with @Produces("application/json"), the other with @Produces("application/xml"), etc.
But I use Apache CXF, and I was glad to find that I could configure CXF to map various content type extensions using jaxrs.extensionsthe init parameter!
<init-param>
<param-name>jaxrs.extensions</param-name>
<param-value>
xml=application/xml
json=application/json
</param-value>
</init-param>
But I can not find absolutely no documentation on how this works in the real world. I naively thought that I could just comment on the method using the extension path, and it would mimic the header Accepts:
@Path("/widgets.{extension}")
@GET
@Produces({ "application/json", "application/xml" })
public List<Widget> getWidgets();
So I call it using api/widgets.json, and it returns XML! Which is especially strange because JAX-RS indicates that the default content type is first.
Where can I find out how to use the CXF extension content type mapping?
PS I do not use Spring.
source
share