Description
Hi All.
I am writing RESTful API code using CXF.
For the versioning, we plan to implement based on Content-Type header.
For this, I'm trying to two ways but both of them aren't work.
1. Use different Consumes annotation at same class.
I try to set different Content-Type at same class, but it always work with one method.
@POST
@Path("/")
@Produces("application/json")
@Consumes("application/json; application,v=2")
public Response createProjectV2(Person person)
...
@POST
@Path("/")
@Produces("application/json")
@Consumes("application/json")
public Response createProject(Person person) { .... }
always "createProject" which has "application/json" on Consumes annotation.
2. Update Request URI at interceptor to use different serviceBean for differnt version.
public class CommonInInterceptorImpl implements RequestHandler{
public Response handleRequest(Message message , ClassResourceInfo resourceClass) {
...
String requestUri = (String)message.get(Message.REQUEST_URI);
String basePath = (String)message.get(Message.BASE_PATH);
String targetPath = basePath+"ver-"version"/"+requestUri.substring(basePath.length());
message.put(Message.CONTENT_TYPE, "application/json;application,v=2");
message.put(Message.REQUEST_URI, targetPath);
...
}
....
Service Bean 1
@Path(PersonService.PERSON_SERVICE_URL)
public class PersonService extends RESTApiHandler{
...
}
Service Bean 2 ( in different package )
@Path("/ver-2/"+com.tfsm.palette.api.rest.PersonService.PERSON_SERVICE_URL)
public class PersonService {
...
}
I update REQUEST_URI at interceptor to redirect request to other serviceBean, but request is processed orginal desired serviceBean.
( I expect redirect request to 2nd service Bean , but it always processed at 1st service Bean. )
I don't know whether 1st approach is correct in JAX RS spec, but I expect 2nd have to be work because it is mentioned at your documentation.
http://cxf.apache.org/docs/jax-rs-filters.html#JAX-RSFilters-OverridingrequestURI%2Cqueryandheaders
Could you let me know how we could redirect request to different serviceBean ?