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:org.apache.juddi.v3.client.config.WebHelperTest.java

/**
 * Test of getUDDIClient method, of class WebHelper.
 *///  w w  w . j  av  a  2s  . c om
@Test
public void testGetUDDIClient() throws Exception {
    System.out.println("getUDDIClient");

    ServletContext req = createNiceMock(ServletContext.class);
    req.setAttribute(JUDDI_CLIENT_NAME, null);
    expect(req.getInitParameter(WebHelper.JUDDI_CLIENT_NAME)).andReturn(null).times(0, 1);
    //using default config
    //     expect(req.getInitParameter(WebHelper.UDDI_CLIENT_NAME)).andReturn(null).times(0, 2);
    //   expect(req.getInitParameter(WebHelper.UDDI_CLIENT_CONFIG_FILE)).andReturn(null).times(0, 2);
    // expect(req.getInitParameter(WebHelper.JUDDI_CLIENT_TRANSPORT)).andReturn(null).times(0, 2);
    //expect(req.getAttribute(WebHelper.JUDDI_CLIENT_NAME)).andReturn(null).times(0, 2);
    //using default config
    // expect(req.getAttribute(WebHelper.UDDI_CLIENT_NAME)).andReturn(null).times(0, 2);
    //expect(req.getAttribute(WebHelper.UDDI_CLIENT_CONFIG_FILE)).andReturn(null).times(0, 2);
    //expect(req.getAttribute(WebHelper.JUDDI_CLIENT_TRANSPORT)).andReturn(null).times(0, 2);

    replay(req);

    UDDIClient result = WebHelper.getUDDIClient(req);
    Assert.assertNotNull(result);
}

From source file:com.alefissak.web.AlefissakListener.java

/**
 * Launching Alefissak in a web context/*from w  w w.  j a  v a2s.c  o  m*/
 * {@inheritDoc}
 */
@Override
public void contextInitialized(ServletContextEvent contextEvent) {

    LOG.debug("Starting Alefissak Configuration");

    try {

        ServletContext servletContext = contextEvent.getServletContext();

        if (servletContext != null) {

            planningsConfigUri = servletContext.getInitParameter(PLANNINGS_CONFIG_PARAM_NAME);

            if (null != planningsConfigUri) {

                LOG.debug("Considering the configuration located here : {}", planningsConfigUri);

                Alefissak alefissak;

                if (isURL(planningsConfigUri)) {

                    alefissak = new Alefissak(new AlefissakPlanningParser(new URL(planningsConfigUri)));
                } else {

                    alefissak = new Alefissak(new AlefissakPlanningParser(planningsConfigUri));
                }

                alefissak.run();
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.jaspersoft.jasperserver.war.util.SpringBeanServletContextPlublisher.java

public void contextInitialized(ServletContextEvent sce) {
    ServletContext servletContext = sce.getServletContext();
    ApplicationContext applicationContext = WebApplicationContextUtils.getWebApplicationContext(servletContext);
    String beanNamesAttr = servletContext.getInitParameter(ATTRIBUTE_BEAN_NAMES);
    String[] beanNames = beanNamesAttr.split("\\,");
    for (int i = 0; i < beanNames.length; i++) {
        String beanName = beanNames[i];
        Object bean = applicationContext.getBean(beanName);
        if (bean == null) {
            log.warn("Bean \"" + beanName + "\" not found");
        } else {//from  w w w .j  a  v a  2  s  . c o m
            servletContext.setAttribute(beanName, bean);

            if (log.isDebugEnabled()) {
                log.debug("Bean \"" + beanName + "\" published in the application context");
            }
        }
    }
}

From source file:info.magnolia.init.DefaultMagnoliaPropertiesResolver.java

protected String getInitParameter(ServletContext ctx, String name, String defaultValue) {
    final String propertiesFilesString = ctx.getInitParameter(name);
    if (StringUtils.isEmpty(propertiesFilesString)) {
        log.debug("{} value in web.xml is undefined, falling back to default: {}", name, defaultValue);
        return defaultValue;
    }/*from  ww  w.  j  av  a 2s. c o m*/
    log.debug("{} value in web.xml is :'{}'", name, propertiesFilesString);
    return propertiesFilesString;
}

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

@Test(expected = ConfigurationException.class)
public void testGetUDDIClientNoConfig() throws Exception {
    System.out.println("testGetUDDIClientNoConfig");

    String random = UUID.randomUUID().toString();
    ServletContext req = createNiceMock(ServletContext.class);

    req.setAttribute(JUDDI_CLIENT_NAME, null);
    expect(req.getInitParameter(WebHelper.JUDDI_CLIENT_NAME)).andReturn(null).times(0, 1);
    req.setAttribute(UDDI_CLIENT_CONFIG_FILE, random);
    expect(req.getInitParameter(WebHelper.UDDI_CLIENT_CONFIG_FILE)).andReturn(random).times(0, 1);

    //using default config
    //     expect(req.getInitParameter(WebHelper.UDDI_CLIENT_NAME)).andReturn(null).times(0, 2);
    //   expect(req.getInitParameter(WebHelper.UDDI_CLIENT_CONFIG_FILE)).andReturn(null).times(0, 2);
    // expect(req.getInitParameter(WebHelper.JUDDI_CLIENT_TRANSPORT)).andReturn(null).times(0, 2);
    //expect(req.getAttribute(WebHelper.JUDDI_CLIENT_NAME)).andReturn(null).times(0, 2);
    //using default config
    // expect(req.getAttribute(WebHelper.UDDI_CLIENT_NAME)).andReturn(null).times(0, 2);
    //expect(req.getAttribute(WebHelper.UDDI_CLIENT_CONFIG_FILE)).andReturn(null).times(0, 2);
    //expect(req.getAttribute(WebHelper.JUDDI_CLIENT_TRANSPORT)).andReturn(null).times(0, 2);

    replay(req);/* w  w w  . j  a  v  a 2  s . c  om*/

    UDDIClient result = WebHelper.getUDDIClient(req);
    Assert.assertNotNull(result);
}

From source file:com.enioka.jqm.api.ServiceSimple.java

public ServiceSimple(@Context ServletContext context) {
    if (context.getInitParameter("jqmnodeid") != null) {
        EntityManager em = null;//from   w  w w .j ava 2s .c o  m
        try {
            em = Helpers.getEm();

            n = em.find(Node.class, Integer.parseInt(context.getInitParameter("jqmnodeid")));
            if (n == null) {
                throw new RuntimeException(
                        "invalid configuration: no node of ID " + context.getInitParameter("jqmnodeid"));
            }
        } finally {
            Helpers.closeQuietly(em);
        }
    }
}

From source file:com.indeed.imhotep.web.config.WebApp.java

protected void initLog4j(ServletContext servletContext) {
    final String log4jConfigLocationParam = "log4jConfigLocation";
    final String log4jConfigLocation = servletContext.getInitParameter(log4jConfigLocationParam);
    if (Strings.isNullOrEmpty(log4jConfigLocation)) {
        servletContext.setInitParameter(log4jConfigLocationParam, getDefaultLog4jConfigLocation());
    }/*from  ww  w.  j a va2 s .com*/
    servletContext.setInitParameter("log4jExposeWebAppRoot", "false");

    servletContext.addListener(Log4jConfigListener.class);
}

From source file:com.nabla.wapp.server.database.Database.java

/**
 * Constructor//from w w  w  .j  a v  a2s.  c  o  m
 * @param dbName         - database name as defined in pool
 * @param serverContext      - web app context
 * @throws SQLException
 */
public Database(final String dbName, final ServletContext serverContext) throws SQLException {
    Assert.argumentNotNull(serverContext);

    pool = ("1".equals(serverContext.getInitParameter(PRODUCTION_MODE))) ? new TomcatConnectionPool(dbName)
            : new CommonConnectionPool(dbName, serverContext);
}

From source file:org.jodconverter.sample.webapp.WebappContext.java

/**
 * Creates a new WebappContext using the specified servlet context.
 *
 * @param servletContext the servlet context that contains properties used to create a JOD
 *     document converter.//from   w  w w. ja  v  a  2s  .c  o m
 */
public WebappContext(final ServletContext servletContext) {
    final DiskFileItemFactory fileItemFactory = new DiskFileItemFactory();
    final String fileSizeMax = servletContext.getInitParameter(PARAMETER_FILEUPLOAD_FILE_SIZE_MAX);
    fileUpload = new ServletFileUpload(fileItemFactory);
    if (fileSizeMax == null) {
        LOGGER.warn("max file upload size not set");
    } else {
        fileUpload.setFileSizeMax(Integer.parseInt(fileSizeMax));
        LOGGER.info("max file upload size set to {}", fileSizeMax);
    }

    final LocalOfficeManager.Builder builder = LocalOfficeManager.builder();
    final String officePortParam = servletContext.getInitParameter(PARAMETER_OFFICE_PORT);
    if (officePortParam != null) {
        builder.portNumbers(Integer.parseInt(officePortParam));
    }
    final String officeHomeParam = servletContext.getInitParameter(PARAMETER_OFFICE_HOME);
    builder.officeHome(officeHomeParam);
    final String officeProfileParam = servletContext.getInitParameter(PARAMETER_OFFICE_PROFILE);
    builder.templateProfileDir(officeProfileParam);

    officeManager = builder.build();
    documentConverter = LocalConverter.make(officeManager);
}

From source file:com.github.persapiens.jsfboot.ServletContextConfigurerIT.java

public void testEmpty() {
    ServletContext servletContext = new MockServletContext();

    ServletContextConfigurer servletContextConfigurer = new JsfServletContextConfigurer(servletContext);

    servletContextConfigurer.configure();

    assertThat(servletContext.getInitParameter("jsf.empty")).isNull();
}