use of org.apache.catalina.webresources.StandardRoot in project joinfaces by joinfaces.
the class JsfTomcatApplicationListenerIT method customize.
@Test
public void customize() {
Context standardContext = mock(Context.class);
StandardRoot webResourceRoot = new StandardRoot(standardContext);
Mockito.when(standardContext.getResources()).thenReturn(webResourceRoot);
Mockito.when(standardContext.getAddWebinfClassesResources()).thenReturn(Boolean.FALSE);
JsfTomcatContextCustomizer jsfTomcatContextCustomizer = new JsfTomcatContextCustomizer();
jsfTomcatContextCustomizer.customize(standardContext);
JsfTomcatApplicationListener jsfTomcatApplicationListener = new JsfTomcatApplicationListener(jsfTomcatContextCustomizer.getContext());
jsfTomcatApplicationListener.onApplicationEvent(mock(ApplicationReadyEvent.class));
assertThat(webResourceRoot.getPostResources().length).isGreaterThanOrEqualTo(9);
}
use of org.apache.catalina.webresources.StandardRoot in project joinfaces by joinfaces.
the class JsfTomcatApplicationListenerIT method customizeTargetTestClasses.
@Test
public void customizeTargetTestClasses() {
Context standardContext = mock(Context.class);
StandardRoot webResourceRoot = new StandardRoot(standardContext);
Mockito.when(standardContext.getResources()).thenReturn(webResourceRoot);
Mockito.when(standardContext.getAddWebinfClassesResources()).thenReturn(Boolean.FALSE);
String absolutePath = new File("").getAbsolutePath();
String internalPath = METAINF_RESOURCES;
String targetTestClassesBase = absolutePath + "/" + "target/test-classes";
File testClassesResources = new File(targetTestClassesBase + internalPath);
if (!testClassesResources.mkdirs()) {
throw new RuntimeException("Could not create dir: " + testClassesResources.toString());
}
JsfTomcatContextCustomizer jsfTomcatContextCustomizer = new JsfTomcatContextCustomizer();
jsfTomcatContextCustomizer.customize(standardContext);
JsfTomcatApplicationListener jsfTomcatApplicationListener = new JsfTomcatApplicationListener(jsfTomcatContextCustomizer.getContext());
jsfTomcatApplicationListener.onApplicationEvent(mock(ApplicationReadyEvent.class));
if (!testClassesResources.delete()) {
throw new RuntimeException("Could not delete dir: " + testClassesResources.toString());
}
assertThat(webResourceRoot.getPostResources().length).isGreaterThanOrEqualTo(10);
}
use of org.apache.catalina.webresources.StandardRoot in project ofbiz-framework by apache.
the class CatalinaContainer method prepareContext.
private StandardContext prepareContext(Host host, ContainerConfig.Configuration configuration, ComponentConfig.WebappInfo appInfo, Property clusterProp) throws ContainerException {
StandardContext context = new StandardContext();
Tomcat.initWebappDefaults(context);
String location = getWebappRootLocation(appInfo);
boolean contextIsDistributable = isContextDistributable(configuration, location);
context.setParent(host);
context.setDocBase(location);
context.setPath(getWebappMountPoint(appInfo));
context.addLifecycleListener(new ContextConfig());
context.setJ2EEApplication("OFBiz");
context.setJ2EEServer("OFBiz Container");
context.setLoader(new WebappLoader(Thread.currentThread().getContextClassLoader()));
context.setDisplayName(appInfo.name);
context.setDocBase(location);
context.setReloadable(ContainerConfig.getPropertyValue(configuration, "apps-context-reloadable", false));
context.setDistributable(contextIsDistributable);
context.setCrossContext(ContainerConfig.getPropertyValue(configuration, "apps-cross-context", true));
context.setPrivileged(appInfo.privileged);
context.getServletContext().setAttribute("_serverId", appInfo.server);
context.getServletContext().setAttribute("componentName", appInfo.componentConfig.getComponentName());
if (clusterProp != null && contextIsDistributable) {
context.setManager(prepareClusterManager(clusterProp));
}
StandardRoot resources = new StandardRoot(context);
resources.setAllowLinking(true);
context.setResources(resources);
JarScanner jarScanner = context.getJarScanner();
if (jarScanner instanceof StandardJarScanner) {
StandardJarScanner standardJarScanner = (StandardJarScanner) jarScanner;
standardJarScanner.setJarScanFilter(new FilterJars());
standardJarScanner.setScanClassPath(true);
}
Map<String, String> initParameters = appInfo.getInitParameters();
// request dumper filter
if ("true".equals(initParameters.get("enableRequestDump"))) {
FilterDef requestDumperFilterDef = new FilterDef();
requestDumperFilterDef.setFilterClass(RequestDumperFilter.class.getName());
requestDumperFilterDef.setFilterName("RequestDumper");
context.addFilterDef(requestDumperFilterDef);
FilterMap requestDumperFilterMap = new FilterMap();
requestDumperFilterMap.setFilterName("RequestDumper");
requestDumperFilterMap.addURLPattern("*");
context.addFilterMap(requestDumperFilterMap);
}
// set the init parameters
initParameters.entrySet().forEach(entry -> context.addParameter(entry.getKey(), entry.getValue()));
return context;
}
use of org.apache.catalina.webresources.StandardRoot in project kontraktor by RuedigerMoeller.
the class TomcatEmbeddedMain method main.
public static void main(String[] args) throws Exception {
String webappDirLocation = "src/main/webapp/";
Tomcat tomcat = new Tomcat();
if (!new File(webappDirLocation + "client/index.html").exists()) {
System.out.println("Please run with working dir: '[..]examples/servlet");
System.exit(-1);
}
// The port that we should run on can be set into an environment variable
// Look for that variable and default to 8080 if it isn't there.
String webPort = System.getenv("PORT");
if (webPort == null || webPort.isEmpty()) {
webPort = "8080";
}
tomcat.setPort(Integer.valueOf(webPort));
StandardContext ctx = (StandardContext) tomcat.addWebapp("", new File(webappDirLocation).getAbsolutePath());
System.out.println("configuring app with basedir: " + new File("./" + webappDirLocation).getAbsolutePath());
// Declare an alternative location for your "WEB-INF/classes" dir
// Servlet 3.0 annotation will work
File additionWebInfClasses = new File("target/classes");
WebResourceRoot resources = new StandardRoot(ctx);
resources.addPreResources(new DirResourceSet(resources, "/WEB-INF/classes", additionWebInfClasses.getAbsolutePath(), "/"));
ctx.setResources(resources);
tomcat.start();
tomcat.getServer().await();
}
use of org.apache.catalina.webresources.StandardRoot in project component-runtime by Talend.
the class EnhancedCli method run.
@Override
public void run() {
try {
try (final Meecrowave meecrowave = new Meecrowave(create(args))) {
this.instance = meecrowave;
meecrowave.start();
meecrowave.deployClasspath(new Meecrowave.DeploymentMeta("", null, stdCtx -> {
stdCtx.setResources(new StandardRoot() {
@Override
protected void registerURLStreamHandlerFactory() {
// no-op: not supported into OSGi since there is already one and it must set a
// single time
}
});
}));
doWait(meecrowave, null);
}
} catch (final Exception e) {
throw new IllegalStateException(e);
}
}
Aggregations