How to create an interceptor for Apache Camel Route in Spring boot application

I have a simple route defined and for this route I want to define an outgoing interceptor so that on any request done, I would invoke an enricher that sets specific header.

from("direct:remoteService")
  .routeId("direct-route")
  .tracing()
  .log(">>> ${body.id}")
  .log(">>> ${body.name}")
  .process(new Processor() {
      @Override
      public void process(Exchange exchange) throws Exception {
          MyBean bodyIn = (MyBean) exchange.getIn().getBody();
          ExampleServices.example(bodyIn);
          exchange.getIn().setBody(bodyIn);
      }
  })
  .setHeader(Exchange.HTTP_RESPONSE_CODE, constant(200));

I've tried to define an implementation of AbstractPhaseInterceptor but it is not invoked. What am I doing wrong?

@OutInterceptors
public class HeaderEnricherInterceptor extends AbstractPhaseInterceptor<Message> {


    public HeaderEnricherInterceptor() {
        super(Phase.POST_PROTOCOL);
    }

    @Override
    public void handleMessage(Message message) {
        log.debug("Message interceptor start enrichment...");
    }
}

1 answer

How many English words
do you know?
Test your English vocabulary size, and measure
how many words do you know
Online Test
Powered by Examplum