// First, we create an advice class that modifies the existing return value of this method: public class ApacheV5ReturnProxyRouteAdvice { @Advice.OnMethodExit public static void determineRoute( @Advice.Return(readOnly = false) HttpRoute returnValue ) { returnValue = new HttpRoute( returnValue.getTargetHost(), returnValue.getLocalAddress(), new HttpHost( HttpProxyAgent.getAgentProxyHost(), HttpProxyAgent.getAgentProxyPort() ), returnValue.isSecure() ); } } // Then, elsewhere, we apply that to all implementations that plan routes: class ApacheClientRoutingV5Transformer(logger: TransformationLogger) : MatchingAgentTransformer(logger) { override fun register(builder: AgentBuilder): AgentBuilder { // Match all concrete implementations of a given type: return builder.type(…