Passing a custom object through context in JAX-RS CXF

I have an InInterceptor that receives some information from HTTPHeaders and creates a custom object

public void handleMessage(Message message) throws Fault {
    final HttpServletRequest request = (HttpServletRequest) message
            .get(AbstractHTTPDestination.HTTP_REQUEST);
    String a= request.getHeader("A");
    String b= request.getHeader("B");
    message.put("CustomObject", new CustomObject(a,b));
}

Then in the maintenance methods, I use the code below to get a custom object

final Message message = PhaseInterceptorChain.getCurrentMessage();
final CustomObject customObject=(CustomObject)message.getContextualProperty("CustomObject");

I was wondering if this is possible to get via @Context ..

@GET
@Path("/custom")
@Produces("application/json")
public List<Node> getA(@Context("CustomObject") String user) throws XYZException;

thank

+3
source share

All Articles