0

I am trying to follow through example but not able to find a tangible one to help me understand how to trace all method calls and it's arguments within a particular method (based on elementMatcher)

The method I'd like to trace is getCustomer and intending to use ByteBuddy to get metadata of all methods called within getCustomer along with accessing all arguments passed to each method

eg. Would like to print out methods

i) customerRepository.findOne , with customerId value as argument

ii) log.info with customer value as argument

and so on ... with return value

public Customer getCustomer(@PathVariable("customerId") Long customerId) {

        /* validate customer Id parameter */
        if (null == customerId) {
            throw new InvalidCustomerRequestException();
        }

        Customer customer = customerRepository.findOne(customerId);

        if (null == customer) {
            throw new CustomerNotFoundException();
        }

        log.info("Customer Data is {}", customer);

        try {
            dispatchEventToSalesForce(String.format(" Customer %s Logged into SalesForce", customer));
        } catch (Exception e) {
            log.error("Failed to Dispatch Event to SalesForce . Details {} ", e.getLocalizedMessage());

        }

        return customer;
    }

Can someone please help me with Interceptor code snippet so that I can follow through as guidance

Rafael Winterhalter
  • 42,759
  • 13
  • 108
  • 192
user2780187
  • 677
  • 7
  • 16

1 Answers1

0

Right now, this is not easily to be done with Byte Buddy. The component you are looking for is called MemberSubstitution and it allows you to replace method calls and field access within a method. What you would like to do would be to add a method call that captures arguments which is currently under development as an additional feature of the mentioned API.

Alternatively, you can intercept all methods being called if you know them and browse the stack trace to validate that they are called from the method in question.

Rafael Winterhalter
  • 42,759
  • 13
  • 108
  • 192