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

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

本文整理了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

  1. /**
  2. * Get the context path for the webapp.
  3. *
  4. * @param deployable the deployable
  5. * @return the context path
  6. */
  7. public static String getContext(Deployable deployable)
  8. {
  9. return "/" + ((WAR) deployable).getContext();
  10. }
  11. }

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

  1. /**
  2. * Deploys the {@link #warFile} to the cargo container ({@link #container}).
  3. */
  4. public void deployWar() {
  5. // Get the cargo war from the war file
  6. WAR war = new WAR(warFile.getAbsolutePath());
  7. // Set context access to nothing
  8. war.setContext("");
  9. // Deploy the war the container's configuration
  10. getConfiguration().addDeployable(war);
  11. logger.info("Deployed WAR file at {}", war.getFile());
  12. }

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

  1. // (1) Optional step to install the container from a URL pointing to its distribution
  2. Installer installer = new ZipURLInstaller(new URL("http://www.apache.org/dist/tomcat/tomcat-6/v6.0.20/bin/apache-tomcat-6.0.20.zip"));
  3. installer.install();
  4. // (2) Create the Cargo Container instance wrapping our physical container
  5. LocalConfiguration configuration = (LocalConfiguration) new DefaultConfigurationFactory()
  6. .createConfiguration("tomcat6x"), ContainerType.INSTALLED, ConfigurationType.STANDALONE);
  7. container = (InstalledLocalContainer) new DefaultContainerFactory()
  8. .createContainer("tomcat6x", ContainerType.INSTALLED, configuration);
  9. container.setHome(installer.getHome());
  10. // (3) Statically deploy some WAR (optional)
  11. WAR deployable = new WAR("./webapp-testing-webapp/target/webapp-testing-webapp-1.0.war");
  12. deployable.setContext("ROOT");
  13. configuration.addDeployable(deployable);
  14. // (4) Start the container
  15. container.start();

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

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

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

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

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

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

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

  1. /**
  2. * Test context when WAR has an extension.
  3. */
  4. public void testGetContextWhenWarHasExtension()
  5. {
  6. WAR war = new WAR("c:/some/path/to/war/test.war");
  7. assertEquals("test", war.getContext());
  8. }

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

  1. /**
  2. * Verify that WAR context change works.
  3. * @throws Exception If anything goes wrong.
  4. */
  5. public void testChangeWarContextAndDeployUndeployRemotely() throws Exception
  6. {
  7. this.war.setContext("simple");
  8. URL warPingURL = new URL("http://localhost:" + getTestData().port + "/"
  9. + this.war.getContext() + "/index.jsp");
  10. deployer.deploy(this.war);
  11. PingUtils.assertPingTrue("simple war not correctly deployed", warPingURL, getLogger());
  12. deployer.undeploy(this.war);
  13. PingUtils.assertPingFalse("simple war not correctly undeployed", warPingURL, getLogger());
  14. }

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

  1. /**
  2. * Test deployment of an expanded WAR in a custom context.
  3. * @throws Exception If anything goes wrong.
  4. */
  5. public void testDeployToNonExistingDirectory() throws Exception
  6. {
  7. WAR war = new WAR("ram:///some/warfile.war");
  8. this.fsManager.resolveFile(war.getFile()).createFile();
  9. AbstractCopyingInstalledLocalDeployer deployer =
  10. new TestableCopyingDeployerWithDifferentDirectory(
  11. createContainer(createContainerCapability(DeployableType.WAR), null));
  12. try
  13. {
  14. deployer.deploy(war);
  15. fail("Should have thrown a CargoException here");
  16. }
  17. catch (CargoException expected)
  18. {
  19. assertTrue("Incorrect message: " + expected.getMessage(),
  20. expected.getMessage().contains("ram:///webapps-nonexisting"));
  21. }
  22. }

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

  1. /**
  2. * Test logger when getting WAR context.
  3. */
  4. public void testLoggerWhenCallingGetContext()
  5. {
  6. MockLogger logger = new MockLogger();
  7. WAR war = new WAR("c:/test.war");
  8. war.setLogger(logger);
  9. // Calling getContext just to trigger the log
  10. war.getContext();
  11. assertEquals(1, logger.severities.size());
  12. assertEquals("debug", logger.severities.get(0));
  13. assertEquals("Parsed web context = [test]", logger.messages.get(0));
  14. assertEquals("org.codehaus.cargo.container.deployable.WAR", logger.categories.get(0));
  15. }

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

  1. /**
  2. * Test deployment of an expanded WAR in a custom context.
  3. * @throws Exception If anything goes wrong.
  4. */
  5. public void testDeployWhenExpandedWarWithCustomContext() throws Exception
  6. {
  7. // Create an expanded WAR
  8. WAR war = new WAR("ram:///some/expanded/warfile");
  9. war.setContext("context");
  10. war.setFileHandler(this.fileHandler);
  11. this.fsManager.resolveFile(war.getFile()).createFolder();
  12. AbstractCopyingInstalledLocalDeployer deployer = new TestableCopyingDeployer(
  13. createContainer(createContainerCapability(DeployableType.WAR), null));
  14. assertFalse(this.fsManager.resolveFile("ram:///webapps/context").exists());
  15. deployer.deploy(war);
  16. assertTrue(this.fsManager.resolveFile("ram:///webapps/context").exists());
  17. }

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

  1. /**
  2. * Creates a Deployable object WAR from the given file object.
  3. *
  4. * @param deployableFile The deployable file to create the Deployable from.
  5. * @return A Deployable object.
  6. */
  7. protected WAR createWAR(File deployableFile) {
  8. return new WAR(deployableFile.getAbsolutePath());
  9. }

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

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

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

  1. /**
  2. * Extract the context name from the WAR file name (without the file extension). For example if
  3. * the WAR is named <code>test.war</code> then the context name is <code>test</code>.
  4. */
  5. private void parseContext()
  6. {
  7. if (this.context == null)
  8. {
  9. String ctx = getFileHandler().getName(getFile());
  10. int warIndex = ctx.toLowerCase().lastIndexOf(".war");
  11. if (warIndex >= 0)
  12. {
  13. ctx = ctx.substring(0, warIndex);
  14. }
  15. getLogger().debug("Parsed web context = [" + ctx + "]", this.getClass().getName());
  16. setContext(ctx);
  17. }
  18. }

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

  1. /**
  2. * Test name when WAR context is overriden.
  3. */
  4. public void testGetNameWhenOverride()
  5. {
  6. WAR war = new WAR("c:/some/path/to/war/test.war");
  7. war.setContext("context");
  8. assertEquals("context", war.getName());
  9. }
  10. }

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

  1. protected void deploy(DeployerFactory deployerFactory, final BuildListener listener, Container container, File f, String contextPath) {
  2. Deployer deployer = deployerFactory.createDeployer(container);
  3. listener.getLogger().println("Deploying " + f + " to container " + container.getName());
  4. deployer.setLogger(new LoggerImpl(listener.getLogger()));
  5. String extension = FilenameUtils.getExtension(f.getAbsolutePath());
  6. if ("WAR".equalsIgnoreCase(extension)) {
  7. WAR war = createWAR(f);
  8. if (!StringUtils.isEmpty(contextPath)) {
  9. war.setContext(contextPath);
  10. }
  11. deployer.redeploy(war);
  12. } else if ("EAR".equalsIgnoreCase(extension)) {
  13. EAR ear = createEAR(f);
  14. deployer.redeploy(ear);
  15. } else {
  16. throw new RuntimeException("Extension File Error.");
  17. }
  18. }

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

  1. /**
  2. * Test equality between WAR deployables.
  3. */
  4. public void testWARTypeEquality()
  5. {
  6. WAR war1 = new WAR("/some/path/to/file.war");
  7. WAR war2 = new WAR("/otherfile.war");
  8. assertEquals(war1.getType(), war2.getType());
  9. }

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

  1. /**
  2. * Test name when WAR has no extension.
  3. */
  4. public void testGetNameWhenWarHasNoExtension()
  5. {
  6. WAR war = new WAR("/some/path/to/war/test");
  7. assertEquals("test", war.getName());
  8. }

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

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

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

  1. /**
  2. * Gets the extra classpath for the WAR as a string array
  3. *
  4. * @param war The WAR being deployed, must not be {@code null}.
  5. * @return The WAR's extra classpath or {@code null} if none.
  6. */
  7. public static String[] getExtraClasspath(WAR war)
  8. {
  9. String[] extraClasspath = war.getExtraClasspath();
  10. if (extraClasspath == null || extraClasspath.length <= 0)
  11. {
  12. return null;
  13. }
  14. return extraClasspath;
  15. }
  16. }

相关文章