Java Code Examples for org.springframework.messaging.handler.invocation.HandlerMethodArgumentResolver

The following examples show how to use org.springframework.messaging.handler.invocation.HandlerMethodArgumentResolver. These examples are extracted from open source projects. 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 Project: spring-analysis-note   Author: Vip-Augus   File: DefaultMessageHandlerMethodFactory.java    License: MIT License 7 votes vote down vote up
protected List<HandlerMethodArgumentResolver> initArgumentResolvers() {
	List<HandlerMethodArgumentResolver> resolvers = new ArrayList<>();
	ConfigurableBeanFactory beanFactory = (this.beanFactory instanceof ConfigurableBeanFactory ?
			(ConfigurableBeanFactory) this.beanFactory : null);

	// Annotation-based argument resolution
	resolvers.add(new HeaderMethodArgumentResolver(this.conversionService, beanFactory));
	resolvers.add(new HeadersMethodArgumentResolver());

	// Type-based argument resolution
	resolvers.add(new MessageMethodArgumentResolver(this.messageConverter));

	if (this.customArgumentResolvers != null) {
		resolvers.addAll(this.customArgumentResolvers);
	}

	Assert.notNull(this.messageConverter, "MessageConverter not configured");
	resolvers.add(new PayloadMethodArgumentResolver(this.messageConverter, this.validator));

	return resolvers;
}
 
Example #2
Source Project: spring-analysis-note   Author: Vip-Augus   File: SimpAnnotationMethodMessageHandler.java    License: MIT License 6 votes vote down vote up
protected List<HandlerMethodArgumentResolver> initArgumentResolvers() {
	ApplicationContext context = getApplicationContext();
	ConfigurableBeanFactory beanFactory = (context instanceof ConfigurableApplicationContext ?
			((ConfigurableApplicationContext) context).getBeanFactory() : null);

	List<HandlerMethodArgumentResolver> resolvers = new ArrayList<>();

	// Annotation-based argument resolution
	resolvers.add(new HeaderMethodArgumentResolver(this.conversionService, beanFactory));
	resolvers.add(new HeadersMethodArgumentResolver());
	resolvers.add(new DestinationVariableMethodArgumentResolver(this.conversionService));

	// Type-based argument resolution
	resolvers.add(new PrincipalMethodArgumentResolver());
	resolvers.add(new MessageMethodArgumentResolver(this.messageConverter));

	resolvers.addAll(getCustomArgumentResolvers());
	resolvers.add(new PayloadMethodArgumentResolver(this.messageConverter, this.validator));

	return resolvers;
}
 
Example #3
Source Project: spring-analysis-note   Author: Vip-Augus   File: AbstractMessageBrokerConfiguration.java    License: MIT License 6 votes vote down vote up
@Bean
public SimpAnnotationMethodMessageHandler simpAnnotationMethodMessageHandler() {
	SimpAnnotationMethodMessageHandler handler = createAnnotationMethodMessageHandler();
	handler.setDestinationPrefixes(getBrokerRegistry().getApplicationDestinationPrefixes());
	handler.setMessageConverter(brokerMessageConverter());
	handler.setValidator(simpValidator());

	List<HandlerMethodArgumentResolver> argumentResolvers = new ArrayList<>();
	addArgumentResolvers(argumentResolvers);
	handler.setCustomArgumentResolvers(argumentResolvers);

	List<HandlerMethodReturnValueHandler> returnValueHandlers = new ArrayList<>();
	addReturnValueHandlers(returnValueHandlers);
	handler.setCustomReturnValueHandlers(returnValueHandlers);

	PathMatcher pathMatcher = getBrokerRegistry().getPathMatcher();
	if (pathMatcher != null) {
		handler.setPathMatcher(pathMatcher);
	}
	return handler;
}
 
Example #4
Source Project: spring-analysis-note   Author: Vip-Augus   File: DefaultMessageHandlerMethodFactoryTests.java    License: MIT License 6 votes vote down vote up
@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 #5
Source Project: spring-analysis-note   Author: Vip-Augus   File: MessageBrokerBeanDefinitionParserTests.java    License: MIT License 6 votes vote down vote up
@Test
public void customArgumentAndReturnValueTypes() {
	loadBeanDefinitions("websocket-config-broker-custom-argument-and-return-value-types.xml");

	SimpAnnotationMethodMessageHandler handler = this.appContext.getBean(SimpAnnotationMethodMessageHandler.class);

	List<HandlerMethodArgumentResolver> customResolvers = handler.getCustomArgumentResolvers();
	assertEquals(2, customResolvers.size());
	assertTrue(handler.getArgumentResolvers().contains(customResolvers.get(0)));
	assertTrue(handler.getArgumentResolvers().contains(customResolvers.get(1)));

	List<HandlerMethodReturnValueHandler> customHandlers = handler.getCustomReturnValueHandlers();
	assertEquals(2, customHandlers.size());
	assertTrue(handler.getReturnValueHandlers().contains(customHandlers.get(0)));
	assertTrue(handler.getReturnValueHandlers().contains(customHandlers.get(1)));
}
 
Example #6
Source Project: java-technology-stack   Author: codeEngraver   File: SimpAnnotationMethodMessageHandler.java    License: MIT License 6 votes vote down vote up
protected List<HandlerMethodArgumentResolver> initArgumentResolvers() {
	ApplicationContext context = getApplicationContext();
	ConfigurableBeanFactory beanFactory = (context instanceof ConfigurableApplicationContext ?
			((ConfigurableApplicationContext) context).getBeanFactory() : null);

	List<HandlerMethodArgumentResolver> resolvers = new ArrayList<>();

	// Annotation-based argument resolution
	resolvers.add(new HeaderMethodArgumentResolver(this.conversionService, beanFactory));
	resolvers.add(new HeadersMethodArgumentResolver());
	resolvers.add(new DestinationVariableMethodArgumentResolver(this.conversionService));

	// Type-based argument resolution
	resolvers.add(new PrincipalMethodArgumentResolver());
	resolvers.add(new MessageMethodArgumentResolver(this.messageConverter));

	resolvers.addAll(getCustomArgumentResolvers());
	resolvers.add(new PayloadArgumentResolver(this.messageConverter, this.validator));

	return resolvers;
}
 
Example #7
Source Project: java-technology-stack   Author: codeEngraver   File: AbstractMessageBrokerConfiguration.java    License: MIT License 6 votes vote down vote up
@Bean
public SimpAnnotationMethodMessageHandler simpAnnotationMethodMessageHandler() {
	SimpAnnotationMethodMessageHandler handler = createAnnotationMethodMessageHandler();
	handler.setDestinationPrefixes(getBrokerRegistry().getApplicationDestinationPrefixes());
	handler.setMessageConverter(brokerMessageConverter());
	handler.setValidator(simpValidator());

	List<HandlerMethodArgumentResolver> argumentResolvers = new ArrayList<>();
	addArgumentResolvers(argumentResolvers);
	handler.setCustomArgumentResolvers(argumentResolvers);

	List<HandlerMethodReturnValueHandler> returnValueHandlers = new ArrayList<>();
	addReturnValueHandlers(returnValueHandlers);
	handler.setCustomReturnValueHandlers(returnValueHandlers);

	PathMatcher pathMatcher = getBrokerRegistry().getPathMatcher();
	if (pathMatcher != null) {
		handler.setPathMatcher(pathMatcher);
	}
	return handler;
}
 
Example #8
Source Project: java-technology-stack   Author: codeEngraver   File: DefaultMessageHandlerMethodFactory.java    License: MIT License 6 votes vote down vote up
protected List<HandlerMethodArgumentResolver> initArgumentResolvers() {
	List<HandlerMethodArgumentResolver> resolvers = new ArrayList<>();
	ConfigurableBeanFactory cbf = (this.beanFactory instanceof ConfigurableBeanFactory ?
			(ConfigurableBeanFactory) this.beanFactory : null);

	// Annotation-based argument resolution
	resolvers.add(new HeaderMethodArgumentResolver(this.conversionService, cbf));
	resolvers.add(new HeadersMethodArgumentResolver());

	// Type-based argument resolution
	resolvers.add(new MessageMethodArgumentResolver(this.messageConverter));

	if (this.customArgumentResolvers != null) {
		resolvers.addAll(this.customArgumentResolvers);
	}
	resolvers.add(new PayloadArgumentResolver(this.messageConverter, this.validator));

	return resolvers;
}
 
Example #9
Source Project: java-technology-stack   Author: codeEngraver   File: DefaultMessageHandlerMethodFactoryTests.java    License: MIT License 6 votes vote down vote up
@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 #10
Source Project: java-technology-stack   Author: codeEngraver   File: MessageBrokerBeanDefinitionParserTests.java    License: MIT License 6 votes vote down vote up
@Test
public void customArgumentAndReturnValueTypes() {
	loadBeanDefinitions("websocket-config-broker-custom-argument-and-return-value-types.xml");

	SimpAnnotationMethodMessageHandler handler = this.appContext.getBean(SimpAnnotationMethodMessageHandler.class);

	List<HandlerMethodArgumentResolver> customResolvers = handler.getCustomArgumentResolvers();
	assertEquals(2, customResolvers.size());
	assertTrue(handler.getArgumentResolvers().contains(customResolvers.get(0)));
	assertTrue(handler.getArgumentResolvers().contains(customResolvers.get(1)));

	List<HandlerMethodReturnValueHandler> customHandlers = handler.getCustomReturnValueHandlers();
	assertEquals(2, customHandlers.size());
	assertTrue(handler.getReturnValueHandlers().contains(customHandlers.get(0)));
	assertTrue(handler.getReturnValueHandlers().contains(customHandlers.get(1)));
}
 
Example #11
Source Project: spring4-understanding   Author: langtianya   File: SimpAnnotationMethodMessageHandler.java    License: Apache License 2.0 6 votes vote down vote up
protected List<HandlerMethodArgumentResolver> initArgumentResolvers() {
	ConfigurableBeanFactory beanFactory = (getApplicationContext() instanceof ConfigurableApplicationContext ?
			((ConfigurableApplicationContext) getApplicationContext()).getBeanFactory() : null);

	List<HandlerMethodArgumentResolver> resolvers = new ArrayList<HandlerMethodArgumentResolver>();

	// Annotation-based argument resolution
	resolvers.add(new HeaderMethodArgumentResolver(this.conversionService, beanFactory));
	resolvers.add(new HeadersMethodArgumentResolver());
	resolvers.add(new DestinationVariableMethodArgumentResolver(this.conversionService));

	// Type-based argument resolution
	resolvers.add(new PrincipalMethodArgumentResolver());
	resolvers.add(new MessageMethodArgumentResolver());

	resolvers.addAll(getCustomArgumentResolvers());
	resolvers.add(new PayloadArgumentResolver(this.messageConverter, this.validator));

	return resolvers;
}
 
Example #12
Source Project: spring4-understanding   Author: langtianya   File: AbstractMessageBrokerConfiguration.java    License: Apache License 2.0 6 votes vote down vote up
@Bean
public SimpAnnotationMethodMessageHandler simpAnnotationMethodMessageHandler() {
	SimpAnnotationMethodMessageHandler handler = createAnnotationMethodMessageHandler();
	handler.setDestinationPrefixes(getBrokerRegistry().getApplicationDestinationPrefixes());
	handler.setMessageConverter(brokerMessageConverter());
	handler.setValidator(simpValidator());

	List<HandlerMethodArgumentResolver> argumentResolvers = new ArrayList<HandlerMethodArgumentResolver>();
	addArgumentResolvers(argumentResolvers);
	handler.setCustomArgumentResolvers(argumentResolvers);

	List<HandlerMethodReturnValueHandler> returnValueHandlers = new ArrayList<HandlerMethodReturnValueHandler>();
	addReturnValueHandlers(returnValueHandlers);
	handler.setCustomReturnValueHandlers(returnValueHandlers);

	PathMatcher pathMatcher = this.getBrokerRegistry().getPathMatcher();
	if (pathMatcher != null) {
		handler.setPathMatcher(pathMatcher);
	}
	return handler;
}
 
Example #13
Source Project: spring4-understanding   Author: langtianya   File: DefaultMessageHandlerMethodFactory.java    License: Apache License 2.0 6 votes vote down vote up
protected List<HandlerMethodArgumentResolver> initArgumentResolvers() {
	List<HandlerMethodArgumentResolver> resolvers = new ArrayList<HandlerMethodArgumentResolver>();
	ConfigurableBeanFactory cbf = (this.beanFactory instanceof ConfigurableBeanFactory ?
			(ConfigurableBeanFactory) this.beanFactory : null);

	// Annotation-based argument resolution
	resolvers.add(new HeaderMethodArgumentResolver(this.conversionService, cbf));
	resolvers.add(new HeadersMethodArgumentResolver());

	// Type-based argument resolution
	resolvers.add(new MessageMethodArgumentResolver());

	if (this.customArgumentResolvers != null) {
		resolvers.addAll(this.customArgumentResolvers);
	}
	resolvers.add(new PayloadArgumentResolver(this.messageConverter, this.validator));

	return resolvers;
}
 
Example #14
Source Project: spring4-understanding   Author: langtianya   File: DefaultMessageHandlerMethodFactoryTests.java    License: Apache License 2.0 6 votes vote down vote up
@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 #15
Source Project: spring4-understanding   Author: langtianya   File: MessageBrokerBeanDefinitionParserTests.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void customArgumentAndReturnValueTypes() {
	loadBeanDefinitions("websocket-config-broker-custom-argument-and-return-value-types.xml");

	SimpAnnotationMethodMessageHandler handler = this.appContext.getBean(SimpAnnotationMethodMessageHandler.class);

	List<HandlerMethodArgumentResolver> customResolvers = handler.getCustomArgumentResolvers();
	assertEquals(2, customResolvers.size());
	assertTrue(handler.getArgumentResolvers().contains(customResolvers.get(0)));
	assertTrue(handler.getArgumentResolvers().contains(customResolvers.get(1)));

	List<HandlerMethodReturnValueHandler> customHandlers = handler.getCustomReturnValueHandlers();
	assertEquals(2, customHandlers.size());
	assertTrue(handler.getReturnValueHandlers().contains(customHandlers.get(0)));
	assertTrue(handler.getReturnValueHandlers().contains(customHandlers.get(1)));
}
 
Example #16
Source Project: spring-cloud-aws   Author: spring-cloud   File: QueueMessageHandler.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected List<? extends HandlerMethodArgumentResolver> initArgumentResolvers() {
	List<HandlerMethodArgumentResolver> resolvers = new ArrayList<>(
			getCustomArgumentResolvers());

	resolvers.add(new HeaderMethodArgumentResolver(null, null));
	resolvers.add(new SqsHeadersMethodArgumentResolver());

	resolvers.add(new NotificationSubjectArgumentResolver());
	resolvers.add(new AcknowledgmentHandlerMethodArgumentResolver(ACKNOWLEDGMENT));
	resolvers.add(new VisibilityHandlerMethodArgumentResolver(VISIBILITY));

	CompositeMessageConverter compositeMessageConverter = createPayloadArgumentCompositeConverter();
	resolvers.add(new NotificationMessageArgumentResolver(compositeMessageConverter));
	resolvers.add(new MessageMethodArgumentResolver(
			this.messageConverters.isEmpty() ? new StringMessageConverter()
					: new CompositeMessageConverter(this.messageConverters)));
	resolvers.add(new PayloadArgumentResolver(compositeMessageConverter,
			new NoOpValidator()));

	return resolvers;
}
 
Example #17
Source Project: rqueue   Author: sonus21   File: RqueueMessageHandler.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected List<? extends HandlerMethodArgumentResolver> initArgumentResolvers() {
  List<HandlerMethodArgumentResolver> resolvers = new ArrayList<>(getCustomArgumentResolvers());
  // Annotation-based argument resolution
  resolvers.add(new HeaderMethodArgumentResolver(this.conversionService, getBeanFactory()));
  resolvers.add(new HeadersMethodArgumentResolver());

  // Type-based argument resolution
  resolvers.add(new PrincipalMethodArgumentResolver());
  resolvers.add(new MessageMethodArgumentResolver(messageConverter));
  resolvers.add(new PayloadArgumentResolver(messageConverter, null));

  return resolvers;
}
 
Example #18
Source Project: spring-analysis-note   Author: Vip-Augus   File: DefaultMessageHandlerMethodFactory.java    License: MIT License 5 votes vote down vote up
/**
 * Configure the complete list of supported argument types effectively overriding
 * the ones configured by default. This is an advanced option. For most use cases
 * it should be sufficient to use {@link #setCustomArgumentResolvers(java.util.List)}.
 */
@SuppressWarnings("ConstantConditions")
public void setArgumentResolvers(List<HandlerMethodArgumentResolver> argumentResolvers) {
	if (argumentResolvers == null) {
		this.argumentResolvers.clear();
		return;
	}
	this.argumentResolvers.addResolvers(argumentResolvers);
}
 
Example #19
Source Project: spring-analysis-note   Author: Vip-Augus   File: MessageBrokerConfigurationTests.java    License: MIT License 5 votes vote down vote up
@Test
public void customArgumentAndReturnValueTypes() {
	ApplicationContext context = loadConfig(CustomConfig.class);

	SimpAnnotationMethodMessageHandler handler =
			context.getBean(SimpAnnotationMethodMessageHandler.class);

	List<HandlerMethodArgumentResolver> customResolvers = handler.getCustomArgumentResolvers();
	assertEquals(1, customResolvers.size());
	assertTrue(handler.getArgumentResolvers().contains(customResolvers.get(0)));

	List<HandlerMethodReturnValueHandler> customHandlers = handler.getCustomReturnValueHandlers();
	assertEquals(1, customHandlers.size());
	assertTrue(handler.getReturnValueHandlers().contains(customHandlers.get(0)));
}
 
Example #20
Source Project: spring-analysis-note   Author: Vip-Augus   File: DefaultMessageHandlerMethodFactoryTests.java    License: MIT License 5 votes vote down vote up
@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 #21
Source Project: java-technology-stack   Author: codeEngraver   File: DefaultMessageHandlerMethodFactory.java    License: MIT License 5 votes vote down vote up
/**
 * Configure the complete list of supported argument types effectively overriding
 * the ones configured by default. This is an advanced option. For most use cases
 * it should be sufficient to use {@link #setCustomArgumentResolvers(java.util.List)}.
 */
public void setArgumentResolvers(List<HandlerMethodArgumentResolver> argumentResolvers) {
	if (argumentResolvers == null) {
		this.argumentResolvers.clear();
		return;
	}
	this.argumentResolvers.addResolvers(argumentResolvers);
}
 
Example #22
Source Project: java-technology-stack   Author: codeEngraver   File: MessageBrokerConfigurationTests.java    License: MIT License 5 votes vote down vote up
@Test
public void customArgumentAndReturnValueTypes() {
	ApplicationContext context = loadConfig(CustomConfig.class);

	SimpAnnotationMethodMessageHandler handler =
			context.getBean(SimpAnnotationMethodMessageHandler.class);

	List<HandlerMethodArgumentResolver> customResolvers = handler.getCustomArgumentResolvers();
	assertEquals(1, customResolvers.size());
	assertTrue(handler.getArgumentResolvers().contains(customResolvers.get(0)));

	List<HandlerMethodReturnValueHandler> customHandlers = handler.getCustomReturnValueHandlers();
	assertEquals(1, customHandlers.size());
	assertTrue(handler.getReturnValueHandlers().contains(customHandlers.get(0)));
}
 
Example #23
Source Project: java-technology-stack   Author: codeEngraver   File: DefaultMessageHandlerMethodFactoryTests.java    License: MIT License 5 votes vote down vote up
@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 #24
Source Project: spring4-understanding   Author: langtianya   File: DefaultMessageHandlerMethodFactory.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Configure the complete list of supported argument types effectively overriding
 * the ones configured by default. This is an advanced option. For most use cases
 * it should be sufficient to use {@link #setCustomArgumentResolvers(java.util.List)}.
 */
public void setArgumentResolvers(List<HandlerMethodArgumentResolver> argumentResolvers) {
	if (argumentResolvers == null) {
		this.argumentResolvers.clear();
		return;
	}
	this.argumentResolvers.addResolvers(argumentResolvers);
}
 
Example #25
Source Project: spring4-understanding   Author: langtianya   File: MessageBrokerConfigurationTests.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void customArgumentAndReturnValueTypes() throws Exception {
	SimpAnnotationMethodMessageHandler handler = this.customContext.getBean(SimpAnnotationMethodMessageHandler.class);

	List<HandlerMethodArgumentResolver> customResolvers = handler.getCustomArgumentResolvers();
	assertEquals(1, customResolvers.size());
	assertTrue(handler.getArgumentResolvers().contains(customResolvers.get(0)));

	List<HandlerMethodReturnValueHandler> customHandlers = handler.getCustomReturnValueHandlers();
	assertEquals(1, customHandlers.size());
	assertTrue(handler.getReturnValueHandlers().contains(customHandlers.get(0)));
}
 
Example #26
Source Project: spring4-understanding   Author: langtianya   File: DefaultMessageHandlerMethodFactoryTests.java    License: Apache License 2.0 5 votes vote down vote up
@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 #27
Source Project: spring-cloud-aws   Author: spring-cloud   File: QueueMessageHandlerTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
void receiveMessage_withCustomArgumentResolvers_shouldCallThemBeforeTheDefaultOnes()
		throws Exception {
	// Arrange
	StaticApplicationContext applicationContext = new StaticApplicationContext();
	applicationContext.registerSingleton("incomingMessageHandler",
			IncomingMessageHandler.class);

	HandlerMethodArgumentResolver handlerMethodArgumentResolver = mock(
			HandlerMethodArgumentResolver.class);
	when(handlerMethodArgumentResolver.supportsParameter(any(MethodParameter.class)))
			.thenReturn(true);
	when(handlerMethodArgumentResolver.resolveArgument(any(MethodParameter.class),
			any(Message.class))).thenReturn("Hello from a sender");
	MutablePropertyValues properties = new MutablePropertyValues(
			Collections.singletonList(new PropertyValue("customArgumentResolvers",
					handlerMethodArgumentResolver)));
	applicationContext.registerSingleton("queueMessageHandler",
			QueueMessageHandler.class, properties);
	applicationContext.refresh();

	QueueMessageHandler queueMessageHandler = applicationContext
			.getBean(QueueMessageHandler.class);

	// Act
	queueMessageHandler.handleMessage(MessageBuilder
			.withPayload("Hello from a sender")
			.setHeader(QueueMessageHandler.LOGICAL_RESOURCE_ID, "receive").build());

	// Assert
	verify(handlerMethodArgumentResolver, times(1))
			.resolveArgument(any(MethodParameter.class), any(Message.class));
}
 
Example #28
Source Project: spring-analysis-note   Author: Vip-Augus   File: AbstractMessageBrokerConfiguration.java    License: MIT License 4 votes vote down vote up
protected void addArgumentResolvers(List<HandlerMethodArgumentResolver> argumentResolvers) {
}
 
Example #29
Source Project: spring-analysis-note   Author: Vip-Augus   File: MessageBrokerConfigurationTests.java    License: MIT License 4 votes vote down vote up
@Override
protected void addArgumentResolvers(List<HandlerMethodArgumentResolver> argumentResolvers) {
	argumentResolvers.add(mock(HandlerMethodArgumentResolver.class));
}
 
Example #30
Source Project: spring-analysis-note   Author: Vip-Augus   File: DelegatingWebSocketMessageBrokerConfiguration.java    License: MIT License 4 votes vote down vote up
@Override
protected void addArgumentResolvers(List<HandlerMethodArgumentResolver> argumentResolvers) {
	for (WebSocketMessageBrokerConfigurer configurer : this.configurers) {
		configurer.addArgumentResolvers(argumentResolvers);
	}
}