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.wso2.bps.humantask.sample.manager.LoginManager.java

protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    String userName = null, userPassword = null;
    ServletContext servletContext = this.getServletContext();
    String backendServerURL = servletContext.getInitParameter(HumanTaskSampleConstants.BACKEND_SERVER_URL);

    // set the required system properties
    System.setProperty("javax.net.ssl.trustStore",
            servletContext.getInitParameter(HumanTaskSampleConstants.CLIENT_TRUST_STORE_PATH).trim());
    System.setProperty("javax.net.ssl.trustStorePassword",
            servletContext.getInitParameter(HumanTaskSampleConstants.CLIENT_TRUST_STORE_PASSWORD).trim());
    System.setProperty("javax.net.ssl.trustStoreType",
            servletContext.getInitParameter(HumanTaskSampleConstants.CLIENT_TRUST_STORE_TYPE).trim());
    try {//from   w w  w .j  a v a2  s.  co m
        AuthenticationAdminStub authenticationAdminStub = new AuthenticationAdminStub(
                backendServerURL + HumanTaskSampleConstants.SERVICE_URL
                        + HumanTaskSampleConstants.AUTHENTICATION_ADMIN_SERVICE_URL);
        // handles logout
        String logout = req.getParameter("logout");
        if (logout != null) {
            authenticationAdminStub.logout();
            req.getRequestDispatcher("/Login.jsp").forward(req, resp);
            return;
        }
        if (req.getParameter("userName") != null) {
            userName = req.getParameter("userName").trim();
        }
        if (req.getParameter("userPassword") != null) {
            userPassword = req.getParameter("userPassword").trim();
        }
        // login to server with given user name and password
        if (authenticationAdminStub.login(userName, userPassword, HumanTaskSampleConstants.HOSTNAME)) {
            ServiceContext serviceContext = authenticationAdminStub._getServiceClient()
                    .getLastOperationContext().getServiceContext();
            String sessionCookie = (String) serviceContext.getProperty(HTTPConstants.COOKIE_STRING);
            HttpSession session = req.getSession();
            session.setAttribute(HumanTaskSampleConstants.USERNAME, userName);
            session.setAttribute(HumanTaskSampleConstants.SESSION_COOKIE, sessionCookie);
            req.getRequestDispatcher("/Home.jsp?queryType=assignedToMe&pageNumber=0").forward(req, resp);

        } else {
            log.warn(userName + " login failed.");
            req.setAttribute("message", "Please enter a valid user name and a password.");
            req.getRequestDispatcher("/Login.jsp").forward(req, resp);
        }

    } catch (Exception e) {
        log.error("Failed to retrieve the user session ", e);
        req.setAttribute(HumanTaskSampleConstants.MESSAGE, e);
        req.getRequestDispatcher("/Login.jsp").forward(req, resp);
    }

}

From source file:pl.softech.learning.gwtp.simple.server.spring.RemoteLoggingHandler.java

@Override
public void setServletContext(final ServletContext servletContext) {
    this.servletContext = servletContext;

    final String path = servletContext.getInitParameter("symbolMapsPath");
    if (path != null) {
        URL url = RemoteLoggingHandler.class.getResource("/");
        LOGGER.debug("Current path is {}", url.getFile());
        String rootPath = "/../../";
        URL rootPathUrl = RemoteLoggingHandler.class.getResource(rootPath);
        if (rootPathUrl != null) {
            LOGGER.debug("Root app path is {}", rootPathUrl.getFile());
        }//  w w w.  j  a v  a  2 s  .  c  o m
        URL symbolMapsUrl = RemoteLoggingHandler.class.getResource(String.format("%s%s", rootPath, path));
        if (symbolMapsUrl != null) {
            String symbolMapsDir = symbolMapsUrl.getPath();
            LOGGER.debug("SymbolMaps absolute path is {}", symbolMapsDir);
            deobfuscator = new StackTraceDeobfuscator(symbolMapsDir);
            LOGGER.debug("Created deobfuscator with symbolMaps located {}", path);
        }
    }
}

From source file:it.openutils.mgnlaws.magnolia.AmazonMgnlServletContextListener.java

@Override
public void contextInitialized(ServletContextEvent sce) {
    ServletContext context = sce.getServletContext();
    String appVersion = context.getInitParameter(PARAM_APP_VERSION_KEY);
    if (!appVersion.equals("${project.version}") || StringUtils.endsWith(appVersion, "SNAPSHOT")) {
        String amazonAwsAccessKey = context.getInitParameter(PARAM_AWS_ACCESS_KEY);
        String amazonAwsSecretKey = context.getInitParameter(PARAM_AWS_SECRET_KEY);
        String amazonAwsRegion = context.getInitParameter(PARAM_AWS_REGION);

        System.setProperty("aws.credentials.accessKey", amazonAwsAccessKey);
        System.setProperty("aws.credentials.secretKey", amazonAwsSecretKey);
        System.setProperty("aws.region", amazonAwsRegion);

        if (StringUtils.isNotEmpty(amazonAwsAccessKey) && StringUtils.isNotEmpty(amazonAwsSecretKey)) {
            try {
                String ec2endpoint = "http://ec2." + amazonAwsRegion + ".amazonaws.com";
                initEc2(amazonAwsAccessKey, amazonAwsSecretKey, ec2endpoint);
            } catch (IOException e) {
                log.warn("Error getting instance id", e);
            } catch (AmazonEc2InstanceNotFound e) {
                log.warn("Error getting instance details", e);
            }/*  www .  j a  v  a2s  .  com*/
        } else {
            log.warn("No Amazon credentials found");
        }
    }
    super.contextInitialized(sce);
}

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

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

        ServletContext ctx = getServletContext();

        _companyId = ctx.getInitParameter("company_id");

        if (GetterUtil.getBoolean(PropsUtil.get(PropsUtil.INDEX_ON_STARTUP))) {

            _indexer = new LuceneIndexer(_companyId);

            if (GetterUtil.getBoolean(PropsUtil.get(PropsUtil.INDEX_WITH_THREAD))) {

                _indexerThread = new Thread(_indexer, THREAD_NAME + "." + _companyId);

                _indexerThread.setPriority(THREAD_PRIORITY);
                _indexerThread.start();/*  www. j  a v a2  s. com*/
            } else {
                _indexer.reIndex();
            }
        } else {
            String luceneDir = LuceneUtil.getLuceneDir(_companyId);

            FileUtil.mkdirs(luceneDir);

            IndexWriter writer = null;

            try {
                writer = new IndexWriter(FSDirectory.open(new File(luceneDir)), new WhitespaceAnalyzer(), false,
                        MaxFieldLength.LIMITED);
            } catch (IOException ioe1) {
                try {
                    writer = new IndexWriter(FSDirectory.open(new File(luceneDir)), new WhitespaceAnalyzer(),
                            true, MaxFieldLength.LIMITED);
                } catch (IOException ioe2) {
                    Logger.error(this, ioe2.getMessage(), ioe2);
                }
            }
        }
    }
}

From source file:com.github.persapiens.jsfboot.omnifaces.OmnifacesServletContextInitializerIT.java

public void testOnStartup() throws ServletException {
    OmnifacesServletContextInitializer omnifacesServletContextInitializer = new OmnifacesServletContextInitializer(
            this.omnifacesProperties);

    ServletContext servletContext = new MockServletContext();

    omnifacesServletContextInitializer.onStartup(servletContext);

    assertThat(servletContext.getInitParameter(CacheInitializerListener.CACHE_PROVIDER_INIT_PARAM_NAME))
            .isEqualTo("myCacheProvider");
}

From source file:org.joinfaces.omnifaces.OmnifacesServletContextInitializerIT.java

@Test
public void testOnStartup() throws ServletException {
    OmnifacesServletContextInitializer omnifacesServletContextInitializer = new OmnifacesServletContextInitializer(
            this.omnifacesProperties);

    ServletContext servletContext = new MockServletContext();

    omnifacesServletContextInitializer.onStartup(servletContext);

    assertThat(servletContext.getInitParameter(CacheInitializerListener.CACHE_PROVIDER_INIT_PARAM_NAME))
            .isEqualTo("myCacheProvider");
}

From source file:com.indeed.boxcar.server.servlet.AbstractBoxcarContextListener.java

protected int getIntInitParameter(final ServletContext servletContext, final String initParameterName,
        final int defaultValue) {
    final String initParameterValue = servletContext.getInitParameter(initParameterName);
    if (initParameterValue == null) {
        return defaultValue;
    }/*from   ww w. j  a  v a2s  .c  om*/
    return Integer.parseInt(initParameterValue);
}

From source file:com.vityuk.ginger.servlet.tags.MessageTag.java

private boolean resolveDefaultEscapeHtml(ServletContext servletContext) {
    return Boolean.valueOf(servletContext.getInitParameter(DEFAULT_HTML_ESCAPE_PARAMETER));
}

From source file:model.NotesImageFile.java

/**
 * Use this for the images that aren't yet hashed by name and date. They
 * have yet to be added to the database.
 *///from  w w  w .  jav  a2s . c o  m
public NotesImageFile(String preHashFileName, String contentType) {
    this.fileName = createUniqueFileName(preHashFileName);
    ServletContext context = ServletActionContext.getServletContext();
    String filePath = context.getInitParameter("file-upload");
    this.uniqueFileLocation = filePath + this.fileName;
    this.contentType = contentType;
}

From source file:org.hippoecm.frontend.util.RequestUtilsTest.java

@Test
public void testGetRemoteAddrsWithCustomForwardedForHeader() {
    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  w  w.j  a va 2s .co  m
    Request request = createRequest(servletContext, null, CUSTOM_X_FORWARDED_FOR_HEADER_VALUE);

    String[] expArr = StringUtils.split(CUSTOM_X_FORWARDED_FOR_HEADER_VALUE, ", ");
    String[] actArr = RequestUtils.getRemoteAddrs(request);
    assertArrayEquals(createErrorMessage(expArr, actArr), expArr, actArr);
    String expVal = StringUtils.split(CUSTOM_X_FORWARDED_FOR_HEADER_VALUE, ", ")[0];
    String actVal = RequestUtils.getFarthestRemoteAddr(request);
    assertEquals(createErrorMessage(expVal, actVal), expVal, actVal);
}