@Test public void testMDCUpdates() { String[] paramNames = { "param1", "param2" }; when(sig.getParameterNames()).thenReturn(paramNames); Object[] args = { "value1", "value2" }; when(joinPoint.getArgs()).thenReturn(args); Object target = new Object(); when(joinPoint.getTarget()).thenReturn(target); underTest.buildLogContextForControllerCalls(joinPoint); verify(logContextService).buildMDCParams(target, paramNames, args); }
@Before("com.sequenceiq.redbeams.aspect.ControllerLogContextAspects.interceptControllerMethodCalls()") public void buildLogContextForControllerCalls(JoinPoint joinPoint) { LOGGER.debug("Intercepted controller method {}", joinPoint.toShortString()); try { Object[] args = joinPoint.getArgs(); CodeSignature sig = (CodeSignature) joinPoint.getSignature(); String[] paramNames = sig.getParameterNames(); for (int i = 0; i < paramNames.length; i++) { if (paramNames[i].equalsIgnoreCase("environmentid")) { paramNames[i] = "environmentCrn"; } } logContextService.buildMDCParams(joinPoint.getTarget(), paramNames, args); LOGGER.debug("A controller method has been intercepted: {} with params {}, {}, MDC logger context is built.", joinPoint.toShortString(), sig.getParameterNames(), AnonymizerUtil.anonymize(Arrays.toString(args))); } catch (Exception e) { LOGGER.warn("Failed to add controller method parameters to MDC, continuing with call", e); } }
ControllerLogContextAspects { @Before("com.sequenceiq.redbeams.aspect.ControllerLogContextAspects.interceptControllerMethodCalls()") public void buildLogContextForControllerCalls(JoinPoint joinPoint) { LOGGER.debug("Intercepted controller method {}", joinPoint.toShortString()); try { Object[] args = joinPoint.getArgs(); CodeSignature sig = (CodeSignature) joinPoint.getSignature(); String[] paramNames = sig.getParameterNames(); for (int i = 0; i < paramNames.length; i++) { if (paramNames[i].equalsIgnoreCase("environmentid")) { paramNames[i] = "environmentCrn"; } } logContextService.buildMDCParams(joinPoint.getTarget(), paramNames, args); LOGGER.debug("A controller method has been intercepted: {} with params {}, {}, MDC logger context is built.", joinPoint.toShortString(), sig.getParameterNames(), AnonymizerUtil.anonymize(Arrays.toString(args))); } catch (Exception e) { LOGGER.warn("Failed to add controller method parameters to MDC, continuing with call", e); } } }
ControllerLogContextAspects { @Before("com.sequenceiq.redbeams.aspect.ControllerLogContextAspects.interceptControllerMethodCalls()") public void buildLogContextForControllerCalls(JoinPoint joinPoint) { LOGGER.debug("Intercepted controller method {}", joinPoint.toShortString()); try { Object[] args = joinPoint.getArgs(); CodeSignature sig = (CodeSignature) joinPoint.getSignature(); String[] paramNames = sig.getParameterNames(); for (int i = 0; i < paramNames.length; i++) { if (paramNames[i].equalsIgnoreCase("environmentid")) { paramNames[i] = "environmentCrn"; } } logContextService.buildMDCParams(joinPoint.getTarget(), paramNames, args); LOGGER.debug("A controller method has been intercepted: {} with params {}, {}, MDC logger context is built.", joinPoint.toShortString(), sig.getParameterNames(), AnonymizerUtil.anonymize(Arrays.toString(args))); } catch (Exception e) { LOGGER.warn("Failed to add controller method parameters to MDC, continuing with call", e); } }  }
ControllerLogContextAspects { @Before("com.sequenceiq.redbeams.aspect.ControllerLogContextAspects.interceptControllerMethodCalls()") public void buildLogContextForControllerCalls(JoinPoint joinPoint) { LOGGER.debug("Intercepted controller method {}", joinPoint.toShortString()); try { Object[] args = joinPoint.getArgs(); CodeSignature sig = (CodeSignature) joinPoint.getSignature(); String[] paramNames = sig.getParameterNames(); for (int i = 0; i < paramNames.length; i++) { if (paramNames[i].equalsIgnoreCase("environmentid")) { paramNames[i] = "environmentCrn"; } } logContextService.buildMDCParams(joinPoint.getTarget(), paramNames, args); LOGGER.debug("A controller method has been intercepted: {} with params {}, {}, MDC logger context is built.", joinPoint.toShortString(), sig.getParameterNames(), AnonymizerUtil.anonymize(Arrays.toString(args))); } catch (Exception e) { LOGGER.warn("Failed to add controller method parameters to MDC, continuing with call", e); } }  @Pointcut("execution(* com.sequenceiq.redbeams..*.*Controller.*(..))") void interceptControllerMethodCalls(); @Before("com.sequenceiq.redbeams.aspect.ControllerLogContextAspects.interceptControllerMethodCalls()") void buildLogContextForControllerCalls(JoinPoint joinPoint); }
ControllerLogContextAspects { @Before("com.sequenceiq.redbeams.aspect.ControllerLogContextAspects.interceptControllerMethodCalls()") public void buildLogContextForControllerCalls(JoinPoint joinPoint) { LOGGER.debug("Intercepted controller method {}", joinPoint.toShortString()); try { Object[] args = joinPoint.getArgs(); CodeSignature sig = (CodeSignature) joinPoint.getSignature(); String[] paramNames = sig.getParameterNames(); for (int i = 0; i < paramNames.length; i++) { if (paramNames[i].equalsIgnoreCase("environmentid")) { paramNames[i] = "environmentCrn"; } } logContextService.buildMDCParams(joinPoint.getTarget(), paramNames, args); LOGGER.debug("A controller method has been intercepted: {} with params {}, {}, MDC logger context is built.", joinPoint.toShortString(), sig.getParameterNames(), AnonymizerUtil.anonymize(Arrays.toString(args))); } catch (Exception e) { LOGGER.warn("Failed to add controller method parameters to MDC, continuing with call", e); } }  @Pointcut("execution(* com.sequenceiq.redbeams..*.*Controller.*(..))") void interceptControllerMethodCalls(); @Before("com.sequenceiq.redbeams.aspect.ControllerLogContextAspects.interceptControllerMethodCalls()") void buildLogContextForControllerCalls(JoinPoint joinPoint);  }