当前位置: 首页>>代码示例>>Java>>正文


Java ServletContext.log方法代码示例

本文整理汇总了Java中javax.servlet.ServletContext.log方法的典型用法代码示例。如果您正苦于以下问题:Java ServletContext.log方法的具体用法?Java ServletContext.log怎么用?Java ServletContext.log使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.servlet.ServletContext的用法示例。


在下文中一共展示了ServletContext.log方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: closeWebApplicationContext

import javax.servlet.ServletContext; //导入方法依赖的package包/类
/**
 * Close Spring's web application context for the given servlet context. If
 * the default {@link #loadParentContext(ServletContext)} implementation,
 * which uses ContextSingletonBeanFactoryLocator, has loaded any shared
 * parent context, release one reference to that shared parent context.
 * <p>If overriding {@link #loadParentContext(ServletContext)}, you may have
 * to override this method as well.
 * @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);
		if (this.parentContextRef != null) {
			this.parentContextRef.release();
		}
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:31,代码来源:ContextLoader.java

示例2: setWebAppRootSystemProperty

import javax.servlet.ServletContext; //导入方法依赖的package包/类
/**
 * Set a system property to the web application root directory.
 * The key of the system property can be defined with the "webAppRootKey"
 * context-param in {@code web.xml}. Default is "webapp.root".
 * <p>Can be used for tools that support substition with {@code System.getProperty}
 * values, like log4j's "${key}" syntax within log file locations.
 * @param servletContext the servlet context of the web application
 * @throws IllegalStateException if the system property is already set,
 * or if the WAR file is not expanded
 * @see #WEB_APP_ROOT_KEY_PARAM
 * @see #DEFAULT_WEB_APP_ROOT_KEY
 * @see WebAppRootListener
 * @see Log4jWebConfigurer
 */
public static void setWebAppRootSystemProperty(ServletContext servletContext) throws IllegalStateException {
	Assert.notNull(servletContext, "ServletContext must not be null");
	String root = servletContext.getRealPath("/");
	if (root == null) {
		throw new IllegalStateException(
			"Cannot set web app root system property when WAR file is not expanded");
	}
	String param = servletContext.getInitParameter(WEB_APP_ROOT_KEY_PARAM);
	String key = (param != null ? param : DEFAULT_WEB_APP_ROOT_KEY);
	String oldValue = System.getProperty(key);
	if (oldValue != null && !StringUtils.pathEquals(oldValue, root)) {
		throw new IllegalStateException(
			"Web app root system property already set to different value: '" +
			key + "' = [" + oldValue + "] instead of [" + root + "] - " +
			"Choose unique values for the 'webAppRootKey' context-param in your web.xml files!");
	}
	System.setProperty(key, root);
	servletContext.log("Set web app root system property: '" + key + "' = [" + root + "]");
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:34,代码来源:WebUtils.java

示例3: init

import javax.servlet.ServletContext; //导入方法依赖的package包/类
public void init(final ServletConfig config) {
    try {
        this.delegate.init(config);

    } catch (final Throwable t) {
        // let the service method know initialization failed.
        this.initSuccess = false;

        /*
         * no matter what went wrong, our role is to capture this error and
         * prevent it from blocking initialization of the servlet. logging
         * overkill so that our deployer will find a record of this problem
         * even if unfamiliar with Commons Logging and properly configuring
         * it.
         */

        final String message = "SafeDispatcherServlet: \n"
            + "The Spring DispatcherServlet we wrap threw on init.\n"
            + "But for our having caught this error, the servlet would not have initialized.";

        // logger it via Commons Logging
        LOGGER.error(message, t);

        // logger it to the ServletContext
        ServletContext context = config.getServletContext();
        context.log(message, t);

        /*
         * record the error so that the application has access to later
         * display a proper error message based on the exception.
         */
        context.setAttribute(CAUGHT_THROWABLE_KEY, t);

    }
}
 
开发者ID:luotuo,项目名称:cas4.0.x-server-wechat,代码行数:36,代码来源:SafeDispatcherServlet.java

示例4: contextInitialized

import javax.servlet.ServletContext; //导入方法依赖的package包/类
public void contextInitialized(final ServletContextEvent sce) {
    try {
        this.delegate.contextInitialized(sce);
    } catch (final Throwable t) {
        /*
         * no matter what went wrong, our role is to capture this error and
         * prevent it from blocking initialization of the context. logging
         * overkill so that our deployer will find a record of this problem
         * even if unfamiliar with Commons Logging and properly configuring
         * it.
         */

        final String message = "SafeContextLoaderListener: \n"
            + "The Spring ContextLoaderListener we wrap threw on contextInitialized.\n"
            + "But for our having caught this error, the web application context would not have initialized.";

        // logger it via Commons Logging
        logger.error(message, t);

        // logger it to the ServletContext
        ServletContext context = sce.getServletContext();
        context.log(message, t);

        /*
         * record the error so that the application has access to later
         * display a proper error message based on the exception.
         */
        context.setAttribute(CAUGHT_THROWABLE_KEY, t);
    }
}
 
开发者ID:luotuo,项目名称:cas4.0.x-server-wechat,代码行数:31,代码来源:SafeContextLoaderListener.java

示例5: contextInitialized

import javax.servlet.ServletContext; //导入方法依赖的package包/类
@Override
public void contextInitialized( ServletContextEvent servletEvent ) {

    ServletContext servletContext = servletEvent.getServletContext();
    servletContext.log("Servlet context initialized event is received. Starting registering configurators");
    try {
        new ClasspathUtils().logProblematicJars();
    } catch (RuntimeException e) {
        log.warn("Error caught while trying to get all JARs in classpath", e);
        // do not rethrow exception as this will stop deployment on incompliant servers like JBoss
    }

    // create the default web service configurator
    String pathToConfigFile = servletContext.getRealPath("/WEB-INF");
    AgentConfigurator defaultConfigurator = new AgentConfigurator(pathToConfigFile);
    TemplateActionsConfigurator templateActionsConfigurator = new TemplateActionsConfigurator(pathToConfigFile);
    List<Configurator> configurators = new ArrayList<Configurator>();
    configurators.add(defaultConfigurator);
    configurators.add(templateActionsConfigurator);

    log.info("Initializing ATS Agent web service, start component registration");

    try {
        MainComponentLoader.getInstance().initialize(configurators);
    } catch (AgentException ae) {
        throw new RuntimeException("Unable to initialize Agent component loader", ae);
    }
}
 
开发者ID:Axway,项目名称:ats-framework,代码行数:29,代码来源:AgentWsContextListener.java

示例6: onStartup

import javax.servlet.ServletContext; //导入方法依赖的package包/类
/**
 * Delegate the {@code ServletContext} to any {@link WebApplicationInitializer}
 * implementations present on the application classpath.
 *
 * <p>Because this class declares @{@code HandlesTypes(WebApplicationInitializer.class)},
 * Servlet 3.0+ containers will automatically scan the classpath for implementations
 * of Spring's {@code WebApplicationInitializer} interface and provide the set of all
 * such types to the {@code webAppInitializerClasses} parameter of this method.
 *
 * <p>If no {@code WebApplicationInitializer} implementations are found on the
 * classpath, this method is effectively a no-op. An INFO-level log message will be
 * issued notifying the user that the {@code ServletContainerInitializer} has indeed
 * been invoked but that no {@code WebApplicationInitializer} implementations were
 * found.
 *
 * <p>Assuming that one or more {@code WebApplicationInitializer} types are detected,
 * they will be instantiated (and <em>sorted</em> if the @{@link
 * org.springframework.core.annotation.Order @Order} annotation is present or
 * the {@link org.springframework.core.Ordered Ordered} interface has been
 * implemented). Then the {@link WebApplicationInitializer#onStartup(ServletContext)}
 * method will be invoked on each instance, delegating the {@code ServletContext} such
 * that each instance may register and configure servlets such as Spring's
 * {@code DispatcherServlet}, listeners such as Spring's {@code ContextLoaderListener},
 * or any other Servlet API componentry such as filters.
 *
 * @param webAppInitializerClasses all implementations of
 * {@link WebApplicationInitializer} found on the application classpath
 * @param servletContext the servlet context to be initialized
 * @see WebApplicationInitializer#onStartup(ServletContext)
 * @see AnnotationAwareOrderComparator
 */
@Override
public void onStartup(Set<Class<?>> webAppInitializerClasses, ServletContext servletContext)
		throws ServletException {

	List<WebApplicationInitializer> initializers = new LinkedList<WebApplicationInitializer>();

	if (webAppInitializerClasses != null) {
		for (Class<?> waiClass : webAppInitializerClasses) {
			// Be defensive: Some servlet containers provide us with invalid classes,
			// no matter what @HandlesTypes says...
			if (!waiClass.isInterface() && !Modifier.isAbstract(waiClass.getModifiers()) &&
					WebApplicationInitializer.class.isAssignableFrom(waiClass)) {
				try {
					initializers.add((WebApplicationInitializer) waiClass.newInstance());
				}
				catch (Throwable ex) {
					throw new ServletException("Failed to instantiate WebApplicationInitializer class", ex);
				}
			}
		}
	}

	if (initializers.isEmpty()) {
		servletContext.log("No Spring WebApplicationInitializer types detected on classpath");
		return;
	}

	AnnotationAwareOrderComparator.sort(initializers);
	servletContext.log("Spring WebApplicationInitializers detected on classpath: " + initializers);

	for (WebApplicationInitializer initializer : initializers) {
		initializer.onStartup(servletContext);
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:66,代码来源:SpringServletContainerInitializer.java

示例7: shutdownLogging

import javax.servlet.ServletContext; //导入方法依赖的package包/类
/**
 * Shut down log4j, properly releasing all file locks
 * and resetting the web app root system property.
 * @param servletContext the current ServletContext
 * @see WebUtils#removeWebAppRootSystemProperty
 */
public static void shutdownLogging(ServletContext servletContext) {
	servletContext.log("Shutting down log4j");
	try {
		Log4jConfigurer.shutdownLogging();
	}
	finally {
		// Remove the web app root system property.
		if (exposeWebAppRoot(servletContext)) {
			WebUtils.removeWebAppRootSystemProperty(servletContext);
		}
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:19,代码来源:Log4jWebConfigurer.java

示例8: testGetLogs

import javax.servlet.ServletContext; //导入方法依赖的package包/类
/**
 * Verify that calls to <code>ServletContext.log()</code> methods can
 * be retrieved and asserted.
 */
public void testGetLogs()
{
    String message = "some test log";
    ServletContext context = config.getServletContext();

    context.log(message);

    Vector logs = ((ServletContextWrapper) context).getLogs();
    assertEquals("Found more than one log message", logs.size(), 1);
    assertTrue("Cannot find expected log message : [" + message + "]",
        logs.contains("some test log"));
}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:17,代码来源:TestServletTestCase2.java

示例9: initWebApplicationContext

import javax.servlet.ServletContext; //导入方法依赖的package包/类
/**
 * Initialize Spring's web application context for the given servlet context,
 * using the application context provided at construction time, or creating a new one
 * according to the "{@link #CONTEXT_CLASS_PARAM contextClass}" and
 * "{@link #CONFIG_LOCATION_PARAM contextConfigLocation}" context-params.
 * @param servletContext current servlet context
 * @return the new WebApplicationContext
 * @see #ContextLoader(WebApplicationContext)
 * @see #CONTEXT_CLASS_PARAM
 * @see #CONFIG_LOCATION_PARAM
 */
public WebApplicationContext initWebApplicationContext(ServletContext servletContext) {
	if (servletContext.getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE) != null) {
		throw new IllegalStateException(
				"Cannot initialize context because there is already a root application context present - " +
				"check whether you have multiple ContextLoader* definitions in your web.xml!");
	}

	Log logger = LogFactory.getLog(ContextLoader.class);
	servletContext.log("Initializing Spring root WebApplicationContext");
	if (logger.isInfoEnabled()) {
		logger.info("Root WebApplicationContext: initialization started");
	}
	long startTime = System.currentTimeMillis();

	try {
		// Store context in local instance variable, to guarantee that
		// it is available on ServletContext shutdown.
		if (this.context == null) {
			this.context = createWebApplicationContext(servletContext);
		}
		if (this.context instanceof ConfigurableWebApplicationContext) {
			ConfigurableWebApplicationContext cwac = (ConfigurableWebApplicationContext) this.context;
			if (!cwac.isActive()) {
				// The context has not yet been refreshed -> provide services such as
				// setting the parent context, setting the application context id, etc
				if (cwac.getParent() == null) {
					// The context instance was injected without an explicit parent ->
					// determine parent for root web application context, if any.
					ApplicationContext parent = loadParentContext(servletContext);
					cwac.setParent(parent);
				}
				configureAndRefreshWebApplicationContext(cwac, servletContext);
			}
		}
		servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, this.context);

		ClassLoader ccl = Thread.currentThread().getContextClassLoader();
		if (ccl == ContextLoader.class.getClassLoader()) {
			currentContext = this.context;
		}
		else if (ccl != null) {
			currentContextPerThread.put(ccl, this.context);
		}

		if (logger.isDebugEnabled()) {
			logger.debug("Published root WebApplicationContext as ServletContext attribute with name [" +
					WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE + "]");
		}
		if (logger.isInfoEnabled()) {
			long elapsedTime = System.currentTimeMillis() - startTime;
			logger.info("Root WebApplicationContext: initialization completed in " + elapsedTime + " ms");
		}

		return this.context;
	}
	catch (RuntimeException ex) {
		logger.error("Context initialization failed", ex);
		servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, ex);
		throw ex;
	}
	catch (Error err) {
		logger.error("Context initialization failed", err);
		servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, err);
		throw err;
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:78,代码来源:ContextLoader.java


注:本文中的javax.servlet.ServletContext.log方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。