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:de.betterform.agent.web.WebFactory.java

public static XSLTGenerator setupTransformer(URI uri, ServletContext context) throws URISyntaxException {
    TransformerService transformerService = (TransformerService) context
            .getAttribute(TransformerService.TRANSFORMER_SERVICE);

    XSLTGenerator generator = new XSLTGenerator();
    generator.setTransformerService(transformerService);
    generator.setStylesheetURI(uri);/*from  w w  w.  j  a  va  2  s .  c o m*/
    return generator;
}

From source file:com.liangc.hq.base.service.permissions.BaseSessionInitializationStrategy.java

protected static ConfigResponse getUserPreferences(ServletContext ctx, Integer sessionId, Integer subjectId,
        AuthzBoss authzBoss) {//from   ww w  . jav a  2s. co  m
    // look up the user's preferences
    ConfigResponse defaultPreferences = (ConfigResponse) ctx.getAttribute(Constants.DEF_USER_PREFS);
    ConfigResponse preferences = authzBoss.getUserPrefs(sessionId, subjectId);

    preferences.merge(defaultPreferences, false);

    return preferences;
}

From source file:be.fedict.eid.idp.sp.protocol.openid.AuthenticationRequestServlet.java

/**
 * Used by the {@link AuthenticationResponseServlet} for processing the
 * returned OpenID response//  w  ww.jav a2 s  . co  m
 * 
 * @param request
 *            HTTP Servlet Request, used to get the OpenID
 *            {@link ConsumerManager} from the {@link ServletContext}
 * @return the OpenID {@link ConsumerManager}
 */
public static ConsumerManager getConsumerManager(HttpServletRequest request) {
    HttpSession httpSession = request.getSession();
    ServletContext servletContext = httpSession.getServletContext();
    ConsumerManager consumerManager = (ConsumerManager) servletContext.getAttribute(CONSUMER_MANAGER_ATTRIBUTE);
    if (null == consumerManager) {
        throw new IllegalStateException("no ConsumerManager found in ServletContext");
    }
    return consumerManager;
}

From source file:com.concursive.connect.web.controller.servlets.URLControllerServlet.java

protected static void freeConnection(Connection db, ServletContext context) {
    if (db != null) {
        ConnectionPool sqlDriver = (ConnectionPool) context.getAttribute("ConnectionPool");
        sqlDriver.free(db);/*from   w  ww  . j a  v a 2  s.  com*/
    }
    db = null;
}

From source file:com.onehippo.gogreen.login.HstConcurrentLoginFilter.java

static void unregisterUserSession(HttpSession session) {
    String username = (String) session.getAttribute(USERNAME_ATTR);
    log.debug("HstConcurrentLoginFilter will unregister session for {}", username);

    if (username == null) {
        return;/*from w w w .j  a  v a2s  .c  o  m*/
    }

    ServletContext servletContext = session.getServletContext();
    @SuppressWarnings("unchecked")
    Map<String, HttpSessionWrapper> map = (Map<String, HttpSessionWrapper>) servletContext
            .getAttribute(USERNAME_SESSIONID_MAP_ATTR);

    if (map != null) {
        HttpSessionWrapper oldHttpSessionWrapper = null;

        synchronized (map) {
            oldHttpSessionWrapper = map.get(username);

            if (oldHttpSessionWrapper != null) {
                if (oldHttpSessionWrapper.equalsTo(session)) {
                    map.remove(username);
                    log.debug("HstConcurrentLoginFilter kicked out session ({}) for {}.",
                            oldHttpSessionWrapper.getId(), username);
                } else {
                    log.debug(
                            "HstConcurrentLoginFilter didn't kick out session ({}) for {} because it's logged on by other http session.",
                            oldHttpSessionWrapper.getId(), username);
                }
            }
        }
    } else {
        log.error("HstConcurrentLoginFilter is in invalid state. The session ids map is not found.");
    }

    session.removeAttribute(USERNAME_ATTR);
    log.debug("HstConcurrentLoginFilter removed user name session attribute: {}", username);
}

From source file:mercury.BaseHandler.java

public static Properties getI18nProperties(final HttpSession session, String module) {
    String lang = (String) (session.getAttribute("I18N"));

    if (lang == null || lang.trim().equals("")) {
        lang = "pt_BR";
        session.setAttribute("I18N", lang);
    }/*from w w w.  j  av  a  2s  . c om*/

    String attrName = "I18N_" + module + "." + lang;
    ServletContext sc = session.getServletContext();

    return (Properties) (sc.getAttribute(attrName));
}

From source file:com.facetime.communication.activemq.AmqConsumer.java

protected static synchronized void initConnectionFactory(ServletContext servletContext) {
    if (factory == null) {
        factory = (ConnectionFactory) servletContext.getAttribute(CONNECTION_FACTORY_ATTRIBUTE);
    }/*from w  ww .  ja v a2  s .  c om*/
    if (factory == null) {
        String brokerURL = servletContext.getInitParameter(BROKER_URL_INIT_PARAM);

        BROKER_URL = brokerURL;

        LOG.debug("Value of: " + BROKER_URL_INIT_PARAM + " is: " + brokerURL);

        if (brokerURL == null) {
            throw new IllegalStateException(
                    "missing brokerURL (specified via " + BROKER_URL_INIT_PARAM + " init-Param");
        }

        ActiveMQConnectionFactory amqfactory = new ActiveMQConnectionFactory(brokerURL);

        // Set prefetch policy for factory
        if (servletContext.getInitParameter(CONNECTION_FACTORY_PREFETCH_PARAM) != null) {
            int prefetch = Integer.valueOf(servletContext.getInitParameter(CONNECTION_FACTORY_PREFETCH_PARAM))
                    .intValue();
            amqfactory.getPrefetchPolicy().setAll(prefetch);
        }

        // Set optimize acknowledge setting
        if (servletContext.getInitParameter(CONNECTION_FACTORY_OPTIMIZE_ACK_PARAM) != null) {
            boolean optimizeAck = Boolean
                    .valueOf(servletContext.getInitParameter(CONNECTION_FACTORY_OPTIMIZE_ACK_PARAM))
                    .booleanValue();
            amqfactory.setOptimizeAcknowledge(optimizeAck);
        }

        factory = amqfactory;

        servletContext.setAttribute(CONNECTION_FACTORY_ATTRIBUTE, factory);
    }
}

From source file:org.apache.nutchbase.searcher.NutchBeanHbase.java

/** Returns the cached instance in the servlet context.
 * @see NutchBeanConstructor*///from   w  w  w .ja v  a2  s.co m
public static NutchBeanHbase get(ServletContext app, Configuration conf) throws IOException {
    final NutchBeanHbase bean = (NutchBeanHbase) app.getAttribute(KEY);
    return bean;
}

From source file:com.qwazr.server.GenericServer.java

/**
 * Returns the named attribute. The method checks the type of the object.
 *
 * @param context the context to request
 * @param name    the name of the attribute
 * @param type    the expected type/*from  ww  w . j a v a 2 s  . c o  m*/
 * @param <T>     the expected object
 * @return the expected object
 */
public static <T> T getContextAttribute(final ServletContext context, final String name, final Class<T> type) {
    final Object object = context.getAttribute(name);
    if (object == null)
        return null;
    if (!object.getClass().isAssignableFrom(type))
        throw new RuntimeException(
                "Wrong returned type: " + object.getClass().getName() + " - Expected: " + type.getName());
    return type.cast(object);
}

From source file:com.concursive.connect.web.rss.servlets.FeedServlet.java

protected static void freeConnection(Connection db, ServletContext context) {
    if (db != null) {
        ConnectionPool sqlDriver = (ConnectionPool) context.getAttribute("ConnectionPoolRSS");
        sqlDriver.free(db);//from w  w  w. j  ava2 s. c o m
    }
    db = null;
}