Search

17.5. Create a Custom Auditor

download PDF

Prerequisities

  • CDI Runtime
  • Annotate your auditor implementations with @Named in order to have Camel recognize them.
    Note
    The Camel Exchange Bus looks for bean definitions with the @Audit annotation.
    Here is code that shows what a very simple auditor would look like:
                    
    @Audit
    @Named("custom auditor")
    public class SimpleAuditor implements Auditor {
     
        @Override
        public void beforeCall(Processors processor, Exchange exchange) {
            System.out.println("Before " + processor.name());
        }
     
        @Override
        public void afterCall(Processors processor, Exchange exchange) {
            System.out.println("After " + processor.name());
        }
     
    }
    
    Important
    Be aware that the afterCall method is not called if the step it surrounds throws an exception. If this happens, afterCall will be skipped.

Result

You can see many statements like 'Before DOMAIN_HANDLERS' and 'Before ADDRESSING' appearing in the server console. This is because every step of mediation is surrounded by this SimpleAuditor class.

Red Hat logoGithubRedditYoutubeTwitter

Learn

Try, buy, & sell

Communities

About Red Hat Documentation

We help Red Hat users innovate and achieve their goals with our products and services with content they can trust.

Making open source more inclusive

Red Hat is committed to replacing problematic language in our code, documentation, and web properties. For more details, see the Red Hat Blog.

About Red Hat

We deliver hardened solutions that make it easier for enterprises to work across platforms and environments, from the core datacenter to the network edge.

© 2024 Red Hat, Inc.