-1

Looking for an example (or suggestions) on how to use ByteBuddy to intercept and append a value on a JDBC connection property. The goal is to be able to use a JavaAgent to append a unique value for transaction correlation WITHOUT client code changes. Example:

    Properties props = new Properties();
    props.put("user", user);
    props.put("password", password);
    props.put("ClientCorrelationToken", "MyToken1");

Want ClientCorrelaionToken to result as "MyToken1appendedValue"

Looked any many examples but cannot find a suitable method.

Ultimately need to be able to pull in a unique token from a web header and place that into the JDBC property, but want to get the intercept working first.

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

1 Answers1

-1

You probably need to intercept the JDBC constructor and mutate or exchange the properties argument upon invocation.

For example, you can use the AgentBuilder to intercept all types that are a subtype of a JDBC driver and adjust their constructors using Advice. If there is a standard API that you know of, you can also implement a more fine-grained interception.

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