@Override protected void doInit() { super.doInit(); if (!this.requiresReplyExplicitlySet) { setRequiresReply(this.expectSingleResult); } }
@Override public void setRequiresReply(boolean requiresReply) { super.setRequiresReply(requiresReply); this.requiresReply = requiresReply; }
private void defaultStatefulRetryRecoverAfterThirdTryGuts(final AtomicInteger counter, AbstractReplyProducingMessageHandler handler, QueueChannel replies, RequestHandlerRetryAdvice advice) { advice.setRecoveryCallback(context -> "baz"); List<Advice> adviceChain = new ArrayList<>(); adviceChain.add(advice); handler.setAdviceChain(adviceChain); handler.setBeanFactory(mock(BeanFactory.class)); handler.afterPropertiesSet(); Message<String> message = new GenericMessage<>("Hello, world!"); for (int i = 0; i < 4; i++) { try { handler.handleMessage(message); } catch (Exception e) { } } assertTrue(counter.get() == 0); Message<?> reply = replies.receive(10000); assertNotNull(reply); assertEquals("baz", reply.getPayload()); }
@Override protected final void onInit() { super.onInit(); initAdvisedRequestHandlerIfAny(); doInit(); }
/** * {@inheritDoc} */ @Override protected final void handleMessageInternal(Message<?> message) { Object result; if (this.advisedRequestHandler == null) { result = handleRequestMessage(message); } else { result = doInvokeAdvisedRequestHandler(message); } if (result != null) { sendOutputs(result, message); } else if (this.requiresReply && !isAsync()) { throw new ReplyRequiredException(message, "No reply produced by handler '" + getComponentName() + "', and its 'requiresReply' property is set to true."); } else if (!isAsync() && logger.isDebugEnabled()) { logger.debug("handler '" + this + "' produced no reply for request Message: " + message); } }
serviceActivator.setRequiresReply(Boolean.parseBoolean(this.beanFactory.resolveEmbeddedValue(requiresReply))); serviceActivator.setAsync(Boolean.parseBoolean(this.beanFactory.resolveEmbeddedValue(isAsync)));
@Override protected Tuple2<ConsumerEndpointFactoryBean, H> doGet() { this.endpointFactoryBean.setAdviceChain(this.adviceChain); if (this.handler instanceof AbstractReplyProducingMessageHandler && !this.adviceChain.isEmpty()) { ((AbstractReplyProducingMessageHandler) this.handler).setAdviceChain(this.adviceChain); } this.endpointFactoryBean.setHandler(this.handler); return super.doGet(); }
@Test @SuppressWarnings("unchecked") public void testNotPropagateAdd() { AbstractReplyProducingMessageHandler handler = new AbstractReplyProducingMessageHandler() { @Override protected Object handleRequestMessage(Message<?> requestMessage) { return new GenericMessage<>("world", Collections.singletonMap("bar", "RAB")); } }; assertThat(handler.getNotPropagatedHeaders(), emptyCollectionOf(String.class)); handler.setNotPropagatedHeaders("foo"); handler.addNotPropagatedHeaders("b*r"); handler.setOutputChannel(this.channel); assertThat(handler.getNotPropagatedHeaders(), containsInAnyOrder("foo", "b*r")); ArgumentCaptor<Message<?>> captor = ArgumentCaptor.forClass(Message.class); willReturn(true).given(this.channel).send(captor.capture()); handler.handleMessage( MessageBuilder.withPayload("hello") .setHeader("foo", "FOO") .setHeader("bar", "BAR") .setHeader("baz", "BAZ") .build()); Message<?> out = captor.getValue(); assertThat(out, notNullValue()); assertThat(out.getHeaders().get("foo"), nullValue()); assertThat(out.getHeaders().get("bar"), equalTo("RAB")); assertThat(out.getHeaders().get("baz"), equalTo("BAZ")); }
this.handler.setAsync(true); this.handler.setOutputChannel(this.output); this.handler.setBeanFactory(mock(BeanFactory.class)); this.latch = new CountDownLatch(1); Log logger = spy(TestUtils.getPropertyValue(this.handler, "logger", Log.class));
/** * @param sendTimeout the send timeout. * @return the endpoint spec. * @see AbstractReplyProducingMessageHandler#setSendTimeout(long) */ public S sendTimeout(long sendTimeout) { assertHandler(); if (this.handler instanceof AbstractReplyProducingMessageHandler) { ((AbstractReplyProducingMessageHandler) this.handler).setSendTimeout(sendTimeout); } else { logger.warn("'sendTimeout' can be applied only for AbstractReplyProducingMessageHandler"); } return _this(); }
/** * Allow async replies. If the handler reply is a {@code ListenableFuture} send * the output when it is satisfied rather than sending the future as the result. * Only subclasses that support this feature should set it. * @param async true to allow. * @return the endpoint spec. * @since 1.2 * @see AbstractReplyProducingMessageHandler#setAsync(boolean) */ public S async(boolean async) { assertHandler(); if (this.handler instanceof AbstractReplyProducingMessageHandler) { ((AbstractReplyProducingMessageHandler) this.handler).setAsync(async); } else { logger.warn("'async' can be applied only for AbstractReplyProducingMessageHandler"); } return _this(); }
@Override public void addNotPropagatedHeaders(String... headers) { super.addNotPropagatedHeaders(headers); populateNotPropagatedHeadersIfAny(); }
@Override protected Object doInvoke(ExecutionCallback callback, Object target, Message<?> message) throws Exception { compName.set(((AbstractReplyProducingMessageHandler.RequestHandler) target).getAdvisedHandler() .getComponentName()); return callback.execute(); }
@Override protected final void onInit() { super.onInit(); initAdvisedRequestHandlerIfAny(); doInit(); }
serviceActivator.setRequiresReply(Boolean.parseBoolean(this.beanFactory.resolveEmbeddedValue(requiresReply))); serviceActivator.setAsync(Boolean.parseBoolean(this.beanFactory.resolveEmbeddedValue(isAsync)));
/** * {@inheritDoc} */ @Override protected final void handleMessageInternal(Message<?> message) { Object result; if (this.advisedRequestHandler == null) { result = handleRequestMessage(message); } else { result = doInvokeAdvisedRequestHandler(message); } if (result != null) { sendOutputs(result, message); } else if (this.requiresReply && !isAsync()) { throw new ReplyRequiredException(message, "No reply produced by handler '" + getComponentName() + "', and its 'requiresReply' property is set to true."); } else if (!isAsync() && logger.isDebugEnabled()) { logger.debug("handler '" + this + "' produced no reply for request Message: " + message); } }
((AbstractReplyProducingMessageHandler) handler).setAdviceChain(adviceChain);
@Test @SuppressWarnings("unchecked") public void testNotPropagateAddWhenNonExist() { AbstractReplyProducingMessageHandler handler = new AbstractReplyProducingMessageHandler() { @Override protected Object handleRequestMessage(Message<?> requestMessage) { return new GenericMessage<>("world", Collections.singletonMap("bar", "RAB")); } }; handler.addNotPropagatedHeaders("boom"); assertThat(handler.getNotPropagatedHeaders(), containsInAnyOrder("boom")); handler.setOutputChannel(this.channel); ArgumentCaptor<Message<?>> captor = ArgumentCaptor.forClass(Message.class); willReturn(true).given(this.channel).send(captor.capture()); handler.handleMessage(MessageBuilder.withPayload("hello") .setHeader("boom", "FOO") .setHeader("bar", "BAR") .setHeader("baz", "BAZ") .build()); Message<?> out = captor.getValue(); assertThat(out, notNullValue()); assertThat(out.getHeaders().get("boom"), nullValue()); assertThat(out.getHeaders().get("bar"), equalTo("RAB")); assertThat(out.getHeaders().get("baz"), equalTo("BAZ")); }
/** * @param sendTimeout the send timeout. * @return the endpoint spec. * @see AbstractReplyProducingMessageHandler#setSendTimeout(long) */ public S sendTimeout(long sendTimeout) { assertHandler(); if (this.handler instanceof AbstractReplyProducingMessageHandler) { ((AbstractReplyProducingMessageHandler) this.handler).setSendTimeout(sendTimeout); } else { logger.warn("'sendTimeout' can be applied only for AbstractReplyProducingMessageHandler"); } return _this(); }
/** * Allow async replies. If the handler reply is a {@code ListenableFuture} send * the output when it is satisfied rather than sending the future as the result. * Only subclasses that support this feature should set it. * @param async true to allow. * @return the endpoint spec. * @since 1.2 * @see AbstractReplyProducingMessageHandler#setAsync(boolean) */ public S async(boolean async) { assertHandler(); if (this.handler instanceof AbstractReplyProducingMessageHandler) { ((AbstractReplyProducingMessageHandler) this.handler).setAsync(async); } else { logger.warn("'async' can be applied only for AbstractReplyProducingMessageHandler"); } return _this(); }