• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java WebappClassLoader类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.apache.catalina.loader.WebappClassLoader的典型用法代码示例。如果您正苦于以下问题:Java WebappClassLoader类的具体用法?Java WebappClassLoader怎么用?Java WebappClassLoader使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



WebappClassLoader类属于org.apache.catalina.loader包,在下文中一共展示了WebappClassLoader类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: shallowCopyFieldState

import org.apache.catalina.loader.WebappClassLoader; //导入依赖的package包/类
private static void shallowCopyFieldState(final WebappClassLoader src, final WebappClassLoader dest) {
	Class<?> targetClass = WebappClassLoader.class;
	// Keep backing up the inheritance hierarchy.
	do {
		Field[] fields = targetClass.getDeclaredFields();
		for (Field field : fields) {
			// Do not copy resourceEntries - it's a cache that holds class entries.
			if (!(Modifier.isStatic(field.getModifiers()) || Modifier.isFinal(field.getModifiers()) ||
					field.getName().equals("resourceEntries"))) {
				try {
					field.setAccessible(true);
					Object srcValue = field.get(src);
					field.set(dest, srcValue);
				}
				catch (IllegalAccessException ex) {
					throw new IllegalStateException(
							"Shouldn't be illegal to access field '" + field.getName() + "': " + ex);
				}
			}
		}
		targetClass = targetClass.getSuperclass();
	}
	while (targetClass != null && targetClass != Object.class);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:25,代码来源:TomcatInstrumentableClassLoader.java


示例2: findReloadedContextMemoryLeaks

import org.apache.catalina.loader.WebappClassLoader; //导入依赖的package包/类
/**
 * Attempt to identify the contexts that have a class loader memory leak.
 * This is usually triggered on context reload. Note: This method attempts
 * to force a full garbage collection. This should be used with extreme
 * caution on a production system.
 */
public String[] findReloadedContextMemoryLeaks() {

    System.gc();

    List<String> result = new ArrayList<String>();

    for (Map.Entry<ClassLoader, String> entry :
            childClassLoaders.entrySet()) {
        ClassLoader cl = entry.getKey();
        if (cl instanceof WebappClassLoader) {
            if (!((WebappClassLoader) cl).isStarted()) {
                result.add(entry.getValue());
            }
        }
    }

    return result.toArray(new String[result.size()]);
}
 
开发者ID:deathspeeder,项目名称:class-guard,代码行数:25,代码来源:StandardHost.java


示例3: doGet

import org.apache.catalina.loader.WebappClassLoader; //导入依赖的package包/类
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
        throws ServletException, IOException {
    resp.setContentType("text/plain");
    PrintWriter out = resp.getWriter();

    ClassLoader system = ClassLoader.getSystemClassLoader();

    ClassLoader cl = Thread.currentThread().getContextClassLoader();
    while (cl != null) {
        if (system == cl) {
            out.print("SYSTEM,");
        } else if (custom == cl) {
            out.print("CUSTOM,");
        } else if (cl instanceof WebappClassLoader) {
            out.print("WEBAPP,");
        } else {
            out.print("OTHER,");
        }
        cl = cl.getParent();
    }
}
 
开发者ID:deathspeeder,项目名称:class-guard,代码行数:23,代码来源:TestTomcatClassLoader.java


示例4: findReloadedContextMemoryLeaks

import org.apache.catalina.loader.WebappClassLoader; //导入依赖的package包/类
/**
 * Attempt to identify the contexts that have a class loader memory leak.
 * This is usually triggered on context reload. Note: This method attempts
 * to force a full garbage collection. This should be used with extreme
 * caution on a production system.
 */
public String[] findReloadedContextMemoryLeaks() {
    
    System.gc();
    
    List<String> result = new ArrayList<String>();
    
    for (Map.Entry<ClassLoader, String> entry :
            childClassLoaders.entrySet()) {
        ClassLoader cl = entry.getKey();
        if (cl instanceof WebappClassLoader) {
            if (!((WebappClassLoader) cl).isStarted()) {
                result.add(entry.getValue());
            }
        }
    }
    
    return result.toArray(new String[result.size()]);
}
 
开发者ID:WhiteBearSolutions,项目名称:WBSAirback,代码行数:25,代码来源:StandardHost.java


示例5: doGet

import org.apache.catalina.loader.WebappClassLoader; //导入依赖的package包/类
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
        throws ServletException, IOException {
    resp.setContentType("text/plain");
    PrintWriter out = resp.getWriter();

    ClassLoader system = ClassLoader.getSystemClassLoader();
    
    ClassLoader cl = Thread.currentThread().getContextClassLoader();
    while (cl != null) {
        if (system == cl) {
            out.print("SYSTEM,");
        } else if (custom == cl) {
            out.print("CUSTOM,");
        } else if (cl instanceof WebappClassLoader) {
            out.print("WEBAPP,");
        } else {
            out.print("OTHER,");
        }
        cl = cl.getParent();
    }
}
 
开发者ID:WhiteBearSolutions,项目名称:WBSAirback,代码行数:23,代码来源:TestTomcatClassLoader.java


示例6: retreiveWebAppName

import org.apache.catalina.loader.WebappClassLoader; //导入依赖的package包/类
/**
 *
 * @return the ContextPath
 */
private static String retreiveWebAppName(final String aName) {
	String wWebAppNane = aName;

	ClassLoader wCurrentClassLoader = CWebAppBase.class.getClassLoader();

	boolean wIsWebappClassLoader = (wCurrentClassLoader instanceof WebappClassLoader);
	if (wIsWebappClassLoader) {
		wWebAppNane = ((WebappClassLoader) wCurrentClassLoader).getContextName();
	}
	// keep only alphanumeric chararcters and underscore '_'
	// @see
	// http://stackoverflow.com/questions/1805518/replacing-all-non-alphanumeric-characters-with-empty-strings
	wWebAppNane = wWebAppNane.replaceAll("[^A-Za-z0-9_]", "");

	CComponentLoggerFile.logInMain(Level.INFO, CWebAppBase.class, "retreiveWebAppName",
			"IsWebappClassLoader=[%s] WebAppNane=[%s]", wIsWebappClassLoader, wWebAppNane);

	return wWebAppNane;
}
 
开发者ID:isandlaTech,项目名称:cohorte-utilities,代码行数:24,代码来源:CWebAppBase.java


示例7: getThrowawayClassLoader

import org.apache.catalina.loader.WebappClassLoader; //导入依赖的package包/类
/**
 * Delegate for LoadTimeWeaver's {@code getThrowawayClassLoader} method.
 * Typically called through ReflectiveLoadTimeWeaver.
 * @see org.springframework.instrument.classloading.LoadTimeWeaver#getThrowawayClassLoader
 * @see org.springframework.instrument.classloading.ReflectiveLoadTimeWeaver
 */
public ClassLoader getThrowawayClassLoader() {
	WebappClassLoader tempLoader = new WebappClassLoader();
	// Use reflection to copy all the fields since they are not exposed any other way.
	shallowCopyFieldState(this, tempLoader);
	return tempLoader;
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:13,代码来源:TomcatInstrumentableClassLoader.java


示例8: getThrowawayClassLoader

import org.apache.catalina.loader.WebappClassLoader; //导入依赖的package包/类
/**
 * Delegate for LoadTimeWeaver's {@code getThrowawayClassLoader} method.
 * Typically called through ReflectiveLoadTimeWeaver.
 * @see org.springframework.instrument.classloading.LoadTimeWeaver#getThrowawayClassLoader
 * @see org.springframework.instrument.classloading.ReflectiveLoadTimeWeaver
 */
public ClassLoader getThrowawayClassLoader() {
	WebappClassLoader tempLoader = new WebappClassLoader();
	// Use reflection to copy all the fields since most of them are private on pre-5.5 Tomcat.
	shallowCopyFieldState(this, tempLoader);
	return tempLoader;
}
 
开发者ID:deathspeeder,项目名称:class-guard,代码行数:13,代码来源:TomcatInstrumentableClassLoader.java


示例9: onResourceInit

import org.apache.catalina.loader.WebappClassLoader; //导入依赖的package包/类
@Override
public void onResourceInit(Object... args) {

    ClassLoader cl = Thread.currentThread().getContextClassLoader();

    if (!WebappClassLoader.class.isAssignableFrom(cl.getClass())) {
        return;
    }

    /**
     * for Application Starting's Resource Init
     */
    InterceptSupport iSupport = InterceptSupport.instance();
    InterceptContext context = iSupport.getThreadLocalContext(Event.WEBCONTAINER_RESOURCE_INIT);

    StandardContext sc = (StandardContext) context.get(InterceptConstants.CONTEXTOBJ);

    /**
     * NOTE: spring boot rewrite the tomcat webappclassloader, makes the addURL for nothing, then we can't do
     * anything on this we may use its webappclassloader's parent as the classloader
     */
    context.put(InterceptConstants.WEBAPPLOADER, sc.getLoader().getClassLoader().getParent());

    context.put(InterceptConstants.WEBWORKDIR, sc.getWorkPath());

    String contextPath = (String) ReflectionHelper.getField(StandardContext.class, sc, "encodedPath", true);
    context.put(InterceptConstants.CONTEXTPATH, contextPath);

    context.put(InterceptConstants.APPNAME, ReflectionHelper.getField(StandardContext.class, sc, "displayName", true));

    ServletContext sContext = (ServletContext) ReflectionHelper.getField(StandardContext.class, sc, "context", true);

    context.put(InterceptConstants.SERVLET_CONTEXT, sContext);

    String basePath = sContext.getRealPath("");

    /*
     * NOTE: springboot couldn't get the basePath through method "getRealPath", temporary process
     */
    if (basePath == null) {
        basePath = "";
    }
    else if (basePath.lastIndexOf("/") == (basePath.length() - 1)
            || basePath.lastIndexOf("\\") == (basePath.length() - 1)) {
        basePath = basePath.substring(0, basePath.length() - 1);
    }

    context.put(InterceptConstants.BASEPATH, basePath);

    iSupport.doIntercept(context);
}
 
开发者ID:uavorg,项目名称:uavstack,代码行数:52,代码来源:SpringBootTomcatPlusIT.java


示例10: onResourceCreate

import org.apache.catalina.loader.WebappClassLoader; //导入依赖的package包/类
@Override
public Object onResourceCreate(Object... args) {

    ClassLoader cl = Thread.currentThread().getContextClassLoader();

    if (!WebappClassLoader.class.isAssignableFrom(cl.getClass())) {
        return args[0];
    }

    /**
     * for Application Starting's Resource Create
     */
    InterceptSupport iSupport = InterceptSupport.instance();
    InterceptContext context = iSupport.getThreadLocalContext(Event.WEBCONTAINER_RESOURCE_CREATE);

    StandardContext sc = (StandardContext) context.get(InterceptConstants.CONTEXTOBJ);

    /**
     * NOTE: spring boot rewrite the tomcat webappclassloader, makes the addURL for nothing, then we can't do
     * anything on this we may use its webappclassloader's parent as the classloader
     */
    context.put(InterceptConstants.WEBAPPLOADER, sc.getLoader().getClassLoader().getParent());

    context.put(InterceptConstants.WEBWORKDIR, sc.getWorkPath());

    String contextPath = (String) ReflectionHelper.getField(StandardContext.class, sc, "encodedPath", true);
    context.put(InterceptConstants.CONTEXTPATH, contextPath);

    context.put(InterceptConstants.APPNAME, ReflectionHelper.getField(StandardContext.class, sc, "displayName", true));

    ServletContext sContext = (ServletContext) ReflectionHelper.getField(StandardContext.class, sc, "context", true);

    context.put(InterceptConstants.SERVLET_CONTEXT, sContext);

    String basePath = sContext.getRealPath("");

    /*
     * NOTE: springboot couldn't get the basePath through method "getRealPath", temporary process
     */
    if (basePath == null) {
        basePath = "";
    }
    else if (basePath.lastIndexOf("/") == (basePath.length() - 1)
            || basePath.lastIndexOf("\\") == (basePath.length() - 1)) {
        basePath = basePath.substring(0, basePath.length() - 1);
    }

    context.put(InterceptConstants.BASEPATH, basePath);

    context.put(InterceptConstants.RESOURCEOBJ, args[0]);
    context.put(InterceptConstants.RESOURCECFG, args[1]);

    iSupport.doIntercept(context);

    return context.get(InterceptConstants.RESOURCEOBJ);
}
 
开发者ID:uavorg,项目名称:uavstack,代码行数:57,代码来源:SpringBootTomcatPlusIT.java


示例11: onResourceInit

import org.apache.catalina.loader.WebappClassLoader; //导入依赖的package包/类
/**
 * on Resource Init
 * 
 * @param args
 */
public void onResourceInit(Object... args) {

    ClassLoader cl = Thread.currentThread().getContextClassLoader();

    try {
        /**
         * after tomcat8, tomcat use ParallelWebappClassLoader instead of WebappClassLoader as it's webapp's
         * classloader, both of them are extends WebappClassLoaderBase
         */
        Class<?> cls = cl.loadClass("org.apache.catalina.loader.WebappClassLoaderBase");
        if (!cls.isAssignableFrom(cl.getClass())) {
            return;
        }
    }
    catch (ClassNotFoundException e) {
        /**
         * before tomcat7.0.64(include), WebappClassLoaderBase doesn't exist
         */
        if (!WebappClassLoader.class.isAssignableFrom(cl.getClass())) {
            return;
        }
    }

    /**
     * for Application Starting's Resource Init
     */
    InterceptSupport iSupport = InterceptSupport.instance();
    InterceptContext context = iSupport.getThreadLocalContext(Event.WEBCONTAINER_RESOURCE_INIT);
    if (context == null) {
        return;
    }

    StandardContext sc = (StandardContext) context.get(InterceptConstants.CONTEXTOBJ);

    if (sc == null) {
        return;
    }

    context.put(InterceptConstants.WEBAPPLOADER, sc.getLoader().getClassLoader());

    context.put(InterceptConstants.WEBWORKDIR, sc.getWorkPath());
    context.put(InterceptConstants.CONTEXTPATH,
            ReflectionHelper.getField(StandardContext.class, sc, "encodedPath", true));
    context.put(InterceptConstants.APPNAME, ReflectionHelper.getField(StandardContext.class, sc, "displayName", true));

    ServletContext sContext = (ServletContext) ReflectionHelper.getField(StandardContext.class, sc, "context", true);

    context.put(InterceptConstants.SERVLET_CONTEXT, sContext);

    getBasePath(context, sContext);

    iSupport.doIntercept(context);

    InterceptContext ic = iSupport.getThreadLocalContext(Event.WEBCONTAINER_RESOURCE_INIT);

    ic.put(InterceptConstants.CONTEXTOBJ, sc);
}
 
开发者ID:uavorg,项目名称:uavstack,代码行数:63,代码来源:TomcatPlusIT.java


示例12: onResourceCreate

import org.apache.catalina.loader.WebappClassLoader; //导入依赖的package包/类
/**
 * on Resource Create
 */
public Object onResourceCreate(Object... args) {

    ClassLoader cl = Thread.currentThread().getContextClassLoader();
    try {
        /**
         * after tomcat8, tomcat use ParallelWebappClassLoader instead of WebappClassLoader as it's webapp's
         * classloader, both of them are extends WebappClassLoaderBase
         */
        Class<?> cls = cl.loadClass("org.apache.catalina.loader.WebappClassLoaderBase");
        if (!cls.isAssignableFrom(cl.getClass())) {
            return args[0];
        }
    }
    catch (ClassNotFoundException e) {
        /**
         * before tomcat7.0.64(include), WebappClassLoaderBase doesn't exist
         */
        if (!WebappClassLoader.class.isAssignableFrom(cl.getClass())) {
            return args[0];
        }
    }

    /**
     * for Application Starting's Resource Create
     */
    InterceptSupport iSupport = InterceptSupport.instance();
    InterceptContext context = iSupport.getThreadLocalContext(Event.WEBCONTAINER_RESOURCE_CREATE, false);
    if (context == null) {
        return args[0];
    }

    StandardContext sc = (StandardContext) context.get(InterceptConstants.CONTEXTOBJ);

    if (sc == null) {
        return args[0];
    }

    context.put(InterceptConstants.WEBAPPLOADER, sc.getLoader().getClassLoader());

    context.put(InterceptConstants.WEBWORKDIR, sc.getWorkPath());
    context.put(InterceptConstants.CONTEXTPATH,
            ReflectionHelper.getField(StandardContext.class, sc, "encodedPath", true));
    context.put(InterceptConstants.APPNAME, ReflectionHelper.getField(StandardContext.class, sc, "displayName", true));

    ServletContext sContext = (ServletContext) ReflectionHelper.getField(StandardContext.class, sc, "context", true);

    context.put(InterceptConstants.SERVLET_CONTEXT, sContext);

    getBasePath(context, sContext);

    context.put(InterceptConstants.RESOURCEOBJ, args[0]);
    context.put(InterceptConstants.RESOURCECFG, args[1]);

    iSupport.doIntercept(context);

    InterceptContext ic = iSupport.getThreadLocalContext(Event.WEBCONTAINER_RESOURCE_CREATE);

    ic.put(InterceptConstants.CONTEXTOBJ, sc);

    return context.get(InterceptConstants.RESOURCEOBJ);
}
 
开发者ID:uavorg,项目名称:uavstack,代码行数:65,代码来源:TomcatPlusIT.java


示例13: main

import org.apache.catalina.loader.WebappClassLoader; //导入依赖的package包/类
public static void main(String[] args) {

    //invoke: http://localhost:8080/Modern or  http://localhost:8080/Primitive

    System.setProperty("catalina.base", System.getProperty("user.dir"));
    Connector connector = new HttpConnector();
    Wrapper wrapper1 = new SimpleWrapper();
    wrapper1.setName("Primitive");
    wrapper1.setServletClass("PrimitiveServlet");
    Wrapper wrapper2 = new SimpleWrapper();
    wrapper2.setName("Modern");
    wrapper2.setServletClass("ModernServlet");

    Context context = new StandardContext();
    // StandardContext's start method adds a default mapper
    context.setPath("/myApp");
    context.setDocBase("myApp");

    context.addChild(wrapper1);
    context.addChild(wrapper2);

    // context.addServletMapping(pattern, name);
    context.addServletMapping("/Primitive", "Primitive");
    context.addServletMapping("/Modern", "Modern");
    // add ContextConfig. This listener is important because it configures
    // StandardContext (sets configured to true), otherwise StandardContext
    // won't start
    LifecycleListener listener = new SimpleContextConfig();
    ((Lifecycle) context).addLifecycleListener(listener);

    // here is our loader
    Loader loader = new WebappLoader();
    // associate the loader with the Context
    context.setLoader(loader);

    connector.setContainer(context);

    try {
      connector.initialize();
      ((Lifecycle) connector).start();
      ((Lifecycle) context).start();
      // now we want to know some details about WebappLoader
      WebappClassLoader classLoader = (WebappClassLoader) loader.getClassLoader();
      System.out.println("Resources' docBase: " + ((ProxyDirContext)classLoader.getResources()).getDocBase());
      String[] repositories = classLoader.findRepositories();
      for (int i=0; i<repositories.length; i++) {
        System.out.println("  repository: " + repositories[i]);
      }

      // make the application wait until we press a key.
      System.in.read();
      ((Lifecycle) context).stop();
    }
    catch (Exception e) {
      e.printStackTrace();
    }
  }
 
开发者ID:eclipsky,项目名称:HowTomcatWorks,代码行数:58,代码来源:Bootstrap.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java IContentProposal类代码示例发布时间:2022-05-21
下一篇:
Java ActionFactory类代码示例发布时间:2022-05-21
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap