org.springframework.messaging.handler.invocation.InvocableHandlerMethod Java Examples
The following examples show how to use
org.springframework.messaging.handler.invocation.InvocableHandlerMethod.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AbstractBinderTests.java From spring-cloud-stream with Apache License 2.0 | 6 votes |
private StreamListenerMessageHandler buildStreamListener(Class<?> handlerClass, String handlerMethodName, Class<?>... parameters) throws Exception { String channelName = "reply_" + System.nanoTime(); this.applicationContext.getBeanFactory().registerSingleton(channelName, new QueueChannel()); Method m = ReflectionUtils.findMethod(handlerClass, handlerMethodName, parameters); InvocableHandlerMethod method = new InvocableHandlerMethod(this, m); HandlerMethodArgumentResolverComposite resolver = new HandlerMethodArgumentResolverComposite(); CompositeMessageConverterFactory factory = new CompositeMessageConverterFactory(); resolver.addResolver(new PayloadArgumentResolver( factory.getMessageConverterForAllRegistered())); method.setMessageMethodArgumentResolvers(resolver); Constructor<?> c = ReflectionUtils.accessibleConstructor( StreamListenerMessageHandler.class, InvocableHandlerMethod.class, boolean.class, String[].class); StreamListenerMessageHandler handler = (StreamListenerMessageHandler) c .newInstance(method, false, new String[] {}); handler.setOutputChannelName(channelName); handler.setBeanFactory(this.applicationContext); handler.afterPropertiesSet(); // context.refresh(); return handler; }
Example #2
Source File: DefaultMessageHandlerMethodFactoryTests.java From java-technology-stack with MIT License | 6 votes |
@Test public void overrideArgumentResolvers() throws Exception { DefaultMessageHandlerMethodFactory instance = createInstance(); List<HandlerMethodArgumentResolver> customResolvers = new ArrayList<>(); customResolvers.add(new CustomHandlerMethodArgumentResolver()); instance.setArgumentResolvers(customResolvers); instance.afterPropertiesSet(); Message<String> message = MessageBuilder.withPayload("sample").build(); // This will work as the local resolver is set InvocableHandlerMethod invocableHandlerMethod = createInvocableHandlerMethod(instance, "customArgumentResolver", Locale.class); invocableHandlerMethod.invoke(message); assertMethodInvocation(sample, "customArgumentResolver"); // This won't work as no resolver is known for the payload InvocableHandlerMethod invocableHandlerMethod2 = createInvocableHandlerMethod(instance, "simpleString", String.class); thrown.expect(MethodArgumentResolutionException.class); thrown.expectMessage("No suitable resolver"); invocableHandlerMethod2.invoke(message); }
Example #3
Source File: DefaultMessageHandlerMethodFactoryTests.java From java-technology-stack with MIT License | 6 votes |
@Test public void customConversion() throws Exception { DefaultMessageHandlerMethodFactory instance = createInstance(); GenericConversionService conversionService = new GenericConversionService(); conversionService.addConverter(SampleBean.class, String.class, new Converter<SampleBean, String>() { @Override public String convert(SampleBean source) { return "foo bar"; } }); instance.setConversionService(conversionService); instance.afterPropertiesSet(); InvocableHandlerMethod invocableHandlerMethod = createInvocableHandlerMethod(instance, "simpleString", String.class); invocableHandlerMethod.invoke(MessageBuilder.withPayload(sample).build()); assertMethodInvocation(sample, "simpleString"); }
Example #4
Source File: DefaultMessageHandlerMethodFactoryTests.java From java-technology-stack with MIT License | 6 votes |
@Test public void customValidation() throws Exception { DefaultMessageHandlerMethodFactory instance = createInstance(); instance.setValidator(new Validator() { @Override public boolean supports(Class<?> clazz) { return String.class.isAssignableFrom(clazz); } @Override public void validate(Object target, Errors errors) { String value = (String) target; if ("failure".equals(value)) { errors.reject("not a valid value"); } } }); instance.afterPropertiesSet(); InvocableHandlerMethod invocableHandlerMethod = createInvocableHandlerMethod(instance, "payloadValidation", String.class); thrown.expect(MethodArgumentNotValidException.class); invocableHandlerMethod.invoke(MessageBuilder.withPayload("failure").build()); }
Example #5
Source File: DefaultMessageHandlerMethodFactoryTests.java From spring4-understanding with Apache License 2.0 | 6 votes |
@Test public void customConversion() throws Exception { DefaultMessageHandlerMethodFactory instance = createInstance(); GenericConversionService conversionService = new GenericConversionService(); conversionService.addConverter(SampleBean.class, String.class, new Converter<SampleBean, String>() { @Override public String convert(SampleBean source) { return "foo bar"; } }); instance.setConversionService(conversionService); instance.afterPropertiesSet(); InvocableHandlerMethod invocableHandlerMethod = createInvocableHandlerMethod(instance, "simpleString", String.class); invocableHandlerMethod.invoke(MessageBuilder.withPayload(sample).build()); assertMethodInvocation(sample, "simpleString"); }
Example #6
Source File: DefaultMessageHandlerMethodFactoryTests.java From spring4-understanding with Apache License 2.0 | 6 votes |
@Test public void overrideArgumentResolvers() throws Exception { DefaultMessageHandlerMethodFactory instance = createInstance(); List<HandlerMethodArgumentResolver> customResolvers = new ArrayList<HandlerMethodArgumentResolver>(); customResolvers.add(new CustomHandlerMethodArgumentResolver()); instance.setArgumentResolvers(customResolvers); instance.afterPropertiesSet(); Message<String> message = MessageBuilder.withPayload("sample").build(); // This will work as the local resolver is set InvocableHandlerMethod invocableHandlerMethod = createInvocableHandlerMethod(instance, "customArgumentResolver", Locale.class); invocableHandlerMethod.invoke(message); assertMethodInvocation(sample, "customArgumentResolver"); // This won't work as no resolver is known for the payload InvocableHandlerMethod invocableHandlerMethod2 = createInvocableHandlerMethod(instance, "simpleString", String.class); thrown.expect(IllegalStateException.class); thrown.expectMessage("No suitable resolver for"); invocableHandlerMethod2.invoke(message); }
Example #7
Source File: DefaultMessageHandlerMethodFactoryTests.java From spring-analysis-note with MIT License | 6 votes |
@Test public void customValidation() throws Exception { DefaultMessageHandlerMethodFactory instance = createInstance(); instance.setValidator(new Validator() { @Override public boolean supports(Class<?> clazz) { return String.class.isAssignableFrom(clazz); } @Override public void validate(Object target, Errors errors) { String value = (String) target; if ("failure".equals(value)) { errors.reject("not a valid value"); } } }); instance.afterPropertiesSet(); InvocableHandlerMethod invocableHandlerMethod = createInvocableHandlerMethod(instance, "payloadValidation", String.class); assertThatExceptionOfType(MethodArgumentNotValidException.class).isThrownBy(() -> invocableHandlerMethod.invoke(MessageBuilder.withPayload("failure").build())); }
Example #8
Source File: DefaultMessageHandlerMethodFactoryTests.java From spring-analysis-note with MIT License | 6 votes |
@Test public void overrideArgumentResolvers() throws Exception { DefaultMessageHandlerMethodFactory instance = createInstance(); List<HandlerMethodArgumentResolver> customResolvers = new ArrayList<>(); customResolvers.add(new CustomHandlerMethodArgumentResolver()); instance.setArgumentResolvers(customResolvers); instance.afterPropertiesSet(); Message<String> message = MessageBuilder.withPayload("sample").build(); // This will work as the local resolver is set InvocableHandlerMethod invocableHandlerMethod = createInvocableHandlerMethod(instance, "customArgumentResolver", Locale.class); invocableHandlerMethod.invoke(message); assertMethodInvocation(sample, "customArgumentResolver"); // This won't work as no resolver is known for the payload InvocableHandlerMethod invocableHandlerMethod2 = createInvocableHandlerMethod(instance, "simpleString", String.class); assertThatExceptionOfType(MethodArgumentResolutionException.class).isThrownBy(() -> invocableHandlerMethod2.invoke(message)).withMessageContaining("No suitable resolver"); }
Example #9
Source File: DefaultMessageHandlerMethodFactoryTests.java From spring4-understanding with Apache License 2.0 | 6 votes |
@Test public void customValidation() throws Exception { DefaultMessageHandlerMethodFactory instance = createInstance(); instance.setValidator(new Validator() { @Override public boolean supports(Class<?> clazz) { return String.class.isAssignableFrom(clazz); } @Override public void validate(Object target, Errors errors) { String value = (String) target; if ("failure".equals(value)) { errors.reject("not a valid value"); } } }); instance.afterPropertiesSet(); InvocableHandlerMethod invocableHandlerMethod = createInvocableHandlerMethod(instance, "payloadValidation", String.class); thrown.expect(MethodArgumentNotValidException.class); invocableHandlerMethod.invoke(MessageBuilder.withPayload("failure").build()); }
Example #10
Source File: DefaultMessageHandlerMethodFactoryTests.java From spring-analysis-note with MIT License | 6 votes |
@Test public void customConversion() throws Exception { DefaultMessageHandlerMethodFactory instance = createInstance(); GenericConversionService conversionService = new GenericConversionService(); conversionService.addConverter(SampleBean.class, String.class, new Converter<SampleBean, String>() { @Override public String convert(SampleBean source) { return "foo bar"; } }); instance.setConversionService(conversionService); instance.afterPropertiesSet(); InvocableHandlerMethod invocableHandlerMethod = createInvocableHandlerMethod(instance, "simpleString", String.class); invocableHandlerMethod.invoke(MessageBuilder.withPayload(sample).build()); assertMethodInvocation(sample, "simpleString"); }
Example #11
Source File: DefaultMessageHandlerMethodFactoryTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void noValidationByDefault() throws Exception { DefaultMessageHandlerMethodFactory instance = createInstance(); instance.afterPropertiesSet(); InvocableHandlerMethod invocableHandlerMethod = createInvocableHandlerMethod(instance, "payloadValidation", String.class); invocableHandlerMethod.invoke(MessageBuilder.withPayload("failure").build()); assertMethodInvocation(sample, "payloadValidation"); }
Example #12
Source File: DefaultMessageHandlerMethodFactoryTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void customArgumentResolver() throws Exception { DefaultMessageHandlerMethodFactory instance = createInstance(); List<HandlerMethodArgumentResolver> customResolvers = new ArrayList<HandlerMethodArgumentResolver>(); customResolvers.add(new CustomHandlerMethodArgumentResolver()); instance.setCustomArgumentResolvers(customResolvers); instance.afterPropertiesSet(); InvocableHandlerMethod invocableHandlerMethod = createInvocableHandlerMethod(instance, "customArgumentResolver", Locale.class); invocableHandlerMethod.invoke(MessageBuilder.withPayload(123).build()); assertMethodInvocation(sample, "customArgumentResolver"); }
Example #13
Source File: DefaultMessageHandlerMethodFactoryTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void customMessageConverterFailure() throws Exception { DefaultMessageHandlerMethodFactory instance = createInstance(); MessageConverter messageConverter = new ByteArrayMessageConverter(); instance.setMessageConverter(messageConverter); instance.afterPropertiesSet(); InvocableHandlerMethod invocableHandlerMethod = createInvocableHandlerMethod(instance, "simpleString", String.class); thrown.expect(MessageConversionException.class); invocableHandlerMethod.invoke(MessageBuilder.withPayload(123).build()); }
Example #14
Source File: DefaultMessageHandlerMethodFactoryTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void customConversionServiceFailure() throws Exception { DefaultMessageHandlerMethodFactory instance = createInstance(); GenericConversionService conversionService = new GenericConversionService(); assertFalse("conversion service should fail to convert payload", conversionService.canConvert(Integer.class, String.class)); instance.setConversionService(conversionService); instance.afterPropertiesSet(); InvocableHandlerMethod invocableHandlerMethod = createInvocableHandlerMethod(instance, "simpleString", String.class); thrown.expect(MessageConversionException.class); invocableHandlerMethod.invoke(MessageBuilder.withPayload(123).build()); }
Example #15
Source File: MethodJmsListenerEndpoint.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Override protected MessagingMessageListenerAdapter createMessageListener(MessageListenerContainer container) { Assert.state(this.messageHandlerMethodFactory != null, "Could not create message listener - MessageHandlerMethodFactory not set"); MessagingMessageListenerAdapter messageListener = createMessageListenerInstance(); InvocableHandlerMethod invocableHandlerMethod = this.messageHandlerMethodFactory.createInvocableHandlerMethod(getBean(), getMethod()); messageListener.setHandlerMethod(invocableHandlerMethod); String responseDestination = getDefaultResponseDestination(); if (StringUtils.hasText(responseDestination)) { if (container.isReplyPubSubDomain()) { messageListener.setDefaultResponseTopicName(responseDestination); } else { messageListener.setDefaultResponseQueueName(responseDestination); } } MessageConverter messageConverter = container.getMessageConverter(); if (messageConverter != null) { messageListener.setMessageConverter(messageConverter); } DestinationResolver destinationResolver = container.getDestinationResolver(); if (destinationResolver != null) { messageListener.setDestinationResolver(destinationResolver); } return messageListener; }
Example #16
Source File: MethodJmsListenerEndpoint.java From java-technology-stack with MIT License | 5 votes |
@Override protected MessagingMessageListenerAdapter createMessageListener(MessageListenerContainer container) { Assert.state(this.messageHandlerMethodFactory != null, "Could not create message listener - MessageHandlerMethodFactory not set"); MessagingMessageListenerAdapter messageListener = createMessageListenerInstance(); InvocableHandlerMethod invocableHandlerMethod = this.messageHandlerMethodFactory.createInvocableHandlerMethod(getBean(), getMethod()); messageListener.setHandlerMethod(invocableHandlerMethod); String responseDestination = getDefaultResponseDestination(); if (StringUtils.hasText(responseDestination)) { if (container.isReplyPubSubDomain()) { messageListener.setDefaultResponseTopicName(responseDestination); } else { messageListener.setDefaultResponseQueueName(responseDestination); } } QosSettings responseQosSettings = container.getReplyQosSettings(); if (responseQosSettings != null) { messageListener.setResponseQosSettings(responseQosSettings); } MessageConverter messageConverter = container.getMessageConverter(); if (messageConverter != null) { messageListener.setMessageConverter(messageConverter); } DestinationResolver destinationResolver = container.getDestinationResolver(); if (destinationResolver != null) { messageListener.setDestinationResolver(destinationResolver); } return messageListener; }
Example #17
Source File: MessagingMessageListenerAdapter.java From java-technology-stack with MIT License | 5 votes |
private String createMessagingErrorMessage(String description) { InvocableHandlerMethod handlerMethod = getHandlerMethod(); StringBuilder sb = new StringBuilder(description).append("\n") .append("Endpoint handler details:\n") .append("Method [").append(handlerMethod.getMethod()).append("]\n") .append("Bean [").append(handlerMethod.getBean()).append("]\n"); return sb.toString(); }
Example #18
Source File: StreamListenerMessageHandler.java From spring-cloud-stream with Apache License 2.0 | 5 votes |
StreamListenerMessageHandler(InvocableHandlerMethod invocableHandlerMethod, boolean copyHeaders, String[] notPropagatedHeaders) { super(); this.invocableHandlerMethod = invocableHandlerMethod; this.copyHeaders = copyHeaders; this.setNotPropagatedHeaders(notPropagatedHeaders); }
Example #19
Source File: DefaultMessageHandlerMethodFactoryTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void noValidationByDefault() throws Exception { DefaultMessageHandlerMethodFactory instance = createInstance(); instance.afterPropertiesSet(); InvocableHandlerMethod invocableHandlerMethod = createInvocableHandlerMethod(instance, "payloadValidation", String.class); invocableHandlerMethod.invoke(MessageBuilder.withPayload("failure").build()); assertMethodInvocation(sample, "payloadValidation"); }
Example #20
Source File: QueueMessageHandler.java From spring-cloud-aws with Apache License 2.0 | 5 votes |
@Override protected void processHandlerMethodException(HandlerMethod handlerMethod, Exception ex, Message<?> message) { InvocableHandlerMethod exceptionHandlerMethod = getExceptionHandlerMethod( handlerMethod, ex); if (exceptionHandlerMethod != null) { super.processHandlerMethodException(handlerMethod, ex, message); } else { this.logger.error("An exception occurred while invoking the handler method", ex); } throw new MessagingException( "An exception occurred while invoking the handler method", ex); }
Example #21
Source File: DefaultMessageHandlerMethodFactoryTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void customMessageConverterFailure() throws Exception { DefaultMessageHandlerMethodFactory instance = createInstance(); MessageConverter messageConverter = new ByteArrayMessageConverter(); instance.setMessageConverter(messageConverter); instance.afterPropertiesSet(); InvocableHandlerMethod invocableHandlerMethod = createInvocableHandlerMethod(instance, "simpleString", String.class); thrown.expect(MessageConversionException.class); invocableHandlerMethod.invoke(MessageBuilder.withPayload(123).build()); }
Example #22
Source File: DefaultMessageHandlerMethodFactoryTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void customConversionServiceFailure() throws Exception { DefaultMessageHandlerMethodFactory instance = createInstance(); GenericConversionService conversionService = new GenericConversionService(); assertFalse("conversion service should fail to convert payload", conversionService.canConvert(Integer.class, String.class)); instance.setConversionService(conversionService); instance.afterPropertiesSet(); InvocableHandlerMethod invocableHandlerMethod = createInvocableHandlerMethod(instance, "simpleString", String.class); thrown.expect(MessageConversionException.class); invocableHandlerMethod.invoke(MessageBuilder.withPayload(123).build()); }
Example #23
Source File: DefaultMessageHandlerMethodFactoryTests.java From spring-analysis-note with MIT License | 5 votes |
@Test public void customConversionServiceFailure() throws Exception { DefaultMessageHandlerMethodFactory instance = createInstance(); GenericConversionService conversionService = new GenericConversionService(); assertFalse("conversion service should fail to convert payload", conversionService.canConvert(Integer.class, String.class)); instance.setConversionService(conversionService); instance.afterPropertiesSet(); InvocableHandlerMethod invocableHandlerMethod = createInvocableHandlerMethod(instance, "simpleString", String.class); assertThatExceptionOfType(MessageConversionException.class).isThrownBy(() -> invocableHandlerMethod.invoke(MessageBuilder.withPayload(123).build())); }
Example #24
Source File: DefaultMessageHandlerMethodFactoryTests.java From spring-analysis-note with MIT License | 5 votes |
@Test public void customMessageConverterFailure() throws Exception { DefaultMessageHandlerMethodFactory instance = createInstance(); MessageConverter messageConverter = new ByteArrayMessageConverter(); instance.setMessageConverter(messageConverter); instance.afterPropertiesSet(); InvocableHandlerMethod invocableHandlerMethod = createInvocableHandlerMethod(instance, "simpleString", String.class); assertThatExceptionOfType(MessageConversionException.class).isThrownBy(() -> invocableHandlerMethod.invoke(MessageBuilder.withPayload(123).build())); }
Example #25
Source File: DefaultMessageHandlerMethodFactoryTests.java From spring-analysis-note with MIT License | 5 votes |
@Test public void customArgumentResolver() throws Exception { DefaultMessageHandlerMethodFactory instance = createInstance(); List<HandlerMethodArgumentResolver> customResolvers = new ArrayList<>(); customResolvers.add(new CustomHandlerMethodArgumentResolver()); instance.setCustomArgumentResolvers(customResolvers); instance.afterPropertiesSet(); InvocableHandlerMethod invocableHandlerMethod = createInvocableHandlerMethod(instance, "customArgumentResolver", Locale.class); invocableHandlerMethod.invoke(MessageBuilder.withPayload(123).build()); assertMethodInvocation(sample, "customArgumentResolver"); }
Example #26
Source File: MethodJmsListenerEndpoint.java From spring-analysis-note with MIT License | 5 votes |
@Override protected MessagingMessageListenerAdapter createMessageListener(MessageListenerContainer container) { Assert.state(this.messageHandlerMethodFactory != null, "Could not create message listener - MessageHandlerMethodFactory not set"); MessagingMessageListenerAdapter messageListener = createMessageListenerInstance(); Object bean = getBean(); Method method = getMethod(); Assert.state(bean != null && method != null, "No bean+method set on endpoint"); InvocableHandlerMethod invocableHandlerMethod = this.messageHandlerMethodFactory.createInvocableHandlerMethod(bean, method); messageListener.setHandlerMethod(invocableHandlerMethod); String responseDestination = getDefaultResponseDestination(); if (StringUtils.hasText(responseDestination)) { if (container.isReplyPubSubDomain()) { messageListener.setDefaultResponseTopicName(responseDestination); } else { messageListener.setDefaultResponseQueueName(responseDestination); } } QosSettings responseQosSettings = container.getReplyQosSettings(); if (responseQosSettings != null) { messageListener.setResponseQosSettings(responseQosSettings); } MessageConverter messageConverter = container.getMessageConverter(); if (messageConverter != null) { messageListener.setMessageConverter(messageConverter); } DestinationResolver destinationResolver = container.getDestinationResolver(); if (destinationResolver != null) { messageListener.setDestinationResolver(destinationResolver); } return messageListener; }
Example #27
Source File: DefaultMessageHandlerMethodFactoryTests.java From spring-analysis-note with MIT License | 5 votes |
@Test public void noValidationByDefault() throws Exception { DefaultMessageHandlerMethodFactory instance = createInstance(); instance.afterPropertiesSet(); InvocableHandlerMethod invocableHandlerMethod = createInvocableHandlerMethod(instance, "payloadValidation", String.class); invocableHandlerMethod.invoke(MessageBuilder.withPayload("failure").build()); assertMethodInvocation(sample, "payloadValidation"); }
Example #28
Source File: MessagingMessageListenerAdapter.java From spring-analysis-note with MIT License | 5 votes |
private String createMessagingErrorMessage(String description) { InvocableHandlerMethod handlerMethod = getHandlerMethod(); StringBuilder sb = new StringBuilder(description).append("\n") .append("Endpoint handler details:\n") .append("Method [").append(handlerMethod.getMethod()).append("]\n") .append("Bean [").append(handlerMethod.getBean()).append("]\n"); return sb.toString(); }
Example #29
Source File: DefaultMessageHandlerMethodFactoryTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void customArgumentResolver() throws Exception { DefaultMessageHandlerMethodFactory instance = createInstance(); List<HandlerMethodArgumentResolver> customResolvers = new ArrayList<>(); customResolvers.add(new CustomHandlerMethodArgumentResolver()); instance.setCustomArgumentResolvers(customResolvers); instance.afterPropertiesSet(); InvocableHandlerMethod invocableHandlerMethod = createInvocableHandlerMethod(instance, "customArgumentResolver", Locale.class); invocableHandlerMethod.invoke(MessageBuilder.withPayload(123).build()); assertMethodInvocation(sample, "customArgumentResolver"); }
Example #30
Source File: MessagingMessageListenerAdapter.java From spring-analysis-note with MIT License | 4 votes |
private InvocableHandlerMethod getHandlerMethod() { Assert.state(this.handlerMethod != null, "No HandlerMethod set"); return this.handlerMethod; }