use of org.apache.catalina.Container in project tomee by apache.
the class TomcatWebAppBuilder method ensureMyFacesDontLooseFacesContext.
private void ensureMyFacesDontLooseFacesContext(final StandardContext standardContext) {
for (final Container w : standardContext.findChildren()) {
if (!Wrapper.class.isInstance(w)) {
continue;
}
final Wrapper wrapper = Wrapper.class.cast(w);
if ("FacesServlet".equals(wrapper.getName()) && "javax.faces.webapp.FacesServlet".equals(wrapper.getServletClass())) {
final ClassLoader loader = standardContext.getLoader().getClassLoader();
try {
if (Files.toFile(loader.getResource("javax/faces/webapp/FacesServlet.class")).getName().startsWith("myfaces")) {
loader.loadClass("org.apache.tomee.myfaces.TomEEWorkaroundFacesServlet");
wrapper.setServletClass("org.apache.tomee.myfaces.TomEEWorkaroundFacesServlet");
break;
}
} catch (final Throwable t) {
// not there, not a big deal in most of cases
}
}
}
}
use of org.apache.catalina.Container in project tomee by apache.
the class TomcatWebAppBuilder method manageCluster.
private void manageCluster(final Cluster cluster) {
if (cluster == null || cluster instanceof SimpleTomEETcpCluster) {
return;
}
Cluster current = cluster;
if (cluster instanceof SimpleTcpCluster) {
final Container container = cluster.getContainer();
current = new SimpleTomEETcpCluster((SimpleTcpCluster) cluster);
container.setCluster(current);
}
if (current instanceof CatalinaCluster) {
final CatalinaCluster haCluster = (CatalinaCluster) current;
TomEEClusterListener listener = SystemInstance.get().getComponent(TomEEClusterListener.class);
if (listener == null) {
listener = new TomEEClusterListener();
SystemInstance.get().setComponent(TomEEClusterListener.class, listener);
}
// better to be a singleton
haCluster.addClusterListener(listener);
clusters.add(haCluster);
}
}
use of org.apache.catalina.Container in project tomee by apache.
the class Contexts method getHostname.
public static String getHostname(final StandardContext ctx) {
String hostName = null;
final Container parentHost = ctx.getParent();
if (parentHost != null) {
hostName = parentHost.getName();
}
if ((hostName == null) || (hostName.length() < 1)) {
hostName = "_";
}
return hostName;
}
use of org.apache.catalina.Container in project tomee by apache.
the class Contexts method realWarPath.
public static File realWarPath(final Context standardContext) {
if (standardContext == null) {
return null;
}
final File docBase;
Container container = standardContext;
while (container != null) {
if (container instanceof Host) {
break;
}
container = container.getParent();
}
String baseName = null;
if (standardContext.getDocBase() != null) {
File file = new File(standardContext.getDocBase());
if (!file.isAbsolute()) {
if (container == null) {
docBase = new File(engineBase(standardContext), standardContext.getDocBase());
} else {
final String appBase = ((Host) container).getAppBase();
file = new File(appBase);
if (!file.isAbsolute()) {
file = new File(engineBase(standardContext), appBase);
}
docBase = new File(file, standardContext.getDocBase());
}
} else {
docBase = file;
}
} else {
final String path = standardContext.getPath();
if (path == null) {
throw new IllegalStateException("Can't find docBase");
} else {
baseName = new ContextName(path, standardContext.getWebappVersion()).getBaseName();
docBase = new File(baseName);
}
}
if (!docBase.exists() && baseName != null) {
// for old compatibility, will be removed soon
if (Host.class.isInstance(container)) {
final File file = new File(Host.class.cast(container).getAppBaseFile(), baseName);
if (file.exists()) {
return file;
}
}
return oldRealWarPath(standardContext);
}
final String name = docBase.getName();
if (name.endsWith(".war")) {
final File extracted = new File(docBase.getParentFile(), name.substring(0, name.length() - ".war".length()));
if (extracted.exists()) {
return extracted;
}
}
return docBase;
}
use of org.apache.catalina.Container in project tomee by apache.
the class TomEEMyFacesContainerInitializer method isFacesServletPresent.
private boolean isFacesServletPresent(final ServletContext ctx) {
if (ctx instanceof ApplicationContextFacade) {
try {
final ApplicationContext appCtx = (ApplicationContext) get(ApplicationContextFacade.class, ctx);
final Context tomcatCtx = (Context) get(ApplicationContext.class, appCtx);
if (tomcatCtx instanceof StandardContext) {
final Container[] servlets = tomcatCtx.findChildren();
if (servlets != null) {
for (final Container s : servlets) {
if (s instanceof Wrapper) {
if ("javax.faces.webapp.FacesServlet".equals(((Wrapper) s).getServletClass()) || "Faces Servlet".equals(s.getName())) {
return true;
}
}
}
}
}
} catch (final Exception e) {
// no-op
}
}
return false;
}
Aggregations