>Resource class
@Path("/mypath")
public class MyResource {
@GET
public MyObject getObject() {
MyObject o = new MyObject();
...
return o;
}
}
> MyObject
< pre>public class MyObject {
private String x;
@MyAnnotation
public String getX() {
return x;
}
public String setX(x) {
this.x = x;
}
}
>Interceptor
< p>
public class MyInterceptor extends AbstractPhaseInterceptor{
public VersionOutInterceptor() {
super(Phase.POST_LOGICAL);
}
public final void handleMessage(Message message) {
// 1. STUCK - get object from the message
// 2. par se annotations and manipulate the object
// 3. put the object back on the message for serialization
}
}
How to get the object from the message, according to the comment Does it operate and put it back in the message?
For the In Interceptor, I used the PRE_INVOKE stage and the Out Interceptor PRE_LOGICAL stage.
This code only shows the log records, but you can change the object as needed.
The code below will get you The object to look for
@Override
public void handleMessage(Message message) throws Fault {
MessageContentsList objs = MessageContentsList.getContentsList(message);
if (objs != null && objs.size() == 1) {
Object responseObj = objs.get(0);
DomainPOJO do= (DomainPOJO)responseObj;
_logger. info(do.toString());
}
}
We have implemented a REST API in CXF. My goal is to be able to Define custom annotations on the POJO and process them in the CXF interceptor before they get marshalled. I believe that in addition to retrieving the actual objects in the interceptor, I also need all the information to be able to do this. My code looks like 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{
public VersionOutInterceptor() {
super(Phase.POST_LOGICAL);
}
< br /> 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 to get the object from the message, manipulate it according to the comment, and put it back in the message?
I have similar requirements, this is what I can do
For In Interceptor, I used the PRE_INVOKE stage And Out Interceptor PRE_LOGICAL stage.
This code only shows log records, but you can change the object as you need.
The following code will get the object you are looking for
p>
@Override
public void handleMessage(Message message) throws Fault {
MessageContentsList objs = MessageContentsList.getContentsList(message);
if (objs != null && objs.size( ) == 1) {
Object responseObj = objs.get(0);
DomainPOJO do = (DomainPOJO)responseObj;
_logger.info(do.toString());
}
}