use of org.springframework.core.annotation.SynthesizingMethodParameter in project spring-framework by spring-projects.
the class SendToMethodReturnValueHandlerTests method sendToUserWithSendToDefaultOverride.
// SPR-14238
@Test
public void sendToUserWithSendToDefaultOverride() throws Exception {
given(this.messageChannel.send(any(Message.class))).willReturn(true);
Class<?> clazz = SendToUserWithSendToOverrideTestBean.class;
Method method = clazz.getDeclaredMethod("handleAndSendToDefaultDestination");
MethodParameter parameter = new SynthesizingMethodParameter(method, -1);
String sessionId = "sess1";
Message<?> inputMessage = createMessage(sessionId, "sub1", null, null, null);
this.handler.handleReturnValue(PAYLOAD, parameter, inputMessage);
verify(this.messageChannel, times(1)).send(this.messageCaptor.capture());
assertResponse(parameter, sessionId, 0, "/user/sess1/dest-default");
}
use of org.springframework.core.annotation.SynthesizingMethodParameter in project spring-framework by spring-projects.
the class SendToMethodReturnValueHandlerTests method sendToUserWithSendToOverride.
// SPR-14238
@Test
public void sendToUserWithSendToOverride() throws Exception {
given(this.messageChannel.send(any(Message.class))).willReturn(true);
Class<?> clazz = SendToUserWithSendToOverrideTestBean.class;
Method method = clazz.getDeclaredMethod("handleAndSendToOverride");
MethodParameter parameter = new SynthesizingMethodParameter(method, -1);
String sessionId = "sess1";
Message<?> inputMessage = createMessage(sessionId, "sub1", null, null, null);
this.handler.handleReturnValue(PAYLOAD, parameter, inputMessage);
verify(this.messageChannel, times(2)).send(this.messageCaptor.capture());
assertResponse(parameter, sessionId, 0, "/dest3");
assertResponse(parameter, sessionId, 1, "/dest4");
}
use of org.springframework.core.annotation.SynthesizingMethodParameter in project spring-framework by spring-projects.
the class ParameterAutowireUtils method resolveDependency.
/**
* Resolve the dependency for the supplied {@link Parameter} from the
* supplied {@link ApplicationContext}.
* <p>Provides comprehensive autowiring support for individual method parameters
* on par with Spring's dependency injection facilities for autowired fields and
* methods, including support for {@link Autowired @Autowired},
* {@link Qualifier @Qualifier}, and {@link Value @Value} with support for property
* placeholders and SpEL expressions in {@code @Value} declarations.
* <p>The dependency is required unless the parameter is annotated with
* {@link Autowired @Autowired} with the {@link Autowired#required required}
* flag set to {@code false}.
* <p>If an explicit <em>qualifier</em> is not declared, the name of the parameter
* will be used as the qualifier for resolving ambiguities.
* @param parameter the parameter whose dependency should be resolved
* @param containingClass the concrete class that contains the parameter; this may
* differ from the class that declares the parameter in that it may be a subclass
* thereof, potentially substituting type variables
* @param applicationContext the application context from which to resolve the
* dependency
* @return the resolved object, or {@code null} if none found
* @throws BeansException if dependency resolution failed
* @see #isAutowirable(Parameter)
* @see Autowired#required
* @see SynthesizingMethodParameter#forParameter(Parameter)
* @see AutowireCapableBeanFactory#resolveDependency(DependencyDescriptor, String)
*/
static Object resolveDependency(Parameter parameter, Class<?> containingClass, ApplicationContext applicationContext) {
boolean required = findMergedAnnotation(parameter, Autowired.class).map(Autowired::required).orElse(true);
MethodParameter methodParameter = SynthesizingMethodParameter.forParameter(parameter);
DependencyDescriptor descriptor = new DependencyDescriptor(methodParameter, required);
descriptor.setContainingClass(containingClass);
return applicationContext.getAutowireCapableBeanFactory().resolveDependency(descriptor, null);
}
use of org.springframework.core.annotation.SynthesizingMethodParameter in project spring-framework by spring-projects.
the class RequestHeaderMapMethodArgumentResolverTests method setUp.
@Before
public void setUp() throws Exception {
resolver = new RequestHeaderMapMethodArgumentResolver();
Method method = getClass().getMethod("params", Map.class, MultiValueMap.class, HttpHeaders.class, Map.class);
paramMap = new SynthesizingMethodParameter(method, 0);
paramMultiValueMap = new SynthesizingMethodParameter(method, 1);
paramHttpHeaders = new SynthesizingMethodParameter(method, 2);
paramUnsupported = new SynthesizingMethodParameter(method, 3);
request = new MockHttpServletRequest();
webRequest = new ServletWebRequest(request, new MockHttpServletResponse());
}
use of org.springframework.core.annotation.SynthesizingMethodParameter in project spring-framework by spring-projects.
the class CookieValueMethodArgumentResolverTests method setup.
@Before
public void setup() throws Exception {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
context.refresh();
ReactiveAdapterRegistry adapterRegistry = new ReactiveAdapterRegistry();
this.resolver = new CookieValueMethodArgumentResolver(context.getBeanFactory(), adapterRegistry);
this.bindingContext = new BindingContext();
Method method = ReflectionUtils.findMethod(getClass(), "params", (Class<?>[]) null);
this.cookieParameter = new SynthesizingMethodParameter(method, 0);
this.cookieStringParameter = new SynthesizingMethodParameter(method, 1);
this.stringParameter = new SynthesizingMethodParameter(method, 2);
this.cookieMonoParameter = new SynthesizingMethodParameter(method, 3);
}
Aggregations