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);
}
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;
}
}
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());
}
}
}
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);
}
}
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);
}
Aggregations