Example usage for javax.servlet ServletContextAttributeEvent getName

List of usage examples for javax.servlet ServletContextAttributeEvent getName

Introduction

In this page you can find the example usage for javax.servlet ServletContextAttributeEvent getName.

Prototype

public String getName() 

Source Link

Document

Gets the name of the ServletContext attribute that changed.

Usage

From source file:com.adeptj.runtime.osgi.BridgeServletContextAttributeListener.java

@Override
public void attributeAdded(ServletContextAttributeEvent event) {
    if (StringUtils.equals(event.getName(), Constants.ATTRIBUTE_BUNDLE_CTX)) {
        ServiceTrackers.getInstance().openEventDispatcherTracker((BundleContext) event.getValue());
    }/*from  ww w. j a  va  2  s  .c o  m*/
}

From source file:io.adeptj.runtime.osgi.BridgeServletContextAttributeListener.java

@Override
public void attributeAdded(ServletContextAttributeEvent event) {
    if (StringUtils.equals(event.getName(), ATTRIBUTE_BUNDLE_CTX)) {
        ServiceTrackers.getInstance().openEventDispatcherTracker((BundleContext) event.getValue());
    }// w w  w .j ava 2  s .c  om
}

From source file:com.adeptj.runtime.osgi.BridgeServletContextAttributeListener.java

@Override
public void attributeReplaced(ServletContextAttributeEvent event) {
    if (StringUtils.equals(event.getName(), Constants.ATTRIBUTE_BUNDLE_CTX)) {
        ServiceTrackers.getInstance().closeEventDispatcherTracker();
        /*/*  w  ww  .  j a  va2 s  . co m*/
         * Now open the EventDispatcherTracker with fresh BundleContext which is already hold by
         * BundleContextHolder after being set in FrameworkLifecycleListener.
         *
         * Rationale: If we use the BundleContext contained in the passed event which is a stale
         * BundleContext in case of a framework restart event and results in a IllegalStateException.
         */
        ServiceTrackers.getInstance()
                .openEventDispatcherTracker(BundleContextHolder.getInstance().getBundleContext());
    }
}

From source file:io.adeptj.runtime.osgi.BridgeServletContextAttributeListener.java

@Override
public void attributeReplaced(ServletContextAttributeEvent event) {
    if (StringUtils.equals(event.getName(), ATTRIBUTE_BUNDLE_CTX)) {
        ServiceTrackers.getInstance().closeEventDispatcherTracker();
        /*/* w ww . jav a  2  s.  co  m*/
         * Now open the EventDispatcherTracker with fresh BundleContext which is already hold by
         * BundleContextHolder after being set in FrameworkLifecycleListener.
         *
         * Rationale: If we use the BundleContext contained in the passed event which is a stale
         * BundleContext in case of a framework restart event and results in a IllegalStateException.
         */
        ServiceTrackers.getInstance()
                .openEventDispatcherTracker(BundleContextHolder.getInstance().getBundleContext());
    }
}

From source file:MyServlet.java

/**
 * Record the fact that a servlet context attribute was added.
 *
 * @param event The servlet context attribute event
 *//*from w  ww .j  av a  2 s .  c  om*/
public void attributeAdded(ServletContextAttributeEvent event) {

    log("attributeAdded('" + event.getName() + "', '" + event.getValue() + "')");

}

From source file:MyServlet.java

/**
 * Record the fact that a servlet context attribute was removed.
 *
 * @param event The servlet context attribute event
 *///from   w  ww . ja  v  a 2 s .  co m
public void attributeRemoved(ServletContextAttributeEvent event) {

    log("attributeRemoved('" + event.getName() + "', '" + event.getValue() + "')");

}

From source file:MyServlet.java

/**
 * Record the fact that a servlet context attribute was replaced.
 *
 * @param event The servlet context attribute event
 *//*www  .j a va 2 s . co m*/
public void attributeReplaced(ServletContextAttributeEvent event) {

    log("attributeReplaced('" + event.getName() + "', '" + event.getValue() + "')");

}

From source file:org.brutusin.rpc.RpcWebInitializer.java

public void onStartup(final ServletContext ctx) throws ServletException {
    final RpcServlet rpcServlet = registerRpcServlet(ctx);
    final WebsocketFilter websocketFilter = new WebsocketFilter();
    FilterRegistration.Dynamic dynamic = ctx.addFilter(WebsocketFilter.class.getName(), websocketFilter);
    dynamic.addMappingForUrlPatterns(null, false, RpcConfig.getInstance().getPath() + "/wskt");
    JsonCodec.getInstance().registerStringFormat(MetaDataInputStream.class, "inputstream");
    final Bean<RpcSpringContext> rpcCtxBean = new Bean<RpcSpringContext>();
    ctx.addListener(new ServletRequestListener() {

        public void requestDestroyed(ServletRequestEvent sre) {
            GlobalThreadLocal.clear();/*from  w  ww . j a  v a  2s  .c  o m*/
        }

        public void requestInitialized(ServletRequestEvent sre) {
            GlobalThreadLocal.set(new GlobalThreadLocal((HttpServletRequest) sre.getServletRequest(), null));
        }
    });
    ctx.addListener(new ServletContextListener() {

        public void contextInitialized(ServletContextEvent sce) {
            RpcSpringContext rpcCtx = createRpcSpringContext(ctx);
            rpcCtxBean.setValue(rpcCtx);
            rpcServlet.setRpcCtx(rpcCtx);
            initWebsocketRpcRuntime(ctx, rpcCtx);
            ctx.setAttribute(RpcSpringContext.class.getName(), rpcCtx);
        }

        public void contextDestroyed(ServletContextEvent sce) {
            LOGGER.info("Destroying RPC context");
            if (rpcCtxBean.getValue() != null) {
                rpcCtxBean.getValue().destroy();
            }
        }
    });
    ctx.addListener(new ServletContextAttributeListener() {
        public void attributeAdded(ServletContextAttributeEvent event) {
            if (event.getName().equals(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE)) {
                updateRootContext();
            }
        }

        public void attributeRemoved(ServletContextAttributeEvent event) {
            if (event.getName().equals(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE)) {
                updateRootContext();
            }
        }

        public void attributeReplaced(ServletContextAttributeEvent event) {
            if (event.getName().equals(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE)) {
                updateRootContext();
            }
        }

        private void updateRootContext() {
            WebApplicationContext rootCtx = WebApplicationContextUtils.getWebApplicationContext(ctx);
            if (rootCtx != null) {
                if (rpcCtxBean.getValue() != null) {
                    rpcCtxBean.getValue().setParent(rootCtx);
                }
                if (rootCtx.containsBean("springSecurityFilterChain")) {
                    LOGGER.info("Moving WebsocketFilter behind springSecurityFilterChain");
                    websocketFilter.disable();
                    FilterChainProxy fcp = (FilterChainProxy) rootCtx.getBean("springSecurityFilterChain");
                    fcp.getFilterChains().get(0).getFilters().add(new WebsocketFilter());
                }
            }
        }
    });
}

From source file:com.manydesigns.portofino.servlets.PortofinoListener.java

@Override
public void attributeAdded(ServletContextAttributeEvent servletContextAttributeEvent) {
    logger.debug("Servlet context attribute added: " + servletContextAttributeEvent.getName() + " = "
            + servletContextAttributeEvent.getValue());
}

From source file:com.manydesigns.portofino.servlets.PortofinoListener.java

@Override
public void attributeRemoved(ServletContextAttributeEvent servletContextAttributeEvent) {
    logger.debug("Servlet context attribute removed: " + servletContextAttributeEvent.getName() + " = "
            + servletContextAttributeEvent.getValue());
}