I would like to intercept all spring integration gateways via AOP.
Is it possible to do that? If not what might be best way to do log input object coming to gateway?
@ContextConfiguration
@RunWith(SpringJUnit4ClassRunner.class)
@DirtiesContext
public class AdviceExample {
@Autowired
private TestGateway testGateway;
@Test
public void testIt() {
System.out.println(this.testGateway.testIt("foo"));
}
@MessagingGateway
public interface TestGateway {
@Gateway(requestChannel = "testChannel")
@CustomAnnotation
String testIt(String payload);
}
@Configuration
@EnableIntegration
@IntegrationComponentScan
@EnableMessageHistory
@EnableAspectJAutoProxy
public static class ContextConfiguration {
LoggingHandler logger = new LoggingHandler(LoggingHandler.Level.INFO.name());
@Bean
public IntegrationFlow testFlow() {
return IntegrationFlows.from("testChannel")
.transform("payload.toUpperCase()")
.channel("testChannel")
.transform("payload.concat(' Manoj')")
.channel("testChannel")
.handle(logger)
.get();
}
@Bean
public GatewayAdvice gtwyAdvice(){
return new GatewayAdvice();
}
}
@Retention(value = RetentionPolicy.RUNTIME)
@Target(value = ElementType.METHOD)
@Inherited
public @interface CustomAnnotation{
}
@Aspect
public static class GatewayAdvice {
@Before("execution(* advice.AdviceExample.TestGateway.testIt(*))")
public void beforeAdvice() {
System.out.println("Before advice called...");
}
@Before("@annotation(advice.AdviceExample.CustomAnnotation)")
public void beforeAnnotationAdvice() {
System.out.println("Before annotation advice called...");
}
}
}