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:
-
ServletIntegrationFactoryRebelServletContextIntegrationReloaderLoggerPlugin
-
Method Summary
Modifier and TypeMethodDescriptiondefault voidAssert that ServletContext#getResourcePaths is not able to find all resources that can be found by ServletContext#getResourcedefault StringgetRealPath(org.zeroturnaround.javarebel.RebelServletContext sc, String path) Returns a String containing the managed real path for a given virtual path.default RebelSource[]getRebelSources(org.zeroturnaround.javarebel.RebelServletContext sc) Returns the additional root paths of the givenServletContextmanaged by JRebel.default URL[]getRebelURLs(org.zeroturnaround.javarebel.RebelServletContext sc) Returns the additional root paths of the givenServletContextmanaged by JRebel.default URLgetResource(org.zeroturnaround.javarebel.RebelServletContext sc, String path) Returns a URL to the managed resource that is mapped to a specified path.default InputStreamgetResourceAsStream(org.zeroturnaround.javarebel.RebelServletContext sc, String path) Returns the managed resource located at the named path as an InputStream object.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.default StringgetTransparentRealPath(org.zeroturnaround.javarebel.RebelServletContext sc, String path) Returns a String containing the original real path for a given virtual path.default URLgetTransparentResource(org.zeroturnaround.javarebel.RebelServletContext sc, String path) Returns a URL to the original resource that is mapped to a specified path.default InputStreamgetTransparentResourceAsStream(org.zeroturnaround.javarebel.RebelServletContext sc, String path) Returns the original resource located at the named path as an InputStream object.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.default booleanhasReplacedResources(org.zeroturnaround.javarebel.RebelServletContext sc) Returnstrueif all resources of the given Servlet Context are managed by JRebel.default booleanisResourceReplaced(org.zeroturnaround.javarebel.RebelServletContext sc, String path) Returnstrueif the given resource is managed by JRebel.default voidregisterAdditionalWebResources(org.zeroturnaround.javarebel.RebelServletContext sc, File explodedWar) Register additional resources with targetServletContext.default voidregisterAdditionalWebResources(org.zeroturnaround.javarebel.RebelServletContext sc, URL url) default voidregisterAdditionalWebResources(org.zeroturnaround.javarebel.RebelServletContext sc, URL url, boolean isStarted) Register additional resources with targetServletContext.default voidregisterAdditionalWebResources(org.zeroturnaround.javarebel.RebelServletContext sc, org.zeroturnaround.javarebel.RebelServletContext additionalWebSc, String filter) Registers additionalServletContext-s rebel web resources with targetServletContextAfter adding some reinitialisation of some plugins may be required to get the new rebel sourcesdefault voidregisterAdditionalWebResourcesWithPrefix(org.zeroturnaround.javarebel.RebelServletContext sc, org.zeroturnaround.javarebel.RebelServletContext additionalWebSc, String prefix) Registers additionalServletContext-s rebel web resources with targetServletContextAfter adding some reinitialisation of some plugins may be required to get the new rebel sourcesdefault voidregisterServletContext(org.zeroturnaround.javarebel.RebelServletContext sc) Registers aServletContextwith JRebel.default voidunregisterAdditionalWebResources(org.zeroturnaround.javarebel.RebelServletContext sc, org.zeroturnaround.javarebel.RebelServletContext additionalWebSc) Unregisters additionalServletContext-s rebel web resources from targetServletContextAfter removing some reinitialisation of some plugins may be required to change rebel sourcesdefault voidunregisterServletContext(org.zeroturnaround.javarebel.RebelServletContext sc) Unregisters aServletContextfrom JRebel.
-
Method Details
-
registerServletContext
default void registerServletContext(org.zeroturnaround.javarebel.RebelServletContext sc) Registers aServletContextwith JRebel. It is necessary to do this before any calls to the rest of the methods ofServletIntegration, the best place is usually the constructor. The customServletContextmust implement theRebelServletContext, The latter can be easily added by the correspondingClassBytecodeProcessor.- Parameters:
sc- The custom Servlet context being integrated.
-
unregisterServletContext
default void unregisterServletContext(org.zeroturnaround.javarebel.RebelServletContext sc) Unregisters aServletContextfrom JRebel. It is recommended to do this in case the correspondingServletContextis destroyed (e.g. the web application is undeployed).- Parameters:
sc- The custom Servlet context being integrated.
-
registerAdditionalWebResources
default void registerAdditionalWebResources(org.zeroturnaround.javarebel.RebelServletContext sc, org.zeroturnaround.javarebel.RebelServletContext additionalWebSc, String filter) Registers additionalServletContext-s rebel web resources with targetServletContextAfter 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 addedadditionalWebSc- The source Servlet context whichrebel.xmlwebtags source is also used for resourcesfilter- Adds only paths that match the filter. Can be null.
-
registerAdditionalWebResourcesWithPrefix
default void registerAdditionalWebResourcesWithPrefix(org.zeroturnaround.javarebel.RebelServletContext sc, org.zeroturnaround.javarebel.RebelServletContext additionalWebSc, String prefix) Registers additionalServletContext-s rebel web resources with targetServletContextAfter 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 addedadditionalWebSc- The source Servlet context whichrebel.xmlwebtags source is also used for resourcesprefix- Attach prefix before every patch
-
registerAdditionalWebResources
default void registerAdditionalWebResources(org.zeroturnaround.javarebel.RebelServletContext sc, URL url, boolean isStarted) Register additional resources with targetServletContext.- Parameters:
sc- The custom Servlet context being integrated.url- URL to a jar with additional web resources.
-
registerAdditionalWebResources
default void registerAdditionalWebResources(org.zeroturnaround.javarebel.RebelServletContext sc, URL url) -
registerAdditionalWebResources
default void registerAdditionalWebResources(org.zeroturnaround.javarebel.RebelServletContext sc, File explodedWar) Register additional resources with targetServletContext.- Parameters:
sc- The custom Servlet context being integrated.explodedWar- File pointing to exploded WAR directory.
-
unregisterAdditionalWebResources
default void unregisterAdditionalWebResources(org.zeroturnaround.javarebel.RebelServletContext sc, org.zeroturnaround.javarebel.RebelServletContext additionalWebSc) Unregisters additionalServletContext-s rebel web resources from targetServletContextAfter removing some reinitialisation of some plugins may be required to change rebel sources- Parameters:
sc- The target Servlet context where new resources are being addedadditionalWebSc- The source Servlet context whichrebel.xmlwebtags source is also used for resources
-
getRebelURLs
Returns the additional root paths of the givenServletContextmanaged by JRebel.- Parameters:
sc- The custom Servlet context being integrated.- Returns:
- additional paths of the given
ServletContextornullif nothing found.
-
getRebelSources
Returns the additional root paths of the givenServletContextmanaged by JRebel.- Parameters:
sc- The custom Servlet context being integrated.- Returns:
- additional paths of the given
ServletContextornullif nothing found.
-
hasReplacedResources
default boolean hasReplacedResources(org.zeroturnaround.javarebel.RebelServletContext sc) Returnstrueif 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.xmlhas been found which defines the new resource locations.- Parameters:
sc- The custom Servlet context being integrated.- Returns:
trueif all resources of the given Servlet Context are managed by JRebel.
-
isResourceReplaced
default boolean isResourceReplaced(org.zeroturnaround.javarebel.RebelServletContext sc, String path) Returnstrueif 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 anullit must be returned by theServletContextas well.- Parameters:
sc- The custom Servlet context being integrated.path- path of the resource.- Returns:
trueif the given resource is managed by JRebel.
-
getResourceAsStream
default 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
nullif there is no resource at that path - See Also:
-
getResource
default 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
nullif there is no resource at that path - Throws:
MalformedURLException- if the pathname is not given in the correct form- See Also:
-
getRealPath
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
nullif the translation cannot be performed - See Also:
-
getResourcePaths
default 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
nullif there are no resources in the web application whose path begins with the supplied path. - See Also:
-
getTransparentResourceAsStream
default 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)returnsfalse.- 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
nullif there is no resource at that path
-
getTransparentResource
default 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)returnsfalse.- 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
nullif there is no resource at that path - Throws:
MalformedURLException- if the pathname is not given in the correct form
-
getTransparentRealPath
default 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)returnsfalse.- 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
nullif the translation cannot be performed
-
getTransparentResourcePaths
default 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)returnsfalse.- 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
nullif there are no resources in the web application whose path begins with the supplied path.
-
disableResourcePathsAssumption
default void disableResourcePathsAssumption()Assert that ServletContext#getResourcePaths is not able to find all resources that can be found by ServletContext#getResource
-