How to get Cxfrs:server input and output types

83 views Asked by At

I'm trying to build Response according to the output type specified in cxfrs:server service class.

@Consumes({MediaType.APPLICATION_JSON}) @Produces({"application/xml"})

How can I get the Consumes type and Produces type using cxf interceptor.

1

There are 1 answers

0
pedrofb On

You can get this information from OperationResourceInfo The interceptor should looks like this

public class MyInterceptor extends AbstractPhaseInterceptor<Message> {
    public MyInterceptor () {
        super(Phase.RECEIVE);
    }

    public void handleMessage(Message message) {
       OperationResourceInfo m = message.getExchange().get(OperationResourceInfo.class);
       List<javax.ws.rs.core.MediaType> consumes = m.getConsumeTypes();
       List<javax.ws.rs.core.MediaType> produces = m.getProduceTypes();
    }

    public void handleFault(Message messageParam) {
        //Invoked when interceptor fails
    }
}

Remember to add a in or out interceptor to your endpoint