Search in sources :

Example 11 with WebAppDescriptor

use of org.jboss.shrinkwrap.descriptor.api.webapp30.WebAppDescriptor in project tomee by apache.

the class DataSourceDefinitionTest method createDeployment.

@Deployment(testable = false)
public static WebArchive createDeployment() {
    WebAppDescriptor descriptor = Descriptors.create(WebAppDescriptor.class).version(WebAppVersionType._3_0).createServlet().servletName(SERVLET_NAME).servletClass(DataSourceServlet.class.getName()).up().createServletMapping().servletName(SERVLET_NAME).urlPattern("/" + TEST_NAME).up();
    WebArchive archive = ShrinkWrap.create(WebArchive.class, TEST_NAME + ".war").addClass(DataSourceDefinitionTest.class).addClass(DataSourceServlet.class).addClass(DataSourceBean.class).addClass(DataSourcePojo.class).addClass(Runner.class).addAsLibraries(JarLocation.jarLocation(Test.class)).addAsWebInfResource(new ClassLoaderAsset(CONTENT_LOCATION_EJB_JAR_XML), RESOURCE_EJB_JAR_XML).setWebXML(new StringAsset(descriptor.exportAsString()));
    return archive;
}
Also used : WebAppDescriptor(org.jboss.shrinkwrap.descriptor.api.webapp30.WebAppDescriptor) Runner(org.apache.openejb.arquillian.tests.Runner) StringAsset(org.jboss.shrinkwrap.api.asset.StringAsset) Test(org.junit.Test) WebArchive(org.jboss.shrinkwrap.api.spec.WebArchive) ClassLoaderAsset(org.jboss.shrinkwrap.api.asset.ClassLoaderAsset) Deployment(org.jboss.arquillian.container.test.api.Deployment)

Example 12 with WebAppDescriptor

use of org.jboss.shrinkwrap.descriptor.api.webapp30.WebAppDescriptor in project tomee by apache.

the class EARTest method createDeployment.

@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;
}
Also used : WebAppDescriptor(org.jboss.shrinkwrap.descriptor.api.webapp30.WebAppDescriptor) EnterpriseArchive(org.jboss.shrinkwrap.api.spec.EnterpriseArchive) StringAsset(org.jboss.shrinkwrap.api.asset.StringAsset) WebArchive(org.jboss.shrinkwrap.api.spec.WebArchive) ResourceAdapterArchive(org.jboss.shrinkwrap.api.spec.ResourceAdapterArchive) File(java.io.File) JavaArchive(org.jboss.shrinkwrap.api.spec.JavaArchive) ApplicationDescriptor(org.jboss.shrinkwrap.descriptor.api.application6.ApplicationDescriptor) Deployment(org.jboss.arquillian.container.test.api.Deployment)

Example 13 with WebAppDescriptor

use of org.jboss.shrinkwrap.descriptor.api.webapp30.WebAppDescriptor in project knox by apache.

the class ShiroDeploymentContributor method contributeProvider.

@Override
public void contributeProvider(DeploymentContext context, Provider provider) {
    // Many filter based authentication mechanisms require a ServletContextListener
    // to be added and the Knox deployment machinery provides the ability to add this
    // through the DeploymentContext.
    // Writing provider specific config out to the war for cluster specific config can be
    // accomplished through the DeploymentContext as well. The JBoss shrinkwrap API can be
    // used to write the asset to the war.
    // add servletContextListener
    context.getWebAppDescriptor().createListener().listenerClass(LISTENER_CLASSNAME);
    // add session timeout
    int st = DEFAULT_SESSION_TIMEOUT;
    SessionConfigType<WebAppDescriptor> sessionConfig = context.getWebAppDescriptor().createSessionConfig();
    Map<String, String> params = provider.getParams();
    String sts = params.get(SESSION_TIMEOUT);
    if (sts != null && sts.trim().length() != 0) {
        st = Integer.parseInt(sts.trim());
    }
    if (st <= 0) {
        // user default session timeout
        st = DEFAULT_SESSION_TIMEOUT;
    }
    sessionConfig.sessionTimeout(st);
    sessionConfig.getOrCreateCookieConfig().httpOnly(true);
    sessionConfig.getOrCreateCookieConfig().secure(true);
    String clusterName = context.getTopology().getName();
    ShiroConfig config = new ShiroConfig(provider, clusterName);
    String configStr = config.toString();
    if (config != null) {
        context.getWebArchive().addAsWebInfResource(new StringAsset(configStr), SHRIO_CONFIG_FILE_NAME);
    }
}
Also used : WebAppDescriptor(org.jboss.shrinkwrap.descriptor.api.webapp30.WebAppDescriptor) StringAsset(org.jboss.shrinkwrap.api.asset.StringAsset)

Example 14 with WebAppDescriptor

use of org.jboss.shrinkwrap.descriptor.api.webapp30.WebAppDescriptor in project wildfly-swarm by wildfly-swarm.

the class HttpSecurityPreparerTest method set_2_security_constraints.

@Test
public void set_2_security_constraints() throws Exception {
    Map<String, Object> deploymentConfig = createConfigStub();
    Map<String, Object> webConfig = findWebConfig(deploymentConfig);
    Map<String, Object> securityConstraint1 = new HashMap<>();
    securityConstraint1.put("url-pattern", "/aaa");
    Map<String, Object> securityConstraint2 = new HashMap<>();
    securityConstraint2.put("url-pattern", "/bbb");
    webConfig.put("security-constraints", Arrays.asList(securityConstraint1, securityConstraint2));
    preparer.deploymentConfigs = deploymentConfig;
    preparer.process();
    WebAppDescriptor webXml = Descriptors.importAs(WebAppDescriptor.class).fromStream(archive.get(WebXmlAsset.NAME).getAsset().openStream());
    assertThat(webXml.getAllSecurityConstraint().size()).isEqualTo(2);
    assertThat(webXml.getAllSecurityConstraint().get(0).getAllWebResourceCollection().get(0).getAllUrlPattern().get(0)).isEqualTo("/aaa");
    assertThat(webXml.getAllSecurityConstraint().get(1).getAllWebResourceCollection().get(0).getAllUrlPattern().get(0)).isEqualTo("/bbb");
}
Also used : WebAppDescriptor(org.jboss.shrinkwrap.descriptor.api.webapp31.WebAppDescriptor) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 15 with WebAppDescriptor

use of org.jboss.shrinkwrap.descriptor.api.webapp30.WebAppDescriptor in project wildfly-swarm by wildfly-swarm.

the class HttpSecurityPreparerTest method set_1_security_constraint.

@Test
public void set_1_security_constraint() throws Exception {
    Map<String, Object> deploymentConfig = createConfigStub();
    Map<String, Object> webConfig = findWebConfig(deploymentConfig);
    Map<String, Object> securityConstraint = new HashMap<>();
    securityConstraint.put("url-pattern", "/aaa");
    webConfig.put("security-constraints", Collections.singletonList(securityConstraint));
    preparer.deploymentConfigs = deploymentConfig;
    preparer.process();
    WebAppDescriptor webXml = Descriptors.importAs(WebAppDescriptor.class).fromStream(archive.get(WebXmlAsset.NAME).getAsset().openStream());
    assertThat(webXml.getAllSecurityConstraint().size()).isEqualTo(1);
    assertThat(webXml.getAllSecurityConstraint().get(0).getAllWebResourceCollection().get(0).getAllUrlPattern().get(0)).isEqualTo("/aaa");
}
Also used : WebAppDescriptor(org.jboss.shrinkwrap.descriptor.api.webapp31.WebAppDescriptor) HashMap(java.util.HashMap) Test(org.junit.Test)

Aggregations

WebAppDescriptor (org.jboss.shrinkwrap.descriptor.api.webapp30.WebAppDescriptor)28 StringAsset (org.jboss.shrinkwrap.api.asset.StringAsset)26 WebArchive (org.jboss.shrinkwrap.api.spec.WebArchive)25 Deployment (org.jboss.arquillian.container.test.api.Deployment)21 Test (org.junit.Test)14 HashMap (java.util.HashMap)7 Runner (org.apache.openejb.arquillian.tests.Runner)7 WebAppDescriptor (org.jboss.shrinkwrap.descriptor.api.webapp31.WebAppDescriptor)7 ClassLoaderAsset (org.jboss.shrinkwrap.api.asset.ClassLoaderAsset)6 EnterpriseArchive (org.jboss.shrinkwrap.api.spec.EnterpriseArchive)4 JavaArchive (org.jboss.shrinkwrap.api.spec.JavaArchive)4 ResourceAdapterArchive (org.jboss.shrinkwrap.api.spec.ResourceAdapterArchive)4 ApplicationDescriptor (org.jboss.shrinkwrap.descriptor.api.application6.ApplicationDescriptor)4 File (java.io.File)2 InputStream (java.io.InputStream)2 Map (java.util.Map)2 Yaml (org.yaml.snakeyaml.Yaml)2 IOException (java.io.IOException)1 StringWriter (java.io.StringWriter)1 GatewayServlet (org.apache.knox.gateway.GatewayServlet)1