use of org.springframework.web.method.HandlerMethod in project spring-mvc-31-demo by rstoyanchev.
the class ExtendedExceptionHandlerExceptionResolver method getExceptionHandlerMethod.
@Override
protected ServletInvocableHandlerMethod getExceptionHandlerMethod(HandlerMethod handlerMethod, Exception exception) {
ServletInvocableHandlerMethod result = super.getExceptionHandlerMethod(handlerMethod, exception);
if (result != null) {
return result;
}
Method method = this.methodResolver.resolveMethod(exception);
return (method != null) ? new ServletInvocableHandlerMethod(this.handler, method) : null;
}
use of org.springframework.web.method.HandlerMethod in project nikita-noark5-core by HiOA-ABI.
the class AfterApplicationStartup method afterApplicationStarts.
/**
* afterApplicationStarts, go through list of endpoints and make a list of
* endpoints and the HTTP methods they support. Really this should be
* handled by Spring. I do not know why I couldn't get spring to handle
* this but we need to get spring to handle these things ... not me!!!
*
* Also create a list of Norwegian names to english names for handling OData
*/
public void afterApplicationStarts() {
for (Map.Entry<RequestMappingInfo, HandlerMethod> entry : handlerMapping.getHandlerMethods().entrySet()) {
RequestMappingInfo requestMappingInfo = entry.getKey();
// Assuming there is always a non-null value
String servletPaths = requestMappingInfo.getPatternsCondition().toString();
// servletPath starts with "[" and ends with "]". Removing them if they are there
if (true == servletPaths.startsWith("[")) {
servletPaths = servletPaths.substring(1);
}
if (true == servletPaths.endsWith("]")) {
servletPaths = servletPaths.substring(0, servletPaths.length() - 1);
}
String[] servletPathList = servletPaths.split("\\s+");
for (String servletPath : servletPathList) {
if (servletPath != null && false == servletPath.contains("|")) {
// This is done to be consist on a lookup
if (false == servletPath.endsWith("/")) {
servletPath += SLASH;
}
Set<RequestMethod> httpMethodRequests = requestMappingInfo.getMethodsCondition().getMethods();
if (null != httpMethodRequests && null != servletPath) {
// RequestMethod and HTTPMethod are different types, have to convert them here
Set<HttpMethod> httpMethods = new TreeSet<>();
for (RequestMethod requestMethod : httpMethodRequests) {
if (requestMethod.equals(RequestMethod.GET)) {
httpMethods.add(HttpMethod.GET);
} else if (requestMethod.equals(RequestMethod.DELETE)) {
httpMethods.add(HttpMethod.DELETE);
} else if (requestMethod.equals(RequestMethod.OPTIONS)) {
httpMethods.add(HttpMethod.OPTIONS);
} else if (requestMethod.equals(RequestMethod.HEAD)) {
httpMethods.add(HttpMethod.HEAD);
} else if (requestMethod.equals(RequestMethod.PATCH)) {
httpMethods.add(HttpMethod.PATCH);
} else if (requestMethod.equals(RequestMethod.POST)) {
httpMethods.add(HttpMethod.POST);
} else if (requestMethod.equals(RequestMethod.PUT)) {
httpMethods.add(HttpMethod.PUT);
} else if (requestMethod.equals(RequestMethod.TRACE)) {
httpMethods.add(HttpMethod.TRACE);
}
}
out.println("Adding " + servletPath + " methods " + httpMethods);
CommonUtils.WebUtils.addRequestToMethodMap(servletPath, httpMethods);
} else {
logger.warn("Missing HTTP Methods for the following servletPath [" + servletPath + "]");
}
}
}
}
populateTranslatedNames();
}
use of org.springframework.web.method.HandlerMethod in project leopard by tanhaichao.
the class RoleInterceptor method preHandle.
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
// logger.info("preHandle uri:" + request.getRequestURI() + " handler:" + handler.getClass());
if (!(handler instanceof HandlerMethod)) {
return true;
}
// TODO ahai 这里要加上缓存?
HandlerMethod method = (HandlerMethod) handler;
Role role = method.getMethodAnnotation(Role.class);
if (role == null) {
return true;
}
this.check(role, request);
return true;
}
use of org.springframework.web.method.HandlerMethod in project leopard by tanhaichao.
the class FrequencyResolver method parseSeconds.
private int parseSeconds(Object handler) {
if (!(handler instanceof HandlerMethod)) {
return 0;
}
HandlerMethod handlerMethod = (HandlerMethod) handler;
Frequency frequency = handlerMethod.getMethodAnnotation(Frequency.class);
if (frequency == null) {
return 0;
}
return frequency.seconds();
}
use of org.springframework.web.method.HandlerMethod in project leopard by tanhaichao.
the class PassportInterceptor method isNeedLogin.
/**
* 判断handler是否需要登录检查.
*
* @param handler
* @return
*/
public static boolean isNeedLogin(Object handler) {
HandlerMethod method = (HandlerMethod) handler;
Nologin nologin = method.getMethodAnnotation(Nologin.class);
return (nologin == null);
}
Aggregations