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 {
MockHttpServletRequest request = new MockHttpServletRequest("OPTIONS", requestURI);
HandlerMethod handlerMethod = getHandler(request);
ServletWebRequest webRequest = new ServletWebRequest(request);
ModelAndViewContainer mavContainer = new ModelAndViewContainer();
Object result = new InvocableHandlerMethod(handlerMethod).invokeForRequest(webRequest, mavContainer);
assertNotNull(result);
assertEquals(HttpHeaders.class, result.getClass());
assertEquals(allowHeader, ((HttpHeaders) result).getFirst("Allow"));
}
use of org.springframework.web.method.HandlerMethod in project spring-framework by spring-projects.
the class RequestMappingInfoHandlerMappingTests method getHandlerGlobMatch.
@Test
public void getHandlerGlobMatch() throws Exception {
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/bar");
HandlerMethod handlerMethod = getHandler(request);
assertEquals(this.barMethod.getMethod(), handlerMethod.getMethod());
}
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);
}
use of org.springframework.web.method.HandlerMethod in project powerauth-restful-integration by lime-company.
the class PowerAuthAnnotationInterceptor method preHandle.
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
// requests before the actual requests.
if (handler instanceof HandlerMethod) {
HandlerMethod handlerMethod = (HandlerMethod) handler;
// Obtain annotations
PowerAuth powerAuthSignatureAnnotation = handlerMethod.getMethodAnnotation(PowerAuth.class);
PowerAuthToken powerAuthTokenAnnotation = handlerMethod.getMethodAnnotation(PowerAuthToken.class);
// Check that only one annotation is active
if (powerAuthSignatureAnnotation != null && powerAuthTokenAnnotation != null) {
Logger.getLogger(this.getClass().getName()).log(Level.SEVERE, "You cannot use both @PowerAuth and @PowerAuthToken on same handler method. We are removing both.");
powerAuthSignatureAnnotation = null;
powerAuthTokenAnnotation = null;
}
// Resolve @PowerAuth annotation
if (powerAuthSignatureAnnotation != null) {
try {
PowerAuthApiAuthentication authentication = this.authenticationProvider.validateRequestSignature(request, powerAuthSignatureAnnotation.resourceId(), request.getHeader(PowerAuthSignatureHttpHeader.HEADER_NAME), new ArrayList<>(Arrays.asList(powerAuthSignatureAnnotation.signatureType())));
request.setAttribute(PowerAuth.AUTHENTICATION_OBJECT, authentication);
} catch (PowerAuthAuthenticationException ex) {
// silently ignore here and make sure authentication object is null
request.setAttribute(PowerAuth.AUTHENTICATION_OBJECT, null);
}
}
// Resolve @PowerAuthToken annotation
if (powerAuthTokenAnnotation != null) {
try {
PowerAuthApiAuthentication authentication = this.authenticationProvider.validateToken(request.getHeader(PowerAuthTokenHttpHeader.HEADER_NAME), new ArrayList<>(Arrays.asList(powerAuthTokenAnnotation.signatureType())));
request.setAttribute(PowerAuth.AUTHENTICATION_OBJECT, authentication);
} catch (PowerAuthAuthenticationException ex) {
// silently ignore here and make sure authentication object is null
request.setAttribute(PowerAuth.AUTHENTICATION_OBJECT, null);
}
}
}
return super.preHandle(request, response, handler);
}
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();
}
Aggregations