Search in sources :

Example 6 with ResteasyDeployment

use of org.jboss.resteasy.spi.ResteasyDeployment in project keycloak by keycloak.

the class UndertowAppServer method discoverPathAnnotatedClasses.

private ResteasyDeployment discoverPathAnnotatedClasses(WebArchive webArchive) {
    // take all classes from war and add those with @Path annotation to RestSamlApplicationConfig
    Set<Class<?>> classes = webArchive.getContent(archivePath -> archivePath.get().startsWith("/WEB-INF/classes/") && archivePath.get().endsWith(".class")).values().stream().filter(node -> node.getAsset() instanceof ClassAsset).map(node -> ((ClassAsset) node.getAsset()).getSource()).filter(clazz -> clazz.isAnnotationPresent(Path.class)).collect(Collectors.toSet());
    ResteasyDeployment deployment = new ResteasyDeployment();
    deployment.setApplication(new RestSamlApplicationConfig(classes));
    return deployment;
}
Also used : Servlet(org.jboss.arquillian.container.spi.client.protocol.metadata.Servlet) ServletException(javax.servlet.ServletException) ProtocolMetaData(org.jboss.arquillian.container.spi.client.protocol.metadata.ProtocolMetaData) DeployableContainer(org.jboss.arquillian.container.spi.client.container.DeployableContainer) UndertowWarClassLoader(org.keycloak.testsuite.utils.undertow.UndertowWarClassLoader) Logger(org.jboss.logging.Logger) Path(javax.ws.rs.Path) Application(javax.ws.rs.core.Application) Node(org.jboss.shrinkwrap.api.Node) ServletInfo(io.undertow.servlet.api.ServletInfo) Undertow(io.undertow.Undertow) PathHandler(io.undertow.server.handlers.PathHandler) UndertowContainerConfiguration(org.arquillian.undertow.UndertowContainerConfiguration) Charset(java.nio.charset.Charset) HTTPContext(org.jboss.arquillian.container.spi.client.protocol.metadata.HTTPContext) ResteasyDeployment(org.jboss.resteasy.spi.ResteasyDeployment) Map(java.util.Map) UndertowJaxrsServer(org.jboss.resteasy.plugins.server.undertow.UndertowJaxrsServer) UndertowWebArchive(org.jboss.shrinkwrap.undertow.api.UndertowWebArchive) WebArchive(org.jboss.shrinkwrap.api.spec.WebArchive) LifecycleException(org.jboss.arquillian.container.spi.client.container.LifecycleException) ClassAsset(org.jboss.shrinkwrap.api.asset.ClassAsset) Collection(java.util.Collection) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ProtocolDescription(org.jboss.arquillian.container.spi.client.protocol.ProtocolDescription) Set(java.util.Set) IOException(java.io.IOException) FileUtils(org.apache.commons.io.FileUtils) Archive(org.jboss.shrinkwrap.api.Archive) ServletContainer(io.undertow.servlet.api.ServletContainer) Field(java.lang.reflect.Field) DeploymentManager(io.undertow.servlet.api.DeploymentManager) Collectors(java.util.stream.Collectors) File(java.io.File) RestSamlApplicationConfig(org.keycloak.testsuite.arquillian.undertow.saml.util.RestSamlApplicationConfig) IOUtils(org.apache.commons.io.IOUtils) Descriptor(org.jboss.shrinkwrap.descriptor.api.Descriptor) Optional(java.util.Optional) DeploymentInfo(io.undertow.servlet.api.DeploymentInfo) DeploymentException(org.jboss.arquillian.container.spi.client.container.DeploymentException) Reflections(org.keycloak.common.util.reflections.Reflections) UndertowDeployerHelper(org.keycloak.testsuite.utils.undertow.UndertowDeployerHelper) InputStream(java.io.InputStream) ResteasyDeployment(org.jboss.resteasy.spi.ResteasyDeployment) ClassAsset(org.jboss.shrinkwrap.api.asset.ClassAsset) RestSamlApplicationConfig(org.keycloak.testsuite.arquillian.undertow.saml.util.RestSamlApplicationConfig)

Example 7 with ResteasyDeployment

use of org.jboss.resteasy.spi.ResteasyDeployment in project keycloak by keycloak.

the class UndertowAppServer method deploy.

@Override
public ProtocolMetaData deploy(Archive<?> archive) throws DeploymentException {
    log.info("Deploying archive " + archive.getName());
    // Remove jsps
    // My Intellij and Terminal stores tmp directory in this property
    String ioTMPDir = System.getProperty("java.io.tmpdir", "");
    if (!ioTMPDir.isEmpty()) {
        ioTMPDir = ioTMPDir.endsWith("/") ? ioTMPDir : ioTMPDir + "/";
        File tmpUndertowJSPDirectory = new File(ioTMPDir + "org/apache/jsp");
        if (tmpUndertowJSPDirectory.exists()) {
            try {
                FileUtils.deleteDirectory(tmpUndertowJSPDirectory);
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
    DeploymentInfo di;
    if (archive instanceof UndertowWebArchive) {
        di = ((UndertowWebArchive) archive).getDeploymentInfo();
    } else if (archive instanceof WebArchive) {
        WebArchive webArchive = (WebArchive) archive;
        Optional<Node> applicationClassNode = archive.getContent(archivePath -> archivePath.get().startsWith("/WEB-INF/classes/") && archivePath.get().endsWith("Application.class")).values().stream().findFirst();
        if (isJaxrsApp(webArchive)) {
            di = new UndertowDeployerHelper().getDeploymentInfo(configuration, webArchive, undertow.undertowDeployment(discoverPathAnnotatedClasses(webArchive)));
        } else if (applicationClassNode.isPresent()) {
            String applicationPath = applicationClassNode.get().getPath().get();
            ResteasyDeployment deployment = new ResteasyDeployment();
            deployment.setApplicationClass(extractClassName(applicationPath));
            di = new UndertowDeployerHelper().getDeploymentInfo(configuration, (WebArchive) archive, undertow.undertowDeployment(deployment));
        } else {
            di = new UndertowDeployerHelper().getDeploymentInfo(configuration, webArchive);
        }
    } else {
        throw new IllegalArgumentException("UndertowContainer only supports UndertowWebArchive or WebArchive.");
    }
    if ("ROOT.war".equals(archive.getName())) {
        di.setContextPath("/");
    }
    ClassLoader parentCl = Thread.currentThread().getContextClassLoader();
    UndertowWarClassLoader classLoader = new UndertowWarClassLoader(parentCl, archive);
    Thread.currentThread().setContextClassLoader(classLoader);
    try {
        undertow.deploy(di);
    } finally {
        Thread.currentThread().setContextClassLoader(parentCl);
    }
    deployedArchivesToContextPath.put(archive.getName(), di.getContextPath());
    return new ProtocolMetaData().addContext(createHttpContextForDeploymentInfo(di));
}
Also used : Optional(java.util.Optional) UndertowWebArchive(org.jboss.shrinkwrap.undertow.api.UndertowWebArchive) WebArchive(org.jboss.shrinkwrap.api.spec.WebArchive) UndertowWebArchive(org.jboss.shrinkwrap.undertow.api.UndertowWebArchive) IOException(java.io.IOException) ResteasyDeployment(org.jboss.resteasy.spi.ResteasyDeployment) UndertowWarClassLoader(org.keycloak.testsuite.utils.undertow.UndertowWarClassLoader) UndertowWarClassLoader(org.keycloak.testsuite.utils.undertow.UndertowWarClassLoader) ProtocolMetaData(org.jboss.arquillian.container.spi.client.protocol.metadata.ProtocolMetaData) DeploymentInfo(io.undertow.servlet.api.DeploymentInfo) File(java.io.File) UndertowDeployerHelper(org.keycloak.testsuite.utils.undertow.UndertowDeployerHelper)

Example 8 with ResteasyDeployment

use of org.jboss.resteasy.spi.ResteasyDeployment in project keycloak by keycloak.

the class JettyAppServer method addRestEasyServlet.

private void addRestEasyServlet(WebArchive archive, WebAppContext webAppContext) {
    log.debug("Starting Resteasy deployment");
    boolean addServlet = true;
    ServletHolder resteasyServlet = new ServletHolder("javax.ws.rs.core.Application", new HttpServlet30Dispatcher());
    String jaxrsApplication = getJaxRsApplication(archive);
    Set<Class<?>> pathAnnotatedClasses = getPathAnnotatedClasses(archive);
    if (jaxrsApplication != null) {
        log.debug("App has an Application.class: " + jaxrsApplication);
        resteasyServlet.setInitParameter("javax.ws.rs.Application", jaxrsApplication);
    } else if (!pathAnnotatedClasses.isEmpty()) {
        log.debug("App has @Path annotated classes: " + pathAnnotatedClasses);
        ResteasyDeployment deployment = new ResteasyDeployment();
        deployment.setApplication(new RestSamlApplicationConfig(pathAnnotatedClasses));
        webAppContext.setAttribute(ResteasyDeployment.class.getName(), deployment);
    } else {
        log.debug("An application doesn't have Application.class, nor @Path annotated classes. Skipping Resteasy initialization.");
        addServlet = false;
    }
    if (addServlet) {
        // this should be /* in general. However Jetty 9.2 (this is bug specific to this version),
        // can not merge two instances of javax.ws.rs.Application together (one from web.xml
        // and the other one added here). In 9.1 and 9.4 this works fine.
        // Once we stop supporting 9.2, this should replaced with /* and this comment should be removed.
        webAppContext.addServlet(resteasyServlet, "/");
    }
    log.debug("Finished Resteasy deployment");
}
Also used : ResteasyDeployment(org.jboss.resteasy.spi.ResteasyDeployment) ServletHolder(org.eclipse.jetty.servlet.ServletHolder) HttpServlet30Dispatcher(org.jboss.resteasy.plugins.server.servlet.HttpServlet30Dispatcher) RestSamlApplicationConfig(org.keycloak.testsuite.arquillian.jetty.saml.util.RestSamlApplicationConfig)

Example 9 with ResteasyDeployment

use of org.jboss.resteasy.spi.ResteasyDeployment in project narayana by jbosstm.

the class VolatileParticipantResourceTestCase method beforeClass.

@BeforeClass
public static void beforeClass() {
    List<String> resourceClasses = new ArrayList<String>();
    resourceClasses.add("org.jboss.narayana.rest.integration.VolatileParticipantResource");
    ResteasyDeployment resteasyDeployment = new ResteasyDeployment();
    resteasyDeployment.setResourceClasses(resourceClasses);
    NETTY = new NettyJaxrsServer();
    NETTY.setDeployment(resteasyDeployment);
    NETTY.setPort(TestPortProvider.getPort());
    NETTY.start();
}
Also used : ResteasyDeployment(org.jboss.resteasy.spi.ResteasyDeployment) NettyJaxrsServer(org.jboss.resteasy.plugins.server.netty.NettyJaxrsServer) ArrayList(java.util.ArrayList) BeforeClass(org.junit.BeforeClass)

Example 10 with ResteasyDeployment

use of org.jboss.resteasy.spi.ResteasyDeployment in project indy by Commonjava.

the class IndyDeployment method getDeployment.

public DeploymentInfo getDeployment(final String contextRoot) {
    final ResteasyDeployment deployment = new ResteasyDeployment();
    Application application = new Application() {

        public Set<Class<?>> getClasses() {
            return classes;
        }
    };
    deployment.setApplication(application);
    deployment.setInjectorFactoryClass(CdiInjectorFactoryImpl.class.getName());
    final ServletInfo resteasyServlet = Servlets.servlet("REST", HttpServlet30Dispatcher.class).setAsyncSupported(true).setLoadOnStartup(1).addMapping("/api*").addMapping("/api/*").addMapping("/api-docs*").addMapping("/api-docs/*");
    final FilterInfo slashTolerationFilter = Servlets.filter("SlashToleration", SlashTolerationFilter.class, new ImmediateInstanceFactory<>(this.slashTolerationFilter));
    final FilterInfo traceFilter = Servlets.filter("O11yphant-Trace", TraceFilter.class, new ImmediateInstanceFactory<>(this.traceFilter));
    final FilterInfo threadContextFilter = Servlets.filter("ThreadContext Management", ThreadContextFilter.class, new ImmediateInstanceFactory<>(this.threadContextFilter));
    final FilterInfo goldenSignalsFilter = Servlets.filter("Golden-Signals", GoldenSignalsFilter.class, new ImmediateInstanceFactory<>(this.goldenSignalsFilter));
    final FilterInfo resourceManagementFilter = Servlets.filter("Naming and Resource Management", ResourceManagementFilter.class, new ImmediateInstanceFactory<ResourceManagementFilter>(this.resourceManagementFilter));
    final FilterInfo apiVersioningFilter = Servlets.filter("ApiVersioning", ApiVersioningFilter.class, new ImmediateInstanceFactory<ApiVersioningFilter>(this.apiVersioningFilter));
    final DeploymentInfo di = new DeploymentInfo().addListener(Servlets.listener(RequestScopeListener.class)).setContextPath(contextRoot).addServletContextAttribute(ResteasyDeployment.class.getName(), deployment).addServlet(resteasyServlet).addFilter(apiVersioningFilter).addFilterServletNameMapping(apiVersioningFilter.getName(), resteasyServlet.getName(), DispatcherType.REQUEST).addFilter(slashTolerationFilter).addFilterServletNameMapping(slashTolerationFilter.getName(), resteasyServlet.getName(), DispatcherType.REQUEST).addFilter(threadContextFilter).addFilterUrlMapping(threadContextFilter.getName(), "/api/*", DispatcherType.REQUEST).addFilter(traceFilter).addFilterUrlMapping(traceFilter.getName(), "/api/*", DispatcherType.REQUEST).addFilter(goldenSignalsFilter).addFilterUrlMapping(goldenSignalsFilter.getName(), "/api/folo/*", DispatcherType.REQUEST).addFilterUrlMapping(goldenSignalsFilter.getName(), "/api/content/*", DispatcherType.REQUEST).addFilterUrlMapping(goldenSignalsFilter.getName(), "/api/promotion/*", DispatcherType.REQUEST).addFilterUrlMapping(goldenSignalsFilter.getName(), "/api/admin/stores/*", DispatcherType.REQUEST).addFilterUrlMapping(goldenSignalsFilter.getName(), "/api/browse/*", DispatcherType.REQUEST).addFilterUrlMapping(goldenSignalsFilter.getName(), "/api/remote/*", DispatcherType.REQUEST).addFilterUrlMapping(goldenSignalsFilter.getName(), "/api/hosted/*", DispatcherType.REQUEST).addFilterUrlMapping(goldenSignalsFilter.getName(), "/api/group/*", DispatcherType.REQUEST).addFilter(resourceManagementFilter).addFilterUrlMapping(resourceManagementFilter.getName(), "/api/*", DispatcherType.REQUEST).setDeploymentName("Indy").setClassLoader(ClassLoader.getSystemClassLoader());
    if (deploymentProviders != null) {
        DeploymentInfoUtils.mergeFromProviders(di, deploymentProviders, contextRoot, application);
    }
    if (uiConfiguration.getEnabled()) {
        // Add UI servlet at the end so its mappings don't obscure any from add-ons.
        final ServletInfo uiServlet = Servlets.servlet("UI", UIServlet.class).setAsyncSupported(true).setLoadOnStartup(99).addMappings(UIServlet.PATHS);
        uiServlet.setInstanceFactory(new ImmediateInstanceFactory<Servlet>(ui));
        di.addServlet(uiServlet);
    }
    return di;
}
Also used : ServletInfo(io.undertow.servlet.api.ServletInfo) ResteasyDeployment(org.jboss.resteasy.spi.ResteasyDeployment) Servlet(javax.servlet.Servlet) UIServlet(org.commonjava.indy.bind.jaxrs.ui.UIServlet) RequestScopeListener(org.commonjava.indy.bind.jaxrs.util.RequestScopeListener) UIServlet(org.commonjava.indy.bind.jaxrs.ui.UIServlet) DeploymentInfo(io.undertow.servlet.api.DeploymentInfo) Application(javax.ws.rs.core.Application) FilterInfo(io.undertow.servlet.api.FilterInfo) CdiInjectorFactoryImpl(org.commonjava.indy.bind.jaxrs.util.CdiInjectorFactoryImpl)

Aggregations

ResteasyDeployment (org.jboss.resteasy.spi.ResteasyDeployment)24 DeploymentInfo (io.undertow.servlet.api.DeploymentInfo)15 ServletInfo (io.undertow.servlet.api.ServletInfo)10 HttpServlet30Dispatcher (org.jboss.resteasy.plugins.server.servlet.HttpServlet30Dispatcher)7 HttpString (io.undertow.util.HttpString)4 Application (javax.ws.rs.core.Application)4 FilterInfo (io.undertow.servlet.api.FilterInfo)3 IOException (java.io.IOException)3 Container (org.openremote.container.Container)3 JacksonConfig (org.openremote.container.json.JacksonConfig)3 HttpHandler (io.undertow.server.HttpHandler)2 PathHandler (io.undertow.server.handlers.PathHandler)2 Servlets (io.undertow.servlet.Servlets)2 DefaultServletConfig (io.undertow.servlet.api.DefaultServletConfig)2 DeploymentManager (io.undertow.servlet.api.DeploymentManager)2 InstanceHandle (io.undertow.servlet.api.InstanceHandle)2 File (java.io.File)2 Map (java.util.Map)2 Optional (java.util.Optional)2 Filter (javax.servlet.Filter)2