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.hippoecm.frontend.util.RequestUtilsTest.java

@Test
public void testGetRemoteAddrsWithCustomForwardedForHeaderSetEmpty() {
    ServletContext servletContext = createNiceMock(ServletContext.class);
    expect(servletContext.getInitParameter(RequestUtils.HTTP_FORWARDED_FOR_HEADER_PARAM))
            .andReturn(CUSTOM_X_FORWARDED_FOR_HEADER_NAME).anyTimes();
    replay(servletContext);//from   w  ww.  jav a 2 s  .c  o m
    Request request = createRequest(servletContext, null, "");

    String[] expArr = new String[] { DEFAULT_REMOTE_ADDR };
    String[] actArr = RequestUtils.getRemoteAddrs(request);
    assertArrayEquals(createErrorMessage(expArr, actArr), expArr, actArr);
    String expVal = DEFAULT_REMOTE_ADDR;
    String actVal = RequestUtils.getFarthestRemoteAddr(request);
    assertEquals(createErrorMessage(expVal, actVal), expVal, actVal);
}

From source file:ubic.gemma.web.listener.StartupListener.java

/**
 * Load the style theme for the site.//from   w  w  w . ja  v  a2s  .c  o m
 *
 * @param context context
 * @param config  config
 */
private void loadTheme(ServletContext context, Map<String, Object> config) {
    if (context.getInitParameter("theme") != null) {
        StartupListener.log.debug("Found theme " + context.getInitParameter("theme"));
        config.put("theme", context.getInitParameter("theme"));
    } else {
        StartupListener.log.warn("No theme found, using default=" + StartupListener.DEFAULT_THEME);
        config.put("theme", StartupListener.DEFAULT_THEME);
    }
}

From source file:com.pliu.powerbiembed.ReportController.java

@RequestMapping(method = { RequestMethod.GET, RequestMethod.POST })
public String getReport(ModelMap model, HttpServletRequest httpRequest) {
    HttpSession session = httpRequest.getSession();
    AuthenticationResult result = (AuthenticationResult) session
            .getAttribute(AuthHelper.PRINCIPAL_SESSION_NAME);
    if (result == null) {
        model.addAttribute("//error", new Exception("AuthenticationResult not found in session."));
        return "/error";
    } else {//  ww  w .  ja  v  a 2  s.c o  m
        try {
            String userid = result.getUserInfo().getDisplayableId();
            // a simple demo of row level security
            String username = "anyone"; //username can't be empty if RLS is enabled on data source
            String roles = "foo"; //empty role means you are authorized to see all data, more secure to default to block all
            if (userid.startsWith("me")) {
                roles = ""; //see everything
            } else if (userid.charAt(0) == 'p') {
                roles = "NWManager";
            } else if (userid.charAt(0) == 'a') {
                username = "adventure-works\\\\pamela0";
                roles = "Sales";
            }
            ServletContext cxt = session.getServletContext();
            String workspaceCollection = cxt.getInitParameter("workspaceCollection");
            String workspaceId = cxt.getInitParameter("workspaceId");
            String accessKey = cxt.getInitParameter("accessKey");
            String resourceId = cxt.getInitParameter("resourceId");
            String reporturl = httpRequest.getParameter("reporturl");
            String accessToken = ComputeJWTToken(workspaceCollection, workspaceId, resourceId, accessKey,
                    reporturl, username, roles);
            model.addAttribute("accessToken", accessToken);
            model.addAttribute("embedUrl", reporturl);
        } catch (Exception e) {
            model.addAttribute("error", e);
            return "/error";
        }
    }
    return "/secure/report";
}

From source file:jp.co.opentone.bsol.linkbinder.view.filter.AbstractFilter.java

private void initLoginParameters(ServletContext context) {
    String redirect = context.getInitParameter(PARAM_REDIRECT_PAGE);
    if (StringUtils.isNotEmpty(redirect)) {
        redirectPage = redirect;/* w w  w  . j  a v a 2  s .co  m*/
    }

    ignorePages = new HashSet<String>();
    String pages = context.getInitParameter(PARAM_IGNORE_PAGES);
    if (StringUtils.isNotEmpty(pages)) {
        for (String page : pages.split("\\s+")) {
            ignorePages.add(page);
        }
    }

    directLoginPages = new HashSet<String>();
    pages = context.getInitParameter(PARAM_DIRECTLOGIN_PAGES);
    if (StringUtils.isNotEmpty(pages)) {
        for (String page : pages.split("\\s+")) {
            directLoginPages.add(page);
        }
    }
}

From source file:org.mule.config.builders.MuleXmlBuilderContextListener.java

public void initialize(ServletContext context) {
    String config = context.getInitParameter(INIT_PARAMETER_MULE_CONFIG);
    if (config == null) {
        config = getDefaultConfigResource();
        if (logger.isDebugEnabled()) {
            logger.debug("No Mule config file(s) specified, using default: " + config);
        }/*www.j  a v  a 2 s. c  o m*/
    } else {
        if (logger.isDebugEnabled()) {
            logger.debug("Mule config file(s): " + config);
        }
    }

    try {
        muleContext = createMuleContext(config, context);
        context.setAttribute(MuleProperties.MULE_CONTEXT_PROPERTY, muleContext);
        muleContext.start();
    } catch (MuleException ex) {
        context.log(ex.getMessage(), ex);
        // Logging is not configured OOTB for Tomcat, so we'd better make a
        // start-up failure plain to see.
        ex.printStackTrace();
    } catch (Error error) {
        // WSAD doesn't always report the java.lang.Error, log it
        context.log(error.getMessage(), error);
        // Logging is not configured OOTB for Tomcat, so we'd better make a
        // start-up failure plain to see.
        error.printStackTrace();
        throw error;
    }
}

From source file:com.liferay.portal.servlet.ImageServlet.java

public void init(ServletConfig sc) throws ServletException {
    synchronized (ImageServlet.class) {
        super.init(sc);

        ServletContext ctx = getServletContext();

        _companyId = ctx.getInitParameter("company_id");
    }/*from  ww  w .j  a v  a 2 s.c om*/
}

From source file:cn.vlabs.umt.ui.UMTStartupListener.java

public void contextInitialized(ServletContextEvent event) {
    ServletContext context = event.getServletContext();
    PropertyConfigurator.configure(context.getRealPath("/WEB-INF/conf/log4j.properties"));
    String contextxml = context.getInitParameter("contextConfigLocation");
    if (contextxml == null) {
        contextxml = "/WEB-INF/conf/UMTContext.xml";
    }/*from www  .  j a  v a2s.c o m*/
    //FIX the bug in linux
    String realpath = context.getRealPath(contextxml);
    if (realpath != null && realpath.startsWith("/")) {
        realpath = "/" + realpath;
    }
    FileSystemXmlApplicationContext factory = new FileSystemXmlApplicationContext(realpath);
    PathMapper mapper = (PathMapper) factory.getBean("PathMapper");
    mapper.setContext(context);

    CreateTable createTable = (CreateTable) factory.getBean("CreateTable");
    if (!createTable.isTableExist()) {
        createTable.createTable();
    }
    factory.getBean("UMTCredUtil");
    context.setAttribute(Attributes.APPLICATION_CONTEXT_KEY, factory);
    UMTContext.setFactory(factory);

}

From source file:com.dp.bigdata.taurus.web.servlet.CreateTaskServlet.java

@Override
public void init(ServletConfig config) throws ServletException {
    super.init(config);
    ServletContext context = getServletContext();
    RESTLET_URL_BASE = context.getInitParameter("RESTLET_SERVER");
    targetUri = RESTLET_URL_BASE + targetUri;
    nameUri = RESTLET_URL_BASE + nameUri;
}

From source file:com.netspective.sparx.template.freemarker.FreeMarkerConfigurationAdapters.java

public void applyWebAppConfiguration(Configuration fmConfig, ServletContext servletContext) {
    String templatePathsText = servletContext
            .getInitParameter("com.netspective.sparx.template.freemarker.template-paths");
    String templatePathsDelim = servletContext
            .getInitParameter("com.netspective.sparx.template.freemarker.template-path-delim");

    List templateLoaders = new ArrayList();
    templateLoaders.add(stringTemplateLoader);
    templateLoaders.add(new WebappTemplateLoader(servletContext));

    try {/*from ww w .  j  a va 2  s .c o  m*/
        if (templatePathsText != null) {
            String[] templatePaths = TextUtils.getInstance().split(templatePathsText,
                    templatePathsDelim == null ? File.pathSeparator : templatePathsDelim, true);
            for (int i = 0; i < templatePaths.length; i++)
                templateLoaders
                        .add(new FileTemplateLoader(new File(servletContext.getRealPath(templatePaths[i]))));
        }
    } catch (Exception e) {
        log.error("Unable to setup file templates loader.", e);
        throw new NestableRuntimeException(e);
    }

    // allow stuff to be loaded from CLASSPATH too (like Console, etc)
    templateLoaders.add(new ClassTemplateLoader(com.netspective.sparx.ProductRelease.class));
    templateLoaders.add(new ClassTemplateLoader(com.netspective.axiom.ProductRelease.class));
    templateLoaders.add(new ClassTemplateLoader(com.netspective.commons.ProductRelease.class));

    fmConfig.setTemplateLoader(new MultiTemplateLoader(
            (TemplateLoader[]) templateLoaders.toArray(new TemplateLoader[templateLoaders.size()])));

    configureSharedVariables(fmConfig);
}

From source file:org.shangridocs.services.omim.OmimResource.java

public OmimResource(@Context ServletContext sc) {
    omimkey = sc.getInitParameter("org.shangridocs.omim.apikey");
    if (omimkey != null) {
        omimkey = PathUtils.replaceEnvVariables(omimkey);
    }/*  w ww.  j  av a  2 s .c  o  m*/
}