Example usage for javax.servlet ServletContext getAttribute

List of usage examples for javax.servlet ServletContext getAttribute

Introduction

In this page you can find the example usage for javax.servlet ServletContext getAttribute.

Prototype

public Object getAttribute(String name);

Source Link

Document

Returns the servlet container attribute with the given name, or null if there is no attribute by that name.

Usage

From source file:h2weibo.InitServlet.java

public JedisPool getPool(ServletContext context) {
    return (JedisPool) context.getAttribute(CONTEXT_JEDIS_POOL);
}

From source file:org.apache.hadoop.dfs.FsckServlet.java

@SuppressWarnings("unchecked")
public void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    Map<String, String[]> pmap = request.getParameterMap();
    try {/*from w  ww .j  a v a  2s  .c  o  m*/
        ServletContext context = getServletContext();
        NameNode nn = (NameNode) context.getAttribute("name.node");
        Configuration conf = (Configuration) context.getAttribute("name.conf");
        NamenodeFsck fscker = new NamenodeFsck(conf, nn, pmap, response);
        fscker.fsck();
    } catch (IOException ie) {
        StringUtils.stringifyException(ie);
        LOG.warn(ie);
        String errMsg = "Fsck on path " + pmap.get("path") + " failed.";
        response.sendError(HttpServletResponse.SC_GONE, errMsg);
        throw ie;
    }
}

From source file:org.apache.hadoop.dfs.DfsServlet.java

/**
 * Create a {@link NameNode} proxy from the current {@link ServletContext}. 
 *//*from   w w w .  ja  v a2 s.c  o m*/
protected ClientProtocol createNameNodeProxy(UnixUserGroupInformation ugi) throws IOException {
    ServletContext context = getServletContext();
    NameNode nn = (NameNode) context.getAttribute("name.node");
    Configuration conf = new Configuration((Configuration) context.getAttribute("name.conf"));
    UnixUserGroupInformation.saveToConf(conf, UnixUserGroupInformation.UGI_PROPERTY_NAME, ugi);
    return DFSClient.createNamenode(nn.getNameNodeAddress(), conf);
}

From source file:com.legstar.host.servlet.ContextListener.java

/** {@inheritDoc}*/
public void contextDestroyed(final ServletContextEvent event) {
    ServletContext context = event.getServletContext();
    EngineHandler engineHandler = (EngineHandler) context.getAttribute(InitiatorServlet.ENGINE_HANDLER_ID);
    if (engineHandler != null) {
        engineHandler.stop();/*  w w  w  . j  a va 2  s .c om*/
    }
    _log.info("LegStar engine context destroyed");
}

From source file:org.apache.dubbo.config.spring.initializer.DubboContextListener.java

@Override
public void contextInitialized(ServletContextEvent servletContextEvent) {
    if (springContextListener != null) {
        // if spring context listener has already been registered, then do nothing
        ServletContext context = servletContextEvent.getServletContext();
        if (context.getAttribute(SPRING_CONTEXT_ROOT) == null) {
            executed = true;/*from  ww  w  .  ja  v a2s. com*/
            springContextListener.contextInitialized(servletContextEvent);
        }
    }
}

From source file:org.spirit.spring.BotListUserSessionListener.java

private ApplicationContext getWebApplicationContext(HttpSessionEvent httpSessionEvent) {
    final HttpSession session = httpSessionEvent.getSession();
    final ServletContext sc = session.getServletContext();
    return (ApplicationContext) sc.getAttribute(CONTEXT_BOTLIST);
}

From source file:org.acoustid.server.ApplicationContextListener.java

@Override
public void contextDestroyed(ServletContextEvent event) {
    ServletContext servletContext = event.getServletContext();
    Injector injector = (Injector) servletContext.getAttribute(INJECTOR_ATTRIBUTE_NAME);
    if (injector == null) {
        logger.warn("Injector not found");
        return;/*from  w w w.  ja  v a 2s .  c o m*/
    }
    servletContext.removeAttribute(INJECTOR_ATTRIBUTE_NAME);

    ApplicationContext context = injector.getInstance(ApplicationContext.class);
    logger.debug("Closing application context " + context);
    context.close();
}

From source file:org.apache.hadoop.hdfsproxy.ProxyForwardServlet.java

/** {@inheritDoc} */
@Override//from ww  w.java2 s  .  c  om
public void init() throws ServletException {
    ServletContext context = getServletContext();
    configuration = (Configuration) context.getAttribute("org.apache.hadoop.hdfsproxy.conf");
}

From source file:org.intermine.web.logic.session.SessionMethods.java

/**
 * Gets the blocking error codes from the servlet context.
 *
 * @param servletContext the ServletContext
 * @return a Map of blocking error codes and replacement value
 *//* www .j  a  v a 2  s  . c o  m*/
public static Map<String, String> getErrorOnInitialiser(ServletContext servletContext) {
    return (servletContext.getAttribute(Constants.INITIALISER_KEY_ERROR) != null)
            ? (Map<String, String>) servletContext.getAttribute(Constants.INITIALISER_KEY_ERROR)
            : null;
}

From source file:org.syncope.buildtools.H2StartStopListener.java

@Override
public void contextDestroyed(final ServletContextEvent sce) {
    ServletContext context = sce.getServletContext();

    Server h2TestDb = (Server) context.getAttribute(H2_TESTDB);
    if (h2TestDb != null) {
        h2TestDb.shutdown();/*from w ww  .ja v  a  2  s  . com*/
    }
}