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