@Override protected MessageHandler createMethodInvokingHandler(Object targetObject, String targetMethodName) { MessageHandler handler = null; handler = createDirectHandlerIfPossible(targetObject, targetMethodName); if (handler == null) { handler = configureHandler( StringUtils.hasText(targetMethodName) ? new ServiceActivatingHandler(targetObject, targetMethodName) : new ServiceActivatingHandler(targetObject)); } return handler; }
/** * Populate a {@link ServiceActivatingHandler} instance to perform {@link MessageTriggerAction} * and endpoint options from {@link GenericEndpointSpec}. * @param triggerAction the {@link MessageTriggerAction}. * @param endpointConfigurer the {@link Consumer} to provide integration endpoint options. * @return the current {@link IntegrationFlowDefinition}. */ public B trigger(MessageTriggerAction triggerAction, Consumer<GenericEndpointSpec<ServiceActivatingHandler>> endpointConfigurer) { return handle(new ServiceActivatingHandler(triggerAction, "trigger"), endpointConfigurer); }
/** * Populate a {@link ServiceActivatingHandler} instance to perform {@link MessageTriggerAction} * and endpoint options from {@link GenericEndpointSpec}. * @param triggerActionId the {@link MessageTriggerAction} bean id. * @param endpointConfigurer the {@link Consumer} to provide integration endpoint options. * @return the current {@link IntegrationFlowDefinition}. */ public B trigger(String triggerActionId, Consumer<GenericEndpointSpec<ServiceActivatingHandler>> endpointConfigurer) { MessageProcessor<Void> trigger = new BeanNameMessageProcessor<>(triggerActionId, "trigger"); return handle(new ServiceActivatingHandler(trigger), endpointConfigurer); }
@Override protected MessageHandler createHandler() { ExpressionCommandMessageProcessor processor = new ExpressionCommandMessageProcessor(methodFilter, this.getBeanFactory()); ServiceActivatingHandler handler = new ServiceActivatingHandler(processor); if (this.sendTimeout != null) { handler.setSendTimeout(this.sendTimeout); } return handler; }
@Bean @ServiceActivator(inputChannel = "annotatedBeanMessageHandlerChannel") @IdempotentReceiver("idempotentReceiverInterceptor") public MessageHandler messageHandler() { return new ServiceActivatingHandler((MessageProcessor<Object>) message -> message); }
private static ServiceActivatingHandler createConsumer(Object object) { ServiceActivatingHandler handler = new ServiceActivatingHandler(object); handler.setBeanFactory(mock(BeanFactory.class)); handler.afterPropertiesSet(); return handler; }
private ServiceActivatingHandler getHandler(String methodName, Class<?>... types) throws Exception { ServiceActivatingHandler serviceActivatingHandler = new ServiceActivatingHandler(bean, TestBean.class.getMethod(methodName, types)); serviceActivatingHandler.setBeanFactory(applicationContext); serviceActivatingHandler.afterPropertiesSet(); return serviceActivatingHandler; }
@Test(expected = IllegalStateException.class) public void twoStringsAmbiguousUsingMethodName() throws Exception { SingleAmbiguousMethodTestBean bean = new SingleAmbiguousMethodTestBean(); new ServiceActivatingHandler(bean, "twoStrings"); }
@Test(expected = IllegalStateException.class) public void twoStringsAmbiguousWithoutMethodName() throws Exception { SingleAmbiguousMethodTestBean bean = new SingleAmbiguousMethodTestBean(); new ServiceActivatingHandler(bean); }
@Test(expected = IllegalArgumentException.class) public void multipleAnnotationFails() { MultipleAnnotationTestBean testBean = new MultipleAnnotationTestBean(); new ServiceActivatingHandler(testBean); }
@Override protected MessageHandler createExpressionEvaluatingHandler(Expression expression) { ExpressionEvaluatingMessageProcessor<Object> processor = new ExpressionEvaluatingMessageProcessor<Object>(expression); processor.setBeanFactory(this.getBeanFactory()); ServiceActivatingHandler handler = new ServiceActivatingHandler(processor); handler.setPrimaryExpression(expression); return this.configureHandler(handler); }
@Test(expected = IllegalArgumentException.class) public void multiplePublicMethodFails() { MultiplePublicMethodTestBean testBean = new MultiplePublicMethodTestBean(); new ServiceActivatingHandler(testBean); }
/** * Populate the {@code Control Bus} EI Pattern specific {@link MessageHandler} implementation * at the current {@link IntegrationFlow} chain position. * @param endpointConfigurer the {@link Consumer} to accept integration endpoint options. * @return the current {@link IntegrationFlowDefinition}. * @see ExpressionCommandMessageProcessor * @see GenericEndpointSpec */ public B controlBus(Consumer<GenericEndpointSpec<ServiceActivatingHandler>> endpointConfigurer) { return handle(new ServiceActivatingHandler(new ExpressionCommandMessageProcessor( new ControlBusMethodFilter())), endpointConfigurer); }
private ServiceActivatingHandler createEndpoint() { ServiceActivatingHandler handler = new ServiceActivatingHandler(new TestBean(), "handle"); handler.setBeanFactory(mock(BeanFactory.class)); handler.afterPropertiesSet(); return handler; }
@Test public void singlePublicMethodMatches() { SinglePublicMethodTestBean testBean = new SinglePublicMethodTestBean(); ServiceActivatingHandler serviceActivator = new ServiceActivatingHandler(testBean); QueueChannel outputChannel = new QueueChannel(); serviceActivator.setOutputChannel(outputChannel); serviceActivator.setBeanFactory(mock(BeanFactory.class)); serviceActivator.afterPropertiesSet(); serviceActivator.handleMessage(new GenericMessage<>("foo")); Message<?> result = outputChannel.receive(0); assertEquals("FOO", result.getPayload()); }
@Test public void singleAnnotationMatches() { SingleAnnotationTestBean testBean = new SingleAnnotationTestBean(); ServiceActivatingHandler serviceActivator = new ServiceActivatingHandler(testBean); QueueChannel outputChannel = new QueueChannel(); serviceActivator.setOutputChannel(outputChannel); serviceActivator.setBeanFactory(mock(BeanFactory.class)); serviceActivator.afterPropertiesSet(); serviceActivator.handleMessage(new GenericMessage<>("foo")); Message<?> result = outputChannel.receive(0); assertEquals("FOO", result.getPayload()); }
@Test public void nullOk() { NullOkTestBean testBean = new NullOkTestBean(); ServiceActivatingHandler serviceActivator = new ServiceActivatingHandler(testBean); QueueChannel outputChannel = new QueueChannel(); serviceActivator.setOutputChannel(outputChannel); serviceActivator.setBeanFactory(mock(BeanFactory.class)); serviceActivator.afterPropertiesSet(); serviceActivator.handleMessage(new GenericMessage<>(new KafkaNull())); Message<?> result = outputChannel.receive(0); assertEquals("gotNull", result.getPayload()); }
@Test(expected = ReplyRequiredException.class) public void noReplyMessageWithRequiresReply() { QueueChannel channel = new QueueChannel(1); ServiceActivatingHandler endpoint = new ServiceActivatingHandler(new TestNullReplyBean(), "handle"); endpoint.setRequiresReply(true); endpoint.setOutputChannel(channel); endpoint.setBeanFactory(mock(BeanFactory.class)); endpoint.afterPropertiesSet(); Message<?> message = MessageBuilder.withPayload("foo").build(); endpoint.handleMessage(message); }
@Test public void sendAndReceiveForRegisteredEndpoint() { ServiceActivatingHandler serviceActivator = new ServiceActivatingHandler(new TestBean(), "handle"); serviceActivator.setOutputChannel(this.targetChannel); context.registerBean("testServiceActivator", serviceActivator); EventDrivenConsumer endpoint = new EventDrivenConsumer(this.sourceChannel, serviceActivator); context.registerEndpoint("testEndpoint", endpoint); context.refresh(); this.sourceChannel.send(new GenericMessage<>("foo")); Message<?> response = this.targetChannel.receive(); assertEquals("foo!", response.getPayload()); }
@Test public void noReplyMessage() { QueueChannel channel = new QueueChannel(1); ServiceActivatingHandler endpoint = new ServiceActivatingHandler(new TestNullReplyBean(), "handle"); endpoint.setOutputChannel(channel); endpoint.setBeanFactory(mock(BeanFactory.class)); endpoint.afterPropertiesSet(); Message<?> message = MessageBuilder.withPayload("foo").build(); endpoint.handleMessage(message); assertNull(channel.receive(0)); }