Example usage for javax.servlet ServletContext log

List of usage examples for javax.servlet ServletContext log

Introduction

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

Prototype

public void log(String msg);

Source Link

Document

Writes the specified message to a servlet log file, usually an event log.

Usage

From source file:org.cloudfoundry.identity.uaa.config.YamlServletProfileInitializer.java

private void applyLog4jConfiguration(ConfigurableEnvironment environment, ServletContext servletContext) {

    String log4jConfigLocation = "classpath:log4j.properties";

    if (environment.containsProperty("logging.file")) {
        String location = environment.getProperty("logging.file");
        servletContext.log("Setting LOG_FILE: " + location);
        System.setProperty("LOG_FILE", location);
    }/*from   w w w  .ja v  a  2  s  .  c o  m*/

    else if (environment.containsProperty("logging.path")) {
        String location = environment.getProperty("logging.path");
        servletContext.log("Setting LOG_PATH: " + location);
        System.setProperty("LOG_PATH", location);
    }

    else if (environment.containsProperty("logging.config")) {
        log4jConfigLocation = environment.getProperty("logging.config");
    }

    try {
        servletContext.log("Loading log4j config from location: " + log4jConfigLocation);
        Log4jConfigurer.initLogging(log4jConfigLocation);
    } catch (FileNotFoundException e) {
        servletContext.log("Error loading log4j config from location: " + log4jConfigLocation, e);
    }

    MDC.put("context", servletContext.getContextPath());

}

From source file:com.qualogy.qafe.web.ContextLoader.java

/**
 * Initialize QAFE Application context for the given servlet context, according to the "contextClass" and
 * "contextConfigLocation" context-params.
 * //from w w  w  .j  a v a2  s .  com
 * @param servletContext current servlet context
 * @return the new ApplicationContext
 * @throws IllegalStateException if there is already a root application context present
 */
public void init(ServletContext servletContext) throws IllegalStateException {
    if (servletContext == null) {
        throw new IllegalArgumentException("servletContext cannot be null in init method");
    }

    initLogging();

    context = servletContext;
    servletContext.log("Initializing QAFE root ApplicationContext");
    logger.log(Level.INFO, "Root ApplicationContext: initialization started");

    try {
        create(servletContext);
    } catch (Throwable e) {
        handleException(e, servletContext);
    }
}

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

@Override
public void onStartup(final ServletContext servletContext) throws ServletException {
    if (lightAdminConfigurationNotEnabled(servletContext)) {
        servletContext.log("LightAdmin Web Administration Module is disabled by default. Skipping.");
        return;/*from   w w  w  .  j  a  v  a2 s  .  c  o  m*/
    }

    if (notValidBaseUrl(lightAdminBaseUrl(servletContext))) {
        servletContext.log("LightAdmin Web Administration Module's 'baseUrl' property must match "
                + BASE_URL_PATTERN.pattern() + " pattern. Skipping.");
        return;
    }

    if (notValidFileStorageDirectoryDefined(servletContext)) {
        servletContext.log(
                "LightAdmin Web Administration Module's global file storage directory doesn't exist or not a directory.");
        return;
    }

    registerCusomResourceServlet(servletContext);
    registerLogoResourceServlet(servletContext);

    registerLightAdminDispatcher(servletContext);

    if (notRootUrl(lightAdminBaseUrl(servletContext))) {
        registerLightAdminDispatcherRedirector(servletContext);
    }

    registerHiddenHttpMethodFilter(servletContext);

    if (lightAdminSecurityEnabled(servletContext)) {
        registerSpringSecurityFilter(servletContext);
    }

    registerCharsetFilter(servletContext);

    registerTilesDecorationFilter(servletContext);
}

From source file:com.piusvelte.hydra.AuthServlet.java

public void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    ServletContext servletContext = getServletContext();
    ConnectionManager connMgr = ConnectionManager.getInstance(servletContext);
    JSONObject j = new JSONObject();
    String token = request.getParameter("token");
    if ((token != null) && (token.length() > 0)) {
        try {/*from   www.j  a  v  a2  s  .  c  om*/
            connMgr.authorizeToken(token);
        } catch (Exception e) {
            servletContext.log(e.getMessage());
            JSONArray errors = new JSONArray();
            errors.add(e.getMessage());
            j.put("errors", errors);
            response.setStatus(403);
        }
    } else {
        try {
            j.put("result", connMgr.createToken());
        } catch (Exception e) {
            servletContext.log(e.getMessage());
            JSONArray errors = new JSONArray();
            errors.add(e.getMessage());
            j.put("errors", errors);
            response.setStatus(403);
        }
    }
    response.getWriter().write(j.toJSONString());
}

From source file:org.jasig.springframework.web.portlet.context.PortletContextLoader.java

/**
 * Close Spring's web application context for the given portlet context. If
 * the default {@link #loadParentContext(PortletContext)} implementation,
 * which uses ContextSingletonBeanFactoryLocator, has loaded any shared
 * parent context, release one reference to that shared parent context.
 * <p>If overriding {@link #loadParentContext(PortletContext)}, you may have
 * to override this method as well./*from   ww  w .j a  v a  2  s . co m*/
 * @param servletContext the PortletContext that the WebApplicationContext runs in
 */
public void closeWebApplicationContext(ServletContext servletContext) {
    servletContext.log("Closing Spring root PortletApplicationContext");
    try {
        if (this.context instanceof ConfigurablePortletApplicationContext) {
            ((ConfigurablePortletApplicationContext) this.context).close();
        }
    } finally {
        ClassLoader ccl = Thread.currentThread().getContextClassLoader();
        if (ccl == PortletContextLoader.class.getClassLoader()) {
            currentContext = null;
        } else if (ccl != null) {
            currentContextPerThread.remove(ccl);
        }
        servletContext.removeAttribute(PortletApplicationContext.ROOT_PORTLET_APPLICATION_CONTEXT_ATTRIBUTE);
        if (this.parentContextRef != null) {
            this.parentContextRef.release();
        }
    }
}

From source file:org.impalaframework.web.spring.loader.BaseImpalaContextLoader.java

/**
 * Overrides <code>ContextLoader</code> superclass. First, the modules are shut down. 
 * The superclass <code>closeWebApplicationContext</code> is then called.
 * Finally Impala is shut down, in the form of the <code>ModuleManagementFacade.close()</code>
 *//*  www  .  j a va2s. c o  m*/
@Override
public void closeWebApplicationContext(ServletContext servletContext) {

    try {
        // the superclass closes the modules
        ModuleManagementFacade facade = WebServletUtils.getModuleManagementFacade(servletContext);

        if (facade != null) {

            servletContext.log("Closing modules and root application context hierarchy");

            facade.getApplicationManager().close();

            // now close the bootstrap factory
            facade.close();
        }
    } finally {
        super.closeWebApplicationContext(servletContext);
    }
}

From source file:org.squale.jraf.initializer.struts.StrutsInitializer.java

public void init(ActionServlet in_actionServlet, ModuleConfig in_moduleConfig) throws ServletException {

    // initializer
    IInitializable lc_initialize = null;

    // map des parametres
    Map lc_paramMap = null;/*  ww w.  j  a  v  a 2s. com*/

    // context
    ServletContext lc_context = in_actionServlet.getServletContext();
    ServletConfig lc_config = in_actionServlet.getServletConfig();
    // log
    log.info("Debut de l'initialisation de l'application Jraf...");

    // repertoire racine
    String lc_rootPath = lc_context.getRealPath("");

    // Initialisation
    lc_context.log("INIT Ok - Recupration du Bean initializer ... ");
    ApplicationContextFactoryInitializer
            .init(lc_context.getInitParameter(IBootstrapConstants.SPRING_CONTEXT_CONFIG));
    // Rcupration du bean initialize.         
    initializer = (Initializer) ApplicationContextFactoryInitializer.getApplicationContext()
            .getBean("initialize");
    lc_context.log("Provider config file = " + initializer.getConfigFile());
    // classe d'initialisation
    String lc_initClassName = initializer.getClass().getName();

    // fichier de configuration d'un provider
    String lc_providerConfigFile = initializer.getConfigFile();

    // bind jndi
    String lc_isJndi = Boolean.toString(initializer.isJndi());

    try {
        // test des parametres recuperees
        if (lc_rootPath == null || lc_rootPath.equals("") || lc_providerConfigFile == null
                || lc_providerConfigFile.equals("")) {

            // affiche une erreur de configuration
            String lc_error = "Pb de configuration : le chemin du contexte racine est vide ou le fichier de configuration des plugins n'est pas specifie.";
            log.fatal(lc_error);
            throw new JrafConfigException(lc_error);

        } else {
            // les parametres ont bien ete recuperes
            // creation de l'initializer
            lc_initialize = InitializableHelper.instanciateInitializable(lc_initClassName);

            // recuperation/creation des parametres
            lc_paramMap = new HashMap();
            lc_paramMap.put(IBootstrapConstants.ROOT_PATH_KEY, lc_rootPath);

            lc_paramMap.put(IBootstrapConstants.PROVIDER_CONFIG_KEY, lc_providerConfigFile);

            // si le bind jndi est positionne
            if (lc_isJndi != null) {
                lc_paramMap.put(IBootstrapConstants.JNDI_BIND, lc_isJndi);
            }

            // execution de la methode d'initialisation
            IBootstrapProvider lc_bootstrapProvider = (IBootstrapProvider) lc_initialize
                    .initialize(lc_paramMap);

            // log de succes
            log.info("L'application s'est initialisee avec succes");
            log.info("Les providers suivants ont ete initialises:" + lc_bootstrapProvider.getProviders());
        }
    } catch (JrafConfigException e) {
        // log
        log.fatal("Probleme lors de l'intialisation de l'application : ", e);
        throw new ServletException("Probleme lors de l'intialisation de l'application : ", e);
    } catch (RuntimeException e) {
        // log
        log.fatal("Probleme lors de l'intialisation de l'application : ", e);
        throw new ServletException("Probleme lors de l'intialisation de l'application : ", e);
    }
}

From source file:org.springframework.web.context.ContextLoader.java

/**
 * Close Spring's web application context for the given servlet context.
 * <p>If overriding {@link #loadParentContext(ServletContext)}, you may have
 * to override this method as well.//from   ww  w.  j  a  v  a 2  s  .  co  m
 * @param servletContext the ServletContext that the WebApplicationContext runs in
 */
public void closeWebApplicationContext(ServletContext servletContext) {
    servletContext.log("Closing Spring root WebApplicationContext");
    try {
        if (this.context instanceof ConfigurableWebApplicationContext) {
            ((ConfigurableWebApplicationContext) this.context).close();
        }
    } finally {
        ClassLoader ccl = Thread.currentThread().getContextClassLoader();
        if (ccl == ContextLoader.class.getClassLoader()) {
            currentContext = null;
        } else if (ccl != null) {
            currentContextPerThread.remove(ccl);
        }
        servletContext.removeAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE);
    }
}

From source file:com.piusvelte.hydra.ApiServlet.java

public void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    if (request.getParameter(PARAM_TOKEN) == null)
        response.getWriter().write(/* w w  w  . ja va2  s . c  o m*/
                "<!doctype html><html lang=\"en\"><head><meta charset=\"utf-8\"><title>Hydra</title></head><body><h3>Hydra API</h3>");
    else {
        ServletContext ctx = getServletContext();
        HydraRequest hydraRequest;
        try {
            hydraRequest = HydraRequest.fromGet(request);
        } catch (Exception e) {
            ctx.log(e.getMessage());
            JSONObject j = new JSONObject();
            JSONArray errors = new JSONArray();
            errors.add(e.getMessage());
            response.setStatus(402);
            j.put("errors", errors);
            response.getWriter().write(j.toJSONString());
            return;
        }
        ConnectionManager connMgr = ConnectionManager.getInstance(ctx);
        if (connMgr.isAuthenticated(request.getParameter(PARAM_TOKEN))) {
            if (hydraRequest.hasDatabase()) {
                if (hydraRequest.hasTarget()) {
                    DatabaseConnection databaseConnection = null;
                    connMgr.queueDatabaseRequest(hydraRequest.database);
                    try {
                        while (databaseConnection == null)
                            databaseConnection = connMgr.getDatabaseConnection(hydraRequest.database);
                    } catch (Exception e) {
                        ctx.log("Hydra: " + e.getMessage());
                    }
                    connMgr.dequeueDatabaseRequest(hydraRequest.database);
                    if (databaseConnection != null) {
                        response.getWriter().write(databaseConnection
                                .query(hydraRequest.target, hydraRequest.columns, hydraRequest.selection)
                                .toJSONString());
                        databaseConnection.release();
                    } else if (hydraRequest.queueable) {
                        JSONObject j = new JSONObject();
                        JSONArray errors = new JSONArray();
                        errors.add("no database connection");
                        connMgr.queueRequest(hydraRequest.toJSONString());
                        errors.add("queued");
                        response.setStatus(200);
                        j.put("errors", errors);
                        response.getWriter().write(j.toJSONString());
                    } else {
                        response.setStatus(502);
                    }
                    connMgr.cleanDatabaseConnections(hydraRequest.database);
                } else {
                    response.getWriter().write(connMgr.getDatabase(hydraRequest.database).toJSONString());
                }
            } else {
                response.getWriter().write(connMgr.getDatabases().toJSONString());
            }
        } else {
            ctx.log("not authenticated");
            JSONObject j = new JSONObject();
            JSONArray errors = new JSONArray();
            errors.add("not authenticated");
            j.put("errors", errors);
            response.getWriter().write(j.toJSONString());
            response.setStatus(401);
        }
    }
}

From source file:org.amplafi.jawr.maven.JawrMojo.java

private void setupJawrConfig(ServletConfig config, ServletContext context, final Map<String, Object> attributes,
        final Response respData) {
    expect(config.getServletContext()).andReturn(context).anyTimes();
    expect(config.getServletName()).andReturn("maven-jawr-plugin").anyTimes();

    context.log(isA(String.class));
    expectLastCall().anyTimes();/*from w w w .  j  a  va2s  .com*/

    expect(context.getResourcePaths(isA(String.class))).andAnswer(new IAnswer<Set>() {

        public Set<String> answer() throws Throwable {
            final Set<String> set = new HashSet<String>();

            // hack to disallow orphan bundles
            Exception e = new Exception();
            for (StackTraceElement trace : e.getStackTrace()) {
                if (trace.getClassName().endsWith("OrphanResourceBundlesMapper")) {
                    return set;
                }
            }

            String path = (String) EasyMock.getCurrentArguments()[0];
            File file = new File(getRootPath() + path);

            if (file.exists() && file.isDirectory()) {
                for (String one : file.list()) {
                    set.add(path + one);
                }
            }

            return set;
        }

    }).anyTimes();

    expect(context.getResourceAsStream(isA(String.class))).andAnswer(new IAnswer<InputStream>() {

        public InputStream answer() throws Throwable {
            String path = (String) EasyMock.getCurrentArguments()[0];
            File file = new File(getRootPath(), path);
            return new FileInputStream(file);
        }

    }).anyTimes();

    expect(context.getAttribute(isA(String.class))).andAnswer(new IAnswer<Object>() {

        public Object answer() throws Throwable {
            return attributes.get(EasyMock.getCurrentArguments()[0]);
        }

    }).anyTimes();

    context.setAttribute(isA(String.class), isA(Object.class));
    expectLastCall().andAnswer(new IAnswer<Object>() {

        public Object answer() throws Throwable {
            String key = (String) EasyMock.getCurrentArguments()[0];
            Object value = EasyMock.getCurrentArguments()[1];
            attributes.put(key, value);
            return null;
        }

    }).anyTimes();

    expect(config.getInitParameterNames()).andReturn(new Enumeration<String>() {

        public boolean hasMoreElements() {
            return false;
        }

        public String nextElement() {
            return null;
        }

    }).anyTimes();

    expect(config.getInitParameter(JawrConstant.TYPE_INIT_PARAMETER)).andAnswer(new IAnswer<String>() {
        public String answer() throws Throwable {
            return respData == null ? null : respData.getType();
        }
    }).anyTimes();

    expect(config.getInitParameter("configLocation")).andReturn(getConfigLocation()).anyTimes();
    expect(config.getInitParameter("configPropertiesSourceClass")).andReturn(null).anyTimes();
}