Example usage for javax.servlet ServletContext getInitParameter

List of usage examples for javax.servlet ServletContext getInitParameter

Introduction

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

Prototype

public String getInitParameter(String name);

Source Link

Document

Returns a String containing the value of the named context-wide initialization parameter, or null if the parameter does not exist.

Usage

From source file:com.bstek.dorado.web.servlet.ServletContextResourceLoader.java

public ServletContextResourceLoader(ServletContext servletContext) {
    this.servletContext = servletContext;
    String resourceLoaderClass = servletContext.getInitParameter("resourceLoaderClass");
    if (StringUtils.isNotEmpty(StringUtils.trim(resourceLoaderClass))) {
        ConsoleUtils.outputLoadingInfo("[resourceLoaderClass=" + resourceLoaderClass + "]");

        try {/*from   ww  w .j  a  v a  2s.c o  m*/
            @SuppressWarnings("unchecked")
            Class<ResourceLoader> type = ClassUtils.forName(resourceLoaderClass);
            Constructor<ResourceLoader> constr = type.getConstructor(new Class[] { ClassLoader.class });
            resourceLoader = constr.newInstance(new Object[] { getClass().getClassLoader() });
        } catch (Exception e) {
            logger.error(e, e);
        }
    }
}

From source file:com.reignite.messaging.server.SpringWebInitializer.java

@Override
protected RAMFServer getServerFromServletContext(ServletContext servletContext) {
    WebApplicationContext wac = WebApplicationContextUtils.getWebApplicationContext(servletContext);
    String beanName = servletContext.getInitParameter("RAMFServerBeanName");
    if (beanName == null || beanName.trim().length() == 0) {
        beanName = "ramfServer";
    }/*from   w  w w.j  a va2s  .co  m*/

    return (RAMFServer) wac.getBean(beanName);
}

From source file:org.apache.myfaces.shared.util.StateUtils.java

/**
 * Does nothing if the user has disabled the SecretKey cache. This is
 * useful when dealing with a JCA provider whose SecretKey 
 * implementation is not thread safe./*from w ww  . jav a2  s  .co  m*/
 * 
 * Instantiates a SecretKey instance based upon what the user has 
 * specified in the deployment descriptor.  The SecretKey is then 
 * stored in application scope where it can be used for all requests.
 */

public static void initSecret(ServletContext ctx) {

    if (ctx == null) {
        throw new NullPointerException("ServletContext ctx");
    }

    if (log.isLoggable(Level.FINE)) {
        log.fine("Storing SecretKey @ " + INIT_SECRET_KEY_CACHE);
    }

    // Create and store SecretKey on application scope
    String cache = ctx.getInitParameter(INIT_SECRET_KEY_CACHE);

    if (cache == null) {
        cache = ctx.getInitParameter(INIT_SECRET_KEY_CACHE.toLowerCase());
    }

    if (!"false".equals(cache)) {
        String algorithm = findAlgorithm(ctx);
        // you want to create this as few times as possible
        ctx.setAttribute(INIT_SECRET_KEY_CACHE, new SecretKeySpec(findSecret(ctx, algorithm), algorithm));
    }

    if (log.isLoggable(Level.FINE)) {
        log.fine("Storing SecretKey @ " + INIT_MAC_SECRET_KEY_CACHE);
    }

    String macCache = ctx.getInitParameter(INIT_MAC_SECRET_KEY_CACHE);

    if (macCache == null) {
        macCache = ctx.getInitParameter(INIT_MAC_SECRET_KEY_CACHE.toLowerCase());
    }

    if (!"false".equals(macCache)) {
        String macAlgorithm = findMacAlgorithm(ctx);
        // init mac secret and algorithm 
        ctx.setAttribute(INIT_MAC_SECRET_KEY_CACHE,
                new SecretKeySpec(findMacSecret(ctx, macAlgorithm), macAlgorithm));
    }
}

From source file:com.athena.sqs.MessageReceiveListener.java

public void contextInitialized(ServletContextEvent sce) {
    ServletContext servletContext = sce.getServletContext();
    listenQueueName = servletContext.getInitParameter("listenQueueName");
    if (listenQueueName == null) {
        listenQueueName = "your_listen_queue_name";
    }//  ww w.  j  a va  2s  .  c  o m

    ApplicationContext applicationContext = (ApplicationContext) servletContext
            .getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE);
    receiver = applicationContext.getBean(MessageReceiver.class);

    // If you want to run multiple receivers, create tasks or change doReceive method to async.
    /*
     * List<BizQueue> list = dao.getBizQueueList();
     * for(BizQueue queue : list) {
     *     BizQueueTask task = new BiaQueueTask(sqsContext, queue);
     *     task.run(); // thread start.
     * }
     */
    try {
        logger.debug("***********************************************");
        logger.debug("SQS Message Receiver is starting");
        logger.debug("***********************************************");

        // Queue names are loaded from sqsContext.xml

        List<String> queueList = (List<String>) applicationContext.getBean("initialQueueList");

        for (String queueName : queueList) {
            receiver.doReceive(queueName);
            Thread.sleep(2000);
        }

        // Default listen queue start
        receiver.doReceive(listenQueueName);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:org.lightadmin.core.config.StandardLightAdminConfiguration.java

private String backToSiteUrl(ServletContext servletContext) {
    final String backToSiteUrl = servletContext.getInitParameter(LIGHT_ADMINISTRATION_BACK_TO_SITE_URL);

    return isBlank(backToSiteUrl) ? LIGHT_ADMINISTRATION_BACK_TO_SITE_DEFAULT_URL : backToSiteUrl;
}

From source file:org.shangridocs.services.pubmed.PubmedResource.java

public PubmedResource(@Context ServletContext sc) {
    pubMedBaseUrlStr = sc.getInitParameter(PUBMED_BASE_URL);
    pubMedIdBaseUrlStr = sc.getInitParameter(PUBMED_ID_BASE_URL);
}

From source file:org.lightadmin.core.config.StandardLightAdminConfiguration.java

private File fileStorageDirectory(ServletContext servletContext) {
    final String fileStoragePath = servletContext.getInitParameter(LIGHT_ADMINISTRATION_FILE_STORAGE_PATH);

    return isBlank(fileStoragePath) ? null : getFile(fileStoragePath);
}

From source file:com.github.persapiens.jsfboot.angularfaces.AngularfacesServletContextInitializerIT.java

public void testOnStartup() throws ServletException {
    AngularfacesServletContextInitializer angularfacesServletContextInitializer = new AngularfacesServletContextInitializer(
            this.angularfacesProperties);

    ServletContext servletContext = new MockServletContext();

    angularfacesServletContextInitializer.onStartup(servletContext);

    assertThat(servletContext.getInitParameter(AngularfacesServletContextConfigurer.PREFFIX + "addLabels"))
            .isEqualTo("true");
    assertThat(servletContext.getInitParameter(ViewHandler.FACELETS_DECORATORS_PARAM_NAME))
            .isEqualTo(AngularTagDecorator.class.getName());
}

From source file:org.joinfaces.angularfaces.AngularfacesServletContextInitializerIT.java

@Test
public void testOnStartup() throws ServletException {
    AngularfacesServletContextInitializer angularfacesServletContextInitializer = new AngularfacesServletContextInitializer(
            this.angularfacesProperties);

    ServletContext servletContext = new MockServletContext();

    angularfacesServletContextInitializer.onStartup(servletContext);

    assertThat(servletContext.getInitParameter(AngularfacesServletContextConfigurer.PREFFIX + "addLabels"))
            .isEqualTo("true");
    assertThat(servletContext.getInitParameter(ViewHandler.FACELETS_DECORATORS_PARAM_NAME))
            .isEqualTo(AngularTagDecorator.class.getName());
}

From source file:org.n52.wfs.WfsDispatcherServlet.java

private String getConfigLocation(ServletContext servletContext, String initParamName) {
    String initParam = servletContext.getInitParameter(initParamName);
    return (initParam == null || initParam.isEmpty()) ? "" : initParam;
}