Search in sources :

Example 11 with RequestMethod

use of org.springframework.web.bind.annotation.RequestMethod 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.
     *
     */
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 + "]");
                }
            }
        }
    }
}
Also used : RequestMappingInfo(org.springframework.web.servlet.mvc.method.RequestMappingInfo) RequestMethod(org.springframework.web.bind.annotation.RequestMethod) TreeSet(java.util.TreeSet) Map(java.util.Map) HandlerMethod(org.springframework.web.method.HandlerMethod) HttpMethod(org.springframework.http.HttpMethod)

Aggregations

RequestMethod (org.springframework.web.bind.annotation.RequestMethod)11 Map (java.util.Map)3 HandlerMethod (org.springframework.web.method.HandlerMethod)3 Visitor (com.baidu.disconf.web.service.user.dto.Visitor)2 Method (java.lang.reflect.Method)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Test (org.junit.Test)2 CrossOrigin (org.springframework.web.bind.annotation.CrossOrigin)2 CorsConfiguration (org.springframework.web.cors.CorsConfiguration)2 RequestMappingInfo (org.springframework.web.servlet.mvc.method.RequestMappingInfo)2 RoleResource (com.baidu.disconf.web.service.roleres.bo.RoleResource)1 AccessDeniedException (com.baidu.dsp.common.exception.AccessDeniedException)1 TreeSet (java.util.TreeSet)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 Around (org.aspectj.lang.annotation.Around)1 Cacheable (org.springframework.cache.annotation.Cacheable)1 HttpMethod (org.springframework.http.HttpMethod)1 MockHttpServletRequest (org.springframework.mock.web.test.MockHttpServletRequest)1