Interface ServletIntegration
-
public interface ServletIntegrationProvides hooks for integrating JRebel with custom Servlet containers. To use it acquire an instance from
ServletIntegrationFactoryA 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 voiddisableResourcePathsAssumption()Assert that ServletContext#getResourcePaths is not able to find all resources that can be found by ServletContext#getResourceStringgetRealPath(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 givenServletContextmanaged by JRebel.URL[]getRebelURLs(org.zeroturnaround.javarebel.RebelServletContext sc)Returns the additional root paths of the givenServletContextmanaged by JRebel.URLgetResource(org.zeroturnaround.javarebel.RebelServletContext sc, String path)Returns a URL to the managed resource that is mapped to a specified path.InputStreamgetResourceAsStream(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.StringgetTransparentRealPath(org.zeroturnaround.javarebel.RebelServletContext sc, String path)Returns a String containing the original real path for a given virtual path.URLgetTransparentResource(org.zeroturnaround.javarebel.RebelServletContext sc, String path)Returns a URL to the original resource that is mapped to a specified path.InputStreamgetTransparentResourceAsStream(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.booleanhasReplacedResources(org.zeroturnaround.javarebel.RebelServletContext sc)Returnstrueif all resources of the given Servlet Context are managed by JRebel.booleanisResourceReplaced(org.zeroturnaround.javarebel.RebelServletContext sc, String path)Returnstrueif the given resource is managed by JRebel.voidregisterAdditionalWebResources(org.zeroturnaround.javarebel.RebelServletContext sc, URL url)Register additional resources with targetServletContext.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 sourcesvoidregisterAdditionalWebResourcesWithPrefix(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 sourcesvoidregisterServletContext(org.zeroturnaround.javarebel.RebelServletContext sc)Registers aServletContextwith JRebel.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 sourcesvoidunregisterServletContext(org.zeroturnaround.javarebel.RebelServletContext sc)Unregisters aServletContextfrom JRebel.
-
-
-
Method Detail
-
registerServletContext
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
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
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
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
void registerAdditionalWebResources(org.zeroturnaround.javarebel.RebelServletContext sc, URL url)Register additional resources with targetServletContext.- 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 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
URL[] getRebelURLs(org.zeroturnaround.javarebel.RebelServletContext sc)
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
RebelSource[] getRebelSources(org.zeroturnaround.javarebel.RebelServletContext sc)
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
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
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
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:
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
nullif 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
nullif 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
nullif 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)returnsfalse.- Parameters:
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
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
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
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
void disableResourcePathsAssumption()
Assert that ServletContext#getResourcePaths is not able to find all resources that can be found by ServletContext#getResource
-
-