2

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.

tvshajeer
  • 1,299
  • 2
  • 12
  • 26

1 Answers1

1

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

pedrofb
  • 37,271
  • 5
  • 94
  • 142