List of usage examples for org.springframework.messaging.support ChannelInterceptorAdapter ChannelInterceptorAdapter
ChannelInterceptorAdapter
From source file:jp.pigumer.web.StompConfig.java
@Override public void configureClientInboundChannel(ChannelRegistration registration) { registration.setInterceptors(new ChannelInterceptorAdapter() { @Override/* w ww. jav a 2s . c o m*/ public Message<?> preSend(Message<?> message, MessageChannel channel) { StompHeaderAccessor accessor = StompHeaderAccessor.wrap(message); if (accessor.getCommand() == StompCommand.SUBSCRIBE) { LOGGER.log(Level.INFO, String.format("%s: %s", channel, message)); } return message; } }); }
From source file:xolpoc.plugins.StreamPlugin.java
private void track(final Module module, MessageChannel channel, final Map<String, Object> historyProps) { final MessageBuilderFactory messageBuilderFactory = module.getComponent( IntegrationUtils.INTEGRATION_MESSAGE_BUILDER_FACTORY_BEAN_NAME, MessageBuilderFactory.class) == null ? new DefaultMessageBuilderFactory() : module.getComponent(IntegrationUtils.INTEGRATION_MESSAGE_BUILDER_FACTORY_BEAN_NAME, MessageBuilderFactory.class); if (channel instanceof ChannelInterceptorAware) { ((ChannelInterceptorAware) channel).addInterceptor(new ChannelInterceptorAdapter() { @Override//from w w w . j a va 2 s. c o m public Message<?> preSend(Message<?> message, MessageChannel channel) { @SuppressWarnings("unchecked") Collection<Map<String, Object>> history = (Collection<Map<String, Object>>) message.getHeaders() .get(XdHeaders.XD_HISTORY); if (history == null) { history = new ArrayList<Map<String, Object>>(1); } else { history = new ArrayList<Map<String, Object>>(history); } Map<String, Object> map = new LinkedHashMap<String, Object>(); map.putAll(historyProps); map.put("thread", Thread.currentThread().getName()); history.add(map); Message<?> out = messageBuilderFactory.fromMessage(message) .setHeader(XdHeaders.XD_HISTORY, history).build(); return out; } }); } }
From source file:org.springframework.integration.config.xml.GatewayParserTests.java
@Test public void testAsyncCompletable() throws Exception { QueueChannel requestChannel = (QueueChannel) context.getBean("requestChannel"); final AtomicReference<Thread> thread = new AtomicReference<>(); requestChannel.addInterceptor(new ChannelInterceptorAdapter() { @Override//w ww . j a v a 2 s. co m public Message<?> preSend(Message<?> message, MessageChannel channel) { thread.set(Thread.currentThread()); return super.preSend(message, channel); } }); MessageChannel replyChannel = (MessageChannel) context.getBean("replyChannel"); this.startResponder(requestChannel, replyChannel); TestService service = context.getBean("asyncCompletable", TestService.class); CompletableFuture<String> result = service.completable("foo").thenApply(String::toUpperCase); String reply = result.get(10, TimeUnit.SECONDS); assertEquals("FOO", reply); assertThat(thread.get().getName(), startsWith("testExec-")); assertNotNull(TestUtils.getPropertyValue(context.getBean("&asyncCompletable"), "asyncExecutor")); }
From source file:org.springframework.integration.config.xml.GatewayParserTests.java
@Test public void testAsyncCompletableNoAsync() throws Exception { QueueChannel requestChannel = (QueueChannel) context.getBean("requestChannel"); final AtomicReference<Thread> thread = new AtomicReference<>(); requestChannel.addInterceptor(new ChannelInterceptorAdapter() { @Override/*from w w w .j ava 2s.c o m*/ public Message<?> preSend(Message<?> message, MessageChannel channel) { thread.set(Thread.currentThread()); return super.preSend(message, channel); } }); MessageChannel replyChannel = (MessageChannel) context.getBean("replyChannel"); this.startResponder(requestChannel, replyChannel); TestService service = context.getBean("completableNoAsync", TestService.class); CompletableFuture<String> result = service.completable("flowCompletable"); String reply = result.get(1, TimeUnit.SECONDS); assertEquals("SYNC_COMPLETABLE", reply); assertEquals(Thread.currentThread(), thread.get()); assertNull(TestUtils.getPropertyValue(context.getBean("&completableNoAsync"), "asyncExecutor")); }
From source file:org.springframework.integration.config.xml.GatewayParserTests.java
@Test public void testCustomCompletableNoAsync() throws Exception { QueueChannel requestChannel = (QueueChannel) context.getBean("requestChannel"); final AtomicReference<Thread> thread = new AtomicReference<>(); requestChannel.addInterceptor(new ChannelInterceptorAdapter() { @Override// w w w.ja va2 s .c om public Message<?> preSend(Message<?> message, MessageChannel channel) { thread.set(Thread.currentThread()); return super.preSend(message, channel); } }); MessageChannel replyChannel = (MessageChannel) context.getBean("replyChannel"); this.startResponder(requestChannel, replyChannel); TestService service = context.getBean("completableNoAsync", TestService.class); MyCompletableFuture result = service.customCompletable("flowCustomCompletable"); String reply = result.get(1, TimeUnit.SECONDS); assertEquals("SYNC_CUSTOM_COMPLETABLE", reply); assertEquals(Thread.currentThread(), thread.get()); assertNull(TestUtils.getPropertyValue(context.getBean("&completableNoAsync"), "asyncExecutor")); }
From source file:org.springframework.integration.config.xml.GatewayParserTests.java
@Test public void testCustomCompletableNoAsyncAttemptAsync() throws Exception { Object gateway = context.getBean("&customCompletableAttemptAsync"); Log logger = spy(TestUtils.getPropertyValue(gateway, "logger", Log.class)); when(logger.isDebugEnabled()).thenReturn(true); new DirectFieldAccessor(gateway).setPropertyValue("logger", logger); QueueChannel requestChannel = (QueueChannel) context.getBean("requestChannel"); final AtomicReference<Thread> thread = new AtomicReference<>(); requestChannel.addInterceptor(new ChannelInterceptorAdapter() { @Override//from ww w .ja v a 2 s . c o m public Message<?> preSend(Message<?> message, MessageChannel channel) { thread.set(Thread.currentThread()); return super.preSend(message, channel); } }); MessageChannel replyChannel = (MessageChannel) context.getBean("replyChannel"); this.startResponder(requestChannel, replyChannel); TestService service = context.getBean("customCompletableAttemptAsync", TestService.class); MyCompletableFuture result = service.customCompletable("flowCustomCompletable"); String reply = result.get(1, TimeUnit.SECONDS); assertEquals("SYNC_CUSTOM_COMPLETABLE", reply); assertEquals(Thread.currentThread(), thread.get()); assertNotNull(TestUtils.getPropertyValue(gateway, "asyncExecutor")); verify(logger) .debug("AsyncTaskExecutor submit*() return types are incompatible with the method return type; " + "running on calling thread; the downstream flow must return the required Future: " + "MyCompletableFuture"); }
From source file:org.springframework.integration.config.xml.GatewayParserTests.java
@Test public void testAsyncCompletableMessage() throws Exception { QueueChannel requestChannel = (QueueChannel) context.getBean("requestChannel"); final AtomicReference<Thread> thread = new AtomicReference<>(); requestChannel.addInterceptor(new ChannelInterceptorAdapter() { @Override/*from www. j a v a2 s . c om*/ public Message<?> preSend(Message<?> message, MessageChannel channel) { thread.set(Thread.currentThread()); return super.preSend(message, channel); } }); MessageChannel replyChannel = (MessageChannel) context.getBean("replyChannel"); this.startResponder(requestChannel, replyChannel); TestService service = context.getBean("asyncCompletable", TestService.class); CompletableFuture<Message<?>> result = service.completableReturnsMessage("foo"); Message<?> reply = result.get(1, TimeUnit.SECONDS); assertEquals("foo", reply.getPayload()); assertThat(thread.get().getName(), startsWith("testExec-")); assertNotNull(TestUtils.getPropertyValue(context.getBean("&asyncCompletable"), "asyncExecutor")); }
From source file:org.springframework.integration.config.xml.GatewayParserTests.java
@Test public void testAsyncCompletableNoAsyncMessage() throws Exception { QueueChannel requestChannel = (QueueChannel) context.getBean("requestChannel"); final AtomicReference<Thread> thread = new AtomicReference<>(); requestChannel.addInterceptor(new ChannelInterceptorAdapter() { @Override//from ww w . ja va2s.c o m public Message<?> preSend(Message<?> message, MessageChannel channel) { thread.set(Thread.currentThread()); return super.preSend(message, channel); } }); MessageChannel replyChannel = (MessageChannel) context.getBean("replyChannel"); this.startResponder(requestChannel, replyChannel); TestService service = context.getBean("completableNoAsync", TestService.class); CompletableFuture<Message<?>> result = service.completableReturnsMessage("flowCompletableM"); Message<?> reply = result.get(1, TimeUnit.SECONDS); assertEquals("flowCompletableM", reply.getPayload()); assertEquals(Thread.currentThread(), thread.get()); assertNull(TestUtils.getPropertyValue(context.getBean("&completableNoAsync"), "asyncExecutor")); }
From source file:org.springframework.integration.config.xml.GatewayParserTests.java
@Test public void testCustomCompletableNoAsyncMessage() throws Exception { QueueChannel requestChannel = (QueueChannel) context.getBean("requestChannel"); final AtomicReference<Thread> thread = new AtomicReference<>(); requestChannel.addInterceptor(new ChannelInterceptorAdapter() { @Override/*from ww w. j ava2 s. co m*/ public Message<?> preSend(Message<?> message, MessageChannel channel) { thread.set(Thread.currentThread()); return super.preSend(message, channel); } }); MessageChannel replyChannel = (MessageChannel) context.getBean("replyChannel"); this.startResponder(requestChannel, replyChannel); TestService service = context.getBean("completableNoAsync", TestService.class); MyCompletableMessageFuture result = service.customCompletableReturnsMessage("flowCustomCompletableM"); Message<?> reply = result.get(1, TimeUnit.SECONDS); assertEquals("flowCustomCompletableM", reply.getPayload()); assertEquals(Thread.currentThread(), thread.get()); assertNull(TestUtils.getPropertyValue(context.getBean("&completableNoAsync"), "asyncExecutor")); }