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

The following examples show how to use org.springframework.messaging.handler.invocation.HandlerMethodArgumentResolver. 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: DefaultMessageHandlerMethodFactory.java    From spring-analysis-note with 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 File: SimpAnnotationMethodMessageHandler.java    From spring-analysis-note with 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 File: QueueMessageHandler.java    From spring-cloud-aws with 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 #4
Source File: MessageBrokerBeanDefinitionParserTests.java    From spring4-understanding with 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 #5
Source File: DefaultMessageHandlerMethodFactoryTests.java    From spring4-understanding with 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 #6
Source File: DefaultMessageHandlerMethodFactory.java    From spring4-understanding with 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 #7
Source File: AbstractMessageBrokerConfiguration.java    From spring4-understanding with 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 #8
Source File: SimpAnnotationMethodMessageHandler.java    From spring4-understanding with 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 #9
Source File: MessageBrokerBeanDefinitionParserTests.java    From java-technology-stack with 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 #10
Source File: DefaultMessageHandlerMethodFactoryTests.java    From java-technology-stack with 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 #11
Source File: DefaultMessageHandlerMethodFactory.java    From java-technology-stack with 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 #12
Source File: AbstractMessageBrokerConfiguration.java    From java-technology-stack with 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 #13
Source File: SimpAnnotationMethodMessageHandler.java    From java-technology-stack with 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 #14
Source File: MessageBrokerBeanDefinitionParserTests.java    From spring-analysis-note with 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 #15
Source File: DefaultMessageHandlerMethodFactoryTests.java    From spring-analysis-note with 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 #16
Source File: AbstractMessageBrokerConfiguration.java    From spring-analysis-note with 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 #17
Source File: DefaultMessageHandlerMethodFactoryTests.java    From spring-analysis-note with 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 #18
Source File: MessageBrokerConfigurationTests.java    From spring4-understanding with 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 #19
Source File: DefaultMessageHandlerMethodFactory.java    From spring4-understanding with 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 #20
Source File: DefaultMessageHandlerMethodFactoryTests.java    From spring4-understanding with 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 #21
Source File: DefaultMessageHandlerMethodFactory.java    From spring-analysis-note with 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 #22
Source File: MessageBrokerConfigurationTests.java    From spring-analysis-note with 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 File: DefaultMessageHandlerMethodFactoryTests.java    From java-technology-stack with 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 File: MessageBrokerConfigurationTests.java    From java-technology-stack with 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 #25
Source File: DefaultMessageHandlerMethodFactory.java    From java-technology-stack with 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 #26
Source File: RqueueMessageHandler.java    From rqueue with 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 #27
Source File: QueueMessageHandlerTest.java    From spring-cloud-aws with 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 File: WebSocketConfig.java    From consensusj with Apache License 2.0 4 votes vote down vote up
@Override
public void addArgumentResolvers(List<HandlerMethodArgumentResolver> argumentResolvers) {
    // TODO: ??
}
 
Example #29
Source File: AbstractMessageBrokerConfiguration.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
protected void addArgumentResolvers(List<HandlerMethodArgumentResolver> argumentResolvers) {
}
 
Example #30
Source File: AbstractWebSocketMessageBrokerConfigurer.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
@Override
public void addArgumentResolvers(List<HandlerMethodArgumentResolver> argumentResolvers) {
}