We have implemented a REST API in CXF. My goal is to be able to define custom annotations on a POJO and process them in a CXF interceptor before they get marshal'd. I believe I have all the information I need to be able to do this except for retrieving the actual object in the interceptor. My code looks like this:
Resource class
@Path("/mypath") public class MyResource { @GET public MyObject getObject() { MyObject o = new MyObject(); ... return o; } }
MyObject
public class MyObject { private String x; @MyAnnotation public String getX() { return x; } public String setX(x) { this.x = x; } }
Interceptor
public class MyInterceptor extends AbstractPhaseInterceptor<Message> { public VersionOutInterceptor() { super(Phase.POST_LOGICAL); } public final void handleMessage(Message message) { // 1. STUCK -- get object from the message // 2. parse annotations and manipulate the object // 3. put the object back on the message for serialization } }
How do I get the object from the message, manipulate it based on the annotations, and put it back on the message?