Class TeamCitySimpleUrlHandlerMapping

  • All Implemented Interfaces:
    org.springframework.beans.factory.Aware, org.springframework.beans.factory.BeanNameAware, org.springframework.context.ApplicationContextAware, org.springframework.core.Ordered, org.springframework.web.context.ServletContextAware, org.springframework.web.servlet.HandlerMapping
    Direct Known Subclasses:
    UrlMapping

    public class TeamCitySimpleUrlHandlerMapping
    extends org.springframework.web.servlet.handler.AbstractHandlerMapping
    This class repeats functionality of SimpleUrlHandlerMapping but supports also unregistering handlers instances (it's needed for hot-reloading plugin issue)
    Since:
    2018.2
    Author:
    Maxim Zaytsev (maxim.zaytsev@jetbrains.com)
    • Field Summary

      • Fields inherited from class org.springframework.web.servlet.handler.AbstractHandlerMapping

        mappingsLogger
      • Fields inherited from class org.springframework.context.support.ApplicationObjectSupport

        logger
      • Fields inherited from interface org.springframework.web.servlet.HandlerMapping

        BEST_MATCHING_HANDLER_ATTRIBUTE, BEST_MATCHING_PATTERN_ATTRIBUTE, INTROSPECT_TYPE_LEVEL_MAPPING, LOOKUP_PATH, MATRIX_VARIABLES_ATTRIBUTE, PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE, PRODUCIBLE_MEDIA_TYPES_ATTRIBUTE, URI_TEMPLATE_VARIABLES_ATTRIBUTE
      • Fields inherited from interface org.springframework.core.Ordered

        HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected Object buildPathExposingHandler​(Object rawHandler, String bestMatchingPattern, String pathWithinMapping, Map<String,​String> uriTemplateVariables)
      Build a handler object for the given raw handler, exposing the actual handler, the HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE, as well as the HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE before executing the handler.
      protected void exposePathWithinMapping​(String bestMatchingPattern, String pathWithinMapping, javax.servlet.http.HttpServletRequest request)
      Expose the path within the current mapping as request attribute.
      protected void exposeUriTemplateVariables​(Map<String,​String> uriTemplateVariables, javax.servlet.http.HttpServletRequest request)
      Expose the URI templates variables as request attribute.
      protected Object getHandlerInternal​(javax.servlet.http.HttpServletRequest request)
      Look up a handler for the URL path of the given request.
      Map<String,​Object> getHandlerMap()
      Return the registered handlers as an unmodifiable Map, with the registered path as key and the handler object (or handler bean name in case of a lazy-init handler) as value.
      Object getRootHandler()
      Return the root handler for this handler mapping (registered for "/"), or null if none.
      Map<String,​?> getUrlMap()
      Allow Map access to the URL path mappings, with the option to add or override specific entries.
      void initApplicationContext()
      Calls the registerHandlers(java.util.Map<java.lang.String, java.lang.Object>) method in addition to the superclass's initialization.
      void initInterceptors()  
      protected Object lookupHandler​(String urlPath, javax.servlet.http.HttpServletRequest request)
      Look up a handler instance for the given URL path.
      protected void registerHandler​(String urlPath, Object handler)
      Register the specified handler for the given URL path.
      protected void registerHandlers​(Map<String,​Object> urlMap)
      Register all handlers specified in the URL map for the corresponding paths.
      void setLazyInitHandlers​(boolean lazyInitHandlers)  
      void setMappings​(Properties mappings)
      Map URL paths to handler bean names.
      void setRootHandler​(Object rootHandler)
      Set the root handler for this handler mapping, that is, the handler to be registered for the root path ("/").
      void setUrlMap​(Map<String,​?> urlMap)
      Set a Map with URL paths as keys and handler beans (or handler bean names) as values.
      protected boolean supportsTypeLevelMappings()
      Indicates whether this handler mapping support type-level mappings.
      Object unregisterHandler​(String urlPath)
      Unregister handler for the given URL path
      protected boolean useTrailingSlashMatch()
      Whether to match to URLs irrespective of the presence of a trailing slash.
      protected void validateHandler​(Object handler, javax.servlet.http.HttpServletRequest request)
      Validate the given handler against the current request.
      • Methods inherited from class org.springframework.web.servlet.handler.AbstractHandlerMapping

        adaptInterceptor, detectMappedInterceptors, extendInterceptors, formatMappingName, getAdaptedInterceptors, getCorsConfiguration, getCorsConfigurationSource, getCorsHandlerExecutionChain, getCorsProcessor, getDefaultHandler, getHandler, getHandlerExecutionChain, getMappedInterceptors, getOrder, getPathMatcher, getPatternParser, getUrlPathHelper, hasCorsConfigurationSource, initLookupPath, setAlwaysUseFullPath, setBeanName, setCorsConfigurations, setCorsConfigurationSource, setCorsProcessor, setDefaultHandler, setInterceptors, setOrder, setPathMatcher, setPatternParser, setRemoveSemicolonContent, setUrlDecode, setUrlPathHelper, usesPathPatterns
      • Methods inherited from class org.springframework.web.context.support.WebApplicationObjectSupport

        getServletContext, getTempDir, getWebApplicationContext, initApplicationContext, initServletContext, isContextRequired, setServletContext
      • Methods inherited from class org.springframework.context.support.ApplicationObjectSupport

        getApplicationContext, getMessageSourceAccessor, obtainApplicationContext, requiredContextClass, setApplicationContext
    • Constructor Detail

      • TeamCitySimpleUrlHandlerMapping

        public TeamCitySimpleUrlHandlerMapping()
    • Method Detail

      • setLazyInitHandlers

        public void setLazyInitHandlers​(boolean lazyInitHandlers)
      • getHandlerMap

        public final Map<String,​Object> getHandlerMap()
        Return the registered handlers as an unmodifiable Map, with the registered path as key and the handler object (or handler bean name in case of a lazy-init handler) as value.
        See Also:
        AbstractHandlerMapping.getDefaultHandler()
      • unregisterHandler

        public Object unregisterHandler​(String urlPath)
        Unregister handler for the given URL path
        Parameters:
        urlPath -
        Returns:
        removed handler instance or handler bean name String
      • registerHandler

        protected void registerHandler​(String urlPath,
                                       Object handler)
                                throws org.springframework.beans.BeansException,
                                       IllegalStateException
        Register the specified handler for the given URL path.
        Parameters:
        urlPath - the URL the bean should be mapped to
        handler - the handler instance or handler bean name String (a bean name will automatically be resolved into the corresponding handler bean)
        Throws:
        org.springframework.beans.BeansException - if the handler couldn't be registered
        IllegalStateException - if there is a conflicting handler registered
      • validateHandler

        protected void validateHandler​(Object handler,
                                       javax.servlet.http.HttpServletRequest request)
                                throws Exception
        Validate the given handler against the current request.

        The default implementation is empty. Can be overridden in subclasses, for example to enforce specific preconditions expressed in URL mappings.

        Parameters:
        handler - the handler object to validate
        request - current HTTP request
        Throws:
        Exception - if validation failed
      • buildPathExposingHandler

        protected Object buildPathExposingHandler​(Object rawHandler,
                                                  String bestMatchingPattern,
                                                  String pathWithinMapping,
                                                  Map<String,​String> uriTemplateVariables)
        Build a handler object for the given raw handler, exposing the actual handler, the HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE, as well as the HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE before executing the handler.

        The default implementation builds a HandlerExecutionChain with a special interceptor that exposes the path attribute and uri template variables

        Parameters:
        rawHandler - the raw handler to expose
        pathWithinMapping - the path to expose before executing the handler
        uriTemplateVariables - the URI template variables, can be null if no variables found
        Returns:
        the final handler object
      • getHandlerInternal

        protected Object getHandlerInternal​(javax.servlet.http.HttpServletRequest request)
                                     throws Exception
        Look up a handler for the URL path of the given request.
        Specified by:
        getHandlerInternal in class org.springframework.web.servlet.handler.AbstractHandlerMapping
        Parameters:
        request - current HTTP request
        Returns:
        the handler instance, or null if none found
        Throws:
        Exception
      • getRootHandler

        public Object getRootHandler()
        Return the root handler for this handler mapping (registered for "/"), or null if none.
      • setRootHandler

        public void setRootHandler​(Object rootHandler)
        Set the root handler for this handler mapping, that is, the handler to be registered for the root path ("/").

        Default is null, indicating no root handler.

      • lookupHandler

        protected Object lookupHandler​(String urlPath,
                                       javax.servlet.http.HttpServletRequest request)
                                throws Exception
        Look up a handler instance for the given URL path.

        Supports direct matches, e.g. a registered "/test" matches "/test", and various Ant-style pattern matches, e.g. a registered "/t*" matches both "/test" and "/team". For details, see the AntPathMatcher class.

        Looks for the most exact pattern, where most exact is defined as the longest path pattern.

        Parameters:
        urlPath - URL the bean is mapped to
        request - current HTTP request (to expose the path within the mapping to)
        Returns:
        the associated handler instance, or null if not found
        Throws:
        Exception
        See Also:
        exposePathWithinMapping(java.lang.String, java.lang.String, javax.servlet.http.HttpServletRequest), AntPathMatcher
      • useTrailingSlashMatch

        protected boolean useTrailingSlashMatch()
        Whether to match to URLs irrespective of the presence of a trailing slash.
      • supportsTypeLevelMappings

        protected boolean supportsTypeLevelMappings()
        Indicates whether this handler mapping support type-level mappings. Default to false.
      • exposePathWithinMapping

        protected void exposePathWithinMapping​(String bestMatchingPattern,
                                               String pathWithinMapping,
                                               javax.servlet.http.HttpServletRequest request)
        Expose the path within the current mapping as request attribute.
        Parameters:
        pathWithinMapping - the path within the current mapping
        request - the request to expose the path to
        See Also:
        HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE
      • exposeUriTemplateVariables

        protected void exposeUriTemplateVariables​(Map<String,​String> uriTemplateVariables,
                                                  javax.servlet.http.HttpServletRequest request)
        Expose the URI templates variables as request attribute.
        Parameters:
        uriTemplateVariables - the URI template variables
        request - the request to expose the path to
        See Also:
        HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE
      • setMappings

        public void setMappings​(Properties mappings)
        Map URL paths to handler bean names. This is the typical way of configuring this HandlerMapping.

        Supports direct URL matches and Ant-style pattern matches. For syntax details, see the AntPathMatcher javadoc.

        Parameters:
        mappings - properties with URLs as keys and bean names as values
        See Also:
        setUrlMap(java.util.Map<java.lang.String, ?>)
      • getUrlMap

        public Map<String,​?> getUrlMap()
        Allow Map access to the URL path mappings, with the option to add or override specific entries.

        Useful for specifying entries directly, for example via "urlMap[myKey]". This is particularly useful for adding or overriding entries in child bean definitions.

      • setUrlMap

        public void setUrlMap​(Map<String,​?> urlMap)
        Set a Map with URL paths as keys and handler beans (or handler bean names) as values. Convenient for population with bean references.

        Supports direct URL matches and Ant-style pattern matches. For syntax details, see the AntPathMatcher javadoc.

        Parameters:
        urlMap - map with URLs as keys and beans as values
        See Also:
        setMappings(java.util.Properties)
      • initApplicationContext

        public void initApplicationContext()
                                    throws org.springframework.beans.BeansException
        Calls the registerHandlers(java.util.Map<java.lang.String, java.lang.Object>) method in addition to the superclass's initialization.
        Overrides:
        initApplicationContext in class org.springframework.web.servlet.handler.AbstractHandlerMapping
        Throws:
        org.springframework.beans.BeansException
      • initInterceptors

        public void initInterceptors()
        Overrides:
        initInterceptors in class org.springframework.web.servlet.handler.AbstractHandlerMapping
      • registerHandlers

        protected void registerHandlers​(Map<String,​Object> urlMap)
                                 throws org.springframework.beans.BeansException
        Register all handlers specified in the URL map for the corresponding paths.
        Parameters:
        urlMap - Map with URL paths as keys and handler beans or bean names as values
        Throws:
        org.springframework.beans.BeansException - if a handler couldn't be registered
        IllegalStateException - if there is a conflicting handler registered