Fix features for jsp with osgi

This commit is contained in:
Jan Bartel 2016-04-20 17:32:22 +10:00
parent 22d2b251e9
commit 70cca692cc
6 changed files with 86 additions and 108 deletions

View File

@ -62,19 +62,7 @@
<Set name="dumpBeforeStop">false</Set>
<!-- =========================================================== -->
<!-- Update the list of default configuration classes -->
<!-- =========================================================== -->
<Call class="org.eclipse.jetty.webapp.Configurations" name="setServerDefault">
<Arg><Ref refid="Server"/></Arg>
<Call name="add">
<Arg>
<Array type="String">
<Item>org.eclipse.jetty.osgi.boot.OSGiWebInfConfiguration</Item>
</Array>
</Arg>
</Call>
</Call>
<Call class="java.lang.System" name="setProperty">
<Arg>java.naming.factory.initial</Arg>

View File

@ -20,6 +20,7 @@ package org.eclipse.jetty.osgi.boot;
import java.io.File;
import java.net.URL;
import java.util.ArrayList;
import java.util.Dictionary;
import java.util.Enumeration;
import java.util.HashMap;
@ -40,6 +41,7 @@ import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;
import org.eclipse.jetty.util.resource.JarResource;
import org.eclipse.jetty.util.resource.Resource;
import org.eclipse.jetty.webapp.Configuration;
import org.eclipse.jetty.webapp.WebAppContext;
import org.eclipse.jetty.xml.XmlConfiguration;
import org.osgi.framework.Bundle;
@ -57,51 +59,21 @@ public abstract class AbstractWebAppProvider extends AbstractLifeCycle implement
{
private static final Logger LOG = Log.getLogger(AbstractWebAppProvider.class);
/* ------------------------------------------------------------ */
/**
* Check if we should be enabling annotation processing
*
* @return true if the jetty-annotations.jar is present, false otherwise
*/
private static boolean annotationsAvailable()
{
boolean result = false;
try
{
Loader.loadClass(AbstractWebAppProvider.class,"org.eclipse.jetty.annotations.AnnotationConfiguration");
result = true;
LOG.debug("Annotation support detected");
}
catch (ClassNotFoundException e)
{
result = false;
LOG.debug("No annotation support detected");
}
return result;
}
/* ------------------------------------------------------------ */
/**
* Check if jndi is support is present.
*
* @return true if the jetty-jndi.jar is present, false otherwise
*/
private static boolean jndiAvailable()
{
try
{
Loader.loadClass(AbstractWebAppProvider.class, "org.eclipse.jetty.plus.jndi.Resource");
Loader.loadClass(AbstractWebAppProvider.class, "org.eclipse.jetty.plus.webapp.EnvConfiguration");
LOG.debug("JNDI support detected");
return true;
}
catch (ClassNotFoundException e)
{
LOG.debug("No JNDI support detected");
return false;
}
}
public static final String[] CONFIGURATION_CLASSES = {
"org.eclipse.jetty.webapp.FragmentConfiguration",
"org.eclipse.jetty.webapp.JettyWebXmlConfiguration",
"org.eclipse.jetty.webapp.WebXmlConfiguration",
"org.eclipse.jetty.webapp.WebAppConfiguration",
"org.eclipse.jetty.webapp.ServletsConfiguration",
"org.eclipse.jetty.webapp.JspConfiguration",
"org.eclipse.jetty.webapp.JaasConfiguration",
"org.eclipse.jetty.webapp.JndiConfiguration",
"org.eclipse.jetty.webapp.JmxConfiguration",
"org.eclipse.jetty.webapp.WebSocketConfiguration",
"org.eclipse.jetty.osgi.annotations.AnnotationConfiguration",
"org.eclipse.jetty.osgi.boot.OSGiWebInfConfiguration",
"org.eclipse.jetty.osgi.boot.OSGiMetaInfConfiguration"
};
private boolean _parentLoaderPriority;
@ -113,8 +85,7 @@ public abstract class AbstractWebAppProvider extends AbstractLifeCycle implement
private String _tldBundles;
private DeploymentManager _deploymentManager;
private String[] _configurationClasses;
private ServerInstanceWrapper _serverWrapper;
@ -290,18 +261,8 @@ public abstract class AbstractWebAppProvider extends AbstractLifeCycle implement
// Set up what has been configured on the provider
_webApp.setParentLoaderPriority(isParentLoaderPriority());
_webApp.setExtractWAR(isExtract());
_webApp.addConfiguration(new OSGiWebInfConfiguration(),new OSGiMetaInfConfiguration());
if (annotationsAvailable())
_webApp.addConfiguration(new AnnotationConfiguration());
//add in EnvConfiguration and PlusConfiguration just after FragmentConfiguration
if (jndiAvailable())
_webApp.addConfiguration(new EnvConfiguration(),new PlusConfiguration());
if (getDefaultsDescriptor() != null)
_webApp.setDefaultsDescriptor(getDefaultsDescriptor());
//Set up configuration from manifest headers
//extra classpath
String tmp = (String)_properties.get(OSGiWebappConstants.JETTY_EXTRA_CLASSPATH);
@ -346,6 +307,23 @@ public abstract class AbstractWebAppProvider extends AbstractLifeCycle implement
webAppLoader.addClassPath(pathsToTldBundles);
_webApp.setClassLoader(webAppLoader);
//set up the configurations appropriate for osgi
for (String classname:CONFIGURATION_CLASSES)
{
try
{
_webApp.addConfiguration((Configuration)(Thread.currentThread().getContextClassLoader().loadClass(classname).newInstance()));
// if (LOG.isDebugEnabled())
LOG.info("Using Configuration {}", classname);
}
catch (ClassNotFoundException cnfe)
{
//not present, ignore
// if (LOG.isDebugEnabled())
LOG.info("Ignoring unavailable Configuration {}", classname);
}
}
// apply any META-INF/context.xml file that is found to configure
// the webapp first

View File

@ -92,7 +92,11 @@ public class OSGiMetaInfConfiguration extends MetaInfConfiguration
public void preConfigure(final WebAppContext context) throws Exception
{
super.preConfigure(context);
}
@Override
protected void scanJars(final WebAppContext context) throws Exception
{
//Check to see if there have been any bundle symbolic names added of bundles that should be
//regarded as being on the container classpath, and scanned for fragments, tlds etc etc.
//This can be defined in:
@ -137,6 +141,8 @@ public class OSGiMetaInfConfiguration extends MetaInfConfiguration
{
context.getMetaData().addContainerResource(r);
}
super.scanJars(context);
}
@Override

View File

@ -60,19 +60,6 @@
<Set name="dumpAfterStart">false</Set>
<Set name="dumpBeforeStop">false</Set>
<!-- =========================================================== -->
<!-- Update the list of default configuration classes -->
<!-- =========================================================== -->
<Call class="org.eclipse.jetty.webapp.Configurations" name="setServerDefault">
<Arg><Ref refid="Server"/></Arg>
<Call name="add">
<Arg>
<Array type="String">
<Item>org.eclipse.jetty.osgi.boot.OSGiWebInfConfiguration</Item>
</Array>
</Arg>
</Call>
</Call>
<Call class="java.lang.System" name="setProperty">

View File

@ -46,29 +46,37 @@ public class Configurations extends AbstractList<Configuration>
private static final List<Configuration> __known = new ArrayList<>();
private static final Set<String> __knownByClassName = new HashSet<>();
static
{
ServiceLoader<Configuration> configs = ServiceLoader.load(Configuration.class);
for (Configuration configuration : configs)
{
__known.add(configuration);
__knownByClassName.add(configuration.getClass().getName());
}
sort(__known);
if (LOG.isDebugEnabled())
{
for (Configuration c: __known)
LOG.debug("known {}",c);
}
LOG.debug("Known Configurations {}",__knownByClassName);
}
/**
* @return
*/
public static List<Configuration> getKnown()
{
synchronized (Configurations.class)
{
if (__known.isEmpty())
{
ServiceLoader<Configuration> configs = ServiceLoader.load(Configuration.class);
for (Configuration configuration : configs)
{
__known.add(configuration);
__knownByClassName.add(configuration.getClass().getName());
}
sort(__known);
if (LOG.isDebugEnabled())
{
for (Configuration c: __known)
LOG.debug("known {}",c);
}
LOG.debug("Known Configurations {}",__knownByClassName);
}
}
return __known;
}
/* ------------------------------------------------------------ */
/** Get/Set/Create the server default Configuration ClassList.
* <p>Get the class list from: a Server bean; or the attribute (which can
@ -149,9 +157,12 @@ public class Configurations extends AbstractList<Configuration>
protected static Configuration newConfiguration(String classname)
{
if (!__knownByClassName.contains(classname))
LOG.warn("Unknown configuration {}. Not declared for ServiceLoader!",classname);
if (LOG.isDebugEnabled())
{
if (!__knownByClassName.contains(classname))
LOG.warn("Unknown configuration {}. Not declared for ServiceLoader!",classname);
}
try
{
@SuppressWarnings("unchecked")
@ -300,8 +311,11 @@ public class Configurations extends AbstractList<Configuration>
{
String name=configuration.getClass().getName();
// Is this configuration known?
if (!__knownByClassName.contains(name))
LOG.warn("Unknown configuration {}. Not declared for ServiceLoader!",name);
if (LOG.isDebugEnabled())
{
if (!__knownByClassName.contains(name))
LOG.warn("Unknown configuration {}. Not declared for ServiceLoader!",name);
}
// Do we need to replace any existing configuration?
Class<? extends Configuration> replaces = configuration.replaces();

View File

@ -164,6 +164,12 @@ public class MetaInfConfiguration extends AbstractConfiguration
//No pattern to appy to classes, just add to metadata
context.getMetaData().setWebInfClassesDirs(findClassDirs(context));
scanJars(context);
}
protected void scanJars (WebAppContext context) throws Exception
{
boolean useContainerCache = DEFAULT_USE_CONTAINER_METAINF_CACHE;
Boolean attr = (Boolean)context.getServer().getAttribute(USE_CONTAINER_METAINF_CACHE);
if (attr != null)
@ -185,7 +191,6 @@ public class MetaInfConfiguration extends AbstractConfiguration
scanJars(context, context.getMetaData().getWebInfJars(), false);
}
@Override
public boolean configure(WebAppContext context) throws Exception