Search in sources :

Example 16 with ProtocolMetaData

use of org.jboss.arquillian.container.spi.client.protocol.metadata.ProtocolMetaData in project wildfly-swarm by wildfly-swarm.

the class WildFlySwarmContainer method deploy.

@Override
public synchronized ProtocolMetaData deploy(Archive<?> archive) throws DeploymentException {
    StartupTimeout startupTimeout = this.testClass.getAnnotation(StartupTimeout.class);
    if (startupTimeout != null) {
        setTimeout(startupTimeout.value());
    }
    this.delegateContainer = new UberjarSimpleContainer(this.containerContext.get(), this.deploymentContext.get(), this.testClass);
    try {
        this.delegateContainer.setJavaVmArguments(this.getJavaVmArguments()).requestedMavenArtifacts(this.requestedMavenArtifacts).start(archive);
        // start wants to connect to the remote container, which isn't up until now, so
        // we override start above and call it here instead
        super.start();
        ProtocolMetaData metaData = new ProtocolMetaData();
        metaData.addContext(createDeploymentContext(archive.getId()));
        return metaData;
    } catch (Throwable e) {
        if (e instanceof LifecycleException) {
            e = e.getCause();
        }
        throw new DeploymentException(e.getMessage(), e);
    }
}
Also used : LifecycleException(org.jboss.arquillian.container.spi.client.container.LifecycleException) DeploymentException(org.jboss.arquillian.container.spi.client.container.DeploymentException) ProtocolMetaData(org.jboss.arquillian.container.spi.client.protocol.metadata.ProtocolMetaData) StartupTimeout(org.wildfly.swarm.arquillian.StartupTimeout)

Example 17 with ProtocolMetaData

use of org.jboss.arquillian.container.spi.client.protocol.metadata.ProtocolMetaData in project keycloak by keycloak.

the class AbstractJettyAppServerTest method testDeployingServletApp.

@Test
public void testDeployingServletApp() throws Exception {
    // given
    WebArchive archive = ShrinkWrap.create(WebArchive.class, "archive.war").addClasses(ExampleServlet.class);
    JettyAppServer server = new JettyAppServer();
    Response responseFromTheApp = null;
    // when
    try {
        server.start();
        ProtocolMetaData data = server.deploy(archive);
        HTTPContext servletContext = data.getContexts(HTTPContext.class).iterator().next();
        URI appURI = servletContext.getServletByName(TEST_SERVLET_NAME).getBaseURI().resolve(TEST_SERVLET_URL_MAPPING);
        Client client = ClientBuilder.newClient();
        responseFromTheApp = client.target(appURI).request().get();
    } finally {
        server.stop();
    }
    // assert
    Assert.assertNotNull(responseFromTheApp);
    Assert.assertEquals(200, responseFromTheApp.getStatus());
}
Also used : HttpServletResponse(javax.servlet.http.HttpServletResponse) Response(javax.ws.rs.core.Response) WebArchive(org.jboss.shrinkwrap.api.spec.WebArchive) HTTPContext(org.jboss.arquillian.container.spi.client.protocol.metadata.HTTPContext) ProtocolMetaData(org.jboss.arquillian.container.spi.client.protocol.metadata.ProtocolMetaData) Client(javax.ws.rs.client.Client) URI(java.net.URI) Test(org.junit.Test)

Example 18 with ProtocolMetaData

use of org.jboss.arquillian.container.spi.client.protocol.metadata.ProtocolMetaData in project keycloak by keycloak.

the class AbstractJettyAppServerTest method testDeployingAndUndeploying.

@Test
public void testDeployingAndUndeploying() throws Exception {
    // given
    WebArchive archive = ShrinkWrap.create(WebArchive.class, "archive.war").addClasses(ExampleRest.class);
    JettyAppServer server = new JettyAppServer();
    Response responseFromTheApp = null;
    // when
    try {
        server.start();
        ProtocolMetaData data = server.deploy(archive);
        HTTPContext servletContext = data.getContexts(HTTPContext.class).iterator().next();
        URI appURI = servletContext.getServlets().get(0).getBaseURI();
        server.undeploy(archive);
        Client client = ClientBuilder.newClient();
        responseFromTheApp = client.target(appURI).request().get();
    } finally {
        server.stop();
    }
    // assert
    Assert.assertNotNull(responseFromTheApp);
    Assert.assertEquals(404, responseFromTheApp.getStatus());
}
Also used : HttpServletResponse(javax.servlet.http.HttpServletResponse) Response(javax.ws.rs.core.Response) WebArchive(org.jboss.shrinkwrap.api.spec.WebArchive) HTTPContext(org.jboss.arquillian.container.spi.client.protocol.metadata.HTTPContext) ProtocolMetaData(org.jboss.arquillian.container.spi.client.protocol.metadata.ProtocolMetaData) Client(javax.ws.rs.client.Client) URI(java.net.URI) Test(org.junit.Test)

Example 19 with ProtocolMetaData

use of org.jboss.arquillian.container.spi.client.protocol.metadata.ProtocolMetaData in project keycloak by keycloak.

the class JettyAppServer method deploy.

@Override
public ProtocolMetaData deploy(Archive<?> archive) throws DeploymentException {
    log.info("Deploying archive " + archive.getName());
    if (!(archive instanceof WebArchive)) {
        throw new IllegalArgumentException("JettyContainer only supports WebArchives.");
    }
    WebArchive webArchive = (WebArchive) archive;
    try {
        KeycloakAdapterApp app = appProvider.createApp(webArchive);
        WebAppContext webAppContext = (WebAppContext) app.getContextHandler();
        addAdditionalConfigurations(webAppContext);
        setContextRoot(webArchive, app, webAppContext);
        if (app.usesOIDCAuthenticator()) {
            addOIDCAuthenticator(webAppContext);
        }
        if (app.usesSAMLAuthenticator()) {
            addSAMLAuthenticator(webAppContext);
        }
        if (app.usesJaxrs()) {
            addRestEasyServlet(webArchive, webAppContext);
        }
        setEmbeddedClassloaderForDeployment(webAppContext);
        deployer.addApp(app);
        deployer.requestAppGoal(app, AppLifeCycle.STARTED);
        deployedApps.put(archive.getId(), app);
        HTTPContext httpContext = new HTTPContext(configuration.getBindAddress(), configuration.getBindHttpPort());
        ServletHandler servletHandler = webAppContext.getServletHandler();
        for (ServletHolder servlet : servletHandler.getServlets()) {
            log.debugf("Servlet context mapping: %s => %s", servlet.getName(), servlet.getContextPath());
            httpContext.add(new Servlet(servlet.getName(), servlet.getContextPath()));
        }
        if (log.isInfoEnabled()) {
            for (ServletMapping mapping : server.getChildHandlerByClass(ServletHandler.class).getServletMappings()) {
                log.debugf("Servlet mapping: %s => %s", mapping.getServletName(), Arrays.toString(mapping.getPathSpecs()));
            }
        }
        return new ProtocolMetaData().addContext(httpContext);
    } catch (Exception e) {
        throw new DeploymentException("Unable to deploy archive", e);
    }
}
Also used : WebAppContext(org.eclipse.jetty.webapp.WebAppContext) ServletMapping(org.eclipse.jetty.servlet.ServletMapping) ServletHandler(org.eclipse.jetty.servlet.ServletHandler) ServletHolder(org.eclipse.jetty.servlet.ServletHolder) WebArchive(org.jboss.shrinkwrap.api.spec.WebArchive) Servlet(org.jboss.arquillian.container.spi.client.protocol.metadata.Servlet) HTTPContext(org.jboss.arquillian.container.spi.client.protocol.metadata.HTTPContext) DeploymentException(org.jboss.arquillian.container.spi.client.container.DeploymentException) ProtocolMetaData(org.jboss.arquillian.container.spi.client.protocol.metadata.ProtocolMetaData) LifecycleException(org.jboss.arquillian.container.spi.client.container.LifecycleException) DeploymentException(org.jboss.arquillian.container.spi.client.container.DeploymentException)

Aggregations

ProtocolMetaData (org.jboss.arquillian.container.spi.client.protocol.metadata.ProtocolMetaData)19 HTTPContext (org.jboss.arquillian.container.spi.client.protocol.metadata.HTTPContext)13 DeploymentException (org.jboss.arquillian.container.spi.client.container.DeploymentException)10 LifecycleException (org.jboss.arquillian.container.spi.client.container.LifecycleException)7 File (java.io.File)6 IOException (java.io.IOException)6 Servlet (org.jboss.arquillian.container.spi.client.protocol.metadata.Servlet)5 WebArchive (org.jboss.shrinkwrap.api.spec.WebArchive)5 NamingException (javax.naming.NamingException)4 URI (java.net.URI)3 HttpServletResponse (javax.servlet.http.HttpServletResponse)3 Client (javax.ws.rs.client.Client)3 Response (javax.ws.rs.core.Response)3 DeploymentInfo (io.undertow.servlet.api.DeploymentInfo)2 Properties (java.util.Properties)2 TestObserver (org.apache.openejb.arquillian.common.TestObserver)2 AppInfo (org.apache.openejb.assembler.classic.AppInfo)2 ZipExporter (org.jboss.shrinkwrap.api.exporter.ZipExporter)2 Test (org.junit.Test)2 UndertowWarClassLoader (org.keycloak.testsuite.utils.undertow.UndertowWarClassLoader)2