Example usage for javax.servlet ServletContext setAttribute

List of usage examples for javax.servlet ServletContext setAttribute

Introduction

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

Prototype

public void setAttribute(String name, Object object);

Source Link

Document

Binds an object to a given attribute name in this ServletContext.

Usage

From source file:org.jaggeryjs.jaggery.app.mgt.TomcatJaggeryWebappsDeployer.java

private static void addLogLevel(Context cx, JSONObject jaggeryConfig) {
    String level = (String) jaggeryConfig.get(JaggeryCoreConstants.JaggeryConfigParams.LOG_LEVEL);
    if (level == null) {
        return;// ww  w.  j  ava2  s. co  m
    }
    ServletContext context = cx.getServletContext();
    context.setAttribute(LogHostObject.LOG_LEVEL, level);
}

From source file:org.apache.tiles.servlet.context.ServletUtil.java

/**
 * Configures the container to be used in the application.
 *
 * @param context The servlet context object to use.
 * @param container The container object to set.
 * @param key The key under which the container will be stored.
 * @since 2.1.2/*w ww .  jav  a2 s  .  c  o m*/
 */
public static void setContainer(ServletContext context, TilesContainer container, String key) {
    Log log = LogFactory.getLog(ServletUtil.class);
    if (key == null) {
        key = TilesAccess.CONTAINER_ATTRIBUTE;
    }

    if (container == null) {
        if (log.isInfoEnabled()) {
            log.info("Removing TilesContext for context: " + context.getClass().getName());
        }
        context.removeAttribute(key);
    }
    if (container != null && log.isInfoEnabled()) {
        log.info("Publishing TilesContext for context: " + context.getClass().getName());
    }
    context.setAttribute(key, container);
}

From source file:org.apache.nutch.webapp.common.ServletContextServiceLocator.java

/**
 * Factory method to get handle to ServiceLocator, or if none exists in
 * ServletContext then one is created./*  w  w w.j  av a2  s.  co  m*/
 *
 * @param context
 * @return ServiceLocator instance bound to ServletContext
 */
public static ServiceLocator getInstance(ServletContext context) {
    ServiceLocator locator = (ServiceLocator) context.getAttribute(KEY);
    if (locator == null) {
        LOG.info("creating new serviceLocator for context:" + context);
        locator = new ServletContextServiceLocator(context) {
            public SearchForm getSearchForm() {
                return null;
            }

            public Preferences getPreferences() {
                return null;
            }

            public Search getSearch() {
                return null;
            }

            public Locale getLocale() {
                return null;
            }
        };
        context.setAttribute(KEY, locator);
    }
    return locator;
}

From source file:com.concursive.connect.web.portal.PortletManager.java

private static synchronized boolean checkServicesRegistry(ServletContext context, ApplicationPrefs prefs) {
    if (!prefs.has("CONCURSIVE_SERVICES.SERVER")) {
        context.setAttribute("isConsumerRegistered", "false");
        return false;
    }//from   w  ww.jav a 2 s. c om
    boolean isConsumerRegistered = StringUtils.isTrue((String) context.getAttribute("isConsumerRegistered"));
    if (!isConsumerRegistered) {
        //load the WSRP producer information
        try {
            String wsrpServer = prefs.get(ApplicationPrefs.CONCURSIVE_SERVICES_SERVER);

            String markupURL = wsrpServer + "/services/WSRPBaseService";
            String serviceDescriptionURL = wsrpServer + "/services/WSRPServiceDescriptionService";
            String registrationURL = wsrpServer + "/services/WSRPRegistrationService";
            String portletManagementURL = wsrpServer + "/services/WSRPPortletManagementService";

            String consumerName = prefs.get(ApplicationPrefs.CONCURSIVE_SERVICES_ID);
            String consumerCode = prefs.get(ApplicationPrefs.CONCURSIVE_SERVICES_KEY);
            String consumerAgent = ApplicationVersion.TITLE + " " + ApplicationVersion.VERSION;

            ProducerImpl producer = new ProducerImpl(PortletManager.CONCURSIVE_WSRP_PRODUCER_ID, markupURL,
                    serviceDescriptionURL);
            //ID and misc info
            producer.setID(PortletManager.CONCURSIVE_WSRP_PRODUCER_ID);
            //WSRP registration interface
            producer.setRegistrationInterfaceEndpoint(registrationURL);
            //WSRP portlet management interface
            producer.setPortletManagementInterfaceEndpoint(portletManagementURL);

            //Registration
            RegistrationData registrationData = new RegistrationData();
            registrationData.setConsumerName(consumerName);
            registrationData.setConsumerAgent(consumerAgent);
            registrationData.setRegistrationProperties(new Property[2]);

            //Send the services key as a registration property; Server will authorize by enforcing a valid key
            Property key = new Property();
            key.setName(ApplicationPrefs.CONCURSIVE_SERVICES_KEY);
            key.setStringValue(consumerCode);

            //Send the services key as a registration property; Server will authorize by enforcing a valid key
            Property sessions = new Property();
            sessions.setName(ApplicationPrefs.CONSUMER_SESSION_SUPPORT);
            sessions.setStringValue("true");

            registrationData.setRegistrationProperties(0, key);
            registrationData.setRegistrationProperties(1, sessions);
            //producer.setRegistrationData(registrationData);

            //Register the consumer with the remote producer
            LOG.info("Registering ConcourseConnect consumer with remote producer <" + wsrpServer + ">: "
                    + producer.getID());
            producer.register(registrationData);

            ProducerRegistry producerRegistry = ProducerRegistryImpl.getInstance();
            producerRegistry.addProducer(producer);

            isConsumerRegistered = true;
            context.setAttribute("isConsumerRegistered", "true");
        } catch (WSRPException e) {
            isConsumerRegistered = false;
            LOG.error("Unable to register the consumer with the remote WSRP producer");
            context.setAttribute("isConsumerRegistered", "false");
        }
    }
    return isConsumerRegistered;
}

From source file:org.apache.hadoop.fs.webdav.WebdavServlet.java

private static Configuration getConf(ServletContext application) {
    Configuration conf = (Configuration) application.getAttribute("dfs.servlet.conf.key");

    if (conf == null) {
        conf = hadoopConfig;/*from ww w.  j  a  va2 s .  c om*/
        Enumeration e = application.getInitParameterNames();
        while (e.hasMoreElements()) {
            String name = (String) e.nextElement();
            conf.set(name, application.getInitParameter(name));
        }
        application.setAttribute("dfs.servlet.conf.key", conf);
    }

    if (currentUserName != null) {
        WebAppContext webapp = (WebAppContext) application.getAttribute(WebdavServer.WEB_APP_CONTEXT);
        WebdavHashUserRealm userRealm = (WebdavHashUserRealm) webapp.getSecurityHandler().getUserRealm();
        List<String> userRoles = userRealm.getUserRoles(currentUserName);
        currentUserRoles = userRoles;

        UnixUserGroupInformation ugi = new UnixUserGroupInformation(currentUserName,
                userRoles.toArray(new String[0]));
        UnixUserGroupInformation.saveToConf(conf, UnixUserGroupInformation.UGI_PROPERTY_NAME, ugi);
    }
    return conf;
}

From source file:com.telefonica.iot.perseo.Utils.java

/**
 * Add an initialized EPServiceProvider to an ServletContext if it is not
 * already/* w ww.j  a  v a 2s.  c  om*/
 *
 * @param sc ServleContext to add ESPServiceProvider
 * @return the initialized EPServiceProvider
 */
public static synchronized EPServiceProvider initEPService(ServletContext sc) {
    EPServiceProvider epService = (EPServiceProvider) sc.getAttribute(EPSERV_ATTR_NAME);
    if (epService == null) {
        epService = EPServiceProviderManager.getDefaultProvider();
        Map<String, Object> def = new HashMap<String, Object>();
        def.put("id", String.class);
        def.put("type", String.class);
        def.put(Constants.SUBSERVICE_FIELD, String.class);
        def.put(Constants.SERVICE_FIELD, String.class);
        ConfigurationOperations cfg = epService.getEPAdministrator().getConfiguration();
        cfg.addEventType(Constants.IOT_EVENT, def);
        sc.setAttribute(EPSERV_ATTR_NAME, epService);
    }
    return epService;
}

From source file:com.betfair.tornjak.monitor.overlay.AuthUtils.java

private static synchronized RolePerms getOrCreateRolePerms(ServletContext servletContext) throws IOException {
    RolePerms rolePerms;//from   w  w w.  j  a  v a 2  s.c  o  m

    rolePerms = (RolePerms) servletContext.getAttribute(CONTEXT_ATTR_NAME);

    if (rolePerms != null) {
        return rolePerms;
    }

    ApplicationContext context = (ApplicationContext) servletContext
            .getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE);
    if (context == null) {
        throw new ApplicationContextException("Unable to find application context");
    }
    String authFileLocation = servletContext.getInitParameter(CONTEXT_INIT_PARAM_NAME);
    if (StringUtils.isBlank(authFileLocation)) {
        throw new ApplicationContextException(String
                .format("Parameter '%s' not defined, unable to load jmx auth file", CONTEXT_INIT_PARAM_NAME));
    }

    rolePerms = AuthFileReader.load(context.getResource(authFileLocation));
    servletContext.setAttribute(CONTEXT_ATTR_NAME, rolePerms);

    return rolePerms;

}

From source file:cn.edu.zjnu.acm.judge.config.StartUpConfiguration.java

@Autowired
public void setStartUpDate(ServletContext servlet, ApplicationContext application) {
    servlet.setAttribute("startUpDate", application.getStartupDate());
    log.debug("{}: {}", ServletContext.TEMPDIR, servlet.getAttribute(ServletContext.TEMPDIR));
}

From source file:com.healthcit.cacure.utils.AppVersionResolver.java

@Override
public void setServletContext(ServletContext sc) {
    if (appVersion != null) {
        sc.setAttribute(APP_VERSION_ATTR, appVersion);
    } else {//from ww w.j a  va 2  s.  c  o  m
        servletContext = sc;
    }
}

From source file:com.chimpler.example.CometConfigurer.java

public void setServletContext(ServletContext servletContext) {
    servletContext.setAttribute(BayeuxServer.ATTRIBUTE, bayeuxServer);
}