Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHugues Malphettes2010-06-21 21:49:37 +0000
committerHugues Malphettes2010-06-21 21:49:37 +0000
commitb2f1594974a276d853c2c7b3e74c8989ed7adeb8 (patch)
tree5bb60c7c6ac159afab9181eb6247631626465528 /jetty-osgi
parent3a1872977203a2c9b765ea07a05f84c84e3c4a09 (diff)
downloadorg.eclipse.jetty.project-b2f1594974a276d853c2c7b3e74c8989ed7adeb8.tar.gz
org.eclipse.jetty.project-b2f1594974a276d853c2c7b3e74c8989ed7adeb8.tar.xz
org.eclipse.jetty.project-b2f1594974a276d853c2c7b3e74c8989ed7adeb8.zip
bug 317231 support the case where the jetty configuration files are inside a jarred fragment or if org.eclipse.jetty.osgi.boot is jarred up.
git-svn-id: svn+ssh://dev.eclipse.org/svnroot/rt/org.eclipse.jetty/jetty/trunk@2033 7e9141cc-0065-0410-87d8-b60c137991c4
Diffstat (limited to 'jetty-osgi')
-rw-r--r--jetty-osgi/jetty-osgi-boot/jettyhome/etc/jetty-osgi-default.xml148
-rw-r--r--jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/internal/webapp/LibExtClassLoaderHelper.java18
-rw-r--r--jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/internal/webapp/WebappRegistrationHelper.java151
-rw-r--r--jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/utils/internal/DefaultFileLocatorHelper.java83
4 files changed, 350 insertions, 50 deletions
diff --git a/jetty-osgi/jetty-osgi-boot/jettyhome/etc/jetty-osgi-default.xml b/jetty-osgi/jetty-osgi-boot/jettyhome/etc/jetty-osgi-default.xml
new file mode 100644
index 0000000000..dc3c164103
--- /dev/null
+++ b/jetty-osgi/jetty-osgi-boot/jettyhome/etc/jetty-osgi-default.xml
@@ -0,0 +1,148 @@
+<?xml version="1.0"?>
+<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure.dtd">
+
+<!-- =============================================================== -->
+<!-- Configure the Jetty Server -->
+<!-- -->
+<!-- Documentation of this file format can be found at: -->
+<!-- http://docs.codehaus.org/display/JETTY/jetty.xml -->
+<!-- -->
+<!-- =============================================================== -->
+
+
+<Configure id="Server" class="org.eclipse.jetty.server.Server">
+
+ <!-- =========================================================== -->
+ <!-- Server Thread Pool -->
+ <!-- =========================================================== -->
+ <Set name="ThreadPool">
+ <!-- Default queued blocking threadpool
+ -->
+ <New class="org.eclipse.jetty.util.thread.QueuedThreadPool">
+ <Set name="minThreads">10</Set>
+ <Set name="maxThreads">200</Set>
+ </New>
+
+ <!-- Optional Java 5 bounded threadpool with job queue
+ <New class="org.eclipse.jetty.util.thread.ExecutorThreadPool">
+ <Arg name="coreSize" type="int">25</Arg>
+ <Arg name="maxSize" type="int">50</Arg>
+ <Arg name="maxIdleMs" type="long">30000</Arg>
+ </New>
+ -->
+ </Set>
+
+
+
+ <!-- =========================================================== -->
+ <!-- Set connectors -->
+ <!-- =========================================================== -->
+
+ <Call name="addConnector">
+ <Arg>
+ <New class="org.eclipse.jetty.server.nio.SelectChannelConnector">
+ <Set name="host"><Property name="jetty.host" /></Set>
+ <Set name="port"><Property name="jetty.port" default="8080"/></Set>
+ <Set name="maxIdleTime">300000</Set>
+ <Set name="Acceptors">2</Set>
+ <Set name="statsOn">false</Set>
+ <Set name="confidentialPort">8443</Set>
+ <Set name="lowResourcesConnections">20000</Set>
+ <Set name="lowResourcesMaxIdleTime">5000</Set>
+ </New>
+ </Arg>
+ </Call>
+
+ <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
+ <!-- To add a HTTP blocking connector -->
+ <!-- mixin jetty-bio.xml: -->
+ <!-- java -jar start.jar etc/jetty.xml etc/jetty-bio.xml -->
+ <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
+
+ <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
+ <!-- To allow Jetty to be started from xinetd -->
+ <!-- mixin jetty-xinetd.xml: -->
+ <!-- java -jar start.jar etc/jetty.xml etc/jetty-xinetd.xml -->
+ <!-- -->
+ <!-- See jetty-xinetd.xml for further instructions. -->
+ <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
+
+ <!-- =========================================================== -->
+ <!-- Set handler Collection Structure -->
+ <!-- =========================================================== -->
+ <Set name="handler">
+ <New id="Handlers" class="org.eclipse.jetty.server.handler.HandlerCollection">
+ <Set name="handlers">
+ <Array type="org.eclipse.jetty.server.Handler">
+ <Item>
+ <New id="Contexts" class="org.eclipse.jetty.server.handler.ContextHandlerCollection"/>
+ </Item>
+ <Item>
+ <New id="DefaultHandler" class="org.eclipse.jetty.server.handler.DefaultHandler"/>
+ </Item>
+ <Item>
+ <New id="RequestLog" class="org.eclipse.jetty.server.handler.RequestLogHandler"/>
+ </Item>
+ </Array>
+ </Set>
+ </New>
+ </Set>
+
+ <!-- =========================================================== -->
+ <!-- Configure the deployment manager -->
+ <!-- -->
+ <!-- Sets up 2 monitored dir app providers that are configured -->
+ <!-- to behave in a similaraly to the legacy ContextDeployer -->
+ <!-- and WebAppDeployer from previous versions of Jetty. -->
+ <!-- =========================================================== -->
+ <Call name="addBean">
+ <Arg>
+ <New id="DeploymentManager" class="org.eclipse.jetty.deploy.DeploymentManager">
+ <Set name="contexts">
+ <Ref id="Contexts" />
+ </Set>
+ <Call name="setContextAttribute">
+ <Arg>org.eclipse.jetty.server.webapp.ContainerIncludeJarPattern</Arg>
+ <Arg>.*/jsp-api-[^/]*\.jar$|.*/jsp-[^/]*\.jar$</Arg>
+ </Call>
+ <!-- Providers of OSGi Apps -->
+ <Call name="addAppProvider">
+ <Arg>
+ <New class="org.eclipse.jetty.osgi.boot.OSGiAppProvider">
+ <!--
+ <Set name="defaultsDescriptor"><Property name="jetty.home" default="."/>/etc/webdefault.xml</Set>
+ -->
+ <Set name="scanInterval">5</Set>
+ <Set name="contextXmlDir"><Property name="jetty.home" default="." />/contexts</Set>
+ <!-- comma separated list of bundle symbolic names that
+ contain custom tag libraries (*.tld files)
+ if those bundles don't exist or can't be loaded no errors or warning will be issued!
+ this default value is to plug the tld files of the reference implementation of JSF -->
+ <Set name="tldBundles"><Property name="org.eclipse.jetty.osgi.tldsbundles" default="javax.faces.jsf-impl" /></Set>
+ </New>
+ </Arg>
+ </Call>
+
+ </New>
+ </Arg>
+ </Call>
+
+ <!-- =========================================================== -->
+ <!-- extra options -->
+ <!-- =========================================================== -->
+ <Set name="stopAtShutdown">true</Set>
+ <Set name="sendServerVersion">true</Set>
+ <Set name="sendDateHeader">true</Set>
+ <Set name="gracefulShutdown">1000</Set>
+
+ <!-- jetty-jndi by default -->
+ <Call class="java.lang.System" name="setProperty">
+ <Arg>java.naming.factory.initial</Arg>
+ <Arg><Property name="java.naming.factory.initial" default="org.eclipse.jetty.jndi.InitialContextFactory"/></Arg>
+ </Call>
+ <Call class="java.lang.System" name="setProperty">
+ <Arg>java.naming.factory.url.pkgs</Arg>
+ <Arg><Property name="java.naming.factory.url.pkgs" default="org.eclipse.jetty.jndi"/></Arg>
+ </Call>
+
+</Configure>
diff --git a/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/internal/webapp/LibExtClassLoaderHelper.java b/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/internal/webapp/LibExtClassLoaderHelper.java
index d11e0bbe4d..ec28aae9cf 100644
--- a/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/internal/webapp/LibExtClassLoaderHelper.java
+++ b/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/internal/webapp/LibExtClassLoaderHelper.java
@@ -92,21 +92,13 @@ public class LibExtClassLoaderHelper
* is the JettyBootStrapper (an osgi classloader.
* @throws MalformedURLException
*/
- public static URLClassLoader createLibEtcClassLoaderHelper(File jettyHome, Server server, ClassLoader parentClassLoader) throws MalformedURLException
- {
- return null;
- }
- /**
- * @param server
- * @return a url classloader with the jars of resources, lib/ext and the
- * jars passed in the other argument. The parent classloader usually
- * is the JettyBootStrapper (an osgi classloader.
- * @throws MalformedURLException
- */
- public static URLClassLoader createLibEtcClassLoader(File jettyHome, Server server,
+ public static ClassLoader createLibEtcClassLoader(File jettyHome, Server server,
ClassLoader parentClassLoader) throws MalformedURLException
{
-
+ if (jettyHome == null)
+ {
+ return parentClassLoader;
+ }
ArrayList<URL> urls = new ArrayList<URL>();
File jettyResources = new File(jettyHome,"resources");
if (jettyResources.exists())
diff --git a/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/internal/webapp/WebappRegistrationHelper.java b/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/internal/webapp/WebappRegistrationHelper.java
index db66fb9b71..7e7aeec3b7 100644
--- a/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/internal/webapp/WebappRegistrationHelper.java
+++ b/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/internal/webapp/WebappRegistrationHelper.java
@@ -209,7 +209,7 @@ public class WebappRegistrationHelper
*/
public void setup(BundleContext context, Map<String, String> configProperties) throws Exception
{
- Enumeration<?> enUrls = context.getBundle().findEntries("/etc", "jetty.xml", false);System.err.println();
+ Enumeration<?> enUrls = context.getBundle().findEntries("/etc", "jetty.xml", false);
if (enUrls != null && enUrls.hasMoreElements())
{
URL url = (URL) enUrls.nextElement();
@@ -236,52 +236,62 @@ public class WebappRegistrationHelper
if (jettyHome == null || jettyHome.length() == 0)
{
- if (_installLocation.getName().endsWith(".jar"))
- {
- jettyHome = JettyHomeHelper.setupJettyHomeInEclipsePDE(_installLocation);
- }
- if (jettyHome == null)
- {
- jettyHome = _installLocation.getAbsolutePath() + "/jettyhome";
- bootBundleCanBeJarred = false;
- }
+ if (_installLocation != null)
+ {
+ if (_installLocation.getName().endsWith(".jar"))
+ {
+ jettyHome = JettyHomeHelper.setupJettyHomeInEclipsePDE(_installLocation);
+ }
+ if (jettyHome == null && _installLocation != null && _installLocation.isDirectory())
+ {
+ jettyHome = _installLocation.getAbsolutePath() + "/jettyhome";
+ bootBundleCanBeJarred = false;
+ }
+ }
}
+ if (jettyHome == null || (!bootBundleCanBeJarred && !_installLocation.isDirectory()))
+ {
+// String install = _installLocation != null?_installLocation.getCanonicalPath():" unresolved_install_location";
+// throw new IllegalArgumentException("The system property -Djetty.home" + " must be set to a directory or the bundle "
+// + context.getBundle().getSymbolicName() + " installed here " + install + " must be unjarred.");
+ }
+ else
+ {
// in case we stripped the quotes.
- System.setProperty("jetty.home",jettyHome);
-
+ System.setProperty("jetty.home",jettyHome);
+ }
String jettyLogs = stripQuotesIfPresent(System.getProperty("jetty.logs"));
if (jettyLogs == null || jettyLogs.length() == 0)
{
System.setProperty("jetty.logs",jettyHome + "/logs");
}
- if (!bootBundleCanBeJarred && !_installLocation.isDirectory())
+ if (jettyHome != null)
{
- String install = _installLocation != null?_installLocation.getCanonicalPath():" unresolved_install_location";
- throw new IllegalArgumentException("The system property -Djetty.home" + " must be set to a directory or the bundle "
- + context.getBundle().getSymbolicName() + " installed here " + install + " must be unjarred.");
+ try
+ {
+ System.err.println("JETTY_HOME set to " + new File(jettyHome).getCanonicalPath());
+ }
+ catch (Throwable t)
+ {
+ System.err.println("JETTY_HOME _set to " + new File(jettyHome).getAbsolutePath());
+ }
}
- try
- {
- System.err.println("JETTY_HOME set to " + new File(jettyHome).getCanonicalPath());
- }
- catch (Throwable t)
+ else
{
- System.err.println("JETTY_HOME _set to " + new File(jettyHome).getAbsolutePath());
+// System.err.println("JETTY_HOME is not set");
}
-
ClassLoader contextCl = Thread.currentThread().getContextClassLoader();
try
{
// passing this bundle's classloader as the context classlaoder
// makes sure there is access to all the jetty's bundles
-
- File jettyHomeF = new File(jettyHome);
- URLClassLoader libExtClassLoader = null;
+ File jettyHomeF = jettyHome != null ? new File(jettyHome) : null;
+ ClassLoader libExtClassLoader = null;
try
{
- libExtClassLoader = LibExtClassLoaderHelper.createLibEtcClassLoaderHelper(jettyHomeF,_server,
+ libExtClassLoader = LibExtClassLoaderHelper.createLibEtcClassLoader(jettyHomeF,_server,
JettyBootstrapActivator.class.getClassLoader());
}
catch (MalformedURLException e)
@@ -297,7 +307,10 @@ public class WebappRegistrationHelper
Map<Object,Object> id_map = new HashMap<Object,Object>();
id_map.put("Server",_server);
Map<Object,Object> properties = new HashMap<Object,Object>();
- properties.put("jetty.home",jettyHome);
+ if (jettyHome != null)
+ {
+ properties.put("jetty.home",jettyHome);
+ }
properties.put("jetty.host",System.getProperty("jetty.host",""));
properties.put("jetty.port",System.getProperty("jetty.port","8080"));
properties.put("jetty.port.ssl",System.getProperty("jetty.port.ssl","8443"));
@@ -305,10 +318,44 @@ public class WebappRegistrationHelper
while (tokenizer.hasMoreTokens())
{
String etcFile = tokenizer.nextToken().trim();
- File conffile = etcFile.startsWith("/")?new File(etcFile):new File(jettyHomeF,etcFile);
- if (!conffile.exists())
+ File conffile = null;
+ enUrls = null;
+ if (etcFile.indexOf(":") != -1)
+ {
+ conffile = Resource.newResource(etcFile).getFile();
+ }
+ else if (etcFile.startsWith("/"))
+ {
+ conffile = new File(etcFile);
+ }
+ else if (jettyHomeF != null)
+ {
+ conffile = new File(jettyHomeF, etcFile);
+ }
+ else
+ {
+ int last = etcFile.lastIndexOf('/');
+ String path = last != -1 && last < etcFile.length() -2
+ ? etcFile.substring(0, last) : "/";
+ if (!path.startsWith("/"))
+ {
+ path = "/" + path;
+ }
+ String pattern = last != -1 && last < etcFile.length() -2
+ ? etcFile.substring(last+1) : etcFile;
+ enUrls = context.getBundle().findEntries(path, pattern, false);
+ if (pattern.equals("jetty.xml") && (enUrls == null || !enUrls.hasMoreElements()))
+ {
+ path = "/jettyhome" + path;
+ pattern = "jetty-osgi-default.xml";
+ enUrls = context.getBundle().findEntries(path, pattern, false);
+ System.err.println("Configuring jetty with the default embedded configuration:" +
+ "bundle org.eclipse.jetty.boot.osgi /jettyhome/etc/jetty-osgi-default.xml");
+ }
+ }
+ if (conffile != null && !conffile.exists())
{
- __logger.warn("Unable to resolve the jetty/etc file " + etcFile);
+ __logger.warn("Unable to resolve the xml configuration file for jetty " + etcFile);
if ("etc/jetty.xml".equals(etcFile))
{
@@ -322,15 +369,45 @@ public class WebappRegistrationHelper
ContextHandlerCollection contexts = new ContextHandlerCollection();
RequestLogHandler requestLogHandler = new RequestLogHandler();
handlers.setHandlers(new Handler[] { contexts, new DefaultHandler(), requestLogHandler });
+
_server.setHandler(handlers);
}
}
else
{
+ InputStream is = null;
try
{
// Execute a Jetty configuration file
- XmlConfiguration config = new XmlConfiguration(new FileInputStream(conffile));
+ XmlConfiguration config = null;
+ if (conffile != null && conffile.exists())
+ {
+ is = new FileInputStream(conffile);
+ config =new XmlConfiguration(is);
+ }
+ else if (enUrls != null && enUrls.hasMoreElements())
+ {
+ URL url = (URL) enUrls.nextElement();
+ if (url != null)
+ {
+ //bug 317231: there is a fragment that defines the jetty configuration file.
+ //let's use that as the jetty home.
+ is = url.openStream();
+ config = new XmlConfiguration(is);
+ }
+ else
+ {
+ System.err.println("Could not locate " + etcFile +
+ " inside " + context.getBundle().getSymbolicName());
+ continue;
+ }
+ }
+ else
+ {
+ //it did not work.
+ continue;
+ }
+
config.setIdMap(id_map);
config.setProperties(properties);
config.configure();
@@ -341,6 +418,10 @@ public class WebappRegistrationHelper
Log.getLogger(WebappRegistrationHelper.class.getName()).warn("Unable to configure the jetty/etc file " + etcFile,saxparse);
throw saxparse;
}
+ finally
+ {
+ if (is != null) try { is.close(); } catch (IOException ioe) {}
+ }
}
}
@@ -406,9 +487,13 @@ public class WebappRegistrationHelper
try
{
_provider = new OSGiAppProvider();
- _provider.setMonitoredDir(
+ if (System.getProperty("jetty.home") != null)
+ {
+ _provider.setMonitoredDir(
Resource.newResource(getDefaultOSGiContextsHome(
new File(System.getProperty("jetty.home"))).toURI()));
+ }
+
} catch (IOException e) {
e.printStackTrace();
}
diff --git a/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/utils/internal/DefaultFileLocatorHelper.java b/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/utils/internal/DefaultFileLocatorHelper.java
index df6c2da3be..fce3b1a68c 100644
--- a/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/utils/internal/DefaultFileLocatorHelper.java
+++ b/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/utils/internal/DefaultFileLocatorHelper.java
@@ -18,6 +18,7 @@ import java.lang.reflect.Method;
import java.net.URI;
import java.net.URL;
import java.net.URLConnection;
+import java.net.URLDecoder;
import java.util.ArrayList;
import java.util.zip.ZipFile;
@@ -67,8 +68,7 @@ public class DefaultFileLocatorHelper implements BundleFileLocatorHelper
// grab the MANIFEST.MF's url
// and then do what it takes.
URL url = bundle.getEntry("/META-INF/MANIFEST.MF");
- // System.err.println(url.toString() + " " + url.toURI() + " " +
- // url.getProtocol());
+// System.err.println(url.toString() + " " + url.toURI() + " " + url.getProtocol());
if (url.getProtocol().equals("file"))
{
// some osgi frameworks do use the file protocole directly in some
@@ -131,11 +131,30 @@ public class DefaultFileLocatorHelper implements BundleFileLocatorHelper
{
// observed this on felix-2.0.0
String location = bundle.getLocation();
+// System.err.println("location " + location);
if (location.startsWith("file:/"))
{
URI uri = new URI(URIUtil.encodePath(location));
return new File(uri);
}
+ else if (location.startsWith("file:"))
+ {
+ //location defined in the BundleArchive m_bundleArchive
+ //it is relative to relative to the BundleArchive's m_archiveRootDir
+ Object bundleArchive = getFelixBundleArchive(bundle);
+ File archiveRoot = getFelixBundleArchiveRootDir(bundleArchive);
+ String currentLocation = getFelixBundleArchiveCurrentLocation(bundleArchive);
+// System.err.println("Got the archive root " + archiveRoot.getAbsolutePath()
+// + " current location " + currentLocation);
+ return new File(archiveRoot, currentLocation != null
+ ? currentLocation : location.substring("file:".length()));
+ }
+ else if (location.startsWith("reference:file:"))
+ {
+ location = URLDecoder.decode(location.substring("reference:".length()), "UTF-8");
+ File file = new File(location.substring("file:".length()));
+ return file;
+ }
}
return null;
}
@@ -206,8 +225,7 @@ public class DefaultFileLocatorHelper implements BundleFileLocatorHelper
}
else
{
- return new File[]
- { jasperLocation };
+ return new File[] { jasperLocation };
}
}
@@ -279,5 +297,62 @@ public class DefaultFileLocatorHelper implements BundleFileLocatorHelper
}
return url;
}
+
+
+ //introspection on felix
+ private static Field m_bundleArchive_FIELD = null;
+ private static Field m_archiveRootDir_FIELD = null;
+ private static Field m_currentLocation_FIELD = null;
+ private static Object getFelixBundleArchive(Bundle bundle)
+ {
+ try
+ {
+ if (m_bundleArchive_FIELD == null)
+ {
+ m_bundleArchive_FIELD = bundle.getClass().getDeclaredField("m_archive");
+ m_bundleArchive_FIELD.setAccessible(true);
+ }
+ return m_bundleArchive_FIELD.get(bundle);
+ }
+ catch (Throwable t)
+ {
+ t.printStackTrace();
+ }
+ return null;
+ }
+ private static File getFelixBundleArchiveRootDir(Object bundleArchive)
+ {
+ try
+ {
+ if (m_archiveRootDir_FIELD == null)
+ {
+ m_archiveRootDir_FIELD = bundleArchive.getClass().getDeclaredField("m_archiveRootDir");
+ m_archiveRootDir_FIELD.setAccessible(true);
+ }
+ return (File)m_archiveRootDir_FIELD.get(bundleArchive);
+ }
+ catch (Throwable t)
+ {
+ t.printStackTrace();
+ }
+ return null;
+ }
+ private static String getFelixBundleArchiveCurrentLocation(Object bundleArchive)
+ {
+ try
+ {
+ if (m_currentLocation_FIELD == null)
+ {
+ m_currentLocation_FIELD = bundleArchive.getClass().getDeclaredField("m_currentLocation");
+ m_currentLocation_FIELD.setAccessible(true);
+ }
+ return (String)m_currentLocation_FIELD.get(bundleArchive);
+ }
+ catch (Throwable t)
+ {
+ t.printStackTrace();
+ }
+ return null;
+ }
}

Back to the top