本文整理汇总了Java中org.apache.catalina.core.StandardHost类的典型用法代码示例。如果您正苦于以下问题:Java StandardHost类的具体用法?Java StandardHost怎么用?Java StandardHost使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
StandardHost类属于org.apache.catalina.core包,在下文中一共展示了StandardHost类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: doTestUnpackWAR
import org.apache.catalina.core.StandardHost; //导入依赖的package包/类
private void doTestUnpackWAR(boolean unpackWARs, boolean unpackWAR,
boolean external, boolean resultDir) throws Exception {
Tomcat tomcat = getTomcatInstance();
StandardHost host = (StandardHost) tomcat.getHost();
host.setUnpackWARs(unpackWARs);
tomcat.start();
File war;
if (unpackWAR) {
war = createWar(WAR_XML_UNPACKWAR_TRUE_SOURCE, !external);
} else {
war = createWar(WAR_XML_UNPACKWAR_FALSE_SOURCE, !external);
}
if (external) {
createXmlInConfigBaseForExternal(war);
}
host.backgroundProcess();
File dir = new File(host.getAppBase(), APP_NAME.getBaseName());
Assert.assertEquals(
Boolean.valueOf(resultDir), Boolean.valueOf(dir.isDirectory()));
}
示例2: mbeansAvailableAfterBinder
import org.apache.catalina.core.StandardHost; //导入依赖的package包/类
@Test
void mbeansAvailableAfterBinder() throws LifecycleException, InterruptedException {
TomcatMetrics.monitor(registry, null);
CountDownLatch latch = new CountDownLatch(1);
registry.config().onMeterAdded(m -> {
if(m.getId().getName().equals("tomcat.global.received"))
latch.countDown();
});
Tomcat server = new Tomcat();
try {
StandardHost host = new StandardHost();
host.setName("localhost");
server.setHost(host);
server.setPort(61000);
server.start();
assertThat(latch.await(10, TimeUnit.SECONDS)).isTrue();
assertThat(registry.find("tomcat.global.received").functionCounter()).isNotNull();
} finally {
server.stop();
server.destroy();
}
}
示例3: mbeansAvailableBeforeBinder
import org.apache.catalina.core.StandardHost; //导入依赖的package包/类
@Test
void mbeansAvailableBeforeBinder() throws LifecycleException {
Tomcat server = new Tomcat();
try {
StandardHost host = new StandardHost();
host.setName("localhost");
server.setHost(host);
server.setPort(61000);
server.start();
TomcatMetrics.monitor(registry, null);
assertThat(registry.find("tomcat.global.received").functionCounter()).isNotNull();
} finally {
server.stop();
server.destroy();
}
}
示例4: testBug57425
import org.apache.catalina.core.StandardHost; //导入依赖的package包/类
@Test
public void testBug57425() throws LifecycleException, IOException {
Tomcat tomcat = getTomcatInstance();
Host host = tomcat.getHost();
if (host instanceof StandardHost) {
((StandardHost) host).setContextClass(ReplicatedContext.class.getName());
}
File root = new File("test/webapp-3.0");
Context context = tomcat.addWebapp(host, "", root.getAbsolutePath());
Tomcat.addServlet(context, "test", new AccessContextServlet());
context.addServletMapping("/access", "test");
tomcat.start();
ByteChunk result = getUrl("http://localhost:" + getPort() + "/access");
Assert.assertEquals("OK", result.toString());
}
示例5: testGetBrokenContextPerAddWepapp
import org.apache.catalina.core.StandardHost; //导入依赖的package包/类
@Test
public void testGetBrokenContextPerAddWepapp() {
Tomcat tomcat = getTomcatInstance();
Host host = tomcat.getHost();
if (host instanceof StandardHost) {
((StandardHost) host).setContextClass("InvalidContextClassName");
}
try {
File appFile = new File("test/deployment/context.war");
tomcat.addWebapp(null, "/test", appFile.getAbsolutePath());
fail();
} catch (IllegalArgumentException e) {
// OK
}
}
示例6: testGetCustomContextPerAddWebappWithNullHost
import org.apache.catalina.core.StandardHost; //导入依赖的package包/类
@Test
public void testGetCustomContextPerAddWebappWithNullHost() {
Tomcat tomcat = getTomcatInstance();
Host host = tomcat.getHost();
if (host instanceof StandardHost) {
((StandardHost) host).setContextClass(ReplicatedContext.class
.getName());
}
File appFile = new File("test/deployment/context.war");
Context context = tomcat.addWebapp(null, "/test",
appFile.getAbsolutePath());
assertEquals(ReplicatedContext.class.getName(), context.getClass()
.getName());
}
示例7: testGetCustomContextPerAddWebappWithHost
import org.apache.catalina.core.StandardHost; //导入依赖的package包/类
@Test
public void testGetCustomContextPerAddWebappWithHost() {
Tomcat tomcat = getTomcatInstance();
Host host = tomcat.getHost();
if (host instanceof StandardHost) {
((StandardHost) host).setContextClass(ReplicatedContext.class
.getName());
}
File appFile = new File("test/deployment/context.war");
Context context = tomcat.addWebapp(host, "/test",
appFile.getAbsolutePath());
assertEquals(ReplicatedContext.class.getName(), context.getClass()
.getName());
}
示例8: testGetBrokenContextPerAddContext
import org.apache.catalina.core.StandardHost; //导入依赖的package包/类
@Test
public void testGetBrokenContextPerAddContext() {
Tomcat tomcat = getTomcatInstance();
Host host = tomcat.getHost();
if (host instanceof StandardHost) {
((StandardHost) host).setContextClass("InvalidContextClassName");
}
// No file system docBase required
try {
tomcat.addContext(null, "", null);
fail();
} catch (IllegalArgumentException e) {
// OK
}
}
示例9: testBrokenAppWithAntiLocking
import org.apache.catalina.core.StandardHost; //导入依赖的package包/类
private void testBrokenAppWithAntiLocking(boolean unpackWARs)
throws Exception {
Tomcat tomcat = getTomcatInstance();
StandardHost host = (StandardHost) tomcat.getHost();
host.setUnpackWARs(unpackWARs);
File war = createWar(WAR_BROKEN_SOURCE, false);
createXmlInConfigBaseForExternal(war, true);
File dir = new File(getAppBaseFile(host), APP_NAME.getBaseName());
tomcat.start();
// Simulate deploy on start-up
tomcat.getHost().backgroundProcess();
Assert.assertTrue(war.isFile());
if (unpackWARs) {
Assert.assertTrue(dir.isDirectory());
}
}
示例10: testSetContextClassName
import org.apache.catalina.core.StandardHost; //导入依赖的package包/类
@Test
public void testSetContextClassName() throws Exception {
Tomcat tomcat = getTomcatInstance();
Host host = tomcat.getHost();
if (host instanceof StandardHost) {
StandardHost standardHost = (StandardHost) host;
standardHost.setContextClass(TesterContext.class.getName());
}
// Copy the WAR file
File war = new File(getAppBaseFile(host),
APP_NAME.getBaseName() + ".war");
copy(WAR_XML_SOURCE, war);
// Deploy the copied war
tomcat.start();
host.backgroundProcess();
// Check the Context class
Context ctxt = (Context) host.findChild(APP_NAME.getName());
Assert.assertTrue(ctxt instanceof TesterContext);
}
示例11: addWebapp
import org.apache.catalina.core.StandardHost; //导入依赖的package包/类
public StandardContext addWebapp(StandardHost host,
String url, String path)
throws ServletException {
silence(url);
StandardContext ctx = new StandardContext();
ctx.setPath( url );
ctx.setDocBase(path);
if (defaultRealm == null) {
initSimpleAuth();
}
ctx.setRealm(defaultRealm);
initWebappDefaults(ctx);
ContextConfig ctxCfg = new ContextConfig();
ctx.addLifecycleListener( ctxCfg );
// prevent it from looking ( if it finds one - it'll have dup error )
ctxCfg.setDefaultWebXml("org/apache/catalin/startup/NO_DEFAULT_XML");
if (host == null) {
host = getHost();
}
host.addChild(ctx);
return ctx;
}
示例12: getValves
import org.apache.catalina.core.StandardHost; //导入依赖的package包/类
/**
* Return the MBean Names of the Valves assoicated with this Host
*
* @exception Exception if an MBean cannot be created or registered
*/
public String [] getValves()
throws Exception {
Registry registry = MBeanUtils.createRegistry();
StandardHost host = (StandardHost) this.resource;
String mname = MBeanUtils.createManagedName(host);
ManagedBean managed = registry.findManagedBean(mname);
String domain = null;
if (managed != null) {
domain = managed.getDomain();
}
if (domain == null)
domain = mserver.getDefaultDomain();
Valve [] valves = host.getValves();
String [] mbeanNames = new String[valves.length];
for (int i = 0; i < valves.length; i++) {
mbeanNames[i] =
MBeanUtils.createObjectName(domain, valves[i]).toString();
}
return mbeanNames;
}
示例13: removeHost
import org.apache.catalina.core.StandardHost; //导入依赖的package包/类
/**
* Remove an existing Host.
*
* @param name MBean Name of the comonent to remove
*
* @exception Exception if a component cannot be removed
*/
public void removeHost(String name) throws Exception {
// Acquire a reference to the component to be removed
ObjectName oname = new ObjectName(name);
String hostName = oname.getKeyProperty("host");
Service service = getService(oname);
Engine engine = (Engine) service.getContainer();
Host host = (Host) engine.findChild(hostName);
// Remove this component from its parent component
if(host!=null) {
if(host instanceof StandardHost)
((StandardHost)host).destroy();
else
engine.removeChild(host);
}
}
示例14: findleaks
import org.apache.catalina.core.StandardHost; //导入依赖的package包/类
/**
* Find potential memory leaks caused by web application reload.
*/
protected void findleaks(boolean statusLine, PrintWriter writer, StringManager smClient) {
if (!(host instanceof StandardHost)) {
writer.println(smClient.getString("managerServlet.findleaksFail"));
return;
}
String[] results = ((StandardHost) host).findReloadedContextMemoryLeaks();
if (results.length > 0) {
if (statusLine) {
writer.println(smClient.getString("managerServlet.findleaksList"));
}
for (String result : results) {
if ("".equals(result)) {
result = "/";
}
writer.println(result);
}
} else if (statusLine) {
writer.println(smClient.getString("managerServlet.findleaksNone"));
}
}
示例15: getPort
import org.apache.catalina.core.StandardHost; //导入依赖的package包/类
public static int getPort(Host h) {
int port = -1;
StandardHost host = (StandardHost) h;
CatalinaUtil.host = (StandardHost) h;
StandardEngine se = (StandardEngine) host.getParent();
StandardService ss = (StandardService) se.getService();
Connector[] cs = ss.findConnectors();
for (Connector c : cs) {
if (c.getProtocolHandlerClassName().contains("Http11Protocol"))
port = c.getPort();
}
return port;
}