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:be.fedict.eid.dss.webapp.StartupServletContextListener.java

/**
 * @param context//from  w w w.  j  a v a  2s . c  o  m
 *            the servlet context
 * @return map of document service with content type as key. This map has
 *         been constructed during startup of the eID DSS service.
 */
@SuppressWarnings("unchecked")
public static Map<String, String> getDocumentServiceClassNames(ServletContext context) {
    return (Map<String, String>) context.getAttribute(DOCUMENT_SERVICES_CONTEXT_ATTRIBUTE);
}

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

/**
 *
 * @param sc/*from   ww w  .ja v  a2  s.c o m*/
 * @return
 */
public static RpcSpringContext getSpringContext(ServletContext sc) {
    return (RpcSpringContext) sc.getAttribute(RpcSpringContext.class.getName());
}

From source file:org.apache.juddi.v3.client.config.WebHelper.java

/**
 * Checks the servlet context for the manager defined in the web context. Optionally, in your 
 * web.xml you can specify either the manager name if you want to use an existing manager 
 * called 'uddi-portlet-manager':/*from w w w .  jav a2s.  c o m*/
 * <pre>
 * &lt;context-param&gt;
 *   &lt;param-name&gt;uddi.client.manager.name&lt;/param-name&gt;
 *   &lt;param-value&gt;uddi-portlet-manager&lt;/param-value&gt;
 * &lt;/context-param&gt;
 * </pre>
 * or, if you don't want to use the default META-INF/uddi.xml file path, but 'META-INF/my-uddi.xml' instead,
 * then you can set:
 * <pre>
 * &lt;context-param&gt;
 *   &lt;param-name&gt;uddi.client.config.path&lt;/param-name&gt;
 *   &lt;param-value&gt;META-INF/my-uddi.xml&lt;/param-value&gt;
 * &lt;/context-param&gt;
 * </pre>
 * @param servletContext
 * @return a UDDI Client instance
 * @throws ConfigurationException
 */
public static UDDIClient getUDDIClient(ServletContext servletContext) throws ConfigurationException {
    if (servletContext.getAttribute(JUDDI_CLIENT_NAME) != null) {
        String clientName = String.valueOf(servletContext.getAttribute(JUDDI_CLIENT_NAME));
        return UDDIClientContainer.getUDDIClient(clientName);
    } else {
        String clientName = servletContext.getInitParameter(UDDI_CLIENT_NAME);
        if (clientName != null) {
            try {
                UDDIClient client = UDDIClientContainer.getUDDIClient(clientName);
                logger.info("Client " + clientName + " was already started.");
                servletContext.setAttribute(JUDDI_CLIENT_NAME, clientName);
                return client;
            } catch (ConfigurationException ce) {
                logger.debug("Client " + clientName + " is not yet started.");
            }
        }
        String clientConfigFile = servletContext.getInitParameter(UDDI_CLIENT_CONFIG_FILE);
        if (clientConfigFile == null)
            clientConfigFile = ClientConfig.DEFAULT_UDDI_CONFIG;

        logger.info("Reading the clientName from the clientConfig file " + clientConfigFile);
        UDDIClient client = new UDDIClient(clientConfigFile);
        if (clientConfigFile == null && client.getName() == null) {
            logger.warn(
                    "Deprecated, client name set to 'default', however it should be provided in the uddi.xml");
            clientName = "default";
        }
        if (client.getName() != null) {
            logger.info("Starting Client " + client.getName() + "...");
        } else {
            throw new ConfigurationException("A client name needs to be specified in the client config file.");
        }

        client.start();
        servletContext.setAttribute(JUDDI_CLIENT_NAME, clientName);
        return client;
    }
}

From source file:com.manydesigns.portofino.dispatcher.DispatcherUtil.java

public static Dispatcher install(HttpServletRequest request) {
    ServletContext servletContext = ElementsThreadLocals.getServletContext();
    Configuration configuration = (Configuration) servletContext
            .getAttribute(BaseModule.PORTOFINO_CONFIGURATION);
    File pagesDir = (File) servletContext.getAttribute(PageactionsModule.PAGES_DIRECTORY);

    Dispatcher dispatcher = new Dispatcher(configuration, pagesDir);
    request.setAttribute(RequestAttributes.DISPATCHER, dispatcher);
    return dispatcher;
}

From source file:org.apache.hadoop.hdfs.qjournal.server.JournalNodeHttpServer.java

public static Journal getJournalFromContext(ServletContext context, String jid) throws IOException {
    JournalNode jn = (JournalNode) context.getAttribute(JN_ATTRIBUTE_KEY);
    return jn.getOrCreateJournal(jid);
}

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.//from  w w w  .j  a va  2  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.betfair.tornjak.monitor.overlay.AuthUtils.java

private static synchronized RolePerms getOrCreateRolePerms(ServletContext servletContext) throws IOException {
    RolePerms rolePerms;//from w ww  .  j a va  2 s.com

    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:org.apache.myfaces.webapp.StartupServletContextListener.java

public static void initFaces(ServletContext servletContext) {
    try {//from  ww w  . ja v a2  s.  co  m
        Boolean b = (Boolean) servletContext.getAttribute(FACES_INIT_DONE);

        if (b == null || b.booleanValue() == false) {
            log.trace("Initializing MyFaces");

            //Load the configuration
            ExternalContext externalContext = new ServletExternalContextImpl(servletContext, null, null);

            //And configure everything
            new FacesConfigurator(externalContext).configure();

            if ("true".equals(servletContext.getInitParameter(FacesConfigValidator.VALIDATE_CONTEXT_PARAM))
                    || "true".equals(servletContext
                            .getInitParameter(FacesConfigValidator.VALIDATE_CONTEXT_PARAM.toLowerCase()))) {
                List list = FacesConfigValidator.validate(externalContext, servletContext.getRealPath("/"));

                Iterator iterator = list.iterator();

                while (iterator.hasNext())
                    log.warn(iterator.next());

            }

            // parse web.xml
            WebXml.init(externalContext);

            servletContext.setAttribute(FACES_INIT_DONE, Boolean.TRUE);
        } else {
            log.info("MyFaces already initialized");
        }
    } catch (Exception ex) {
        log.error("Error initializing ServletContext", ex);
        ex.printStackTrace();
    }
    log.info("ServletContext '" + servletContext.getRealPath("/") + "' initialized.");

    if (servletContext.getInitParameter(StateUtils.INIT_SECRET) != null
            || servletContext.getInitParameter(StateUtils.INIT_SECRET.toLowerCase()) != null)
        StateUtils.initSecret(servletContext);
}

From source file:org.axe.helper.mvc.FormRequestHelper.java

/**
 * ?//from   w  w w . j  a v  a  2s . c  o  m
 */
public static void init(ServletContext servletContext) {
    File repository = (File) servletContext.getAttribute("javax.servlet.context.tempdir");
    servletFileUpload = new ServletFileUpload(
            new DiskFileItemFactory(DiskFileItemFactory.DEFAULT_SIZE_THRESHOLD, repository));
    int uploadLimit = ConfigHelper.getAppUploadLimit();
    if (uploadLimit > 0) {
        servletFileUpload.setFileSizeMax(uploadLimit * 1024 * 1024);
    }
}

From source file:org.apache.hadoop.hdfs.server.namenode.NameNodeHttpServer.java

public static FSImage getFsImageFromContext(ServletContext context) {
    return (FSImage) context.getAttribute(FSIMAGE_ATTRIBUTE_KEY);
}