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());
}
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);
}
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;
}
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;
}
}
Aggregations