Repository: camel Updated Branches: refs/heads/camel-2.12.x 3bca492fc -> c12e76955 refs/heads/camel-2.13.x 3fe46305d -> 82b3e0785 refs/heads/master 75b2c0a24 -> 05a972ec2
CAMEL-7711: camel-servletlistener - Store created CamelContext on ServletContext attribute Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/eed678ad Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/eed678ad Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/eed678ad Branch: refs/heads/master Commit: eed678adc8310f9a10b599b7e6375f236d954c3b Parents: 75b2c0a Author: Claus Ibsen <davscl...@apache.org> Authored: Sun Aug 17 09:09:35 2014 +0200 Committer: Claus Ibsen <davscl...@apache.org> Committed: Sun Aug 17 09:09:35 2014 +0200 ---------------------------------------------------------------------- .../servletlistener/CamelServletContextListener.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/eed678ad/components/camel-servletlistener/src/main/java/org/apache/camel/component/servletlistener/CamelServletContextListener.java ---------------------------------------------------------------------- diff --git a/components/camel-servletlistener/src/main/java/org/apache/camel/component/servletlistener/CamelServletContextListener.java b/components/camel-servletlistener/src/main/java/org/apache/camel/component/servletlistener/CamelServletContextListener.java index 5ea3e82..efe1fdd 100644 --- a/components/camel-servletlistener/src/main/java/org/apache/camel/component/servletlistener/CamelServletContextListener.java +++ b/components/camel-servletlistener/src/main/java/org/apache/camel/component/servletlistener/CamelServletContextListener.java @@ -64,6 +64,11 @@ public abstract class CamelServletContextListener<R extends Registry> implements */ public static ServletCamelContext instance; + /** + * Key to store the created {@link org.apache.camel.CamelContext} as an attribute on the {@link javax.servlet.ServletContext}. + */ + public static final String CAMEL_CONTEXT_KEY = "CamelContext"; + protected static final Logger LOG = LoggerFactory.getLogger(CamelServletContextListener.class); protected ServletCamelContext camelContext; protected CamelContextLifecycle<R> camelContextLifecycle; @@ -189,6 +194,9 @@ public abstract class CamelServletContextListener<R extends Registry> implements instance = camelContext; } + // store the CamelContext as an attribute + sce.getServletContext().setAttribute(CAMEL_CONTEXT_KEY, camelContext); + LOG.info("CamelContextServletListener initialized"); } @@ -211,6 +219,10 @@ public abstract class CamelServletContextListener<R extends Registry> implements camelContext = null; registry = null; instance = null; + + // store the CamelContext as an attribute + sce.getServletContext().removeAttribute(CAMEL_CONTEXT_KEY); + LOG.info("CamelContextServletListener destroyed"); }