Java Code Examples for org.apache.catalina.core.StandardHost#setUnpackWARs()

The following examples show how to use org.apache.catalina.core.StandardHost#setUnpackWARs() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestHostConfigAutomaticDeployment.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
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()));
}
 
Example 2
Source File: TestHostConfigAutomaticDeployment.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
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(host.getAppBaseFile(), APP_NAME.getBaseName());

    tomcat.start();

    // Simulate deploy on start-up
    tomcat.getHost().backgroundProcess();

    Assert.assertTrue(war.isFile());
    if (unpackWARs) {
        Assert.assertTrue(dir.isDirectory());
    }
}
 
Example 3
Source File: TestHostConfigAutomaticDeployment.java    From Tomcat7.0.67 with Apache License 2.0 6 votes vote down vote up
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()));
}
 
Example 4
Source File: TestHostConfigAutomaticDeployment.java    From Tomcat7.0.67 with Apache License 2.0 6 votes vote down vote up
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());
    }
}
 
Example 5
Source File: TestHostConfigAutomaticDeployment.java    From tomcatsrc with Apache License 2.0 6 votes vote down vote up
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()));
}
 
Example 6
Source File: TestHostConfigAutomaticDeployment.java    From tomcatsrc with Apache License 2.0 6 votes vote down vote up
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());
    }
}
 
Example 7
Source File: HostUtil.java    From carbon-commons with Apache License 2.0 6 votes vote down vote up
/**
 * add host to engine.
 * 
 * @param hostName
 *            name of the host
 * @return will return the added host of Engine
 */
public static Host addHostToEngine(String hostName) {
	String hostBaseDir = CarbonUtils.getCarbonRepository() + "/"
			+ UrlMapperConstants.HostProperties.WEB_APPS + "/";
	CarbonTomcatService carbonTomcatService = DataHolder.getInstance().getCarbonTomcatService();
	// adding virtual host to tomcat engine
	Engine engine = carbonTomcatService.getTomcat().getEngine();
	StandardHost host = new StandardHost();
	host.setAppBase(hostBaseDir);
	host.setName(hostName);
	host.setUnpackWARs(false);
	host.addValve(new CarbonContextCreatorValve());
	host.addValve(new CompositeValve());
	engine.addChild(host);
	log.info("host added to the tomcat: " + host);
	return host;
}
 
Example 8
Source File: MBeanFactory.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
/**
 * Create a new StandardHost.
 *
 * @param parent MBean Name of the associated parent component
 * @param name Unique name of this Host
 * @param appBase Application base directory name
 * @param autoDeploy Should we auto deploy?
 * @param deployOnStartup Deploy on server startup?
 * @param deployXML Should we deploy Context XML config files property?
 * @param unpackWARs Should we unpack WARs when auto deploying?
 * @return the object name of the created host
 *
 * @exception Exception if an MBean cannot be created or registered
 */
public String createStandardHost(String parent, String name,
                                 String appBase,
                                 boolean autoDeploy,
                                 boolean deployOnStartup,
                                 boolean deployXML,
                                 boolean unpackWARs)
    throws Exception {

    // Create a new StandardHost instance
    StandardHost host = new StandardHost();
    host.setName(name);
    host.setAppBase(appBase);
    host.setAutoDeploy(autoDeploy);
    host.setDeployOnStartup(deployOnStartup);
    host.setDeployXML(deployXML);
    host.setUnpackWARs(unpackWARs);

    // add HostConfig for active reloading
    HostConfig hostConfig = new HostConfig();
    host.addLifecycleListener(hostConfig);

    // Add the new instance to its parent component
    ObjectName pname = new ObjectName(parent);
    Service service = getService(pname);
    Engine engine = service.getContainer();
    engine.addChild(host);

    // Return the corresponding MBean name
    return host.getObjectName().toString();

}
 
Example 9
Source File: MBeanFactory.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
/**
 * Create a new StandardHost.
 *
 * @param parent MBean Name of the associated parent component
 * @param name Unique name of this Host
 * @param appBase Application base directory name
 * @param autoDeploy Should we auto deploy?
 * @param deployOnStartup Deploy on server startup?
 * @param deployXML Should we deploy Context XML config files property?
 * @param unpackWARs Should we unpack WARs when auto deploying?
 *
 * @exception Exception if an MBean cannot be created or registered
 */
public String createStandardHost(String parent, String name,
                                 String appBase,
                                 boolean autoDeploy,
                                 boolean deployOnStartup,
                                 boolean deployXML,                                       
                                 boolean unpackWARs)
    throws Exception {

    // Create a new StandardHost instance
    StandardHost host = new StandardHost();
    host.setName(name);
    host.setAppBase(appBase);
    host.setAutoDeploy(autoDeploy);
    host.setDeployOnStartup(deployOnStartup);
    host.setDeployXML(deployXML);
    host.setUnpackWARs(unpackWARs);

    // add HostConfig for active reloading
    HostConfig hostConfig = new HostConfig();
    host.addLifecycleListener(hostConfig);

    // Add the new instance to its parent component
    ObjectName pname = new ObjectName(parent);
    Service service = getService(pname);
    Engine engine = (Engine) service.getContainer();
    engine.addChild(host);

    // Return the corresponding MBean name
    return (host.getObjectName().toString());

}
 
Example 10
Source File: MBeanFactory.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
/**
 * Create a new StandardHost.
 *
 * @param parent MBean Name of the associated parent component
 * @param name Unique name of this Host
 * @param appBase Application base directory name
 * @param autoDeploy Should we auto deploy?
 * @param deployOnStartup Deploy on server startup?
 * @param deployXML Should we deploy Context XML config files property?
 * @param unpackWARs Should we unpack WARs when auto deploying?
 *
 * @exception Exception if an MBean cannot be created or registered
 */
public String createStandardHost(String parent, String name,
                                 String appBase,
                                 boolean autoDeploy,
                                 boolean deployOnStartup,
                                 boolean deployXML,                                       
                                 boolean unpackWARs)
    throws Exception {

    // Create a new StandardHost instance
    StandardHost host = new StandardHost();
    host.setName(name);
    host.setAppBase(appBase);
    host.setAutoDeploy(autoDeploy);
    host.setDeployOnStartup(deployOnStartup);
    host.setDeployXML(deployXML);
    host.setUnpackWARs(unpackWARs);

    // add HostConfig for active reloading
    HostConfig hostConfig = new HostConfig();
    host.addLifecycleListener(hostConfig);

    // Add the new instance to its parent component
    ObjectName pname = new ObjectName(parent);
    Service service = getService(pname);
    Engine engine = (Engine) service.getContainer();
    engine.addChild(host);

    // Return the corresponding MBean name
    return (host.getObjectName().toString());

}
 
Example 11
Source File: VirtualHostClusterUtil.java    From carbon-commons with Apache License 2.0 5 votes vote down vote up
public static Host addHostToEngine(String hostName) {
    String hostBaseDir = CarbonUtils.getCarbonRepository() + "/webapps/";
    CarbonTomcatService carbonTomcatService = DataHolder.getInstance().getCarbonTomcatService();
    // adding virtual host to tomcat engine
    Engine engine = carbonTomcatService.getTomcat().getEngine();
    StandardHost host = new StandardHost();
    host.setAppBase(hostBaseDir);
    host.setName(hostName);
    host.setUnpackWARs(false);
    host.addValve(new CarbonContextCreatorValve());
    host.addValve(new CompositeValve());
    engine.addChild(host);
    log.info("host added to the tomcat: " + host);
    return host;
}
 
Example 12
Source File: TestHostConfigAutomaticDeployment.java    From Tomcat8-Source-Read with MIT License 4 votes vote down vote up
private void doTestDeployment(boolean deployXML, boolean copyXML,
        boolean unpackWARs, LifecycleState resultState, String cookieName,
        boolean resultXml, boolean resultWar, boolean resultDir)
        throws Exception {

    Tomcat tomcat = getTomcatInstance();

    // Start the instance
    tomcat.start();

    // Set the attributes
    StandardHost host = (StandardHost) tomcat.getHost();
    host.setDeployXML(deployXML);
    host.setCopyXML(copyXML);
    host.setUnpackWARs(unpackWARs);

    // Trigger automatic deployment
    host.backgroundProcess();

    // Test the results
    Context ctxt = (Context) tomcat.getHost().findChild(APP_NAME.getPath());
    if (resultState == null) {
        Assert.assertNull(ctxt);
    } else {
        Assert.assertNotNull(ctxt);
        Assert.assertEquals(resultState, ctxt.getState());
        Assert.assertEquals(cookieName, ctxt.getSessionCookieName());
    }

    File xml = new File(
            host.getConfigBaseFile(), APP_NAME.getBaseName() + ".xml");
    Assert.assertEquals(
            Boolean.valueOf(resultXml), Boolean.valueOf(xml.isFile()));

    File war = new File(
            host.getAppBaseFile(), APP_NAME.getBaseName() + ".war");
    Assert.assertEquals(
            Boolean.valueOf(resultWar), Boolean.valueOf(war.isFile()));

    File dir = new File(host.getAppBase(), APP_NAME.getBaseName());
    Assert.assertEquals(
            Boolean.valueOf(resultDir), Boolean.valueOf(dir.isDirectory()));
}
 
Example 13
Source File: TestHostConfigAutomaticDeployment.java    From Tomcat7.0.67 with Apache License 2.0 4 votes vote down vote up
private void doTestDeployment(boolean deployXML, boolean copyXML,
        boolean unpackWARs, LifecycleState resultState, String cookieName,
        boolean resultXml, boolean resultWar, boolean resultDir)
        throws Exception {

    Tomcat tomcat = getTomcatInstance();

    // Start the instance
    tomcat.start();

    // Set the attributes
    StandardHost host = (StandardHost) tomcat.getHost();
    host.setDeployXML(deployXML);
    host.setCopyXML(copyXML);
    host.setUnpackWARs(unpackWARs);

    // Trigger automatic deployment
    host.backgroundProcess();

    // Test the results
    Context ctxt = (Context) tomcat.getHost().findChild(APP_NAME.getPath());
    if (resultState == null) {
        Assert.assertNull(ctxt);
    } else {
        Assert.assertNotNull(ctxt);
        Assert.assertEquals(resultState, ctxt.getState());
        Assert.assertEquals(cookieName, ctxt.getSessionCookieName());
    }

    File xml = new File(
            getConfigBaseFile(host), APP_NAME.getBaseName() + ".xml");
    Assert.assertEquals(
            Boolean.valueOf(resultXml), Boolean.valueOf(xml.isFile()));

    File war = new File(
            getAppBaseFile(host), APP_NAME.getBaseName() + ".war");
    Assert.assertEquals(
            Boolean.valueOf(resultWar), Boolean.valueOf(war.isFile()));

    File dir = new File(host.getAppBase(), APP_NAME.getBaseName());
    Assert.assertEquals(
            Boolean.valueOf(resultDir), Boolean.valueOf(dir.isDirectory()));
}
 
Example 14
Source File: TestHostConfigAutomaticDeployment.java    From tomcatsrc with Apache License 2.0 4 votes vote down vote up
private void doTestDeployment(boolean deployXML, boolean copyXML,
        boolean unpackWARs, LifecycleState resultState, String cookieName,
        boolean resultXml, boolean resultWar, boolean resultDir)
        throws Exception {

    Tomcat tomcat = getTomcatInstance();

    // Start the instance
    tomcat.start();

    // Set the attributes
    StandardHost host = (StandardHost) tomcat.getHost();
    host.setDeployXML(deployXML);
    host.setCopyXML(copyXML);
    host.setUnpackWARs(unpackWARs);

    // Trigger automatic deployment
    host.backgroundProcess();

    // Test the results
    Context ctxt = (Context) tomcat.getHost().findChild(APP_NAME.getPath());
    if (resultState == null) {
        Assert.assertNull(ctxt);
    } else {
        Assert.assertNotNull(ctxt);
        Assert.assertEquals(resultState, ctxt.getState());
        Assert.assertEquals(cookieName, ctxt.getSessionCookieName());
    }

    File xml = new File(
            getConfigBaseFile(host), APP_NAME.getBaseName() + ".xml");
    Assert.assertEquals(
            Boolean.valueOf(resultXml), Boolean.valueOf(xml.isFile()));

    File war = new File(
            getAppBaseFile(host), APP_NAME.getBaseName() + ".war");
    Assert.assertEquals(
            Boolean.valueOf(resultWar), Boolean.valueOf(war.isFile()));

    File dir = new File(host.getAppBase(), APP_NAME.getBaseName());
    Assert.assertEquals(
            Boolean.valueOf(resultDir), Boolean.valueOf(dir.isDirectory()));
}