Search in sources :

Example 1 with RequestMapping

use of com.revolsys.ui.web.annotation.RequestMapping in project com.revolsys.open by revolsys.

the class MenuViewController method header.

@RequestMapping("/view/header/{menuName}")
public void header(final HttpServletRequest request, final HttpServletResponse response, @PathVariable("menuName") final String menuName) throws IOException {
    final Navbar navbar = (Navbar) request.getAttribute(menuName);
    bootstrapNavbar(request, response, navbar);
}
Also used : Navbar(com.revolsys.ui.model.Navbar) RequestMapping(com.revolsys.ui.web.annotation.RequestMapping)

Example 2 with RequestMapping

use of com.revolsys.ui.web.annotation.RequestMapping in project com.revolsys.open by revolsys.

the class DefaultAnnotationHandlerMapping method determineUrlsForHandler.

/**
 * Checks for presence of the {@link org.springframework.web.bind.annotation.RequestMapping}
 * annotation on the handler class and on any of its methods.
 */
@Override
protected String[] determineUrlsForHandler(final String beanName) {
    final ApplicationContext context = getApplicationContext();
    final Class<?> handlerType = context.getType(beanName);
    final RequestMapping mapping = context.findAnnotationOnBean(beanName, RequestMapping.class);
    if (mapping != null) {
        // @RequestMapping found at type level
        this.cachedMappings.put(handlerType, mapping);
        final Set<String> urls = new LinkedHashSet<>();
        final String[] typeLevelPatterns = mapping.value();
        if (typeLevelPatterns.length > 0) {
            // @RequestMapping specifies paths at type level
            final String[] methodLevelPatterns = determineUrlsForHandlerMethods(handlerType, true);
            for (String typeLevelPattern : typeLevelPatterns) {
                if (!typeLevelPattern.startsWith("/")) {
                    typeLevelPattern = "/" + typeLevelPattern;
                }
                boolean hasEmptyMethodLevelMappings = false;
                for (final String methodLevelPattern : methodLevelPatterns) {
                    if (methodLevelPattern == null) {
                        hasEmptyMethodLevelMappings = true;
                    } else {
                        final String combinedPattern = getPathMatcher().combine(typeLevelPattern, methodLevelPattern);
                        addUrlsForPath(urls, combinedPattern);
                    }
                }
                if (hasEmptyMethodLevelMappings || org.springframework.web.servlet.mvc.Controller.class.isAssignableFrom(handlerType)) {
                    addUrlsForPath(urls, typeLevelPattern);
                }
            }
            return StringUtils.toStringArray(urls);
        } else {
            // actual paths specified by @RequestMapping at method level
            return determineUrlsForHandlerMethods(handlerType, false);
        }
    } else if (AnnotationUtils.findAnnotation(handlerType, Controller.class) != null) {
        // @RequestMapping to be introspected at method level
        return determineUrlsForHandlerMethods(handlerType, false);
    } else {
        return null;
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ApplicationContext(org.springframework.context.ApplicationContext) Controller(org.springframework.stereotype.Controller) RequestMapping(com.revolsys.ui.web.annotation.RequestMapping)

Example 3 with RequestMapping

use of com.revolsys.ui.web.annotation.RequestMapping in project com.revolsys.open by revolsys.

the class AnnotationHandlerMethodResolver method resolveHandlerMethod.

public WebMethodHandler resolveHandlerMethod(final HttpServletRequest request) throws ServletException {
    final String lookupPath = this.adapter.urlPathHelper.getLookupPathForRequest(request);
    final Comparator<String> pathComparator = this.adapter.pathMatcher.getPatternComparator(lookupPath);
    final Map<RequestMappingInfo, WebMethodHandler> targetHandlerMethods = new LinkedHashMap<>();
    final Set<String> allowedMethods = new LinkedHashSet<>(7);
    String resolvedMethodName = null;
    for (final WebMethodHandler webMethodHandler : this.handlerMethods) {
        final Method handlerMethod = webMethodHandler.getMethod();
        final RequestMappingInfo mappingInfo = new RequestMappingInfo();
        final RequestMapping mapping = AnnotationUtils.findAnnotation(handlerMethod, RequestMapping.class);
        mappingInfo.paths = mapping.value();
        if (!hasTypeLevelMapping() || !Arrays.equals(mapping.method(), this.typeLevelMapping.method())) {
            mappingInfo.methods = mapping.method();
        }
        boolean match = false;
        if (mappingInfo.paths.length > 0) {
            final List<String> matchedPaths = new ArrayList<>(mappingInfo.paths.length);
            for (final String methodLevelPattern : mappingInfo.paths) {
                final String matchedPattern = getMatchedPattern(methodLevelPattern, lookupPath, request);
                if (matchedPattern != null) {
                    if (mappingInfo.matches(request)) {
                        match = true;
                        matchedPaths.add(matchedPattern);
                    } else {
                        for (final RequestMethod requestMethod : mappingInfo.methods) {
                            allowedMethods.add(requestMethod.toString());
                        }
                        break;
                    }
                }
            }
            Collections.sort(matchedPaths, pathComparator);
            mappingInfo.matchedPaths = matchedPaths;
        } else {
            // No paths specified: parameter match sufficient.
            match = mappingInfo.matches(request);
            if (match && mappingInfo.methods.length == 0 && resolvedMethodName != null && !resolvedMethodName.equals(handlerMethod.getName())) {
                match = false;
            } else {
                for (final RequestMethod requestMethod : mappingInfo.methods) {
                    allowedMethods.add(requestMethod.toString());
                }
            }
        }
        if (match) {
            WebMethodHandler oldMappedMethod = targetHandlerMethods.put(mappingInfo, webMethodHandler);
            if (oldMappedMethod != null && oldMappedMethod != webMethodHandler) {
                if (this.adapter.methodNameResolver != null && mappingInfo.paths.length == 0) {
                    if (!oldMappedMethod.getMethod().getName().equals(handlerMethod.getName())) {
                        if (resolvedMethodName == null) {
                            resolvedMethodName = this.adapter.methodNameResolver.getHandlerMethodName(request);
                        }
                        if (!resolvedMethodName.equals(oldMappedMethod.getMethod().getName())) {
                            oldMappedMethod = null;
                        }
                        if (!resolvedMethodName.equals(handlerMethod.getName())) {
                            if (oldMappedMethod != null) {
                                targetHandlerMethods.put(mappingInfo, oldMappedMethod);
                                oldMappedMethod = null;
                            } else {
                                targetHandlerMethods.remove(mappingInfo);
                            }
                        }
                    }
                }
                if (oldMappedMethod != null) {
                    throw new IllegalStateException("Ambiguous handler methods mapped for HTTP path '" + lookupPath + "': {" + oldMappedMethod + ", " + handlerMethod + "}. If you intend to handle the same path in multiple methods, then factor " + "them out into a dedicated handler class with that path mapped at the type level!");
                }
            }
        }
    }
    if (!targetHandlerMethods.isEmpty()) {
        final List<RequestMappingInfo> matches = new ArrayList<>(targetHandlerMethods.keySet());
        final RequestMappingInfoComparator requestMappingInfoComparator = new RequestMappingInfoComparator(pathComparator);
        Collections.sort(matches, requestMappingInfoComparator);
        final RequestMappingInfo bestMappingMatch = matches.get(0);
        final String bestMatchedPath = bestMappingMatch.bestMatchedPath();
        if (bestMatchedPath != null) {
            extractHandlerMethodUriTemplates(bestMatchedPath, lookupPath, request);
        }
        return targetHandlerMethods.get(bestMappingMatch);
    } else {
        if (!allowedMethods.isEmpty()) {
            throw new HttpRequestMethodNotSupportedException(request.getMethod(), StringUtils.toStringArray(allowedMethods));
        } else {
            throw new NoSuchRequestHandlingMethodException(lookupPath, request.getMethod(), request.getParameterMap());
        }
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) NoSuchRequestHandlingMethodException(org.springframework.web.servlet.mvc.multiaction.NoSuchRequestHandlingMethodException) RequestMethod(org.springframework.web.bind.annotation.RequestMethod) ArrayList(java.util.ArrayList) Method(java.lang.reflect.Method) RequestMethod(org.springframework.web.bind.annotation.RequestMethod) HttpRequestMethodNotSupportedException(org.springframework.web.HttpRequestMethodNotSupportedException) LinkedHashMap(java.util.LinkedHashMap) RequestMapping(com.revolsys.ui.web.annotation.RequestMapping)

Example 4 with RequestMapping

use of com.revolsys.ui.web.annotation.RequestMapping in project com.revolsys.open by revolsys.

the class MenuViewController method menu.

@RequestMapping("/view/menu/{menuName}")
public void menu(final HttpServletRequest request, final HttpServletResponse response, @PathVariable("menuName") final String menuName) throws IOException {
    final Menu menu = (Menu) request.getAttribute(menuName);
    if (menu != null) {
        final MenuElement menuElement = new MenuElement(menu, menuName);
        final OutputStream out = response.getOutputStream();
        menuElement.serialize(out);
    }
}
Also used : OutputStream(java.io.OutputStream) Menu(com.revolsys.ui.model.Menu) MenuElement(com.revolsys.ui.html.view.MenuElement) RequestMapping(com.revolsys.ui.web.annotation.RequestMapping)

Example 5 with RequestMapping

use of com.revolsys.ui.web.annotation.RequestMapping in project com.revolsys.open by revolsys.

the class MenuViewController method footer.

@RequestMapping("/view/footer/{menuName}")
public void footer(final HttpServletRequest request, final HttpServletResponse response, @PathVariable("menuName") final String menuName) throws IOException {
    final Navbar navbar = (Navbar) request.getAttribute(menuName);
    bootstrapNavbar(request, response, navbar);
}
Also used : Navbar(com.revolsys.ui.model.Navbar) RequestMapping(com.revolsys.ui.web.annotation.RequestMapping)

Aggregations

RequestMapping (com.revolsys.ui.web.annotation.RequestMapping)7 Navbar (com.revolsys.ui.model.Navbar)2 Method (java.lang.reflect.Method)2 ArrayList (java.util.ArrayList)2 LinkedHashSet (java.util.LinkedHashSet)2 MenuElement (com.revolsys.ui.html.view.MenuElement)1 Menu (com.revolsys.ui.model.Menu)1 ColumnSortOrder (com.revolsys.ui.web.annotation.ColumnSortOrder)1 Page (com.revolsys.ui.web.config.Page)1 OutputStream (java.io.OutputStream)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 ApplicationContext (org.springframework.context.ApplicationContext)1 Controller (org.springframework.stereotype.Controller)1 HttpRequestMethodNotSupportedException (org.springframework.web.HttpRequestMethodNotSupportedException)1 RequestMethod (org.springframework.web.bind.annotation.RequestMethod)1 NoSuchRequestHandlingMethodException (org.springframework.web.servlet.mvc.multiaction.NoSuchRequestHandlingMethodException)1