use of org.apache.catalina.webresources.StandardRoot in project Synthese_2BIN by TheYoungSensei.
the class Main method main.
public static void main(String[] args) throws Exception {
Tomcat tomcat = new Tomcat();
tomcat.setPort(8080);
StandardContext ctx = (StandardContext) tomcat.addWebapp("/", new File("./web").getAbsolutePath());
WebResourceRoot resources = new StandardRoot(ctx);
ctx.setResources(resources);
tomcat.start();
tomcat.getServer().await();
}
use of org.apache.catalina.webresources.StandardRoot in project tomee by apache.
the class ReloadingLoaderTest method initContext.
@Before
public void initContext() throws LifecycleException {
final OpenEjbConfiguration configuration = new OpenEjbConfiguration();
configuration.facilities = new FacilitiesInfo();
final CoreContainerSystem containerSystem = new CoreContainerSystem(new IvmJndiFactory());
SystemInstance.get().setComponent(OpenEjbConfiguration.class, configuration);
SystemInstance.get().setComponent(ContainerSystem.class, containerSystem);
SystemInstance.get().setComponent(WebAppEnricher.class, new WebAppEnricher() {
@Override
public URL[] enrichment(final ClassLoader webappClassLaoder) {
return new URL[0];
}
});
parentInstance = new AtomicReference<>(ParentClassLoaderFinder.Helper.get());
loader = new TomEEWebappClassLoader(parentInstance.get()) {
@Override
public ClassLoader getInternalParent() {
return parentInstance.get();
}
@Override
protected void clearReferences() {
// no-op: this test should be reworked to support it but in real life a loader is not stopped/started
}
};
loader.init();
final StandardRoot resources = new StandardRoot();
loader.setResources(resources);
resources.setContext(new StandardContext() {
@Override
public String getDocBase() {
final File file = new File("target/foo");
file.mkdirs();
return file.getAbsolutePath();
}
@Override
public String getMBeanKeyProperties() {
return "foo";
}
{
}
});
resources.start();
loader.start();
info = new AppInfo();
info.appId = "test";
context = new AppContext(info.appId, SystemInstance.get(), loader, new IvmContext(), new IvmContext(), true);
containerSystem.addAppContext(context);
final WebContext webDeployment = new WebContext(context);
webDeployment.setId(context.getId());
webDeployment.setClassLoader(loader);
containerSystem.addWebContext(webDeployment);
}
use of org.apache.catalina.webresources.StandardRoot in project tomee by apache.
the class ReloadingLoaderTest method tomcatClassLoaderParentShouldntBeNulAfterAStopStartOtherwiseReloadIsBroken.
@Test
public void tomcatClassLoaderParentShouldntBeNulAfterAStopStartOtherwiseReloadIsBroken() throws Exception {
final CxfRSService server = new CxfRSService();
try {
server.init(new Properties());
server.start();
server.afterApplicationCreated(new AssemblerAfterApplicationCreated(info, context, Collections.<BeanContext>emptyList()));
{
final ClassLoader beforeLoader = SystemInstance.get().getComponent(ContainerSystem.class).getWebContext("test").getClassLoader();
assertSame(loader, beforeLoader);
assertNotNull(beforeLoader);
assertNotNull(Reflections.get(beforeLoader, "parent"));
}
loader.internalStop();
server.undeploy(new AssemblerBeforeApplicationDestroyed(info, context));
{
final URLClassLoader afterLoader = URLClassLoader.class.cast(SystemInstance.get().getComponent(ContainerSystem.class).getWebContext("test").getClassLoader());
assertSame(loader, afterLoader);
assertNotNull(afterLoader);
assertEquals(0, afterLoader.getURLs().length);
assertEquals(LifecycleState.STOPPED, loader.getState());
}
final StandardRoot resources = new StandardRoot();
loader.setResources(resources);
resources.setContext(new StandardContext() {
@Override
public String getDocBase() {
final File file = new File("target/foo");
file.mkdirs();
return file.getAbsolutePath();
}
@Override
public String getMBeanKeyProperties() {
return "foo";
}
{
}
});
resources.start();
loader.start();
// TomcatWebAppBuilder ill catch start event from StandardContext and force a classloader
// Reflections.set(loader, "parent", ParentClassLoaderFinder.Helper.get());
parentInstance.set(ParentClassLoaderFinder.Helper.get());
server.afterApplicationCreated(new AssemblerAfterApplicationCreated(info, context, Collections.<BeanContext>emptyList()));
{
final ClassLoader afterLoader = SystemInstance.get().getComponent(ContainerSystem.class).getWebContext("test").getClassLoader();
assertSame(loader, afterLoader);
assertNotNull(afterLoader);
assertNotNull(Reflections.get(afterLoader, "parent"));
}
server.undeploy(new AssemblerBeforeApplicationDestroyed(info, context));
} finally {
server.stop();
}
}
use of org.apache.catalina.webresources.StandardRoot in project tomee by apache.
the class StandardContextCustomizer method customize.
public void customize(@Observes final LifecycleEvent event) {
final Object data = event.getSource();
if (!StandardContext.class.isInstance(data)) {
return;
}
final StandardContext context = StandardContext.class.cast(data);
final String contextRoot = module.getContextRoot();
final String path = context.getPath();
final boolean rightPath = (path.isEmpty() && contextRoot.equals(path)) || (contextRoot.startsWith("/") ? contextRoot : '/' + contextRoot).equals(path);
if (!rightPath) {
return;
}
switch(event.getType()) {
case Lifecycle.BEFORE_START_EVENT:
final StandardRoot resources = new StandardRoot(context);
resources.setCachingAllowed(config.areWebResourcesCached());
context.setResources(resources);
if (!module.getProperties().containsKey("fakeJarLocation")) {
context.setDocBase(module.getJarLocation());
}
// move last fake folder, tomcat is broken without it so we can't remove it
final List allResources = List.class.cast(Reflections.get(resources, "allResources"));
final Object mainResources = allResources.remove(1);
allResources.add(mainResources);
for (final URL url : module.getScannableUrls()) {
final File file = URLs.toFile(url);
final String absolutePath = file.getAbsolutePath();
if (file.isDirectory()) {
resources.createWebResourceSet(WebResourceRoot.ResourceSetType.CLASSES_JAR, "/WEB-INF/classes", absolutePath, "", "/");
if (new File(file, "META-INF/resources").exists()) {
resources.createWebResourceSet(WebResourceRoot.ResourceSetType.RESOURCE_JAR, "/", absolutePath, "", "/META-INF/resources");
}
} else {
if (absolutePath.endsWith(".jar") || Boolean.getBoolean("tomee.embedded.resources.add-war-as-jar")) {
resources.createWebResourceSet(WebResourceRoot.ResourceSetType.CLASSES_JAR, "/WEB-INF/lib", absolutePath, null, "/");
resources.createWebResourceSet(WebResourceRoot.ResourceSetType.RESOURCE_JAR, "/", url, "/META-INF/resources");
}
// else endsWith .war => ignore
}
}
if (config.getCustomWebResources() != null) {
for (final String web : config.getCustomWebResources()) {
final File file = new File(web);
if (file.isDirectory()) {
try {
resources.createWebResourceSet(WebResourceRoot.ResourceSetType.RESOURCE_JAR, "/", file.toURI().toURL(), "/");
} catch (final MalformedURLException e) {
throw new IllegalArgumentException(e);
}
} else {
Logger.getLogger(StandardContextCustomizer.class.getName()).warning("'" + web + "' is not a directory, ignoring");
}
}
}
if (config.getLoginConfig() != null) {
context.setLoginConfig(config.getLoginConfig().build());
}
for (final SecurityConstaintBuilder sc : config.getSecurityConstraints()) {
context.addConstraint(sc.build());
}
if (config.getWebXml() != null) {
context.getServletContext().setAttribute(Globals.ALT_DD_ATTR, config.getWebXml());
}
if (loader != null) {
context.setLoader(new ProvidedLoader(loader));
}
break;
case Lifecycle.CONFIGURE_START_EVENT:
SystemInstance.get().getComponent(TomcatWebAppBuilder.class).setFinderOnContextConfig(context, module.appModule());
break;
default:
}
}
use of org.apache.catalina.webresources.StandardRoot in project cxf by apache.
the class StatsServer method resourcesFrom.
private static WebResourceRoot resourcesFrom(final Context context, final String path) {
final File additionResources = new File(path);
final WebResourceRoot resources = new StandardRoot(context);
resources.addPreResources(new DirResourceSet(resources, "/", additionResources.getAbsolutePath(), "/"));
return resources;
}
Aggregations