use of org.springframework.web.method.HandlerMethod in project spring-framework by spring-projects.
the class AbstractHandlerMethodMapping method createHandlerMethod.
/**
* Create the HandlerMethod instance.
* @param handler either a bean name or an actual handler instance
* @param method the target method
* @return the created HandlerMethod
*/
protected HandlerMethod createHandlerMethod(Object handler, Method method) {
HandlerMethod handlerMethod;
if (handler instanceof String) {
String beanName = (String) handler;
handlerMethod = new HandlerMethod(beanName, getApplicationContext().getAutowireCapableBeanFactory(), method);
} else {
handlerMethod = new HandlerMethod(handler, method);
}
return handlerMethod;
}
use of org.springframework.web.method.HandlerMethod in project spring-framework by spring-projects.
the class MessageReaderArgumentResolverTests method parameterizedMethodArgument.
// SPR-9964
@Test
public void parameterizedMethodArgument() throws Exception {
Method method = AbstractParameterizedController.class.getMethod("handleDto", Identifiable.class);
HandlerMethod handlerMethod = new HandlerMethod(new ConcreteParameterizedController(), method);
MethodParameter methodParam = handlerMethod.getMethodParameters()[0];
SimpleBean simpleBean = resolveValue(methodParam, "{\"name\" : \"Jad\"}");
assertEquals("Jad", simpleBean.getName());
}
use of org.springframework.web.method.HandlerMethod in project spring-framework by spring-projects.
the class RequestMappingInfoHandlerMappingTests method testHttpOptions.
private void testHttpOptions(String requestURI, String allowHeader) throws Exception {
ServerWebExchange exchange = MockServerHttpRequest.options(requestURI).toExchange();
HandlerMethod handlerMethod = (HandlerMethod) this.handlerMapping.getHandler(exchange).block();
BindingContext bindingContext = new BindingContext();
InvocableHandlerMethod invocable = new InvocableHandlerMethod(handlerMethod);
Mono<HandlerResult> mono = invocable.invoke(exchange, bindingContext);
HandlerResult result = mono.block();
assertNotNull(result);
Optional<Object> value = result.getReturnValue();
assertTrue(value.isPresent());
assertEquals(HttpHeaders.class, value.get().getClass());
assertEquals(allowHeader, ((HttpHeaders) value.get()).getFirst("Allow"));
}
use of org.springframework.web.method.HandlerMethod in project spring-framework by spring-projects.
the class HandlerResultMatchers method method.
/**
* Assert the controller method used to process the request.
*/
public ResultMatcher method(final Method method) {
return new ResultMatcher() {
@Override
public void match(MvcResult result) throws Exception {
HandlerMethod handlerMethod = getHandlerMethod(result);
assertEquals("Handler method", method, handlerMethod.getMethod());
}
};
}
use of org.springframework.web.method.HandlerMethod in project spring-framework by spring-projects.
the class HandlerResultMatchers method methodName.
/**
* Assert the name of the controller method used to process the request
* using the given Hamcrest {@link Matcher}.
*/
public ResultMatcher methodName(final Matcher<? super String> matcher) {
return new ResultMatcher() {
@Override
public void match(MvcResult result) throws Exception {
HandlerMethod handlerMethod = getHandlerMethod(result);
assertThat("Handler method", handlerMethod.getMethod().getName(), matcher);
}
};
}
Aggregations