/* * JBoss, Home of Professional Open Source * Copyright 2010, Red Hat Middleware LLC, and individual contributors * by the @authors tag. See the copyright.txt in the distribution for a * full listing of individual contributors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * http://www.apache.org/licenses/LICENSE-2.0 * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.jboss.weld.environment.jetty8; import java.util.EventListener; import javax.servlet.Filter; import javax.servlet.Servlet; import javax.servlet.ServletContext; import javax.servlet.ServletContextEvent; import javax.servlet.ServletException; import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.servlet.FilterHolder; import org.eclipse.jetty.servlet.ServletContextHandler; import org.eclipse.jetty.servlet.ServletHolder; import org.eclipse.jetty.webapp.Configuration; import org.eclipse.jetty.webapp.WebAppContext; import org.jboss.weld.environment.jetty.JettyWeldInjector; import org.jboss.weld.environment.servlet.Listener; import org.jboss.weld.manager.api.WeldManager; /** * A Jetty decorator implementation that performs CDI injections and cleanup for * Servlet, Filter and Listener components. * *
* This class wraps the post-instantiation and destruction of Servlet, Filter * and Listener components and performs CDI injections and release, * respectively, using the Jetty Weld injector. *
* ** Releasing of the creational context for Listener components is performed * using a Jetty Configuration to ensure that it happens after all Listener * components have been notified of the ServletContext destroyed event. This * workaround is necessary since Jetty does not yet notify the decorator of a * listener being destroyed. *
* * @author Dan Allen */ public class WeldWebAppDecorator implements Configuration, ServletContextHandler.Decorator { private ServletContext ctx; private JettyWeldInjector injector; public WeldWebAppDecorator(WebAppContext context) { ctx = context.getServletContext(); } public static void register(WebAppContext wac) { WeldWebAppDecorator d = new WeldWebAppDecorator(wac); wac.addDecorator(d); appendConfiguration(wac, d); } @Override public