/** * Calls the {@link #registerHandlers} method in addition to the * superclass's initialization. */ @Override public void initApplicationContext() throws BeansException { super.initApplicationContext(); registerHandlers(this.urlMap); }
@Nullable protected Object getHandlerInternal(HttpServletRequest request) throws Exception { String lookupPath = getUrlPathHelper().getLookupPathForRequest(request); Object handler = lookupHandler(lookupPath, request); if (handler == null) { rawHandler = getRootHandler(); rawHandler = getDefaultHandler(); rawHandler = obtainApplicationContext().getBean(handlerName); validateHandler(rawHandler, request); handler = buildPathExposingHandler(rawHandler, lookupPath, lookupPath, null);
@Override public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) { exposePathWithinMapping(this.bestMatchingPattern, this.pathWithinMapping, request); request.setAttribute(BEST_MATCHING_HANDLER_ATTRIBUTE, handler); request.setAttribute(INTROSPECT_TYPE_LEVEL_MAPPING, supportsTypeLevelMappings()); return true; }
@Override @Nullable public RequestMatchResult match(HttpServletRequest request, String pattern) { String lookupPath = getUrlPathHelper().getLookupPathForRequest(request); if (getPathMatcher().match(pattern, lookupPath)) { return new RequestMatchResult(pattern, lookupPath, getPathMatcher()); } else if (useTrailingSlashMatch()) { if (!pattern.endsWith("/") && getPathMatcher().match(pattern + "/", lookupPath)) { return new RequestMatchResult(pattern + "/", lookupPath, getPathMatcher()); } } return null; }
handler = obtainApplicationContext().getBean(handlerName); validateHandler(handler, request); return buildPathExposingHandler(handler, urlPath, urlPath, null); if (getPathMatcher().match(registeredPattern, urlPath)) { matchingPatterns.add(registeredPattern); else if (useTrailingSlashMatch()) { if (!registeredPattern.endsWith("/") && getPathMatcher().match(registeredPattern + "/", urlPath)) { matchingPatterns.add(registeredPattern +"/"); Comparator<String> patternComparator = getPathMatcher().getPatternComparator(urlPath); if (!matchingPatterns.isEmpty()) { matchingPatterns.sort(patternComparator); handler = obtainApplicationContext().getBean(handlerName); validateHandler(handler, request); String pathWithinMapping = getPathMatcher().extractPathWithinPattern(bestMatch, urlPath); for (String matchingPattern : matchingPatterns) { if (patternComparator.compare(bestMatch, matchingPattern) == 0) { Map<String, String> vars = getPathMatcher().extractUriTemplateVariables(matchingPattern, urlPath); Map<String, String> decodedVars = getUrlPathHelper().decodePathVariables(request, vars); uriTemplateVariables.putAll(decodedVars); return buildPathExposingHandler(handler, bestMatch, pathWithinMapping, uriTemplateVariables);
ApplicationContext applicationContext = obtainApplicationContext(); if (applicationContext.isSingleton(handlerName)) { resolvedHandler = applicationContext.getBean(handlerName); if (mappedHandler != resolvedHandler) { throw new IllegalStateException( "Cannot map " + getHandlerDescription(handler) + " to URL path [" + urlPath + "]: There is already " + getHandlerDescription(mappedHandler) + " mapped."); if (urlPath.equals("/")) { if (logger.isTraceEnabled()) { logger.trace("Root mapping to " + getHandlerDescription(handler)); setRootHandler(resolvedHandler); logger.trace("Default mapping to " + getHandlerDescription(handler)); setDefaultHandler(resolvedHandler); logger.trace("Mapped [" + urlPath + "] onto " + getHandlerDescription(handler));
if (mappedHandler != resolvedHandler) { throw new IllegalStateException( "Cannot map " + getHandlerDescription(handler) + " to URL path [" + urlPath + "]: There is already " + getHandlerDescription(mappedHandler) + " mapped."); if (urlPath.equals("/")) { if (logger.isInfoEnabled()) { logger.info("Root mapping to " + getHandlerDescription(handler)); setRootHandler(resolvedHandler); logger.info("Default mapping to " + getHandlerDescription(handler)); setDefaultHandler(resolvedHandler); logger.info("Mapped URL path [" + urlPath + "] onto " + getHandlerDescription(handler));
public ReverseUrlHandlerMapping(AbstractUrlHandlerMapping mapping) { context = mapping.getApplicationContext(); Map<String, ?> handlers = mapping.getHandlerMap(); for (Map.Entry<String,?> entry : handlers.entrySet()) { String url = entry.getKey(); Object handler = entry.getValue(); if (!(handler instanceof String)) { Class<?> handlerClass = handler.getClass(); register(handlerClass, url, urlsForClass); } String handlerName = getHandlerName(handler); register(handlerName, url, urlsForName); } }
@Override public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) { exposeUriTemplateVariables(this.uriTemplateVariables, request); return true; } }
@Override protected Object lookupHandler(String urlPath, HttpServletRequest request) throws Exception { if (this.errorController != null && urlPath.equals(this.errorController.getErrorPath())) { return null; } if (isIgnoredPath(urlPath, this.routeLocator.getIgnoredPaths())) return null; RequestContext ctx = RequestContext.getCurrentContext(); if (ctx.containsKey("forward.to")) { return null; } if (this.dirty) { synchronized (this) { if (this.dirty) { registerHandlers(); this.dirty = false; } } } return super.lookupHandler(urlPath, request); }
@Override public List<DispatcherServletMappingDescription> describe( AbstractUrlHandlerMapping handlerMapping) { return handlerMapping.getHandlerMap().entrySet().stream().map(this::describe) .collect(Collectors.toList()); }
handler = obtainApplicationContext().getBean(handlerName); validateHandler(handler, request); return buildPathExposingHandler(handler, urlPath, urlPath, null); if (getPathMatcher().match(registeredPattern, urlPath)) { matchingPatterns.add(registeredPattern); else if (useTrailingSlashMatch()) { if (!registeredPattern.endsWith("/") && getPathMatcher().match(registeredPattern + "/", urlPath)) { matchingPatterns.add(registeredPattern +"/"); Comparator<String> patternComparator = getPathMatcher().getPatternComparator(urlPath); if (!matchingPatterns.isEmpty()) { matchingPatterns.sort(patternComparator); handler = obtainApplicationContext().getBean(handlerName); validateHandler(handler, request); String pathWithinMapping = getPathMatcher().extractPathWithinPattern(bestMatch, urlPath); for (String matchingPattern : matchingPatterns) { if (patternComparator.compare(bestMatch, matchingPattern) == 0) { Map<String, String> vars = getPathMatcher().extractUriTemplateVariables(matchingPattern, urlPath); Map<String, String> decodedVars = getUrlPathHelper().decodePathVariables(request, vars); uriTemplateVariables.putAll(decodedVars); return buildPathExposingHandler(handler, bestMatch, pathWithinMapping, uriTemplateVariables);
@Override @Nullable public RequestMatchResult match(HttpServletRequest request, String pattern) { String lookupPath = getUrlPathHelper().getLookupPathForRequest(request); if (getPathMatcher().match(pattern, lookupPath)) { return new RequestMatchResult(pattern, lookupPath, getPathMatcher()); } else if (useTrailingSlashMatch()) { if (!pattern.endsWith("/") && getPathMatcher().match(pattern + "/", lookupPath)) { return new RequestMatchResult(pattern + "/", lookupPath, getPathMatcher()); } } return null; }
ApplicationContext applicationContext = obtainApplicationContext(); if (applicationContext.isSingleton(handlerName)) { resolvedHandler = applicationContext.getBean(handlerName); if (mappedHandler != resolvedHandler) { throw new IllegalStateException( "Cannot map " + getHandlerDescription(handler) + " to URL path [" + urlPath + "]: There is already " + getHandlerDescription(mappedHandler) + " mapped."); if (urlPath.equals("/")) { if (logger.isTraceEnabled()) { logger.trace("Root mapping to " + getHandlerDescription(handler)); setRootHandler(resolvedHandler); logger.trace("Default mapping to " + getHandlerDescription(handler)); setDefaultHandler(resolvedHandler); logger.trace("Mapped [" + urlPath + "] onto " + getHandlerDescription(handler));
@Override public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) { exposeUriTemplateVariables(this.uriTemplateVariables, request); return true; } }
private Map<String, Object> getHandlerMap(AbstractUrlHandlerMapping mapping) { if (AopUtils.isCglibProxy(mapping)) { // If the AbstractUrlHandlerMapping is a cglib proxy we can't call // the final getHandlerMap() method. return Collections.emptyMap(); } return mapping.getHandlerMap(); } }
@Nullable protected Object getHandlerInternal(HttpServletRequest request) throws Exception { String lookupPath = getUrlPathHelper().getLookupPathForRequest(request); Object handler = lookupHandler(lookupPath, request); if (handler == null) { rawHandler = getRootHandler(); rawHandler = getDefaultHandler(); rawHandler = obtainApplicationContext().getBean(handlerName); validateHandler(rawHandler, request); handler = buildPathExposingHandler(rawHandler, lookupPath, lookupPath, null);
handler = getApplicationContext().getBean(handlerName); validateHandler(handler, request); return buildPathExposingHandler(handler, urlPath, urlPath, null); if (getPathMatcher().match(registeredPattern, urlPath)) { matchingPatterns.add(registeredPattern); else if (useTrailingSlashMatch()) { if (!registeredPattern.endsWith("/") && getPathMatcher().match(registeredPattern + "/", urlPath)) { matchingPatterns.add(registeredPattern +"/"); Comparator<String> patternComparator = getPathMatcher().getPatternComparator(urlPath); if (!matchingPatterns.isEmpty()) { Collections.sort(matchingPatterns, patternComparator); handler = getApplicationContext().getBean(handlerName); validateHandler(handler, request); String pathWithinMapping = getPathMatcher().extractPathWithinPattern(bestMatch, urlPath); for (String matchingPattern : matchingPatterns) { if (patternComparator.compare(bestMatch, matchingPattern) == 0) { Map<String, String> vars = getPathMatcher().extractUriTemplateVariables(matchingPattern, urlPath); Map<String, String> decodedVars = getUrlPathHelper().decodePathVariables(request, vars); uriTemplateVariables.putAll(decodedVars); return buildPathExposingHandler(handler, bestMatch, pathWithinMapping, uriTemplateVariables);
@Override public RequestMatchResult match(HttpServletRequest request, String pattern) { String lookupPath = getUrlPathHelper().getLookupPathForRequest(request); if (getPathMatcher().match(pattern, lookupPath)) { return new RequestMatchResult(pattern, lookupPath, getPathMatcher()); } else if (useTrailingSlashMatch()) { if (!pattern.endsWith("/") && getPathMatcher().match(pattern + "/", lookupPath)) { return new RequestMatchResult(pattern + "/", lookupPath, getPathMatcher()); } } return null; }
/** * Calls the {@link #detectHandlers()} method in addition to the * superclass's initialization. */ @Override public void initApplicationContext() throws ApplicationContextException { super.initApplicationContext(); detectHandlers(); }