Interface ServletIntegration


  • public interface ServletIntegration

    Provides hooks for integrating JRebel with custom Servlet containers. To use it acquire an instance from ServletIntegrationFactory

    A typical (Servlet context) integration will look like this:

     class MyServletContext implements ServletContext, RebelServletContext {
    
       ServletIntegration integration;
    
       public MyServletContext() {
         ...
         integration = ServletIntegrationFactory.getInstance();
         integration.registerServletContext(this);
       }
       ...
       public String getRealPath(String path) {
         if (integration.isResourceReplaced(this, path))
           return integration.getRealPath(this, path);
         ...
       }
    
       public URL getResource(String path) throws MalformedURLException {
         if (integration.isResourceReplaced(this, path))
           return integration.getResource(this, path);
         ...
       }
    
       public InputStream getResourceAsStream(String path) {
         if (integration.isResourceReplaced(this, path))
           return integration.getResourceAsStream(this, path);
         ...
       }
    
       public Set getResourcePaths(String path) {
         if (integration.isResourceReplaced(this, path))
           return integration.getResourcePaths(this, path);
         ...
       }
     }
     
    Author:
    Rein Raudjärv
    See Also:
    ServletIntegrationFactory, RebelServletContext, Integration, Reloader, Logger, Plugin
    • Method Summary

      All Methods Instance Methods Abstract Methods 
      Modifier and Type Method Description
      void disableResourcePathsAssumption()
      Assert that ServletContext#getResourcePaths is not able to find all resources that can be found by ServletContext#getResource
      String getRealPath​(org.zeroturnaround.javarebel.RebelServletContext sc, String path)
      Returns a String containing the managed real path for a given virtual path.
      RebelSource[] getRebelSources​(org.zeroturnaround.javarebel.RebelServletContext sc)
      Returns the additional root paths of the given ServletContext managed by JRebel.
      URL[] getRebelURLs​(org.zeroturnaround.javarebel.RebelServletContext sc)
      Returns the additional root paths of the given ServletContext managed by JRebel.
      URL getResource​(org.zeroturnaround.javarebel.RebelServletContext sc, String path)
      Returns a URL to the managed resource that is mapped to a specified path.
      InputStream getResourceAsStream​(org.zeroturnaround.javarebel.RebelServletContext sc, String path)
      Returns the managed resource located at the named path as an InputStream object.
      Set<String> getResourcePaths​(org.zeroturnaround.javarebel.RebelServletContext sc, String path)
      Returns a directory-like listing of all the paths to managed resources within the web application whose longest sub-path matches the supplied path argument.
      String getTransparentRealPath​(org.zeroturnaround.javarebel.RebelServletContext sc, String path)
      Returns a String containing the original real path for a given virtual path.
      URL getTransparentResource​(org.zeroturnaround.javarebel.RebelServletContext sc, String path)
      Returns a URL to the original resource that is mapped to a specified path.
      InputStream getTransparentResourceAsStream​(org.zeroturnaround.javarebel.RebelServletContext sc, String path)
      Returns the original resource located at the named path as an InputStream object.
      Set<String> getTransparentResourcePaths​(org.zeroturnaround.javarebel.RebelServletContext sc, String path)
      Returns a directory-like listing of all the paths to resources within the web application whose longest sub-path matches the supplied path argument.
      boolean hasReplacedResources​(org.zeroturnaround.javarebel.RebelServletContext sc)
      Returns true if all resources of the given Servlet Context are managed by JRebel.
      boolean isResourceReplaced​(org.zeroturnaround.javarebel.RebelServletContext sc, String path)
      Returns true if the given resource is managed by JRebel.
      void registerAdditionalWebResources​(org.zeroturnaround.javarebel.RebelServletContext sc, URL url)
      Register additional resources with target ServletContext.
      void registerAdditionalWebResources​(org.zeroturnaround.javarebel.RebelServletContext sc, org.zeroturnaround.javarebel.RebelServletContext additionalWebSc, String filter)
      Registers additional ServletContext-s rebel web resources with target ServletContext After adding some reinitialisation of some plugins may be required to get the new rebel sources
      void registerAdditionalWebResourcesWithPrefix​(org.zeroturnaround.javarebel.RebelServletContext sc, org.zeroturnaround.javarebel.RebelServletContext additionalWebSc, String prefix)
      Registers additional ServletContext-s rebel web resources with target ServletContext After adding some reinitialisation of some plugins may be required to get the new rebel sources
      void registerServletContext​(org.zeroturnaround.javarebel.RebelServletContext sc)
      Registers a ServletContext with JRebel.
      void unregisterAdditionalWebResources​(org.zeroturnaround.javarebel.RebelServletContext sc, org.zeroturnaround.javarebel.RebelServletContext additionalWebSc)
      Unregisters additional ServletContext-s rebel web resources from target ServletContext After removing some reinitialisation of some plugins may be required to change rebel sources
      void unregisterServletContext​(org.zeroturnaround.javarebel.RebelServletContext sc)
      Unregisters a ServletContext from JRebel.
    • Method Detail

      • registerServletContext

        void registerServletContext​(org.zeroturnaround.javarebel.RebelServletContext sc)
        Registers a ServletContext with JRebel. It is necessary to do this before any calls to the rest of the methods of ServletIntegration, the best place is usually the constructor. The custom ServletContext must implement the RebelServletContext, The latter can be easily added by the corresponding ClassBytecodeProcessor.
        Parameters:
        sc - The custom Servlet context being integrated.
      • unregisterServletContext

        void unregisterServletContext​(org.zeroturnaround.javarebel.RebelServletContext sc)
        Unregisters a ServletContext from JRebel. It is recommended to do this in case the corresponding ServletContext is destroyed (e.g. the web application is undeployed).
        Parameters:
        sc - The custom Servlet context being integrated.
      • registerAdditionalWebResources

        void registerAdditionalWebResources​(org.zeroturnaround.javarebel.RebelServletContext sc,
                                            org.zeroturnaround.javarebel.RebelServletContext additionalWebSc,
                                            String filter)
        Registers additional ServletContext-s rebel web resources with target ServletContext After adding some reinitialisation of some plugins may be required to get the new rebel sources
        Parameters:
        sc - The target Servlet context where new resources are being added
        additionalWebSc - The source Servlet context which rebel.xml web tags source is also used for resources
        filter - Adds only paths that match the filter. Can be null.
      • registerAdditionalWebResourcesWithPrefix

        void registerAdditionalWebResourcesWithPrefix​(org.zeroturnaround.javarebel.RebelServletContext sc,
                                                      org.zeroturnaround.javarebel.RebelServletContext additionalWebSc,
                                                      String prefix)
        Registers additional ServletContext-s rebel web resources with target ServletContext After adding some reinitialisation of some plugins may be required to get the new rebel sources
        Parameters:
        sc - The target Servlet context where new resources are being added
        additionalWebSc - The source Servlet context which rebel.xml web tags source is also used for resources
        prefix - Attach prefix before every patch
      • registerAdditionalWebResources

        void registerAdditionalWebResources​(org.zeroturnaround.javarebel.RebelServletContext sc,
                                            URL url)
        Register additional resources with target ServletContext.
        Parameters:
        sc - The custom Servlet context being integrated.
        url - URL to a jar with additional web resources.
      • unregisterAdditionalWebResources

        void unregisterAdditionalWebResources​(org.zeroturnaround.javarebel.RebelServletContext sc,
                                              org.zeroturnaround.javarebel.RebelServletContext additionalWebSc)
        Unregisters additional ServletContext-s rebel web resources from target ServletContext After removing some reinitialisation of some plugins may be required to change rebel sources
        Parameters:
        sc - The target Servlet context where new resources are being added
        additionalWebSc - The source Servlet context which rebel.xml web tags source is also used for resources
      • getRebelURLs

        URL[] getRebelURLs​(org.zeroturnaround.javarebel.RebelServletContext sc)
        Returns the additional root paths of the given ServletContext managed by JRebel.
        Parameters:
        sc - The custom Servlet context being integrated.
        Returns:
        additional paths of the given ServletContext or null if nothing found.
      • getRebelSources

        RebelSource[] getRebelSources​(org.zeroturnaround.javarebel.RebelServletContext sc)
        Returns the additional root paths of the given ServletContext managed by JRebel.
        Parameters:
        sc - The custom Servlet context being integrated.
        Returns:
        additional paths of the given ServletContext or null if nothing found.
      • hasReplacedResources

        boolean hasReplacedResources​(org.zeroturnaround.javarebel.RebelServletContext sc)
        Returns true if all resources of the given Servlet Context are managed by JRebel.

        All Servlet Context resources are managed by JRebel if the Servlet Context has been registered and a valid rebel.xml has been found which defines the new resource locations.

        Parameters:
        sc - The custom Servlet context being integrated.
        Returns:
        true if all resources of the given Servlet Context are managed by JRebel.
      • isResourceReplaced

        boolean isResourceReplaced​(org.zeroturnaround.javarebel.RebelServletContext sc,
                                   String path)
        Returns true if the given resource is managed by JRebel.

        In that case resources can be resolved using the corresponding methods of the ServletIntegration. If any of these methods returns a null it must be returned by the ServletContext as well.

        Parameters:
        sc - The custom Servlet context being integrated.
        path - path of the resource.
        Returns:
        true if the given resource is managed by JRebel.
      • getResourceAsStream

        InputStream getResourceAsStream​(org.zeroturnaround.javarebel.RebelServletContext sc,
                                        String path)
        Returns the managed resource located at the named path as an InputStream object.

        A typical usage will look like this:

         class MyServletContext implements ServletContext, RebelServletContext {
           ...
           public InputStream getResourceAsStream(String path) throws MalformedURLException {
             ServletIntegration integration = ServletIntegrationFactory.getInstance();
             if (integration.isResourceReplaced(this, path))
               return integration.getResourceAsStream(this, path);
             ...
           }
           ...
         }
         

        The Servlet context instance must be first registered with JRebel.

        Parameters:
        sc - The custom Servlet context being integrated.
        path - a String specifying the path to the resource
        Returns:
        the resource located at the named path as an InputStream object, or null if there is no resource at that path
        See Also:
        registerServletContext(RebelServletContext)
      • getResource

        URL getResource​(org.zeroturnaround.javarebel.RebelServletContext sc,
                        String path)
                 throws MalformedURLException
        Returns a URL to the managed resource that is mapped to a specified path.

        A typical usage will look like this:

         class MyServletContext implements ServletContext, RebelServletContext {
           ...
           public URL getResource(String path) throws MalformedURLException {
             ServletIntegration integration = ServletIntegrationFactory.getInstance();
             if (integration.isResourceReplaced(this, path))
               return integration.getResource(this, path);
             ...
           }
           ...
         }
         

        The Servlet context instance must be first registered with JRebel.

        Parameters:
        sc - The custom Servlet context being integrated.
        path - a String specifying the path to the resource
        Returns:
        the resource located at the named path, or null if there is no resource at that path
        Throws:
        MalformedURLException - if the pathname is not given in the correct form
        See Also:
        registerServletContext(RebelServletContext)
      • getRealPath

        String getRealPath​(org.zeroturnaround.javarebel.RebelServletContext sc,
                           String path)
        Returns a String containing the managed real path for a given virtual path.

        A typical usage will look like this:

         class MyServletContext implements ServletContext, RebelServletContext {
           ...
           public String getRealPath(String path) throws MalformedURLException {
             ServletIntegration integration = ServletIntegrationFactory.getInstance();
             if (integration.isResourceReplaced(this, path))
               return integration.getRealPath(this, path);
             ...
           }
           ...
         }
         

        The Servlet context instance must be first registered with JRebel.

        Parameters:
        sc - The custom Servlet context being integrated.
        path - a String specifying the path to the resource
        Returns:
        a String specifying the real path, or null if the translation cannot be performed
        See Also:
        registerServletContext(RebelServletContext)
      • getResourcePaths

        Set<String> getResourcePaths​(org.zeroturnaround.javarebel.RebelServletContext sc,
                                     String path)
        Returns a directory-like listing of all the paths to managed resources within the web application whose longest sub-path matches the supplied path argument.
         class MyServletContext implements ServletContext, RebelServletContext {
           ...
           public Set getResourcePaths(String path) throws MalformedURLException {
             ServletIntegration integration = ServletIntegrationFactory.getInstance();
             if (integration.isResourceReplaced(this, path))
               return integration.getResourcePaths(this, path);
             ...
           }
           ...
         }
         

        The Servlet context instance must be first registered with JRebel.

        Parameters:
        sc - The custom Servlet context being integrated.
        path - a String specifying the path to the resource
        Returns:
        a Set containing the directory listing, or null if there are no resources in the web application whose path begins with the supplied path.
        See Also:
        registerServletContext(RebelServletContext)
      • getTransparentResourceAsStream

        InputStream getTransparentResourceAsStream​(org.zeroturnaround.javarebel.RebelServletContext sc,
                                                   String path)
        Returns the original resource located at the named path as an InputStream object.

        This is used to get the original result unaltered by JRebel.

        The corresponding Servlet context method will be invoked such that isResourceReplaced(RebelServletContext, String) returns false.

        Parameters:
        path - a String specifying the path to the resource
        Returns:
        the resource located at the named path as an InputStream object, or null if there is no resource at that path
      • getTransparentResource

        URL getTransparentResource​(org.zeroturnaround.javarebel.RebelServletContext sc,
                                   String path)
                            throws MalformedURLException
        Returns a URL to the original resource that is mapped to a specified path.

        This is used to get the original result unaltered by JRebel.

        The corresponding Servlet context method will be invoked such that isResourceReplaced(RebelServletContext, String) returns false.

        Parameters:
        sc - The custom Servlet context being integrated.
        path - a String specifying the path to the resource
        Returns:
        the resource located at the named path, or null if there is no resource at that path
        Throws:
        MalformedURLException - if the pathname is not given in the correct form
      • getTransparentRealPath

        String getTransparentRealPath​(org.zeroturnaround.javarebel.RebelServletContext sc,
                                      String path)
        Returns a String containing the original real path for a given virtual path.

        This is used to get the original result unaltered by JRebel.

        The corresponding Servlet context method will be invoked such that isResourceReplaced(RebelServletContext, String) returns false.

        Parameters:
        sc - The custom Servlet context being integrated.
        path - a String specifying the path to the resource
        Returns:
        a String specifying the real path, or null if the translation cannot be performed
      • getTransparentResourcePaths

        Set<String> getTransparentResourcePaths​(org.zeroturnaround.javarebel.RebelServletContext sc,
                                                String path)
        Returns a directory-like listing of all the paths to resources within the web application whose longest sub-path matches the supplied path argument.

        This is used to get the original result unaltered by JRebel.

        The corresponding Servlet context method will be invoked such that isResourceReplaced(RebelServletContext, String) returns false.

        Parameters:
        sc - The custom Servlet context being integrated.
        path - a String specifying the path to the resource
        Returns:
        a Set containing the directory listing, or null if there are no resources in the web application whose path begins with the supplied path.
      • disableResourcePathsAssumption

        void disableResourcePathsAssumption()
        Assert that ServletContext#getResourcePaths is not able to find all resources that can be found by ServletContext#getResource