Search in sources :

Example 21 with ResteasyDeployment

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

the class ManagerWebService method createApiHandler.

protected HttpHandler createApiHandler(Container container, ResteasyDeployment resteasyDeployment) {
    if (resteasyDeployment == null)
        return null;
    ServletInfo restServlet = Servlets.servlet("RESTEasy Servlet", HttpServlet30Dispatcher.class).setAsyncSupported(true).setLoadOnStartup(1).addMapping("/*");
    DeploymentInfo deploymentInfo = new DeploymentInfo().setDeploymentName("RESTEasy Deployment").setContextPath(API_PATH).addServletContextAttribute(ResteasyDeployment.class.getName(), resteasyDeployment).addServlet(restServlet).setClassLoader(Container.class.getClassLoader());
    IdentityService identityService = container.getService(IdentityService.class);
    if (identityService != null) {
        resteasyDeployment.setSecurityEnabled(true);
    } else {
        throw new RuntimeException("No identity service deployed, can't enable API security");
    }
    return addServletDeployment(container, deploymentInfo, resteasyDeployment.isSecurityEnabled());
}
Also used : ServletInfo(io.undertow.servlet.api.ServletInfo) IdentityService(org.openremote.container.security.IdentityService) ResteasyDeployment(org.jboss.resteasy.spi.ResteasyDeployment) Container(org.openremote.model.Container) HttpServlet30Dispatcher(org.jboss.resteasy.plugins.server.servlet.HttpServlet30Dispatcher) DeploymentInfo(io.undertow.servlet.api.DeploymentInfo)

Example 22 with ResteasyDeployment

use of org.jboss.resteasy.spi.ResteasyDeployment in project motan by weibocom.

the class NettyEndpointFactory method innerCreateServer.

@Override
protected RestServer innerCreateServer(URL url) {
    NettyJaxrsServer server = new NettyJaxrsServer();
    server.setMaxRequestSize(url.getIntParameter(URLParamType.maxContentLength.getName(), URLParamType.maxContentLength.getIntValue()));
    ResteasyDeployment deployment = new ResteasyDeployment();
    server.setDeployment(deployment);
    server.setExecutorThreadCount(url.getIntParameter(URLParamType.maxWorkerThread.getName(), URLParamType.maxWorkerThread.getIntValue()));
    server.setPort(url.getPort());
    server.setRootResourcePath("");
    server.setSecurityDomain(null);
    deployment.setInjectorFactoryClass(RestfulInjectorFactory.class.getName());
    deployment.getProviderClasses().add(RpcExceptionMapper.class.getName());
    return new EmbedRestServer(server);
}
Also used : ResteasyDeployment(org.jboss.resteasy.spi.ResteasyDeployment) NettyJaxrsServer(org.jboss.resteasy.plugins.server.netty.NettyJaxrsServer) RestfulInjectorFactory(com.weibo.api.motan.protocol.restful.support.RestfulInjectorFactory) RpcExceptionMapper(com.weibo.api.motan.protocol.restful.support.RpcExceptionMapper) EmbedRestServer(com.weibo.api.motan.protocol.restful.EmbedRestServer)

Example 23 with ResteasyDeployment

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

the class KeycloakOnUndertow method createAuthServerDeploymentInfo.

private DeploymentInfo createAuthServerDeploymentInfo() {
    ResteasyDeployment deployment = new ResteasyDeployment();
    deployment.setApplicationClass(KeycloakApplication.class.getName());
    // RESTEASY-2034
    deployment.setProperty(ResteasyContextParameters.RESTEASY_DISABLE_HTML_SANITIZER, true);
    // Prevent double gzip encoding of resources
    deployment.getDisabledProviderClasses().add("org.jboss.resteasy.plugins.interceptors.encoding.GZIPEncodingInterceptor");
    DeploymentInfo di = undertow.undertowDeployment(deployment);
    di.setClassLoader(getClass().getClassLoader());
    di.setContextPath("/auth");
    di.setDeploymentName("Keycloak");
    if (configuration.getKeycloakConfigPropertyOverridesMap() != null) {
        try {
            di.addInitParameter(JsonConfigProviderFactory.SERVER_CONTEXT_CONFIG_PROPERTY_OVERRIDES, JsonSerialization.writeValueAsString(configuration.getKeycloakConfigPropertyOverridesMap()));
        } catch (IOException ex) {
            throw new RuntimeException(ex);
        }
    }
    di.setDefaultServletConfig(new DefaultServletConfig(true));
    di.addWelcomePage("theme/keycloak/welcome/resources/index.html");
    // This is needed as in case of clustered undertow, several undertow instances share the same JVM, hence the default
    // way accessing the factory in the UndertowRequestFilter via static reference to KeycloakApplication does not work:
    // There are several KeycloakApplication instances in the JVM with no classloader separation as in a full-blown server.
    InstanceHandle<Filter> filterInstance = new InstanceHandle<Filter>() {

        @Override
        public Filter getInstance() {
            return new UndertowRequestFilter(sessionFactory);
        }

        @Override
        public void release() {
        }
    };
    FilterInfo filter = Servlets.filter("SessionFilter", UndertowRequestFilter.class, () -> filterInstance);
    di.addFilter(filter);
    di.addFilterUrlMapping("SessionFilter", "/*", DispatcherType.REQUEST);
    filter.setAsyncSupported(true);
    return di;
}
Also used : ResteasyDeployment(org.jboss.resteasy.spi.ResteasyDeployment) UndertowRequestFilter(org.keycloak.testsuite.UndertowRequestFilter) KeycloakApplication(org.keycloak.services.resources.KeycloakApplication) Filter(javax.servlet.Filter) UndertowRequestFilter(org.keycloak.testsuite.UndertowRequestFilter) IOException(java.io.IOException) DefaultServletConfig(io.undertow.servlet.api.DefaultServletConfig) InstanceHandle(io.undertow.servlet.api.InstanceHandle) DeploymentInfo(io.undertow.servlet.api.DeploymentInfo) FilterInfo(io.undertow.servlet.api.FilterInfo)

Example 24 with ResteasyDeployment

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

the class KeycloakServer method start.

public void start() throws Throwable {
    long start = System.currentTimeMillis();
    ResteasyDeployment deployment = new ResteasyDeployment();
    deployment.setApplicationClass(KeycloakApplication.class.getName());
    Builder builder = Undertow.builder().addHttpListener(config.getPort(), config.getHost()).setWorkerThreads(config.getWorkerThreads()).setIoThreads(config.getWorkerThreads() / 8);
    if (config.getPortHttps() != -1) {
        builder = builder.addHttpsListener(config.getPortHttps(), config.getHost(), createSSLContext()).setSocketOption(Options.SSL_CLIENT_AUTH_MODE, SslClientAuthMode.REQUESTED);
    }
    server = new UndertowJaxrsServer();
    try {
        server.start(builder);
        DeploymentInfo di = server.undertowDeployment(deployment, "");
        di.setClassLoader(getClass().getClassLoader());
        di.setContextPath("/auth");
        di.setDeploymentName("Keycloak");
        di.setDefaultEncoding("UTF-8");
        di.setDefaultServletConfig(new DefaultServletConfig(true));
        // Note that the ResteasyServlet is configured via server.undertowDeployment(...);
        // KEYCLOAK-14178
        deployment.setProperty(ResteasyContextParameters.RESTEASY_DISABLE_HTML_SANITIZER, true);
        InstanceHandle<Filter> filterInstance = new InstanceHandle<Filter>() {

            @Override
            public Filter getInstance() {
                return new UndertowRequestFilter(sessionFactory);
            }

            @Override
            public void release() {
            }
        };
        FilterInfo filter = Servlets.filter("SessionFilter", UndertowRequestFilter.class, () -> filterInstance);
        filter.setAsyncSupported(true);
        di.addFilter(filter);
        di.addFilterUrlMapping("SessionFilter", "/*", DispatcherType.REQUEST);
        server.deploy(di);
        sessionFactory = KeycloakApplication.getSessionFactory();
        setupDevConfig();
        if (config.getResourcesHome() != null) {
            info("Loading resources from " + config.getResourcesHome());
        }
        info("Started Keycloak (http://" + config.getHost() + ":" + config.getPort() + "/auth" + (config.getPortHttps() > 0 ? ", https://" + config.getHost() + ":" + config.getPortHttps() + "/auth" : "") + ") in " + (System.currentTimeMillis() - start) + " ms\n");
    } catch (RuntimeException e) {
        server.stop();
        throw e;
    }
}
Also used : KeycloakApplication(org.keycloak.services.resources.KeycloakApplication) Builder(io.undertow.Undertow.Builder) ResteasyDeployment(org.jboss.resteasy.spi.ResteasyDeployment) Filter(javax.servlet.Filter) DefaultServletConfig(io.undertow.servlet.api.DefaultServletConfig) InstanceHandle(io.undertow.servlet.api.InstanceHandle) DeploymentInfo(io.undertow.servlet.api.DeploymentInfo) FilterInfo(io.undertow.servlet.api.FilterInfo) UndertowJaxrsServer(org.jboss.resteasy.plugins.server.undertow.UndertowJaxrsServer)

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