org.codehaus.cargo.container.deployable.WAR类的使用及代码示例

x33g5p2x  于2022-02-03 转载在 其他  
字(9.7k)|赞(0)|评价(0)|浏览(140)

本文整理了Java中org.codehaus.cargo.container.deployable.WAR类的一些代码示例,展示了WAR类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。WAR类的具体详情如下:
包路径:org.codehaus.cargo.container.deployable.WAR
类名称:WAR

WAR介绍

[英]Wraps a WAR file that will be deployed in the container. The root context for this WAR is taken from the name of the WAR file (without the extension).
[中]包装将部署在容器中的WAR文件。此WAR的根上下文取自WAR文件的名称(不带扩展名)。

代码示例

代码示例来源:origin: org.codehaus.cargo/cargo-core-container-jetty

/**
   * Get the context path for the webapp.
   * 
   * @param deployable the deployable
   * @return the context path
   */
  public static String getContext(Deployable deployable)
  {
    return "/" + ((WAR) deployable).getContext();
  }
}

代码示例来源:origin: apache/geode

/**
 * Deploys the {@link #warFile} to the cargo container ({@link #container}).
 */
public void deployWar() {
 // Get the cargo war from the war file
 WAR war = new WAR(warFile.getAbsolutePath());
 // Set context access to nothing
 war.setContext("");
 // Deploy the war the container's configuration
 getConfiguration().addDeployable(war);
 logger.info("Deployed WAR file at {}", war.getFile());
}

代码示例来源:origin: stackoverflow.com

// (1) Optional step to install the container from a URL pointing to its distribution
Installer installer = new ZipURLInstaller(new URL("http://www.apache.org/dist/tomcat/tomcat-6/v6.0.20/bin/apache-tomcat-6.0.20.zip"));
installer.install();

// (2) Create the Cargo Container instance wrapping our physical container
LocalConfiguration configuration = (LocalConfiguration) new DefaultConfigurationFactory()
    .createConfiguration("tomcat6x"), ContainerType.INSTALLED, ConfigurationType.STANDALONE);
container = (InstalledLocalContainer) new DefaultContainerFactory()
    .createContainer("tomcat6x", ContainerType.INSTALLED, configuration);
container.setHome(installer.getHome());

// (3) Statically deploy some WAR (optional)
WAR deployable = new WAR("./webapp-testing-webapp/target/webapp-testing-webapp-1.0.war");
deployable.setContext("ROOT");
configuration.addDeployable(deployable);

// (4) Start the container
container.start();

代码示例来源:origin: org.codehaus.cargo/cargo-core-container-jetty

@Override
protected String createContextXml(WAR war)
{
  StringBuilder buffer = new StringBuilder();
  buffer.append("<?xml version=\"1.0\"  encoding=\"UTF-8\"?>\n");
  buffer.append("<!DOCTYPE Configure PUBLIC \"-//Jetty//Configure//EN\" "
    + "\"http://www.eclipse.org/jetty/configure.dtd\">\n");
  buffer.append("<Configure class=\"org.eclipse.jetty.webapp.WebAppContext\">\n");
  buffer.append("  <Set name=\"contextPath\">/" + war.getContext() + "</Set>\n");
  buffer.append("  <Set name=\"war\">" + war.getFile() + "</Set>\n");
  buffer.append("  <Set name=\"extractWAR\">true</Set>\n");
  buffer.append("  <Set name=\"defaultsDescriptor\"><SystemProperty name=\"config.home\" "
    + "default=\".\"/>/etc/webdefault.xml</Set>\n");
  buffer.append(getExtraClasspathXmlFragment(war));
  buffer.append(getSharedClasspathXmlFragment());
  buffer.append("</Configure>\n");
  return buffer.toString();
}

代码示例来源:origin: org.codehaus.cargo/cargo-core-container-jo

final String webappName = war.getContext().replace('.', '_').replace('=', '_');
String mapping = war.getContext();
if (mapping == null)
String docbase = getFileHandler().getURL(war.getFile()).toString();
if (war.isExpanded())
keyWebApps.append("# CARGO! Context: " + war.getContext() + " File: "
  + war.getFile() + LINE_SEPARATOR);
keyWebApps.append("host.webapp." + webappName + ".mapping=" + mapping
  + LINE_SEPARATOR);

代码示例来源:origin: codehaus-cargo/cargo

/**
 * Test WAR context overriden with a slash in the middhe.
 */
public void testGetContextWhenOverrideAndMiddleSlash()
{
  WAR war = new WAR("c:/some/path/to/war/test.war");
  war.setContext("/a/b");
  assertEquals("a/b", war.getContext());
}

代码示例来源:origin: codehaus-cargo/cargo

/**
 * Test context when WAR has an extension.
 */
public void testGetContextWhenWarHasExtension()
{
  WAR war = new WAR("c:/some/path/to/war/test.war");
  assertEquals("test", war.getContext());
}

代码示例来源:origin: codehaus-cargo/cargo

/**
 * Verify that WAR context change works.
 * @throws Exception If anything goes wrong.
 */
public void testChangeWarContextAndDeployUndeployRemotely() throws Exception
{
  this.war.setContext("simple");
  URL warPingURL = new URL("http://localhost:" + getTestData().port + "/"
    + this.war.getContext() + "/index.jsp");
  deployer.deploy(this.war);
  PingUtils.assertPingTrue("simple war not correctly deployed", warPingURL, getLogger());
  deployer.undeploy(this.war);
  PingUtils.assertPingFalse("simple war not correctly undeployed", warPingURL, getLogger());
}

代码示例来源:origin: codehaus-cargo/cargo

/**
 * Test deployment of an expanded WAR in a custom context.
 * @throws Exception If anything goes wrong.
 */
public void testDeployToNonExistingDirectory() throws Exception
{
  WAR war = new WAR("ram:///some/warfile.war");
  this.fsManager.resolveFile(war.getFile()).createFile();
  AbstractCopyingInstalledLocalDeployer deployer =
    new TestableCopyingDeployerWithDifferentDirectory(
      createContainer(createContainerCapability(DeployableType.WAR), null));
  try
  {
    deployer.deploy(war);
    fail("Should have thrown a CargoException here");
  }
  catch (CargoException expected)
  {
    assertTrue("Incorrect message: " + expected.getMessage(),
      expected.getMessage().contains("ram:///webapps-nonexisting"));
  }
}

代码示例来源:origin: codehaus-cargo/cargo

/**
 * Test logger when getting WAR context.
 */
public void testLoggerWhenCallingGetContext()
{
  MockLogger logger = new MockLogger();
  WAR war = new WAR("c:/test.war");
  war.setLogger(logger);
  // Calling getContext just to trigger the log
  war.getContext();
  assertEquals(1, logger.severities.size());
  assertEquals("debug", logger.severities.get(0));
  assertEquals("Parsed web context = [test]", logger.messages.get(0));
  assertEquals("org.codehaus.cargo.container.deployable.WAR", logger.categories.get(0));
}

代码示例来源:origin: codehaus-cargo/cargo

/**
 * Test deployment of an expanded WAR in a custom context.
 * @throws Exception If anything goes wrong.
 */
public void testDeployWhenExpandedWarWithCustomContext() throws Exception
{
  // Create an expanded WAR
  WAR war = new WAR("ram:///some/expanded/warfile");
  war.setContext("context");
  war.setFileHandler(this.fileHandler);
  this.fsManager.resolveFile(war.getFile()).createFolder();
  AbstractCopyingInstalledLocalDeployer deployer = new TestableCopyingDeployer(
    createContainer(createContainerCapability(DeployableType.WAR), null));
  assertFalse(this.fsManager.resolveFile("ram:///webapps/context").exists());
  deployer.deploy(war);
  assertTrue(this.fsManager.resolveFile("ram:///webapps/context").exists());
}

代码示例来源:origin: org.jenkins-ci.plugins/deploy

/**
 * Creates a Deployable object WAR from the given file object.
 *
 * @param deployableFile The deployable file to create the Deployable from.
 * @return A Deployable object.
 */
protected WAR createWAR(File deployableFile) {
  return new WAR(deployableFile.getAbsolutePath());
}

代码示例来源:origin: codehaus-cargo/cargo

String context = war.getContext();
if ("".equals(context) || "/".equals(context))
  context = "ROOT";
if (war.isExpanded())

代码示例来源:origin: codehaus-cargo/cargo

/**
 * Extract the context name from the WAR file name (without the file extension). For example if
 * the WAR is named <code>test.war</code> then the context name is <code>test</code>.
 */
private void parseContext()
{
  if (this.context == null)
  {
    String ctx = getFileHandler().getName(getFile());
    int warIndex = ctx.toLowerCase().lastIndexOf(".war");
    if (warIndex >= 0)
    {
      ctx = ctx.substring(0, warIndex);
    }
    getLogger().debug("Parsed web context = [" + ctx + "]", this.getClass().getName());
    setContext(ctx);
  }
}

代码示例来源:origin: codehaus-cargo/cargo

/**
   * Test name when WAR context is overriden.
   */
  public void testGetNameWhenOverride()
  {
    WAR war = new WAR("c:/some/path/to/war/test.war");
    war.setContext("context");
    assertEquals("context", war.getName());
  }
}

代码示例来源:origin: org.jenkins-ci.plugins/deploy

protected void deploy(DeployerFactory deployerFactory, final BuildListener listener, Container container, File f, String contextPath) {
  Deployer deployer = deployerFactory.createDeployer(container);
  listener.getLogger().println("Deploying " + f + " to container " + container.getName());
  deployer.setLogger(new LoggerImpl(listener.getLogger()));
  String extension = FilenameUtils.getExtension(f.getAbsolutePath());
  if ("WAR".equalsIgnoreCase(extension)) {
    WAR war = createWAR(f);
    if (!StringUtils.isEmpty(contextPath)) {
      war.setContext(contextPath);
    }
    deployer.redeploy(war);
  } else if ("EAR".equalsIgnoreCase(extension)) {
    EAR ear = createEAR(f);
    deployer.redeploy(ear);
  } else {
    throw new RuntimeException("Extension File Error.");
  }
}

代码示例来源:origin: codehaus-cargo/cargo

/**
 * Test equality between WAR deployables.
 */
public void testWARTypeEquality()
{
  WAR war1 = new WAR("/some/path/to/file.war");
  WAR war2 = new WAR("/otherfile.war");
  assertEquals(war1.getType(), war2.getType());
}

代码示例来源:origin: codehaus-cargo/cargo

/**
 * Test name when WAR has no extension.
 */
public void testGetNameWhenWarHasNoExtension()
{
  WAR war = new WAR("/some/path/to/war/test");
  assertEquals("test", war.getName());
}

代码示例来源:origin: org.codehaus.cargo/cargo-core-container-geronimo

if (deployable instanceof WAR && ((WAR) deployable).isExpanded())

代码示例来源:origin: org.codehaus.cargo/cargo-core-container-tomcat

/**
   * Gets the extra classpath for the WAR as a string array
   * 
   * @param war The WAR being deployed, must not be {@code null}.
   * @return The WAR's extra classpath or {@code null} if none.
   */
  public static String[] getExtraClasspath(WAR war)
  {
    String[] extraClasspath = war.getExtraClasspath();
    if (extraClasspath == null || extraClasspath.length <= 0)
    {
      return null;
    }
    return extraClasspath;
  }
}

相关文章