Class VaadinServlet

    • Constructor Detail

      • VaadinServlet

        public VaadinServlet()
    • Method Detail

      • init

        public void init​(javax.servlet.ServletConfig servletConfig)
                  throws javax.servlet.ServletException
        Called by the servlet container to indicate to a servlet that the servlet is being placed into service.
        Specified by:
        init in interface javax.servlet.Servlet
        Overrides:
        init in class javax.servlet.GenericServlet
        Parameters:
        servletConfig - the object containing the servlet's configuration and initialization parameters
        Throws:
        javax.servlet.ServletException - if an exception has occurred that interferes with the servlet's normal operation.
      • servletInitialized

        protected void servletInitialized()
                                   throws javax.servlet.ServletException
        Throws:
        javax.servlet.ServletException
      • getCurrent

        public static VaadinServlet getCurrent()
        Gets the currently used Vaadin servlet. The current servlet is automatically defined when initializing the servlet and when processing requests to the server and in threads started at a point when the current servlet is defined (see InheritableThreadLocal). In other cases, (e.g. from background threads started in some other way), the current servlet is not automatically defined.

        The current servlet is derived from the current service using VaadinService.getCurrent()

        Returns:
        the current Vaadin servlet instance if available, otherwise null
        Since:
        7.0
      • service

        protected void service​(javax.servlet.http.HttpServletRequest request,
                               javax.servlet.http.HttpServletResponse response)
                        throws javax.servlet.ServletException,
                               IOException
        Receives standard HTTP requests from the public service method and dispatches them.
        Overrides:
        service in class javax.servlet.http.HttpServlet
        Parameters:
        request - the object that contains the request the client made of the servlet.
        response - the object that contains the response the servlet returns to the client.
        Throws:
        javax.servlet.ServletException - if an input or output error occurs while the servlet is handling the TRACE request.
        IOException - if the request for the TRACE cannot be handled.
      • handleContextRootWithoutSlash

        protected boolean handleContextRootWithoutSlash​(javax.servlet.http.HttpServletRequest request,
                                                        javax.servlet.http.HttpServletResponse response)
                                                 throws IOException
        Invoked for every request to this servlet to potentially send a redirect to avoid problems with requests to the context root with no trailing slash.
        Parameters:
        request - the processed request
        response - the processed response
        Returns:
        true if a redirect has been sent and the request should not be processed further; false if the request should be processed as usual
        Throws:
        IOException - If an input or output exception occurs
      • getLastPathParameter

        protected static String getLastPathParameter​(String uri)
        Finds any path parameter added to the last part of the uri. A path parameter is any string separated by ";" from the path and ends in / or at the end of the string.

        For example the uri http://myhost.com/foo;a=1/bar;b=1 contains two path parameters, a=1 related to /foo and b=1 related to /bar.

        For http://myhost.com/foo;a=1/bar;b=1 this method will return ;b=1

        Parameters:
        uri - a URI
        Returns:
        the last path parameter of the uri including the semicolon or an empty string. Never null.
        Since:
        7.2
      • createVaadinRequest

        protected VaadinServletRequest createVaadinRequest​(javax.servlet.http.HttpServletRequest request)
        Create a Vaadin request for a http servlet request. This method can be overridden if the Vaadin request should have special properties.
        Parameters:
        request - the original http servlet request
        Returns:
        a Vaadin request for the original request
      • getService

        protected VaadinServletService getService()
        Gets a the vaadin service for this servlet.
        Returns:
        the vaadin service
      • criticalNotification

        @Deprecated
        protected void criticalNotification​(VaadinServletRequest request,
                                            VaadinServletResponse response,
                                            String caption,
                                            String message,
                                            String details,
                                            String url)
                                     throws IOException
        Deprecated.
        As of 7.0. This method is retained only for backwards compatibility and for GAEVaadinServlet.
        Send a notification to client-side widgetset. Used to notify client of critical errors, session expiration and more. Server has no knowledge of what UI client refers to.
        Parameters:
        request - the HTTP request instance.
        response - the HTTP response to write to.
        caption - the notification caption
        message - to notification body
        details - a detail message to show in addition to the message. Currently shown directly below the message but could be hidden behind a details drop down in the future. Mainly used to give additional information not necessarily useful to the end user.
        url - url to load when the message is dismissed. Null will reload the current page.
        Throws:
        IOException - if the writing failed due to input/output error.
      • getResourcePath

        @Deprecated
        protected static String getResourcePath​(javax.servlet.ServletContext servletContext,
                                                String path)
        Deprecated.
        As of 7.0. Will likely change or be removed in a future version
        Gets resource path using different implementations. Required to supporting different servlet container implementations (application servers).
        Parameters:
        servletContext -
        path - the resource path.
        Returns:
        the resource path.
      • stripSpecialChars

        @Deprecated
        public static String stripSpecialChars​(String themeName)
        Deprecated.
        As of 7.0. Will likely change or be removed in a future version
        A helper method to strip away characters that might somehow be used for XSS attacks. Leaves at least alphanumeric characters intact. Also removes e.g. '(' and ')', so values should be safe in javascript too.
        Parameters:
        themeName -
        Returns:
      • getDefaultTheme

        public static String getDefaultTheme()
        Returns the default theme. Must never return null.
        Returns:
      • serveStaticResources

        protected boolean serveStaticResources​(javax.servlet.http.HttpServletRequest request,
                                               javax.servlet.http.HttpServletResponse response)
                                        throws IOException,
                                               javax.servlet.ServletException
        Check if this is a request for a static resource and, if it is, serve the resource to the client.
        Parameters:
        request -
        response -
        Returns:
        true if a file was served and the request has been handled, false otherwise.
        Throws:
        IOException
        javax.servlet.ServletException
        Since:
        7.7.14
      • serveStaticResourcesInVAADIN

        protected void serveStaticResourcesInVAADIN​(String filename,
                                                    javax.servlet.http.HttpServletRequest request,
                                                    javax.servlet.http.HttpServletResponse response)
                                             throws IOException,
                                                    javax.servlet.ServletException
        Serve resources from VAADIN directory.
        Parameters:
        filename - The filename to serve. Should always start with /VAADIN/.
        request -
        response -
        Throws:
        IOException
        javax.servlet.ServletException
        Since:
        7.7.14
      • getCacheTime

        protected int getCacheTime​(String filename)
        Calculates the cache lifetime for the given filename in seconds. By default filenames containing ".nocache." return 0, filenames containing ".cache." return one year, all other return the value defined in the web.xml using resourceCacheTime (defaults to 1 hour).
        Parameters:
        filename -
        Returns:
        cache lifetime for the given filename in seconds
      • writeStaticResourceResponse

        protected void writeStaticResourceResponse​(javax.servlet.http.HttpServletRequest request,
                                                   javax.servlet.http.HttpServletResponse response,
                                                   URL resourceUrl)
                                            throws IOException
        Writes the contents of the given resourceUrl in the response. Can be overridden to add/modify response headers and similar.
        Parameters:
        request - The request for the resource
        response - The response
        resourceUrl - The url to send
        Throws:
        IOException
      • allowServePrecompressedResource

        protected boolean allowServePrecompressedResource​(javax.servlet.http.HttpServletRequest request,
                                                          String url)
        Returns whether this servlet should attempt to serve a precompressed version of the given static resource. If this method returns true, the suffix .gz is appended to the URL and the corresponding resource is served if it exists. It is assumed that the compression method used is gzip. If this method returns false or a compressed version is not found, the original URL is used. The base implementation of this method returns true if and only if the request indicates that the client accepts gzip compressed responses and the filename extension of the requested resource is .js, .css, or .html.
        Parameters:
        request - the request for the resource
        url - the URL of the requested resource
        Returns:
        true if the servlet should attempt to serve a precompressed version of the resource, false otherwise
        Since:
        7.5.0
      • findResourceURL

        protected URL findResourceURL​(String filename)
                               throws IOException
        Finds the given resource from the web content folder or using the class loader.
        Parameters:
        filename - The file to find, starting with a "/"
        Returns:
        The URL to the given file, or null if the file was not found
        Throws:
        IOException - if there was a problem while locating the file
        Since:
        7.7
      • isAllowedVAADINResourceUrl

        @Deprecated
        protected boolean isAllowedVAADINResourceUrl​(javax.servlet.http.HttpServletRequest request,
                                                     URL resourceUrl)
        Deprecated.
        As of 7.0. Will likely change or be removed in a future version
        Check whether a URL obtained from a classloader refers to a valid static resource in the directory VAADIN. Directories do not count as valid resources. Warning: Overriding of this method is not recommended, but is possible to support non-default classloaders or servers that may produce URLs different from the normal ones. The method prototype may change in the future. Care should be taken not to expose class files or other resources outside the VAADIN directory if the method is overridden.
        Parameters:
        request -
        resourceUrl -
        Returns:
        Since:
        6.6.7
      • isStaticResourceRequest

        protected boolean isStaticResourceRequest​(javax.servlet.http.HttpServletRequest request)
      • getApplicationUrl

        @Deprecated
        protected URL getApplicationUrl​(javax.servlet.http.HttpServletRequest request)
                                 throws MalformedURLException
        Deprecated.
        As of 7.0. Will likely change or be removed in a future version
        Gets the current application URL from request.
        Parameters:
        request - the HTTP request.
        Throws:
        MalformedURLException - if the application is denied access to the persistent data store represented by the given URL.
      • destroy

        public void destroy()
        Specified by:
        destroy in interface javax.servlet.Servlet
        Overrides:
        destroy in class javax.servlet.GenericServlet
      • safeEscapeForHtml

        @Deprecated
        public static final String safeEscapeForHtml​(String unsafe)
        Deprecated.
        As of 7.0. Will likely change or be removed in a future version
        Escapes characters to html entities. An exception is made for some "safe characters" to keep the text somewhat readable.
        Parameters:
        unsafe -
        Returns:
        a safe string to be added inside an html tag