Java Code Examples for org.jboss.shrinkwrap.api.spec.WebArchive#addAsWebInfResource()

The following examples show how to use org.jboss.shrinkwrap.api.spec.WebArchive#addAsWebInfResource() . These examples are extracted from open source projects. 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
@Override
public void process(TestDeployment testDeployment, Archive<?> protocolArchive) {
    WebArchive war = (WebArchive) protocolArchive;
    war.addAsWebInfResource("WEB-INF/jboss-web.xml", "jboss-web.xml");
    String[] deps = {
            "io.smallrye:smallrye-config",
            "io.smallrye:smallrye-metrics",
            "io.smallrye:smallrye-metrics-testsuite-common",
            "org.eclipse.microprofile.metrics:microprofile-metrics-api",
            "org.jboss.weld.servlet:weld-servlet-core"
    };

    File[] dependencies = Maven.resolver().loadPomFromFile(new File("pom.xml")).resolve(deps).withTransitivity().asFile();

    war.addAsLibraries(dependencies);

    war.addClass(SmallRyeBeanArchiveHandler.class);
    war.addClass(MetricsHttpServlet.class);
    war.addClass(MetricsInitializer.class);
    war.addAsResource("io/smallrye/metrics/base-metrics.properties", "/io/smallrye/metrics/base-metrics.properties");
    war.addAsServiceProvider(BeanArchiveHandler.class, SmallRyeBeanArchiveHandler.class);
    war.addAsServiceProvider(Extension.class, ConfigExtension.class);
    war.addAsServiceProvider(ConfigProviderResolver.class, SmallRyeConfigProviderResolver.class);
}
 
Example 2
@Override
public Archive<?> generateDeployment(final TestDeployment testDeployment,
                                     final Collection<ProtocolArchiveProcessor> processors) {

    final WebArchive webArchive = ShrinkWrap.create(WebArchive.class, "microprofile-opentracing.war")
                                            .merge(testDeployment.getApplicationArchive());

    // opentracing-api jar added by Geronimo Impl. Also added by TCK causes issues with same classes in different Classloaders
    final Map<ArchivePath, Node> content = webArchive.getContent(object -> object.get().matches(".*opentracing-api.*jar.*"));
    content.forEach((archivePath, node) -> webArchive.delete(archivePath));

    // TCK expects a MockTracer. Check org/eclipse/microprofile/opentracing/tck/application/TracerWebService.java:133
    webArchive.addAsLibrary(jarLocation(MockTracer.class));
    webArchive.addAsLibrary(jarLocation(ThreadLocalScopeManager.class));
    webArchive.addAsWebInfResource("META-INF/beans.xml");
    webArchive.addClass(MicroProfileOpenTracingTCKTracer.class);

    System.out.println(webArchive.toString(true));

    return super.generateDeployment(
            new TestDeployment(null, webArchive, testDeployment.getAuxiliaryArchives()), processors);
}
 
Example 3
protected static WebArchive servletDeployment(String name, String adapterConfig, Class... servletClasses) {
    String webInfPath = "/adapter-test/" + name + "/WEB-INF/";

    URL keycloakJSON = AbstractServletsAdapterTest.class.getResource(webInfPath + adapterConfig);
    URL webXML = AbstractServletsAdapterTest.class.getResource(webInfPath + "web.xml");

    WebArchive deployment = ShrinkWrap.create(WebArchive.class, name + ".war")
            .addClasses(servletClasses)
            .addAsWebInfResource(webXML, "web.xml")
            .addAsWebInfResource(jbossDeploymentStructure, JBOSS_DEPLOYMENT_STRUCTURE_XML);

    URL keystore = AbstractServletsAdapterTest.class.getResource(webInfPath + "keystore.jks");
    if (keystore != null) {
        deployment.addAsWebInfResource(keystore, "classes/keystore.jks");
    }

    if (keycloakJSON != null) {
        deployment.addAsWebInfResource(keycloakJSON, "keycloak.json");
    }

    addContextXml(deployment, name);

    return deployment;
}
 
Example 4
@Deployment
public static WebArchive createdeployment() {
    WebArchive archive = ShrinkWrap.create(WebArchive.class, "ahc-wss-test.war");
    archive.addClasses(WebSocketServerEndpoint.class);
    archive.addAsResource("ahc/application.keystore", "application.keystore");
    archive.addAsWebResource("ahc/websocket.js", "websocket.js");
    archive.addAsWebResource("ahc/index.jsp", "index.jsp");
    archive.addAsWebInfResource("ahc/web.xml", "web.xml");
    return archive;
}
 
Example 5
/**
 * Test hooks so we can do some cleanupCreatedProject
 *
 * @return
 */
static WebArchive getTestDeployment() {
    final WebArchive archive = ShrinkWrap.create(WebArchive.class, "test.war")
            .addPackages(
                    true,
                    OpenShiftServiceSpi.class.getPackage(),
                    OpenShiftProjectImpl.class.getPackage(),
                    OpenShiftServiceFactory.class.getPackage(),
                    GitHubServiceSpi.class.getPackage(),
                    KohsukeGitHubServiceImpl.class.getPackage(),
                    GitHubServiceFactory.class.getPackage())
            .addPackage(TestSupport.class.getPackage());
    final File[] depsOpenshift = Resolvers.use(MavenResolverSystem.class).
            loadPomFromFile("../services/openshift-service-impl/pom.xml").
            importRuntimeAndTestDependencies().
            resolve().
            withTransitivity().
            asFile();
    final File[] depsGithub = Resolvers.use(MavenResolverSystem.class).
            loadPomFromFile("../services/github-service-impl/pom.xml").
            importRuntimeAndTestDependencies().
            resolve().
            withTransitivity().
            asFile();

    final File[] ourTestDeps = Resolvers.use(MavenResolverSystem.class).
            loadPomFromFile("pom.xml").
            importTestDependencies().
            resolve().
            withTransitivity().
            asFile();
    archive.addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml");
    archive.addAsLibraries(depsOpenshift);
    archive.addAsLibraries(depsGithub);
    archive.addAsLibraries(ourTestDeps);
    return archive;
}
 
Example 6
@Deployment
public static WebArchive createDeployment() {
    final WebArchive archive = ShrinkWrap.create(WebArchive.class, "camel.war");
    archive.addAsWebInfResource("servlet/web.xml", "web.xml");
    archive.addClasses(HttpRequest.class);
    return archive;
}
 
Example 7
@Deployment
public static WebArchive createDeployment() {
    WebArchive archive = ShrinkWrap.create(WebArchive.class, "camel-global-modules.war");
    archive.addAsWebInfResource("modules/jboss-camel-context.xml", "jboss-camel-context.xml");
    archive.addClasses(HttpRequest.class, CamelServlet.class);
    return archive;
}
 
Example 8
Source Project: pnc   File: Deployments.java    License: Apache License 2.0 5 votes vote down vote up
private static WebArchive prepareRestArchive(EnterpriseArchive ear) {
    WebArchive restWar = ear.getAsType(WebArchive.class, "/rest-new.war");
    restWar.addAsWebInfResource("WEB-INF/web-new.xml", "web.xml");
    restWar.addAsWebInfResource("WEB-INF/jboss-web.xml");
    logger.info("REST archive listing: {}", restWar.toString(true));
    return restWar;
}
 
Example 9
@Deployment(name = SIMPLE_WAR, managed = false)
public static Archive<?> getSimpleWar() {
    final WebArchive archive = ShrinkWrap.create(WebArchive.class, SIMPLE_WAR);
    final StringAsset jbossWebAsset = new StringAsset("<jboss-web><security-domain>cxf-security-domain</security-domain></jboss-web>");
    archive.addClasses(Endpoint.class, SecureEndpointImpl.class);
    archive.addAsResource("cxf/secure/cxf-roles.properties", "cxf-roles.properties");
    archive.addAsResource("cxf/secure/cxf-users.properties", "cxf-users.properties");
    archive.addAsWebInfResource(jbossWebAsset, "jboss-web.xml");
    return archive;
}
 
Example 10
@SuppressWarnings("unchecked")
protected void handleWebArchiveInternal(WebArchive war) {
    addService(war, TestLifecycle.class,
        CapeDwarfExecutionLifecycle.class,
        CapeDwarfImageLifecycle.class,
        CapeDwarfInstanceLifecycle.class,
        CapeDwarfMergeLifecycle.class,
        CapeDwarfPropertyLifecycle.class,
        CapeDwarfServicesLifecycle.class,
        CapeDwarfTestContextEnhancer.class
    );

    war.addClass(CapedwarfEmailAddressFormatter.class);

    addCompatibility(war, COMPATIBILITY);

    String xmppUsername = System.getProperty("capedwarf.xmpp.username", "[email protected]");
    String xmppPassword = System.getProperty("capedwarf.xmpp.password", "MISSING_PASSWORD");

    log.info(String.format("XMPP: %s / %s", xmppUsername, xmppPassword));

    String mailUser = System.getProperty("capedwarf.mail.username", "[email protected]");
    String mailPassword = System.getProperty("capedwarf.mail.password", "MISSING_PASSWORD");

    String inboundMailProtocol = System.getProperty("capedwarf.inbound.mail.protocol", "imaps");
    String inboundMailHost = System.getProperty("capedwarf.inbound.mail.host", "imap.gmail.com");
    String inboundMailUsername = System.getProperty("capedwarf.inbound.mail.username", "[email protected]");
    String inboundMailPassword = System.getProperty("capedwarf.inbound.mail.password", "MISSING_PASSWORD");
    String inboundMailFolder = System.getProperty("capedwarf.inbound.mail.folder", "INBOX");

    String cdw = String.format(CAPEDWARF_WEB,
        xmppUsername, xmppPassword,
        mailUser, mailPassword,
        inboundMailProtocol, inboundMailHost, inboundMailUsername, inboundMailPassword, inboundMailFolder);
    war.addAsWebInfResource(new StringAsset(cdw), "capedwarf-web.xml");
}
 
Example 11
public static WebArchive buildArchive(String clazz) {
    WebArchive war = createWar();
    addClasses(war, clazz, AppEngineDataNucleusTransformer.class.getClassLoader());

    war.addPackage("com.google.appengine.datanucleus");

    war.addClass("com.google.appengine.datanucleus.jpa.JPATestCase$EntityManagerFactoryName");
    war.addClass("com.google.appengine.datanucleus.jdo.JDOTestCase$PersistenceManagerFactoryName");

    war.addPackage("com.google.appengine.datanucleus.query");

    war.addPackage("com.google.appengine.datanucleus.test.jdo");
    war.addPackage("com.google.appengine.datanucleus.test.jpa");

    war.setWebXML(new org.jboss.shrinkwrap.api.asset.StringAsset("<web/>"));
    war.addAsWebInfResource("appengine-web.xml");
    war.addAsWebInfResource("META-INF/persistence.xml", "classes/META-INF/persistence.xml");
    war.addAsWebInfResource("META-INF/jdoconfig.xml", "classes/META-INF/jdoconfig.xml");
    war.addAsResource(new StringAsset("ignore.logging=true\n"), "capedwarf-compatibility.properties");

    final PomEquippedResolveStage resolver = getResolver("pom.xml");
    // GAE DN libs
    war.addAsLibraries(resolve(resolver, "com.google.appengine.orm:datanucleus-appengine"));
    war.addAsLibraries(resolve(resolver, "com.google.appengine:appengine-api-1.0-sdk"));
    war.addAsLibraries(resolve(resolver, "com.google.appengine:appengine-testing"));
    war.addAsLibraries(resolve(resolver, "com.google.appengine:appengine-api-stubs"));
    war.addAsLibraries(resolve(resolver, "org.datanucleus:datanucleus-core"));
    war.addAsLibraries(resolve(resolver, "org.datanucleus:datanucleus-api-jdo"));
    war.addAsLibraries(resolve(resolver, "org.datanucleus:datanucleus-api-jpa"));
    war.addAsLibraries(resolve(resolver, "javax.jdo:jdo-api"));
    war.addAsLibraries(resolve(resolver, "org.apache.geronimo.specs:geronimo-jpa_2.0_spec"));
    war.addAsLibraries(resolve(resolver, "org.easymock:easymock"));
    war.addAsLibraries(resolve(resolver, "org.easymock:easymockclassextension"));
    // TCK Internals
    war.addAsLibraries(resolve(resolver, "com.google.appengine.tck:appengine-tck-transformers")); // cleanup dep
    war.addAsLibraries(resolve(resolver, "com.google.appengine.tck:appengine-tck-base")); // lifecycle dep

    return war;
}
 
Example 12
Source Project: wildfly-camel   File: SecurityUtils.java    License: Apache License 2.0 5 votes vote down vote up
public static void addSpringXml(WebArchive archive, String file, String endpointUrl) {
    final StringBuilder sb = new StringBuilder();
    try {
        FileUtils.copy(
                SecurityUtils.class.getClassLoader().getResource("cxf/secure/spring/"+ file), sb);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    final String xml = sb.toString()
            .replace("${SPRING_CONSUMER_ENDPOINT_ADDRESS}", endpointUrl)
            .replace("${SERVER_TRUST_STORE_PATH}", EnvironmentUtils.getWildFlyHome() + "/standalone/configuration/" + SERVER_TRUSTSTORE)
            .replace("${SERVER_TRUST_STORE_PASSWORD}", CLIENT_CERT_KEYSTORE_PASSWORD);
    archive.addAsWebInfResource(new StringAsset(xml), file);
}
 
Example 13
private static WebArchive app(String war, String springContextXml, Map<String, String> pathRoleMap) {
    final WebArchive archive = ShrinkWrap.create(WebArchive.class, war).addClasses(BasicSecurityDomainASetup.class,
            CXFRSSecureUtils.class, TestClient.class, AbstractUndertowSecureRestDslClientTest.class);
    SecurityUtils.enhanceArchive(archive, BasicSecurityDomainASetup.SECURITY_DOMAIN,
            BasicSecurityDomainASetup.AUTH_METHOD, pathRoleMap);
    archive.addAsWebInfResource("rest/" + springContextXml, springContextXml);
    return archive;
}
 
Example 14
@Deployment
public static WebArchive createdeployment() {
    final WebArchive archive = ShrinkWrap.create(WebArchive.class, "package-scan.war");
    archive.addAsWebInfResource("spring/package-scan-camel-context.xml");
    archive.addClasses(ScannedRouteBuilder.class);
    return archive;
}
 
Example 15
Source Project: appengine-tck   File: RpcTest.java    License: Apache License 2.0 5 votes vote down vote up
@Deployment
public static WebArchive getDeployment() {
    TestContext context = new TestContext().setWebXmlFile("rpc-web.xml");
    WebArchive war = getDefaultDeployment(context);
    war.addClasses(RpcEndpoint.class, TestData.class);
    war.add(new ClassLoaderAsset("xindex.html"), "index.html");
    war.add(new ClassLoaderAsset("js/base.js"), "js/base.js");
    war.addAsWebInfResource("rpcendpoint-v1-rest.discovery");
    war.addAsWebInfResource("rpcendpoint-v1-rpc.discovery");
    return war;
}
 
Example 16
@Deployment(testable = false)
public static WebArchive createDeployment() {
    final WebAppDescriptor webAppDescriptor = Descriptors.create(WebAppDescriptor.class);
    webAppDescriptor.version("3.0");

    final WebArchive webArchive = ShrinkWrap.create(WebArchive.class, "connector-sample-war.war");
    webArchive.addPackage("org.superbiz.connector.api");
    webArchive.addPackage("org.superbiz.connector.adapter");
    webArchive.addPackage("org.superbiz.application");
    webArchive.addAsWebInfResource(ConnectorWithApplicationResourcesInEarTest.class.getResource("/connector/resources.xml"), "resources.xml");
    webArchive.setWebXML(new StringAsset(webAppDescriptor.exportAsString()));
    System.out.println("Webapp:\n" + webArchive.toString(true));

    return webArchive;
}
 
Example 17
Source Project: trimou   File: IntegrationTestUtils.java    License: Apache License 2.0 4 votes vote down vote up
public static WebArchive createCDITestArchiveBase() {
    WebArchive testArchive = createTestArchiveBase();
    testArchive.addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml");
    return testArchive;
}
 
Example 18
Source Project: appengine-tck   File: CapabilityTest.java    License: Apache License 2.0 4 votes vote down vote up
@Deployment
public static WebArchive getDeployment() {
    WebArchive war = getTckDeployment();
    war.addAsWebInfResource(new StringAsset("capability"), "dummy.txt");
    return war;
}
 
Example 19
Source Project: tomee   File: EARTest.java    License: Apache License 2.0 4 votes vote down vote up
@Deployment
public static EnterpriseArchive createDeployment() {

    final JavaArchive apiJar = ShrinkWrap.create(JavaArchive.class, "connector-sample-api.jar");
    apiJar.addPackage("org.superbiz.connector.api");
    System.out.println("API JAR:\n" + apiJar.toString(true));

    final JavaArchive implJar = ShrinkWrap.create(JavaArchive.class, "connector-sample-impl.jar");
    implJar.addPackage("org.superbiz.connector.adapter");
    System.out.println("IMPL JAR:\n" + implJar.toString(true));

    final ResourceAdapterArchive rar = ShrinkWrap.create(ResourceAdapterArchive.class,"connector-sample-ra.rar");
    rar.addAsLibraries(implJar);

    final File raXml = Basedir.basedir("../connector-sample-rar/src/main/rar/META-INF/ra.xml");
    rar.setResourceAdapterXML(raXml);
    System.out.println("RAR:\n" + rar.toString(true));

    final WebArchive webArchive = ShrinkWrap.create(WebArchive.class, "connector-sample-war.war");
    webArchive.addPackage("org.superbiz.application");

    final WebAppDescriptor webAppDescriptor = Descriptors.create(WebAppDescriptor.class);
    webAppDescriptor.version("3.0");

    final File resourcesXml = Basedir.basedir("../connector-sample-war/src/main/webapp/WEB-INF/resources.xml");
    webArchive.addAsWebInfResource(resourcesXml);
    webArchive.setWebXML(new StringAsset(webAppDescriptor.exportAsString()));
    webArchive.addAsWebInfResource(resourcesXml);
    webArchive.addAsWebInfResource(new StringAsset("<beans/>"), "beans.xml");
    System.out.println("Webapp:\n" + webArchive.toString(true));

    final EnterpriseArchive enterpriseArchive = ShrinkWrap.create(EnterpriseArchive.class, "connector-sample.ear");
    enterpriseArchive.addAsLibraries(apiJar);
    enterpriseArchive.addAsModule(rar);
    enterpriseArchive.addAsModule(webArchive);

    ApplicationDescriptor applicationXml = Descriptors.create(ApplicationDescriptor.class);
    applicationXml.displayName("connector-sample-ear");
    applicationXml.createModule()
            .getOrCreateWeb()
                .webUri("connector-sample-war.war")
                .contextRoot("/sample")
            .up().up()
            .createModule().connector("connector-sample-ra.rar")
            .up().libraryDirectory("lib");

    enterpriseArchive.setApplicationXML(new StringAsset(applicationXml.exportAsString()));
    System.out.println(enterpriseArchive.toString(true));

    return enterpriseArchive;
}
 
Example 20
protected void handleWebArchive(WebArchive war) {
    handleWebArchiveInternal(war);
    war.addAsWebInfResource("test-contexts.properties", "classes/test-contexts.properties");
}