项目:tomcat7
文件:Mbeanfactory.java
/**
* Create a new Web Application Loader.
*
* @param parent MBean Name of the associated parent component
*
* @exception Exception if an MBean cannot be created or registered
*/
public String createWebappLoader(String parent)
throws Exception {
// Create a new WebappLoader instance
WebappLoader loader = new WebappLoader();
// Add the new instance to its parent component
ObjectName pname = new ObjectName(parent);
ContainerBase containerBase = getParentContainerFromParent(pname);
if (containerBase != null) {
containerBase.setLoader(loader);
}
// FIXME add Loader.getobjectName
//ObjectName oname = loader.getobjectName();
ObjectName oname =
MBeanUtils.createObjectName(pname.getDomain(),loader);
return (oname.toString());
}
项目:lams
文件:Mbeanfactory.java
/**
* Create a new Web Application Loader.
*
* @param parent MBean Name of the associated parent component
*
* @exception Exception if an MBean cannot be created or registered
*/
public String createWebappLoader(String parent)
throws Exception {
// Create a new WebappLoader instance
WebappLoader loader = new WebappLoader();
// Add the new instance to its parent component
ObjectName pname = new ObjectName(parent);
ContainerBase containerBase = getParentContainerFromParent(pname);
if (containerBase != null) {
containerBase.setLoader(loader);
}
// FIXME add Loader.getobjectName
//ObjectName oname = loader.getobjectName();
ObjectName oname =
MBeanUtils.createObjectName(pname.getDomain(),loader);
return (oname.toString());
}
项目:jerrydog
文件:StandardServer.java
/**
* Is this an instance of the default <code>Loader</code> configuration,* with all-default properties?
*
* @param loader Loader to be tested
*/
private boolean isDefaultLoader(Loader loader) {
if (!(loader instanceof WebappLoader)) {
return (false);
}
WebappLoader wloader = (WebappLoader) loader;
if ((wloader.getCheckInterval() != 15) ||
(wloader.getDebug() != 0) ||
(wloader.getDelegate() != false) ||
!wloader.getLoaderClass().equals
("org.apache.catalina.loader.WebappClassLoader")) {
return (false);
}
return (true);
}
项目:apache-tomcat-7.0.73-with-comment
文件:Mbeanfactory.java
/**
* Create a new Web Application Loader.
*
* @param parent MBean Name of the associated parent component
*
* @exception Exception if an MBean cannot be created or registered
*/
public String createWebappLoader(String parent)
throws Exception {
// Create a new WebappLoader instance
WebappLoader loader = new WebappLoader();
// Add the new instance to its parent component
ObjectName pname = new ObjectName(parent);
ContainerBase containerBase = getParentContainerFromParent(pname);
if (containerBase != null) {
containerBase.setLoader(loader);
}
// FIXME add Loader.getobjectName
//ObjectName oname = loader.getobjectName();
ObjectName oname =
MBeanUtils.createObjectName(pname.getDomain(),loader);
return (oname.toString());
}
项目:lazycat
文件:Mbeanfactory.java
/**
* Create a new Web Application Loader.
*
* @param parent
* MBean Name of the associated parent component
*
* @exception Exception
* if an MBean cannot be created or registered
*/
public String createWebappLoader(String parent) throws Exception {
// Create a new WebappLoader instance
WebappLoader loader = new WebappLoader();
// Add the new instance to its parent component
ObjectName pname = new ObjectName(parent);
ContainerBase containerBase = getParentContainerFromParent(pname);
if (containerBase != null) {
containerBase.setLoader(loader);
}
// FIXME add Loader.getobjectName
// ObjectName oname = loader.getobjectName();
ObjectName oname = MBeanUtils.createObjectName(pname.getDomain(),loader);
return (oname.toString());
}
项目:product-ei
文件:Starter.java
public void startPeopleService() throws Exception {
final File base = createBaseDirectory();
log.info("Using base folder: " + base.getAbsolutePath());
final Tomcat tomcat = new Tomcat();
tomcat.setPort(8080);
tomcat.setBaseDir(base.getAbsolutePath());
Context context = tomcat.addContext("/",base.getAbsolutePath());
Tomcat.addServlet(context,"CXFServlet",new CXFServlet());
context.addServletMapping("/rest/*","CXFServlet");
context.addApplicationListener(ContextLoaderListener.class.getName());
context.setLoader(new WebappLoader(Thread.currentThread().getContextClassLoader()));
context.addParameter("contextClass",AnnotationConfigWebApplicationContext.class.getName());
context.addParameter("contextConfigLocation",AppConfig.class.getName());
tomcat.start();
tomcat.getServer().await();
}
项目:product-ei
文件:Server.java
public static void main(final String[] args) throws Exception {
final File base = createBaseDirectory();
log.info("Using base folder: " + base.getAbsolutePath());
final Tomcat tomcat = new Tomcat();
tomcat.setPort(8080);
tomcat.setBaseDir( base.getAbsolutePath() );
Context context = tomcat.addContext( "/",base.getAbsolutePath() );
Tomcat.addServlet( context,new CXFServlet() );
context.addServletMapping( "/rest/*","CXFServlet" );
context.addApplicationListener( ContextLoaderListener.class.getName() );
context.setLoader( new WebappLoader( Thread.currentThread().getContextClassLoader() ) );
context.addParameter( "contextClass",AnnotationConfigWebApplicationContext.class.getName() );
context.addParameter( "contextConfigLocation",MusicConfig.class.getName() );
tomcat.start();
tomcat.getServer().await();
}
@Before
public void setUp() throws Exception {
this.manager = mock( RedisSessionManager.class );
this.request = mock( Request.class,withSettings().useConstructor() ); // useConstructor to instantiate fields
this.response = mock( Response.class );
final Context contextContainer = mock(Context.class);
this.hostContainer = mock(Host.class);
when(contextContainer.getParent()).thenReturn(hostContainer);
when(contextContainer.getPath()).thenReturn("/");
when(request.getRequestURI()).thenReturn( "/requestURI"); // override for tests
when(request.getmethod()).thenReturn("GET");
when(request.getQueryString()).thenReturn(null);
when(request.getContext()).thenReturn(contextContainer);
doCallRealMethod().when(request).setNote(Mockito.anyString(),Mockito.anyObject());
doCallRealMethod().when(request).removeNote(Mockito.anyString());
when(request.getNote(Mockito.anyString())).thenCallRealMethod();
when(contextContainer.getLoader()).thenReturn(new WebappLoader(Thread.currentThread().getContextClassLoader()));
}
项目:apm-agent
文件:WebappLoaderStartInterceptor.java
@Override
public void after(Object target,Object[] args,Object result,Throwable throwable) {
// target should be an instance of WebappLoader.
if (target instanceof WebappLoader) {
WebappLoader webappLoader = (WebappLoader)target;
try {
String contextKey = extractContextKey(webappLoader);
List<String> loadedJarNames = extractLibJars(webappLoader);
dispatchLibJars(contextKey,loadedJarNames);
} catch (Exception e) {
if (logger.isWarnEnabled()) {
logger.warn(e.getMessage(),e);
}
}
} else {
logger.warn("Webapp loader is not an instance of org.apache.catalina.loader.WebappLoader. Found [{}]",target.getClass().toString());
}
}
项目:apm-agent
文件:WebappLoaderStartInterceptor.java
private String extractContextKey(WebappLoader webappLoader) {
final String defaultContextName = "";
try {
Container container = extractContext(webappLoader);
// WebappLoader's associated Container should be a Context.
if (container instanceof Context) {
Context context = (Context)container;
String contextName = context.getName();
Host host = (Host)container.getParent();
Engine engine = (Engine)host.getParent();
StringBuilder sb = new StringBuilder();
sb.append(engine.getName()).append("/").append(host.getName());
if (!contextName.startsWith("/")) {
sb.append('/');
}
sb.append(contextName);
return sb.toString();
}
} catch (Exception e) {
// Same action for any and all exceptions.
logger.warn("Error extracting context name.",e);
}
return defaultContextName;
}
项目:apm-agent
文件:WebappLoaderStartInterceptor.java
private Container extractContext(WebappLoader webappLoader) throws IllegalArgumentException,illegalaccessexception,InvocationTargetException {
Method m;
try {
// Tomcat 6,7 - org.apache.catalina.loader.getContainer()
m = webappLoader.getClass().getDeclaredMethod("getContainer");
} catch (NoSuchMethodException e1) {
try {
// Tomcat 8 - org.apache.catalina.loader.getContainer()
m = webappLoader.getClass().getDeclaredMethod("getContext");
} catch (NoSuchMethodException e2) {
logger.warn("Webapp loader does not have access to its container.");
return null;
}
}
Object container = m.invoke(webappLoader);
if (container instanceof Container) {
return (Container)container;
}
return null;
}
项目:class-guard
文件:Mbeanfactory.java
/**
* Create a new Web Application Loader.
*
* @param parent MBean Name of the associated parent component
*
* @exception Exception if an MBean cannot be created or registered
*/
public String createWebappLoader(String parent)
throws Exception {
// Create a new WebappLoader instance
WebappLoader loader = new WebappLoader();
// Add the new instance to its parent component
ObjectName pname = new ObjectName(parent);
ContainerBase containerBase = getParentContainerFromParent(pname);
if (containerBase != null) {
containerBase.setLoader(loader);
}
// FIXME add Loader.getobjectName
//ObjectName oname = loader.getobjectName();
ObjectName oname =
MBeanUtils.createObjectName(pname.getDomain(),loader);
return (oname.toString());
}
项目:glowroot
文件:JsfRenderIT.java
@Override
public void executeApp() throws Exception {
int port = getAvailablePort();
Tomcat tomcat = new Tomcat();
tomcat.setBaseDir("target/tomcat");
tomcat.setPort(port);
Context context =
tomcat.addWebapp("",new File("src/test/resources").getAbsolutePath());
WebappLoader webappLoader = new WebappLoader(RenderJsfInTomcat.class.getClassLoader());
context.setLoader(webappLoader);
tomcat.start();
doTest(port);
tomcat.stop();
tomcat.destroy();
}
项目:glowroot
文件:GrailsIT.java
@Override
public void executeApp() throws Exception {
int port = getAvailablePort();
Tomcat tomcat = new Tomcat();
tomcat.setBaseDir("target/tomcat");
tomcat.setPort(port);
Context context =
tomcat.addWebapp("",new File("src/test/resources").getAbsolutePath());
WebappLoader webappLoader = new WebappLoader(RenderInTomcat.class.getClassLoader());
context.setLoader(webappLoader);
// this is needed in order for Tomcat to find annotated classes
VirtualDirContext resources = new VirtualDirContext();
resources.setExtraResourcePaths("/WEB-INF/classes=target/test-classes");
context.setResources(resources);
tomcat.start();
doTest(port);
tomcat.stop();
tomcat.destroy();
}
项目:glowroot
文件:InvokeServletInTomcat.java
@Override
public void executeApp() throws Exception {
int port = getAvailablePort();
Tomcat tomcat = new Tomcat();
tomcat.setBaseDir("target/tomcat");
tomcat.setPort(port);
Context context =
tomcat.addWebapp(contextpath,new File("src/test/resources").getAbsolutePath());
WebappLoader webappLoader =
new WebappLoader(InvokeServletInTomcat.class.getClassLoader());
context.setLoader(webappLoader);
// this is needed in order for Tomcat to find annotated servlet
VirtualDirContext resources = new VirtualDirContext();
resources.setExtraResourcePaths("/WEB-INF/classes=target/test-classes");
context.setResources(resources);
tomcat.start();
doTest(port);
tomcat.stop();
tomcat.destroy();
}
项目:glowroot
文件:StrutsOneIT.java
@Override
public void executeApp() throws Exception {
int port = getAvailablePort();
Tomcat tomcat = new Tomcat();
tomcat.setBaseDir("target/tomcat");
tomcat.setPort(port);
Context context =
tomcat.addWebapp("",new File("src/test/resources/struts1").getAbsolutePath());
WebappLoader webappLoader =
new WebappLoader(ExecuteActionInTomcat.class.getClassLoader());
context.setLoader(webappLoader);
tomcat.start();
AsyncHttpClient asyncHttpClient = new AsyncHttpClient();
int statusCode = asyncHttpClient.prepareGet("http://localhost:" + port + "/hello.do")
.execute().get().getStatusCode();
asyncHttpClient.close();
if (statusCode != 200) {
throw new IllegalStateException("Unexpected status code: " + statusCode);
}
tomcat.stop();
tomcat.destroy();
}
项目:glowroot
文件:InvokeJaxrsResourceInTomcat.java
public void executeApp(String webapp,String contextpath,String url) throws Exception {
int port = getAvailablePort();
Tomcat tomcat = new Tomcat();
tomcat.setBaseDir("target/tomcat");
tomcat.setPort(port);
Context context = tomcat.addWebapp(contextpath,new File("src/test/resources/" + webapp).getAbsolutePath());
WebappLoader webappLoader =
new WebappLoader(InvokeJaxrsResourceInTomcat.class.getClassLoader());
context.setLoader(webappLoader);
tomcat.start();
AsyncHttpClient asyncHttpClient = new AsyncHttpClient();
int statusCode = asyncHttpClient.prepareGet("http://localhost:" + port + contextpath + url)
.execute().get().getStatusCode();
asyncHttpClient.close();
if (statusCode != 200) {
throw new IllegalStateException("Unexpected status code: " + statusCode);
}
tomcat.stop();
tomcat.destroy();
}
项目:glowroot
文件:InvokeJaxwsWebServiceInTomcat.java
public void executeApp(String webapp,new File("src/test/resources/" + webapp).getAbsolutePath());
WebappLoader webappLoader =
new WebappLoader(InvokeJaxwsWebServiceInTomcat.class.getClassLoader());
context.setLoader(webappLoader);
tomcat.start();
JaxWsProxyfactorybean factory = new JaxWsProxyfactorybean();
factory.setServiceClass(ForBothHelloAndRootService.class);
factory.setAddress("http://localhost:" + port + contextpath + url);
ForBothHelloAndRootService client = (ForBothHelloAndRootService) factory.create();
client.echo("abc");
checkForRequestThreads(webappLoader);
tomcat.stop();
tomcat.destroy();
}
项目:glowroot
文件:InvokeJaxwsWebServiceInTomcat.java
private void checkForRequestThreads(WebappLoader webappLoader) throws Exception {
Method getThreadsMethod = WebappClassLoaderBase.class.getDeclaredMethod("getThreads");
getThreadsMethod.setAccessible(true);
Method isRequestThreadMethod =
WebappClassLoaderBase.class.getDeclaredMethod("isRequestThread",Thread.class);
isRequestThreadMethod.setAccessible(true);
ClassLoader webappClassLoader = webappLoader.getClassLoader();
Thread[] threads = (Thread[]) getThreadsMethod.invoke(webappClassLoader);
for (Thread thread : threads) {
if (thread == null) {
continue;
}
if ((boolean) isRequestThreadMethod.invoke(webappClassLoader,thread)) {
StringBuilder sb = new StringBuilder();
for (StackTraceElement element : thread.getStackTrace()) {
sb.append(element);
sb.append('\n');
}
logger.error("tomcat request thread \"{}\" is still active:\n{}",thread.getName(),sb);
}
}
}
项目:glowroot
文件:InvokeSpringControllerInTomcat.java
private void checkForRequestThreads(WebappLoader webappLoader) throws Exception {
Method getThreadsMethod = WebappClassLoaderBase.class.getDeclaredMethod("getThreads");
getThreadsMethod.setAccessible(true);
Method isRequestThreadMethod =
WebappClassLoaderBase.class.getDeclaredMethod("isRequestThread",Thread.class);
isRequestThreadMethod.setAccessible(true);
ClassLoader webappClassLoader = webappLoader.getClassLoader();
Thread[] threads = (Thread[]) getThreadsMethod.invoke(webappClassLoader);
for (Thread thread : threads) {
if (thread == null) {
continue;
}
if ((Boolean) isRequestThreadMethod.invoke(webappClassLoader,sb);
}
}
}
项目:apache-tomcat-7.0.57
文件:Mbeanfactory.java
/**
* Create a new Web Application Loader.
*
* @param parent MBean Name of the associated parent component
*
* @exception Exception if an MBean cannot be created or registered
*/
public String createWebappLoader(String parent)
throws Exception {
// Create a new WebappLoader instance
WebappLoader loader = new WebappLoader();
// Add the new instance to its parent component
ObjectName pname = new ObjectName(parent);
ContainerBase containerBase = getParentContainerFromParent(pname);
if (containerBase != null) {
containerBase.setLoader(loader);
}
// FIXME add Loader.getobjectName
//ObjectName oname = loader.getobjectName();
ObjectName oname =
MBeanUtils.createObjectName(pname.getDomain(),loader);
return (oname.toString());
}
项目:carbon-platform-integration
文件:TomcatServerManager.java
public void startJaxRSServer() throws LifecycleException,IOException {
final File base = createBaseDirectory(basedir);
log.info("Using base folder: " + base.getAbsolutePath());
tomcat = new Tomcat();
tomcat.setPort(tomcatPort);
tomcat.setBaseDir(base.getAbsolutePath());
Context context = tomcat.addContext("/",new CXFServlet());
context.addServletMapping("/rest/*","CXFServlet");
context.addApplicationListener(ContextLoaderListener.class.getName());
context.setLoader(new WebappLoader(Thread.currentThread().getContextClassLoader()));
context.addParameter("contextClass",tomcatClass);
tomcat.start();
tomcat.getServer().await();
}
项目:pinpoint
文件:WebappLoaderStartInterceptor.java
@Override
public void after(Object target,target.getClass().toString());
}
}
项目:pinpoint
文件:WebappLoaderStartInterceptor.java
private String extractContextKey(WebappLoader webappLoader) {
final String defaultContextName = "";
try {
Container container = extractContext(webappLoader);
// WebappLoader's associated Container should be a Context.
if (container instanceof Context) {
Context context = (Context)container;
String contextName = context.getName();
Host host = (Host)container.getParent();
Engine engine = (Engine)host.getParent();
StringBuilder sb = new StringBuilder();
sb.append(engine.getName()).append("/").append(host.getName());
if (!contextName.startsWith("/")) {
sb.append('/');
}
sb.append(contextName);
return sb.toString();
}
} catch (Exception e) {
// Same action for any and all exceptions.
logger.warn("Error extracting context name.",e);
}
return defaultContextName;
}
项目:pinpoint
文件:WebappLoaderStartInterceptor.java
private Container extractContext(WebappLoader webappLoader) throws IllegalArgumentException,7 - org.apache.catalina.loader.getContainer()
m = webappLoader.getClass().getDeclaredMethod("getContainer");
} catch (NoSuchMethodException e1) {
try {
// Tomcat 8 - org.apache.catalina.loader.getContainer()
m = webappLoader.getClass().getDeclaredMethod("getContext");
} catch (NoSuchMethodException e2) {
logger.warn("Webapp loader does not have access to its container.");
return null;
}
}
Object container = m.invoke(webappLoader);
if (container instanceof Container) {
return (Container)container;
}
return null;
}
项目:HowTomcatWorks
文件:StandardServer.java
/**
* Is this an instance of the default <code>Loader</code> configuration,* with all-default properties?
*
* @param loader Loader to be tested
*/
private boolean isDefaultLoader(Loader loader) {
if (!(loader instanceof WebappLoader)) {
return (false);
}
WebappLoader wloader = (WebappLoader) loader;
if ((wloader.getCheckInterval() != 15) ||
(wloader.getDebug() != 0) ||
(wloader.getDelegate() != false) ||
!wloader.getLoaderClass().equals
("org.apache.catalina.loader.WebappClassLoader")) {
return (false);
}
return (true);
}
项目:WBSAirback
文件:Mbeanfactory.java
/**
* Create a new Web Application Loader.
*
* @param parent MBean Name of the associated parent component
*
* @exception Exception if an MBean cannot be created or registered
*/
public String createWebappLoader(String parent)
throws Exception {
// Create a new WebappLoader instance
WebappLoader loader = new WebappLoader();
// Add the new instance to its parent component
ObjectName pname = new ObjectName(parent);
ContainerBase containerBase = getParentContainerFromParent(pname);
if (containerBase != null) {
containerBase.setLoader(loader);
}
// FIXME add Loader.getobjectName
//ObjectName oname = loader.getobjectName();
ObjectName oname =
MBeanUtils.createObjectName(pname.getDomain(),loader);
return (oname.toString());
}
/**
* Create and return a class loader manager that can be customized,and
* then attached to a Context,before it is started.
*
* @param parent ClassLoader that will be the parent of the one
* created by this Loader
*/
public Loader createLoader(ClassLoader parent) {
if( log.isDebugEnabled() )
log.debug("Creating Loader with parent class loader '" +
parent + "'");
WebappLoader loader = new WebappLoader(parent);
return (loader);
}
/**
* Create and return a class loader manager that can be customized,before it is started.
*
* @param parent ClassLoader that will be the parent of the one
* created by this Loader
*/
public Loader createLoader(ClassLoader parent) {
if( log.isDebugEnabled() )
log.debug("Creating Loader with parent class loader '" +
parent + "'");
WebappLoader loader = new WebappLoader(parent);
return (loader);
}
/**
* Create and return a class loader manager that can be customized,before it is started.
*
* @param parent ClassLoader that will be the parent of the one
* created by this Loader
*/
public Loader createLoader(ClassLoader parent) {
if (debug >= 1)
logger.log("Creating Loader with parent class loader '" +
parent + "'");
WebappLoader loader = new WebappLoader(parent);
return (loader);
}
/**
* Create and return a class loader manager that can be customized,before it is started.
*
* @param parent ClassLoader that will be the parent of the one
* created by this Loader
*/
public Loader createLoader(ClassLoader parent) {
if( log.isDebugEnabled() )
log.debug("Creating Loader with parent class loader '" +
parent + "'");
WebappLoader loader = new WebappLoader(parent);
return (loader);
}
@Test
public void test() throws Exception {
StandardContext context = new StandardContext();
context.setName("foo");
WebappLoader loader = new WebappLoader() {
@Override
public ClassLoader getClassLoader() {
return WebappLoader.class.getClassLoader();
}
};
context.setLoader(loader);
StandardHost host = new StandardHost();
StandardEngine engine = new StandardEngine();
engine.setService(new StandardService());
host.setParent(engine);
context.setParent(host);
loader.setContext(context);
RedisSessionManager manager = new RedisSessionManager();
manager.setSessionIdGenerator(new StandardSessionIdGenerator());
manager.setContext(context);
manager.initializeSerializer();
manager.initializeDatabaseConnection();
manager.clear();
StandardSession session = manager.createSession(null);
session.setAttribute("foo","test");
manager.afterRequest();
StandardSession loaded = manager.findSession(session.getId());
Assert.assertEquals(session.getAttribute("foo"),loaded.getAttribute("foo"));
Assert.assertEquals(1,manager.getSize());
Assert.assertArrayEquals(new String[] { session.getId() },manager.keys());
manager.processExpires();
}
protected void prepareContext(Host host,ServletContextinitializer[] initializers) {
File docBase = getValidDocumentRoot();
docBase = (docBase != null ? docBase : createTempDir("tomcat-docbase"));
TomcatEmbeddedContext context = new TomcatEmbeddedContext();
context.setName(getcontextpath());
context.setdisplayName(getdisplayName());
context.setPath(getcontextpath());
context.setDocBase(docBase.getAbsolutePath());
context.addLifecycleListener(new FixContextListener());
context.setParentClassLoader(
this.resourceLoader != null ? this.resourceLoader.getClassLoader()
: ClassUtils.getDefaultClassLoader());
try {
context.setUseRelativeRedirects(false);
}
catch (NoSuchMethodError ex) {
// Tomcat is < 8.0.30. Continue
}
SkipPatternJarScanner.apply(context,this.tldSkip);
WebappLoader loader = new WebappLoader(context.getParentClassLoader());
loader.setLoaderClass(TomcatEmbeddedWebappClassLoader.class.getName());
loader.setDelegate(true);
context.setLoader(loader);
if (isRegisterDefaultServlet()) {
addDefaultServlet(context);
}
if (shouldRegisterJspServlet()) {
addJspServlet(context);
addJasperInitializer(context);
context.addLifecycleListener(new StoreMergedWebXmlListener());
}
ServletContextinitializer[] initializersToUse = mergeInitializers(initializers);
configureContext(context,initializersToUse);
host.addChild(context);
postProcessContext(context);
}
protected void prepareContext(Host host,ServletContextinitializer[] initializers) {
File docBase = getValidDocumentRoot();
docBase = (docBase != null ? docBase : createTempDir("tomcat-docbase"));
TomcatEmbeddedContext context = new TomcatEmbeddedContext();
context.setName(getcontextpath());
context.setdisplayName(getdisplayName());
context.setPath(getcontextpath());
context.setDocBase(docBase.getAbsolutePath());
context.addLifecycleListener(new FixContextListener());
context.setParentClassLoader(
this.resourceLoader != null ? this.resourceLoader.getClassLoader()
: ClassUtils.getDefaultClassLoader());
try {
context.setUseRelativeRedirects(false);
context.setMapperContextRootRedirectEnabled(true);
}
catch (NoSuchMethodError ex) {
// Tomcat is < 8.0.30. Continue
}
SkipPatternJarScanner.apply(context,initializersToUse);
host.addChild(context);
postProcessContext(context);
}
protected void prepareContext(Host host,ServletContextinitializer[] initializers) {
File docBase = getValidDocumentRoot();
docBase = (docBase != null ? docBase : createTempDir("tomcat-docbase"));
TomcatEmbeddedContext context = new TomcatEmbeddedContext();
context.setName(getcontextpath());
context.setdisplayName(getdisplayName());
context.setPath(getcontextpath());
context.setDocBase(docBase.getAbsolutePath());
context.addLifecycleListener(new FixContextListener());
context.setParentClassLoader(
this.resourceLoader != null ? this.resourceLoader.getClassLoader()
: ClassUtils.getDefaultClassLoader());
SkipPatternJarScanner.apply(context,initializersToUse);
host.addChild(context);
postProcessContext(context);
}
项目:apm-agent
文件:WebappLoaderStartInterceptor.java
private List<String> extractLibJars(WebappLoader webappLoader) {
ClassLoader classLoader = webappLoader.getClassLoader();
if (classLoader instanceof urlclassloader) {
urlclassloader webappClassLoader = (urlclassloader)classLoader;
URL[] urls = webappClassLoader.getURLs();
return extractLibJarNamesFromURLs(urls);
} else {
logger.warn("Webapp class loader is not an instance of urlclassloader. Found [{}]",classLoader.getClass().toString());
return Collections.emptyList();
}
}
/**
* Create and return a class loader manager that can be customized,before it is started.
*
* @param parent ClassLoader that will be the parent of the one
* created by this Loader
*/
public Loader createLoader(ClassLoader parent) {
if( log.isDebugEnabled() )
log.debug("Creating Loader with parent class loader '" +
parent + "'");
WebappLoader loader = new WebappLoader(parent);
return (loader);
}
项目:glowroot
文件:StrutsTwoIT.java
@Override
public void executeApp() throws Exception {
int port = getAvailablePort();
Tomcat tomcat = new Tomcat();
tomcat.setBaseDir("target/tomcat");
tomcat.setPort(port);
String subdir;
try {
Class.forName("org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter");
subdir = "struts2.5";
} catch (ClassNotFoundException e) {
subdir = "struts2";
}
Context context = tomcat.addWebapp("",new File("src/test/resources/" + subdir).getAbsolutePath());
WebappLoader webappLoader =
new WebappLoader(ExecuteActionInTomcat.class.getClassLoader());
context.setLoader(webappLoader);
tomcat.start();
AsyncHttpClient asyncHttpClient = new AsyncHttpClient();
int statusCode =
asyncHttpClient.prepareGet("http://localhost:" + port + "/hello.action")
.execute().get().getStatusCode();
asyncHttpClient.close();
if (statusCode != 200) {
throw new IllegalStateException("Unexpected status code: " + statusCode);
}
tomcat.stop();
tomcat.destroy();
}
项目:glowroot
文件:JspRenderIT.java
@Override
public void executeApp() throws Exception {
int port = getAvailablePort();
Tomcat tomcat = new Tomcat();
tomcat.setBaseDir("target/tomcat");
tomcat.setPort(port);
Context context =
tomcat.addContext("",new File("src/test/resources").getAbsolutePath());
WebappLoader webappLoader = new WebappLoader(RenderJspInTomcat.class.getClassLoader());
context.setLoader(webappLoader);
Tomcat.addServlet(context,"hello",new ForwardingServlet());
context.addServletMapping("/hello","hello");
Tomcat.addServlet(context,"jsp",new JspServlet());
context.addServletMapping("*.jsp","jsp");
tomcat.start();
AsyncHttpClient asyncHttpClient = new AsyncHttpClient();
int statusCode = asyncHttpClient.prepareGet("http://localhost:" + port + "/hello")
.execute().get().getStatusCode();
asyncHttpClient.close();
if (statusCode != 200) {
throw new IllegalStateException("Unexpected status code: " + statusCode);
}
tomcat.stop();
tomcat.destroy();
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。