use of org.springframework.web.method.HandlerMethod in project BroadleafCommerce by BroadleafCommerce.
the class FrameworkMvcUriComponentsBuilder method fromMappingName.
/**
* An alternative to {@link #fromMappingName(String)} that accepts a
* {@code UriComponentsBuilder} representing the base URL. This is useful
* when using MvcUriComponentsBuilder outside the context of processing a
* request or to apply a custom baseUrl not matching the current request.
* @param builder the builder for the base URL; the builder will be cloned
* and therefore not modified and may be re-used for further calls.
* @param name the mapping name
* @return a builder to prepare the URI String
* @throws IllegalArgumentException if the mapping name is not found or
* if there is no unique match
* @since 4.2
*/
public static MethodArgumentBuilder fromMappingName(UriComponentsBuilder builder, String name) {
RequestMappingInfoHandlerMapping handlerMapping = getRequestMappingInfoHandlerMapping();
List<HandlerMethod> handlerMethods = handlerMapping.getHandlerMethodsForMappingName(name);
if (handlerMethods == null) {
throw new IllegalArgumentException("Mapping mappingName not found: " + name);
}
if (handlerMethods.size() != 1) {
throw new IllegalArgumentException("No unique match for mapping mappingName " + name + ": " + handlerMethods);
}
HandlerMethod handlerMethod = handlerMethods.get(0);
Class<?> controllerType = handlerMethod.getBeanType();
Method method = handlerMethod.getMethod();
return new MethodArgumentBuilder(builder, controllerType, method);
}
use of org.springframework.web.method.HandlerMethod in project shepher by XiaoMi.
the class AuthorizationInterceptor method preHandle.
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
if (handler instanceof HandlerMethod) {
HandlerMethod handlerMethod = (HandlerMethod) handler;
Auth annotation = getAnnotation(handlerMethod);
if (annotation != null && !authStrategy.validate(request, annotation.value())) {
throw ShepherException.createNoAuthorizationException();
}
}
return true;
}
use of org.springframework.web.method.HandlerMethod in project neubbs by nuitcoder.
the class ApiInterceptor method doLoginAuthorization.
/*
* ***********************************************
* private method
* ***********************************************
*/
/*
* ***********************************************
* authority management method
* ***********************************************
*/
/**
* 执行登录验证
* - 判断 api 函数是否标识 @LoginAuthorization
* - 判断是否存在 authentication Cookie(不存在表明未登陆, 未登录无权操作)
* - 判断 authentication Cookie 是否解密成功(解密失败,表示认证信息已经过期)
*
* @param request http 请求
* @param handler 接口方法对象
*/
private void doLoginAuthorization(HttpServletRequest request, Object handler) throws ServiceException {
HandlerMethod handlerMethod = (HandlerMethod) handler;
if (handlerMethod.getMethodAnnotation(LoginAuthorization.class) != null) {
String authentication = CookieUtil.getCookieValue(request, ParamConst.AUTHENTICATION);
this.judgeAuthentication(authentication);
}
}
use of org.springframework.web.method.HandlerMethod in project kork by spinnaker.
the class MetricsInterceptor method afterCompletion.
@Override
public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
if (handler instanceof HandlerMethod) {
HandlerMethod handlerMethod = (HandlerMethod) handler;
String controller = handlerMethod.getMethod().getDeclaringClass().getSimpleName();
if (controllersToExclude.contains(controller)) {
return;
}
Integer status = response.getStatus();
if (ex != null) {
// propagated exceptions should get tracked as '500' regardless of response status
status = 500;
}
Id id = registry.createId(metricName).withTag("controller", controller).withTag("method", handlerMethod.getMethod().getName()).withTag("status", status.toString().charAt(0) + "xx").withTag("statusCode", status.toString());
Map variables = (Map) request.getAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE);
for (String pathVariable : pathVariablesToTag) {
if (variables.containsKey(pathVariable)) {
id = id.withTag(pathVariable, variables.get(pathVariable).toString());
}
}
if (ex != null) {
id = id.withTag("success", "false").withTag("cause", ex.getClass().getSimpleName());
} else {
id = id.withTag("success", "true");
}
registry.timer(id).record(getNanoTime() - ((Long) request.getAttribute(TIMER_ATTRIBUTE)), TimeUnit.NANOSECONDS);
}
}
use of org.springframework.web.method.HandlerMethod in project ma-modules-public by infiniteautomation.
the class BaseRestTest method createHandlerExceptionResolvers.
/**
* Create Handlers for use in Testing
* @return
*/
private ExceptionHandlerExceptionResolver createHandlerExceptionResolvers(final List<HttpMessageConverter<?>> converters) {
ExceptionHandlerExceptionResolver exceptionResolver = new ExceptionHandlerExceptionResolver() {
/* (non-Javadoc)
* @see org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerExceptionResolver#getMessageConverters()
*/
@Override
public List<HttpMessageConverter<?>> getMessageConverters() {
return converters;
}
@Override
protected ServletInvocableHandlerMethod getExceptionHandlerMethod(HandlerMethod handlerMethod, Exception exception) {
// return new ServletInvocableHandlerMethod(new ExceptionHandlingController(), method);
return null;
}
};
exceptionResolver.afterPropertiesSet();
return exceptionResolver;
}
Aggregations