Home > front end >  Spring-Integration: Logging: Getting the bean name from within a AbstractRequestHandlerAdvice
Spring-Integration: Logging: Getting the bean name from within a AbstractRequestHandlerAdvice

Time:01-06

With Spring-Integration 6.0.0 I'm using AbstractRequestHandlerAdvice to log calls to http:outbound-gateway implicitly (both the outgoing request message headers and payload and the incoming response message headers and payload).

But I'm a bit stuck on retrieving the name of the http:outbound-gateway bean itself from within the AbstractRequestHandlerAdvice.

The doInvoke() method receives an argument that contain the name of the http:outbound-gateway beans, unfortunately within a private class.

@Override
protected Object doInvoke(ExecutionCallback callback, Object target, Message<?> message) {
    ...
    final String outboundGatewayName = ((AbstractReplyProducingMessageHandler.AdvisedRequestHandler) target).getAdvisedHandler().getBeanName();
    ...
}

The target argument is a private subclass AbstractReplyProducingMessageHandler.AdvisedRequestHandler which does contain the method getAdvisedHandler() which returns the http:outbound-gateway bean and allows retrieving the bean name with getBeanName(): however, since this subclass is private, I can't do this without some special reflection work.

Is there a non-private way of retrieving the name of the target bean from the AbstractRequestHandlerAdvice? I would think that this would be important for logging.

CodePudding user response:

Looks like this will do it: using the public interface RequestHandler :

    final String outboundGatewayName = 
        ((AbstractReplyProducingMessageHandler.RequestHandler) target)
            .getAdvisedHandler()
            .getBeanName();
  • Related