Search in sources :

Example 31 with WebAppDescriptor

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

the class DeploymentFactory method createDeploymentContext.

private static DeploymentContext createDeploymentContext(GatewayConfig config, String archivePath, Topology topology, Map<String, List<ProviderDeploymentContributor>> providers) {
    archivePath = Urls.encode(archivePath);
    WebArchive webArchive = ShrinkWrap.create(WebArchive.class, archivePath);
    WebAppDescriptor webAppDesc = Descriptors.create(WebAppDescriptor.class);
    GatewayDescriptor gateway = GatewayDescriptorFactory.create();
    DeploymentContext context = new DeploymentContextImpl(config, topology, gateway, webArchive, webAppDesc, providers);
    return context;
}
Also used : WebAppDescriptor(org.jboss.shrinkwrap.descriptor.api.webapp30.WebAppDescriptor) GatewayDescriptor(org.apache.knox.gateway.descriptor.GatewayDescriptor) WebArchive(org.jboss.shrinkwrap.api.spec.WebArchive)

Example 32 with WebAppDescriptor

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

the class DeploymentFactory method finalize.

private static void finalize(DeploymentContext context, Map<String, List<ProviderDeploymentContributor>> providers, Map<String, List<ServiceDeploymentContributor>> services, Map.Entry<String, ServiceDeploymentContributor> application) {
    try {
        // Write the gateway descriptor (gateway.xml) into the war.
        StringWriter writer = new StringWriter();
        GatewayDescriptorFactory.store(context.getGatewayDescriptor(), "xml", writer);
        context.getWebArchive().addAsWebInfResource(new StringAsset(writer.toString()), GatewayServlet.GATEWAY_DESCRIPTOR_LOCATION_DEFAULT);
        // Set the location of the gateway descriptor as a servlet init param.
        if (application == null) {
            String servletName = context.getTopology().getName() + SERVLET_NAME_SUFFIX;
            ServletType<WebAppDescriptor> servlet = findServlet(context, servletName);
            // Coverity CID 1352314
            if (servlet == null) {
                throw new DeploymentException("Missing servlet " + servletName);
            } else {
                servlet.createInitParam().paramName(GatewayServlet.GATEWAY_DESCRIPTOR_LOCATION_PARAM).paramValue("/WEB-INF/" + GatewayServlet.GATEWAY_DESCRIPTOR_LOCATION_DEFAULT);
            }
        } else {
            String servletName = context.getTopology().getName() + FILTER_NAME_SUFFIX;
            FilterType<WebAppDescriptor> filter = findFilter(context, servletName);
            // Coverity CID 1352313
            if (filter == null) {
                throw new DeploymentException("Missing filter " + servletName);
            } else {
                filter.createInitParam().paramName(GatewayServlet.GATEWAY_DESCRIPTOR_LOCATION_PARAM).paramValue("/WEB-INF/" + GatewayServlet.GATEWAY_DESCRIPTOR_LOCATION_DEFAULT);
            }
        }
        if (gatewayServices != null) {
            gatewayServices.finalizeContribution(context);
        }
        finalizeProviders(context, providers);
        finalizeServices(context, services);
        finalizeApplications(context, application);
        writeDeploymentDescriptor(context, application != null);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
Also used : WebAppDescriptor(org.jboss.shrinkwrap.descriptor.api.webapp30.WebAppDescriptor) StringAsset(org.jboss.shrinkwrap.api.asset.StringAsset) StringWriter(java.io.StringWriter) IOException(java.io.IOException)

Example 33 with WebAppDescriptor

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

the class DeploymentFactory method initialize.

private static void initialize(DeploymentContext context, Map<String, List<ProviderDeploymentContributor>> providers, Map<String, List<ServiceDeploymentContributor>> services, Map.Entry<String, ServiceDeploymentContributor> applications) {
    WebAppDescriptor wad = context.getWebAppDescriptor();
    String topoName = context.getTopology().getName();
    if (applications == null) {
        String servletName = topoName + SERVLET_NAME_SUFFIX;
        wad.createServlet().servletName(servletName).servletClass(GatewayServlet.class.getName());
        wad.createServletMapping().servletName(servletName).urlPattern("/*");
    } else {
        String filterName = topoName + FILTER_NAME_SUFFIX;
        wad.createFilter().filterName(filterName).filterClass(GatewayServlet.class.getName());
        wad.createFilterMapping().filterName(filterName).urlPattern("/*");
    }
    if (gatewayServices != null) {
        gatewayServices.initializeContribution(context);
    } else {
        log.gatewayServicesNotInitialized();
    }
    initializeProviders(context, providers);
    initializeServices(context, services);
    initializeApplications(context, applications);
}
Also used : WebAppDescriptor(org.jboss.shrinkwrap.descriptor.api.webapp30.WebAppDescriptor) GatewayServlet(org.apache.knox.gateway.GatewayServlet)

Example 34 with WebAppDescriptor

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

the class HttpSecurityPreparerTest method unsupported_auth_method.

@Test
public void unsupported_auth_method() throws Exception {
    Map<String, Object> deploymentConfig = createConfigStub();
    Map<String, Object> webConfig = findWebConfig(deploymentConfig);
    Map<String, Object> loginConfig = new HashMap<>();
    loginConfig.put("auth-method", "foobar");
    webConfig.put("login-config", loginConfig);
    preparer.deploymentConfigs = deploymentConfig;
    preparer.process();
    WebAppDescriptor webXml = Descriptors.importAs(WebAppDescriptor.class).fromStream(archive.get(WebXmlAsset.NAME).getAsset().openStream());
    assertThat(webXml.getOrCreateLoginConfig().getAuthMethod()).isEqualTo("foobar");
}
Also used : WebAppDescriptor(org.jboss.shrinkwrap.descriptor.api.webapp31.WebAppDescriptor) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 35 with WebAppDescriptor

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

the class HttpSecurityPreparerTest method yaml_parsing_again.

@SuppressWarnings("unchecked")
@Test
public void yaml_parsing_again() throws Exception {
    InputStream in = getClass().getClassLoader().getResourceAsStream("security2.yml");
    assertThat(in).isNotNull().as("security2.yml is null");
    Yaml yaml = new Yaml();
    Map<String, Object> httpConfig = (Map<String, Object>) yaml.load(in);
    preparer.deploymentConfigs = (Map) ((Map) httpConfig.get("swarm")).get("deployment");
    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("/protected");
}
Also used : WebAppDescriptor(org.jboss.shrinkwrap.descriptor.api.webapp31.WebAppDescriptor) InputStream(java.io.InputStream) HashMap(java.util.HashMap) Map(java.util.Map) Yaml(org.yaml.snakeyaml.Yaml) 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