Added ability to use a META-INF/jetty-webapp-context.xml file to apply a context configuration file to a webapp.
Replaced more printStackTrace with log calls; more formatting.
This commit is contained in:
parent
50f545b29a
commit
d47d4b15ea
|
@ -349,7 +349,7 @@ public class OSGiAppProvider extends ScanningAppProvider implements AppProvider
|
||||||
}
|
}
|
||||||
catch (IOException e)
|
catch (IOException e)
|
||||||
{
|
{
|
||||||
e.printStackTrace();
|
LOG.warn(e);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -370,11 +370,11 @@ public class OSGiAppProvider extends ScanningAppProvider implements AppProvider
|
||||||
}
|
}
|
||||||
catch (IOException e)
|
catch (IOException e)
|
||||||
{
|
{
|
||||||
e.printStackTrace();
|
LOG.warn(e);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isExtract()
|
public boolean isExtract()
|
||||||
{
|
{
|
||||||
return _extractWars;
|
return _extractWars;
|
||||||
|
|
|
@ -167,18 +167,21 @@ public class DefaultJettyAtJettyHomeHelper {
|
||||||
*/
|
*/
|
||||||
private static String getJettyConfigurationURLs(File jettyhome)
|
private static String getJettyConfigurationURLs(File jettyhome)
|
||||||
{
|
{
|
||||||
String jettyetc = System.getProperty(SYS_PROP_JETTY_ETC_FILES,"etc/jetty.xml");
|
String jettyetc = System.getProperty(SYS_PROP_JETTY_ETC_FILES, "etc/jetty.xml");
|
||||||
StringTokenizer tokenizer = new StringTokenizer(jettyetc,";,", false);
|
StringTokenizer tokenizer = new StringTokenizer(jettyetc, ";,", false);
|
||||||
StringBuilder res = new StringBuilder();
|
StringBuilder res = new StringBuilder();
|
||||||
while (tokenizer.hasMoreTokens())
|
while (tokenizer.hasMoreTokens())
|
||||||
{
|
{
|
||||||
String next = tokenizer.nextToken().trim();
|
String next = tokenizer.nextToken().trim();
|
||||||
if (!next.startsWith("/") && next.indexOf(':') == -1)
|
if (!next.startsWith("/") && next.indexOf(':') == -1)
|
||||||
{
|
{
|
||||||
try {
|
try
|
||||||
|
{
|
||||||
next = new File(jettyhome, next).toURI().toURL().toString();
|
next = new File(jettyhome, next).toURI().toURL().toString();
|
||||||
} catch (MalformedURLException e) {
|
}
|
||||||
e.printStackTrace();
|
catch (MalformedURLException e)
|
||||||
|
{
|
||||||
|
LOG.warn(e);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -225,7 +228,7 @@ public class DefaultJettyAtJettyHomeHelper {
|
||||||
}
|
}
|
||||||
if (enUrls == null || !enUrls.hasMoreElements())
|
if (enUrls == null || !enUrls.hasMoreElements())
|
||||||
{
|
{
|
||||||
System.err.println("Unable to locate a jetty configuration file for " + etcFile);
|
LOG.warn("Unable to locate a jetty configuration file for " + etcFile);
|
||||||
}
|
}
|
||||||
if (enUrls != null)
|
if (enUrls != null)
|
||||||
{
|
{
|
||||||
|
|
|
@ -24,6 +24,8 @@ import org.eclipse.jetty.osgi.boot.internal.serverfactory.DefaultJettyAtJettyHom
|
||||||
import org.eclipse.jetty.osgi.boot.internal.serverfactory.IManagedJettyServerRegistry;
|
import org.eclipse.jetty.osgi.boot.internal.serverfactory.IManagedJettyServerRegistry;
|
||||||
import org.eclipse.jetty.osgi.boot.internal.serverfactory.ServerInstanceWrapper;
|
import org.eclipse.jetty.osgi.boot.internal.serverfactory.ServerInstanceWrapper;
|
||||||
import org.eclipse.jetty.server.handler.ContextHandler;
|
import org.eclipse.jetty.server.handler.ContextHandler;
|
||||||
|
import org.eclipse.jetty.util.log.Log;
|
||||||
|
import org.eclipse.jetty.util.log.Logger;
|
||||||
import org.eclipse.jetty.util.Scanner;
|
import org.eclipse.jetty.util.Scanner;
|
||||||
import org.eclipse.jetty.webapp.WebAppContext;
|
import org.eclipse.jetty.webapp.WebAppContext;
|
||||||
import org.osgi.framework.Bundle;
|
import org.osgi.framework.Bundle;
|
||||||
|
@ -52,7 +54,8 @@ import org.osgi.framework.ServiceReference;
|
||||||
*/
|
*/
|
||||||
public class JettyContextHandlerServiceTracker implements ServiceListener
|
public class JettyContextHandlerServiceTracker implements ServiceListener
|
||||||
{
|
{
|
||||||
|
private static Logger __logger = Log.getLogger(WebBundleDeployerHelper.class.getName());
|
||||||
|
|
||||||
/** New style: ability to manage multiple jetty instances */
|
/** New style: ability to manage multiple jetty instances */
|
||||||
private final IManagedJettyServerRegistry _registry;
|
private final IManagedJettyServerRegistry _registry;
|
||||||
|
|
||||||
|
@ -149,8 +152,7 @@ public class JettyContextHandlerServiceTracker implements ServiceListener
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
// TODO Auto-generated catch block
|
__logger.warn(e);
|
||||||
e.printStackTrace();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -236,7 +238,7 @@ public class JettyContextHandlerServiceTracker implements ServiceListener
|
||||||
}
|
}
|
||||||
catch (Throwable e)
|
catch (Throwable e)
|
||||||
{
|
{
|
||||||
e.printStackTrace();
|
__logger.warn(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -270,8 +272,7 @@ public class JettyContextHandlerServiceTracker implements ServiceListener
|
||||||
}
|
}
|
||||||
catch (Throwable e)
|
catch (Throwable e)
|
||||||
{
|
{
|
||||||
// TODO Auto-generated catch block
|
__logger.warn(e);
|
||||||
e.printStackTrace();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -229,6 +229,11 @@ public class WebBundleDeployerHelper implements IWebBundleDeployerHelper
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
|
//apply any META-INF/context.xml file that is found to configure the webapp first
|
||||||
|
applyMetaInfContextXml (contributor, context);
|
||||||
|
|
||||||
// make sure we provide access to all the jetty bundles by going
|
// make sure we provide access to all the jetty bundles by going
|
||||||
// through this bundle.
|
// through this bundle.
|
||||||
OSGiWebappClassLoader composite = createWebappClassLoader(contributor);
|
OSGiWebappClassLoader composite = createWebappClassLoader(contributor);
|
||||||
|
@ -661,7 +666,7 @@ public class WebBundleDeployerHelper implements IWebBundleDeployerHelper
|
||||||
}
|
}
|
||||||
catch (FileNotFoundException e)
|
catch (FileNotFoundException e)
|
||||||
{
|
{
|
||||||
e.printStackTrace();
|
__logger.warn(e);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -726,18 +731,15 @@ public class WebBundleDeployerHelper implements IWebBundleDeployerHelper
|
||||||
}
|
}
|
||||||
catch (SAXException e)
|
catch (SAXException e)
|
||||||
{
|
{
|
||||||
// TODO Auto-generated catch block
|
__logger.warn(e);
|
||||||
e.printStackTrace();
|
|
||||||
}
|
}
|
||||||
catch (IOException e)
|
catch (IOException e)
|
||||||
{
|
{
|
||||||
// TODO Auto-generated catch block
|
__logger.warn(e);
|
||||||
e.printStackTrace();
|
|
||||||
}
|
}
|
||||||
catch (Throwable e)
|
catch (Throwable e)
|
||||||
{
|
{
|
||||||
// TODO Auto-generated catch block
|
__logger.warn(e);
|
||||||
e.printStackTrace();
|
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
|
@ -802,21 +804,46 @@ public class WebBundleDeployerHelper implements IWebBundleDeployerHelper
|
||||||
// know.
|
// know.
|
||||||
OSGiWebappClassLoader webappClassLoader = new OSGiWebappClassLoader(_wrapper.getParentClassLoaderForWebapps(), new WebAppContext(), contributor,
|
OSGiWebappClassLoader webappClassLoader = new OSGiWebappClassLoader(_wrapper.getParentClassLoaderForWebapps(), new WebAppContext(), contributor,
|
||||||
BUNDLE_CLASS_LOADER_HELPER);
|
BUNDLE_CLASS_LOADER_HELPER);
|
||||||
/*
|
|
||||||
* DEBUG try { Class c =
|
|
||||||
* webappClassLoader.loadClass("org.glassfish.jsp.api.ResourceInjector"
|
|
||||||
* );
|
|
||||||
* System.err.println("LOADED org.glassfish.jsp.api.ResourceInjector from "
|
|
||||||
* +c.getClassLoader()); } catch (Exception e) {e.printStackTrace();}
|
|
||||||
* try { Class c =
|
|
||||||
* webappClassLoader.loadClass("org.apache.jasper.xmlparser.ParserUtils"
|
|
||||||
* );
|
|
||||||
* System.err.println("LOADED org.apache.jasper.xmlparser.ParserUtils from "
|
|
||||||
* +c.getClassLoader()); } catch (Exception e) {e.printStackTrace();}
|
|
||||||
*/
|
|
||||||
return webappClassLoader;
|
return webappClassLoader;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected void applyMetaInfContextXml (Bundle bundle, ContextHandler contextHandler)
|
||||||
|
throws Exception
|
||||||
|
{
|
||||||
|
if (bundle == null)
|
||||||
|
return;
|
||||||
|
if (contextHandler == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
ClassLoader cl = Thread.currentThread().getContextClassLoader();
|
||||||
|
__logger.info("Context classloader = "+cl);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Thread.currentThread().setContextClassLoader(_wrapper.getParentClassLoaderForWebapps());
|
||||||
|
|
||||||
|
//find if there is a META-INF/context.xml file
|
||||||
|
URL contextXmlUrl = bundle.getEntry("/META-INF/jetty-webapp-context.xml");
|
||||||
|
if (contextXmlUrl == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
//Apply it just as the standard jetty ContextProvider would do
|
||||||
|
__logger.info("Applying "+contextXmlUrl+" to "+contextHandler);
|
||||||
|
|
||||||
|
XmlConfiguration xmlConfiguration = new XmlConfiguration(contextXmlUrl);
|
||||||
|
HashMap properties = new HashMap();
|
||||||
|
properties.put("Server", _wrapper.getServer());
|
||||||
|
xmlConfiguration.getProperties().putAll(properties);
|
||||||
|
xmlConfiguration.configure(contextHandler);
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
Thread.currentThread().setContextClassLoader(cl);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the property "this.bundle.install" to point to the location
|
* Set the property "this.bundle.install" to point to the location
|
||||||
* of the bundle. Useful when <SystemProperty name="this.bundle.home"/> is
|
* of the bundle. Useful when <SystemProperty name="this.bundle.home"/> is
|
||||||
|
|
|
@ -167,8 +167,7 @@ public class WebBundleTrackerCustomizer implements BundleTrackerCustomizer
|
||||||
catch (Throwable e)
|
catch (Throwable e)
|
||||||
{
|
{
|
||||||
LOG.warn("Starting the web-bundle " + bundle.getSymbolicName() + " threw an exception.", e);
|
LOG.warn("Starting the web-bundle " + bundle.getSymbolicName() + " threw an exception.", e);
|
||||||
return true;// maybe it did not work maybe it did. safer to
|
return true;// maybe it did not work maybe it did. safer to track this bundle.
|
||||||
// track this bundle.
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (dic.get(OSGiWebappConstants.JETTY_CONTEXT_FILE_PATH) != null)
|
else if (dic.get(OSGiWebappConstants.JETTY_CONTEXT_FILE_PATH) != null)
|
||||||
|
@ -189,8 +188,7 @@ public class WebBundleTrackerCustomizer implements BundleTrackerCustomizer
|
||||||
}
|
}
|
||||||
catch (Throwable e)
|
catch (Throwable e)
|
||||||
{
|
{
|
||||||
// TODO Auto-generated catch block
|
LOG.warn(e);
|
||||||
e.printStackTrace();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
@ -221,10 +219,8 @@ public class WebBundleTrackerCustomizer implements BundleTrackerCustomizer
|
||||||
}
|
}
|
||||||
catch (Throwable e)
|
catch (Throwable e)
|
||||||
{
|
{
|
||||||
// TODO Auto-generated catch block
|
LOG.warn(e);
|
||||||
e.printStackTrace();
|
return true;// maybe it did not work maybe it did. safer to track this bundle.
|
||||||
return true;// maybe it did not work maybe it did. safer to
|
|
||||||
// track this bundle.
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -69,7 +69,7 @@ public class DefaultFileLocatorHelper implements BundleFileLocatorHelper
|
||||||
// grab the MANIFEST.MF's url
|
// grab the MANIFEST.MF's url
|
||||||
// and then do what it takes.
|
// and then do what it takes.
|
||||||
URL url = bundle.getEntry("/META-INF/MANIFEST.MF");
|
URL url = bundle.getEntry("/META-INF/MANIFEST.MF");
|
||||||
//System.err.println(url.toString() + " " + url.toURI() + " " + url.getProtocol());
|
|
||||||
if (url.getProtocol().equals("file"))
|
if (url.getProtocol().equals("file"))
|
||||||
{
|
{
|
||||||
// some osgi frameworks do use the file protocole directly in some
|
// some osgi frameworks do use the file protocole directly in some
|
||||||
|
|
Loading…
Reference in New Issue