From 911643b783619b831cf0bbf229f41c8d62a13c46 Mon Sep 17 00:00:00 2001
From: Jan Bartel
- * Pluggable tlds at the server level are handled by {@link PluggableWebAppRegistrationCustomizerImpl}.
+ * Pluggable tlds at the server level are handled by
+ * {@link PluggableWebAppRegistrationCustomizerImpl}.
*
- * The workaround consists of setting the entity resolver. That is a patch
- * added to the version of glassfish-jasper-jetty. IT is also present in the latest
- * version of glassfish jasper. Could not use introspection to set new value
- * on a static friendly field :(
+ * The workaround consists of setting the entity resolver. That is a patch
+ * added to the version of glassfish-jasper-jetty. IT is also present in the
+ * latest version of glassfish jasper. Could not use introspection to set
+ * new value on a static friendly field :(
*
- * It must be placed in the org.eclipse.jetty.osgi.boot.jsp package:
- * this is because org.eclipse.jetty.osgi.boot.jsp is the sympbolic-name
- * of this fragment. From that name, the PackageadminTracker will call
- * this class. IN a different package it won't be called.
+ * It must be placed in the org.eclipse.jetty.osgi.boot.jsp package: this is
+ * because org.eclipse.jetty.osgi.boot.jsp is the sympbolic-name of this
+ * fragment. From that name, the PackageadminTracker will call this class. IN a
+ * different package it won't be called.
*
- * In the case of a WAB, tlds can be located in OSGi bundles that are dependencies - * of the WAB. - * It is expected that each WAB lists the symbolic-names of the bundles that contain - * tld files. The list is defined as the value of the header 'Require-TldBundle' + * In the case of a WAB, tlds can be located in OSGi bundles that are + * dependencies of the WAB. It is expected that each WAB lists the + * symbolic-names of the bundles that contain tld files. The list is defined as + * the value of the header 'Require-TldBundle' *
*- * Discussions about this are logged in https://bugs.eclipse.org/bugs/show_bug.cgi?id=306971 + * Discussions about this are logged in + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=306971 *
*/ public class TagLibOSGiConfiguration extends TagLibConfiguration { private static final Logger LOG = Log.getLogger(TagLibOSGiConfiguration.class); - private ServiceTracker packageAdminServiceTracker = null; - - /** - * Override the preConfigure; locates the bundles that contain - * tld files according to the value of the manifest header Require-TldBundle. - *- * Set or add to the property TldProcessor.TLDResources the list of located jars - * so that the super class will scan those. - *
- */ + private ServiceTracker packageAdminServiceTracker = null; + + /** + * Override the preConfigure; locates the bundles that contain tld files + * according to the value of the manifest header Require-TldBundle. + *+ * Set or add to the property TldProcessor.TLDResources the list of located + * jars so that the super class will scan those. + *
+ */ public void preConfigure(WebAppContext context) throws Exception { - String requireTldBundle = (String)context.getAttribute(OSGiWebappConstants.REQUIRE_TLD_BUNDLE); - if (requireTldBundle != null) - { - CollectionServiceEvent
object.
+ * @param ev The ServiceEvent
object.
*/
public void serviceChanged(ServiceEvent ev)
{
@@ -148,7 +145,7 @@ public class JettyContextHandlerServiceTracker implements ServiceListener
{
try
{
- getWebBundleDeployerHelp(sr).unregister(ctxtHandler);
+ getWebBundleDeployerHelp(sr).unregister(ctxtHandler);
}
catch (Exception e)
{
@@ -170,30 +167,32 @@ public class JettyContextHandlerServiceTracker implements ServiceListener
{
Bundle contributor = sr.getBundle();
BundleContext context = FrameworkUtil.getBundle(JettyBootstrapActivator.class).getBundleContext();
- ContextHandler contextHandler = (ContextHandler)context.getService(sr);
+ ContextHandler contextHandler = (ContextHandler) context.getService(sr);
if (contextHandler.getServer() != null)
{
// is configured elsewhere.
return;
}
- String contextFilePath = (String)sr.getProperty(OSGiWebappConstants.SERVICE_PROP_CONTEXT_FILE_PATH);
+ String contextFilePath = (String) sr.getProperty(OSGiWebappConstants.SERVICE_PROP_CONTEXT_FILE_PATH);
if (contextHandler instanceof WebAppContext && contextFilePath == null)
- //it could be a web-application that will in fact be configured via a context file.
- //that case is identified by the fact that the contextFilePath is not null
- //in that case we must use the register context methods.
+ // it could be a web-application that will in fact be configured
+ // via a context file.
+ // that case is identified by the fact that the contextFilePath
+ // is not null
+ // in that case we must use the register context methods.
{
- WebAppContext webapp = (WebAppContext)contextHandler;
- String contextPath = (String)sr.getProperty(OSGiWebappConstants.SERVICE_PROP_CONTEXT_PATH);
+ WebAppContext webapp = (WebAppContext) contextHandler;
+ String contextPath = (String) sr.getProperty(OSGiWebappConstants.SERVICE_PROP_CONTEXT_PATH);
if (contextPath == null)
{
contextPath = webapp.getContextPath();
}
- String webXmlPath = (String)sr.getProperty(OSGiWebappConstants.SERVICE_PROP_WEB_XML_PATH);
+ String webXmlPath = (String) sr.getProperty(OSGiWebappConstants.SERVICE_PROP_WEB_XML_PATH);
if (webXmlPath == null)
{
webXmlPath = webapp.getDescriptor();
}
- String defaultWebXmlPath = (String)sr.getProperty(OSGiWebappConstants.SERVICE_PROP_DEFAULT_WEB_XML_PATH);
+ String defaultWebXmlPath = (String) sr.getProperty(OSGiWebappConstants.SERVICE_PROP_DEFAULT_WEB_XML_PATH);
if (defaultWebXmlPath == null)
{
String jettyHome = System.getProperty(DefaultJettyAtJettyHomeHelper.SYS_PROP_JETTY_HOME);
@@ -202,7 +201,7 @@ public class JettyContextHandlerServiceTracker implements ServiceListener
File etc = new File(jettyHome, "etc");
if (etc.exists() && etc.isDirectory())
{
- File webDefault = new File (etc, "webdefault.xml");
+ File webDefault = new File(etc, "webdefault.xml");
if (webDefault.exists())
defaultWebXmlPath = webDefault.getAbsolutePath();
else
@@ -212,27 +211,28 @@ public class JettyContextHandlerServiceTracker implements ServiceListener
defaultWebXmlPath = webapp.getDefaultsDescriptor();
}
}
- String war = (String)sr.getProperty("war");
+ String war = (String) sr.getProperty("war");
try
{
- IWebBundleDeployerHelper deployerHelper = getWebBundleDeployerHelp(sr);
- if (deployerHelper == null)
- {
-
- }
- else
- {
- WebAppContext handler = deployerHelper
- .registerWebapplication(contributor,war,contextPath,
- (String)sr.getProperty(OSGiWebappConstants.SERVICE_PROP_EXTRA_CLASSPATH),
- (String)sr.getProperty(OSGiWebappConstants.SERVICE_PROP_BUNDLE_INSTALL_LOCATION_OVERRIDE),
- (String)sr.getProperty(OSGiWebappConstants.SERVICE_PROP_REQUIRE_TLD_BUNDLE),
- webXmlPath,defaultWebXmlPath,webapp);
+ IWebBundleDeployerHelper deployerHelper = getWebBundleDeployerHelp(sr);
+ if (deployerHelper == null)
+ {
+
+ }
+ else
+ {
+ WebAppContext handler = deployerHelper.registerWebapplication(contributor,
+ war,
+ contextPath,
+ (String) sr.getProperty(OSGiWebappConstants.SERVICE_PROP_EXTRA_CLASSPATH),
+ (String) sr.getProperty(OSGiWebappConstants.SERVICE_PROP_BUNDLE_INSTALL_LOCATION_OVERRIDE),
+ (String) sr.getProperty(OSGiWebappConstants.SERVICE_PROP_REQUIRE_TLD_BUNDLE),
+ webXmlPath, defaultWebXmlPath, webapp);
if (handler != null)
{
- registerInIndex(handler,sr);
+ registerInIndex(handler, sr);
}
- }
+ }
}
catch (Throwable e)
{
@@ -242,34 +242,31 @@ public class JettyContextHandlerServiceTracker implements ServiceListener
else
{
// consider this just an empty skeleton:
- if (contextFilePath == null)
- {
- throw new IllegalArgumentException("the property contextFilePath is required");
- }
+ if (contextFilePath == null) { throw new IllegalArgumentException("the property contextFilePath is required"); }
try
{
- IWebBundleDeployerHelper deployerHelper = getWebBundleDeployerHelp(sr);
- if (deployerHelper == null)
- {
- //more warnings?
- }
- else
- {
- if (Boolean.TRUE.toString().equals(sr.getProperty(
- IWebBundleDeployerHelper.INTERNAL_SERVICE_PROP_UNKNOWN_CONTEXT_HANDLER_TYPE)))
- {
- contextHandler = null;
- }
- ContextHandler handler = deployerHelper.registerContext(contributor,contextFilePath,
- (String)sr.getProperty(OSGiWebappConstants.SERVICE_PROP_EXTRA_CLASSPATH),
- (String)sr.getProperty(OSGiWebappConstants.SERVICE_PROP_BUNDLE_INSTALL_LOCATION_OVERRIDE),
- (String)sr.getProperty(OSGiWebappConstants.SERVICE_PROP_REQUIRE_TLD_BUNDLE),
- contextHandler);
- if (handler != null)
- {
- registerInIndex(handler,sr);
- }
- }
+ IWebBundleDeployerHelper deployerHelper = getWebBundleDeployerHelp(sr);
+ if (deployerHelper == null)
+ {
+ // more warnings?
+ }
+ else
+ {
+ if (Boolean.TRUE.toString().equals(sr.getProperty(IWebBundleDeployerHelper.INTERNAL_SERVICE_PROP_UNKNOWN_CONTEXT_HANDLER_TYPE)))
+ {
+ contextHandler = null;
+ }
+ ContextHandler handler = deployerHelper.registerContext(contributor,
+ contextFilePath,
+ (String) sr.getProperty(OSGiWebappConstants.SERVICE_PROP_EXTRA_CLASSPATH),
+ (String) sr.getProperty(OSGiWebappConstants.SERVICE_PROP_BUNDLE_INSTALL_LOCATION_OVERRIDE),
+ (String) sr.getProperty(OSGiWebappConstants.SERVICE_PROP_REQUIRE_TLD_BUNDLE),
+ contextHandler);
+ if (handler != null)
+ {
+ registerInIndex(handler, sr);
+ }
+ }
}
catch (Throwable e)
{
@@ -278,17 +275,17 @@ public class JettyContextHandlerServiceTracker implements ServiceListener
}
}
}
- break;
+ break;
}
}
private void registerInIndex(ContextHandler handler, ServiceReference sr)
{
- _indexByServiceReference.put(sr,handler);
+ _indexByServiceReference.put(sr, handler);
String key = getSymbolicNameAndContextFileKey(sr);
if (key != null)
{
- _indexByContextFile.put(key,sr);
+ _indexByContextFile.put(key, sr);
}
}
@@ -320,11 +317,8 @@ public class JettyContextHandlerServiceTracker implements ServiceListener
*/
private String getSymbolicNameAndContextFileKey(ServiceReference sr)
{
- String contextFilePath = (String)sr.getProperty(OSGiWebappConstants.SERVICE_PROP_CONTEXT_FILE_PATH);
- if (contextFilePath != null)
- {
- return sr.getBundle().getSymbolicName() + "/" + contextFilePath;
- }
+ String contextFilePath = (String) sr.getProperty(OSGiWebappConstants.SERVICE_PROP_CONTEXT_FILE_PATH);
+ if (contextFilePath != null) { return sr.getBundle().getSymbolicName() + "/" + contextFilePath; }
return null;
}
@@ -336,17 +330,14 @@ public class JettyContextHandlerServiceTracker implements ServiceListener
public void reloadJettyContextHandler(String canonicalNameOfFileChanged, String osgiContextHomeFolderCanonicalPath)
{
String key = getNormalizedRelativePath(canonicalNameOfFileChanged, osgiContextHomeFolderCanonicalPath);
- if (key == null)
- {
- return;
- }
+ if (key == null) { return; }
ServiceReference sr = _indexByContextFile.get(key);
if (sr == null)
{
// nothing to do?
return;
}
- serviceChanged(new ServiceEvent(ServiceEvent.MODIFIED,sr));
+ serviceChanged(new ServiceEvent(ServiceEvent.MODIFIED, sr));
}
/**
@@ -362,36 +353,31 @@ public class JettyContextHandlerServiceTracker implements ServiceListener
// warning?
return null;
}
- return canFilename.substring(osgiContextHomeFolderCanonicalPath.length()).replace('\\','/');
+ return canFilename.substring(osgiContextHomeFolderCanonicalPath.length()).replace('\\', '/');
}
-
+
/**
* @return The server on which this webapp is meant to be deployed
*/
private ServerInstanceWrapper getServerInstanceWrapper(String managedServerName)
{
- if (_registry == null)
- {
- return null;
- }
- if (managedServerName == null)
- {
- managedServerName = OSGiServerConstants.MANAGED_JETTY_SERVER_DEFAULT_NAME;
- }
- ServerInstanceWrapper wrapper = _registry.getServerInstanceWrapper(managedServerName);
- //System.err.println("Returning " + managedServerName + " = " + wrapper);
- return wrapper;
+ if (_registry == null) { return null; }
+ if (managedServerName == null)
+ {
+ managedServerName = OSGiServerConstants.MANAGED_JETTY_SERVER_DEFAULT_NAME;
+ }
+ ServerInstanceWrapper wrapper = _registry.getServerInstanceWrapper(managedServerName);
+ // System.err.println("Returning " + managedServerName + " = " +
+ // wrapper);
+ return wrapper;
}
-
+
private IWebBundleDeployerHelper getWebBundleDeployerHelp(ServiceReference sr)
{
- if (_registry == null)
- {
- return null;
- }
- String managedServerName = (String)sr.getProperty(OSGiServerConstants.MANAGED_JETTY_SERVER_NAME);
- ServerInstanceWrapper wrapper = getServerInstanceWrapper(managedServerName);
- return wrapper != null ? wrapper.getWebBundleDeployerHelp() : null;
+ if (_registry == null) { return null; }
+ String managedServerName = (String) sr.getProperty(OSGiServerConstants.MANAGED_JETTY_SERVER_NAME);
+ ServerInstanceWrapper wrapper = getServerInstanceWrapper(managedServerName);
+ return wrapper != null ? wrapper.getWebBundleDeployerHelp() : null;
}
-
+
}
diff --git a/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/internal/webapp/OSGiWebappClassLoader.java b/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/internal/webapp/OSGiWebappClassLoader.java
index 4a7dcf96e90..c662d2cae02 100644
--- a/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/internal/webapp/OSGiWebappClassLoader.java
+++ b/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/internal/webapp/OSGiWebappClassLoader.java
@@ -247,7 +247,7 @@ public class OSGiWebappClassLoader extends WebAppClassLoader implements BundleRe
catch (IOException e)
{
// nevermind. just trying our best
- e.printStackTrace();
+ __logger.ignore(e);
}
return true;
}
@@ -279,7 +279,7 @@ public class OSGiWebappClassLoader extends WebAppClassLoader implements BundleRe
catch (Throwable t)
{
// humf that will hurt if it does not work.
- t.printStackTrace();
+ __logger.warn("Unable to set webappcontext", t);
}
}
}
diff --git a/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/internal/webapp/WebBundleDeployerHelper.java b/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/internal/webapp/WebBundleDeployerHelper.java
index b30d9a81d02..97d72cb2c38 100644
--- a/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/internal/webapp/WebBundleDeployerHelper.java
+++ b/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/internal/webapp/WebBundleDeployerHelper.java
@@ -78,13 +78,14 @@ public class WebBundleDeployerHelper implements IWebBundleDeployerHelper
private static Logger __logger = Log.getLogger(WebBundleDeployerHelper.class.getName());
private static boolean INITIALIZED = false;
-
+
/**
* By default set to: {@link DefaultBundleClassLoaderHelper}. It supports
* equinox and apache-felix fragment bundles that are specific to an OSGi
* implementation should set a different implementation.
*/
public static BundleClassLoaderHelper BUNDLE_CLASS_LOADER_HELPER = null;
+
/**
* By default set to: {@link DefaultBundleClassLoaderHelper}. It supports
* equinox and apache-felix fragment bundles that are specific to an OSGi
@@ -97,8 +98,9 @@ public class WebBundleDeployerHelper implements IWebBundleDeployerHelper
* equinox and apache-felix fragment bundles that are specific to an OSGi
* implementation should set a different implementation.
* - * Several of those objects can be added here: For example we could have an optional fragment that setups - * a specific implementation of JSF for the whole of jetty-osgi. + * Several of those objects can be added here: For example we could have an + * optional fragment that setups a specific implementation of JSF for the + * whole of jetty-osgi. *
*/ public static Collection// configure it
*/
- protected void configureWebAppContext(ContextHandler wah, Bundle contributor,
- String requireTldBundle) throws IOException
+ protected void configureWebAppContext(ContextHandler wah, Bundle contributor, String requireTldBundle) throws IOException
{
// rfc66
- wah.setAttribute(OSGiWebappConstants.RFC66_OSGI_BUNDLE_CONTEXT,contributor.getBundleContext());
+ wah.setAttribute(OSGiWebappConstants.RFC66_OSGI_BUNDLE_CONTEXT, contributor.getBundleContext());
- //spring-dm-1.2.1 looks for the BundleContext as a different attribute.
- //not a spec... but if we want to support
- //org.springframework.osgi.web.context.support.OsgiBundleXmlWebApplicationContext
- //then we need to do this to:
- wah.setAttribute("org.springframework.osgi.web." + BundleContext.class.getName(),
- contributor.getBundleContext());
-
- //also pass the bundle directly. sometimes a bundle does not have a bundlecontext.
- //it is still useful to have access to the Bundle from the servlet context.
+ // spring-dm-1.2.1 looks for the BundleContext as a different attribute.
+ // not a spec... but if we want to support
+ // org.springframework.osgi.web.context.support.OsgiBundleXmlWebApplicationContext
+ // then we need to do this to:
+ wah.setAttribute("org.springframework.osgi.web." + BundleContext.class.getName(), contributor.getBundleContext());
+
+ // also pass the bundle directly. sometimes a bundle does not have a
+ // bundlecontext.
+ // it is still useful to have access to the Bundle from the servlet
+ // context.
wah.setAttribute(OSGiWebappConstants.JETTY_OSGI_BUNDLE, contributor);
-
- //pass the value of the require tld bundle so that the TagLibOSGiConfiguration
- //can pick it up.
+
+ // pass the value of the require tld bundle so that the
+ // TagLibOSGiConfiguration
+ // can pick it up.
wah.setAttribute(OSGiWebappConstants.REQUIRE_TLD_BUNDLE, requireTldBundle);
-
Bundle[] fragments = PackageAdminServiceTracker.INSTANCE.getFragmentsAndRequiredBundles(contributor);
if (fragments != null && fragments.length != 0)
{
- //sorted extra resource base found in the fragments.
- //the resources are either overriding the resourcebase found in the web-bundle
- //or appended.
- //amongst each resource we sort them according to the alphabetical order
- //of the name of the internal folder and the symbolic name of the fragment.
- //this is useful to make sure that the lookup path of those
- //resource base defined by fragments is always the same.
- //This natural order could be abused to define the order in which the base resources are
- //looked up.
- TreeMapBundleTracker
.
+ *
+ *
+ * This method is called before a bundle which matched the search parameters
+ * of the BundleTracker
is added to the
+ * BundleTracker
. This method should return the object to be
+ * tracked for the specified Bundle
. The returned object is
+ * stored in the BundleTracker
and is available from the
+ * {@link BundleTracker#getObject(Bundle) getObject} method.
+ *
+ * @param bundle The Bundle
being added to the
+ * BundleTracker
.
+ * @param event The bundle event which caused this customizer method to be
+ * called or null
if there is no bundle event
+ * associated with the call to this method.
+ * @return The object to be tracked for the specified Bundle
+ * object or null
if the specified Bundle
+ * object should not be tracked.
+ */
+ public Object addingBundle(Bundle bundle, BundleEvent event)
+ {
+ if (bundle.getState() == Bundle.ACTIVE)
+ {
+ boolean isWebBundle = register(bundle);
+ return isWebBundle ? bundle : null;
+ }
+ else if (bundle.getState() == Bundle.STOPPING)
+ {
+ unregister(bundle);
+ }
+ else
+ {
+ // we should not be called in that state as
+ // we are registered only for ACTIVE and STOPPING
+ }
+ return null;
+ }
- /**
- * A bundle is being added to the BundleTracker
.
- *
- *
- * This method is called before a bundle which matched the search parameters
- * of the BundleTracker
is added to the
- * BundleTracker
. This method should return the object to be
- * tracked for the specified Bundle
. The returned object is
- * stored in the BundleTracker
and is available from the
- * {@link BundleTracker#getObject(Bundle) getObject} method.
- *
- * @param bundle The Bundle
being added to the
- * BundleTracker
.
- * @param event The bundle event which caused this customizer method to be
- * called or null
if there is no bundle event associated
- * with the call to this method.
- * @return The object to be tracked for the specified Bundle
- * object or null
if the specified Bundle
- * object should not be tracked.
- */
- public Object addingBundle(Bundle bundle, BundleEvent event)
- {
- if (bundle.getState() == Bundle.ACTIVE)
- {
- boolean isWebBundle = register(bundle);
- return isWebBundle ? bundle : null;
- }
- else if (bundle.getState() == Bundle.STOPPING)
- {
- unregister(bundle);
- }
- else
- {
- //we should not be called in that state as
- //we are registered only for ACTIVE and STOPPING
- }
- return null;
- }
+ /**
+ * A bundle tracked by the BundleTracker
has been modified.
+ *
+ *
+ * This method is called when a bundle being tracked by the
+ * BundleTracker
has had its state modified.
+ *
+ * @param bundle The Bundle
whose state has been modified.
+ * @param event The bundle event which caused this customizer method to be
+ * called or null
if there is no bundle event
+ * associated with the call to this method.
+ * @param object The tracked object for the specified bundle.
+ */
+ public void modifiedBundle(Bundle bundle, BundleEvent event, Object object)
+ {
+ // nothing the web-bundle was already track. something changed.
+ // we only reload the webapps if the bundle is stopped and restarted.
+ if (bundle.getState() == Bundle.STOPPING || bundle.getState() == Bundle.ACTIVE)
+ {
+ unregister(bundle);
+ }
+ if (bundle.getState() == Bundle.ACTIVE)
+ {
+ register(bundle);
+ }
+ }
- /**
- * A bundle tracked by the BundleTracker
has been modified.
- *
- *
- * This method is called when a bundle being tracked by the
- * BundleTracker
has had its state modified.
- *
- * @param bundle The Bundle
whose state has been modified.
- * @param event The bundle event which caused this customizer method to be
- * called or null
if there is no bundle event associated
- * with the call to this method.
- * @param object The tracked object for the specified bundle.
- */
- public void modifiedBundle(Bundle bundle, BundleEvent event,
- Object object)
- {
- //nothing the web-bundle was already track. something changed.
- //we only reload the webapps if the bundle is stopped and restarted.
-// System.err.println(bundle.getSymbolicName());
- if (bundle.getState() == Bundle.STOPPING || bundle.getState() == Bundle.ACTIVE)
- {
- unregister(bundle);
- }
- if (bundle.getState() == Bundle.ACTIVE)
- {
- register(bundle);
- }
- }
+ /**
+ * A bundle tracked by the BundleTracker
has been removed.
+ *
+ *
+ * This method is called after a bundle is no longer being tracked by the
+ * BundleTracker
.
+ *
+ * @param bundle The Bundle
that has been removed.
+ * @param event The bundle event which caused this customizer method to be
+ * called or null
if there is no bundle event
+ * associated with the call to this method.
+ * @param object The tracked object for the specified bundle.
+ */
+ public void removedBundle(Bundle bundle, BundleEvent event, Object object)
+ {
+ unregister(bundle);
+ }
- /**
- * A bundle tracked by the BundleTracker
has been removed.
- *
- *
- * This method is called after a bundle is no longer being tracked by the
- *
- * Get a URL to the bundle entry that uses a common protocol (i.e. file:
- * jar: or http: etc.).
- *
- * Get a URL to the content of the bundle entry that uses the file: protocol.
- * The content of the bundle entry may be downloaded or extracted to the local
- * file system in order to create a file: URL.
- * @return a URL to the content of the bundle entry that uses the file: protocol
- *
+ * Get a URL to the bundle entry that uses a common protocol (i.e. file:
+ * jar: or http: etc.).
+ *
+ * Get a URL to the content of the bundle entry that uses the file:
+ * protocol. The content of the bundle entry may be downloaded or extracted
+ * to the local file system in order to create a file: URL.
+ *
+ * @return a URL to the content of the bundle entry that uses the file:
+ * protocol
+ * BundleTracker
.
- *
- * @param bundle The Bundle
that has been removed.
- * @param event The bundle event which caused this customizer method to be
- * called or null
if there is no bundle event associated
- * with the call to this method.
- * @param object The tracked object for the specified bundle.
- */
- public void removedBundle(Bundle bundle, BundleEvent event,
- Object object)
- {
- unregister(bundle);
- }
-
-
- /**
- * @param bundle
- * @return true if this bundle in indeed a web-bundle.
- */
+ /**
+ * @param bundle
+ * @return true if this bundle in indeed a web-bundle.
+ */
private boolean register(Bundle bundle)
{
Dictionary, ?> dic = bundle.getHeaders();
- String warFolderRelativePath = (String)dic.get(OSGiWebappConstants.JETTY_WAR_FOLDER_PATH);
+ String warFolderRelativePath = (String) dic.get(OSGiWebappConstants.JETTY_WAR_FOLDER_PATH);
if (warFolderRelativePath != null)
{
- String contextPath = getWebContextPath(bundle, dic, false);//(String)dic.get(OSGiWebappConstants.RFC66_WEB_CONTEXTPATH);
+ String contextPath = getWebContextPath(bundle, dic, false);// (String)dic.get(OSGiWebappConstants.RFC66_WEB_CONTEXTPATH);
if (contextPath == null || !contextPath.startsWith("/"))
{
- LOG.warn("The manifest header '" + OSGiWebappConstants.JETTY_WAR_FOLDER_PATH +
- ": " + warFolderRelativePath + "' in the bundle " + bundle.getSymbolicName() +
- " is not valid: there is no Web-ContextPath defined in the manifest.");
- return false;
+ LOG.warn("The manifest header '" + OSGiWebappConstants.JETTY_WAR_FOLDER_PATH
+ + ": "
+ + warFolderRelativePath
+ + "' in the bundle "
+ + bundle.getSymbolicName()
+ + " is not valid: there is no Web-ContextPath defined in the manifest.");
+ return false;
}
// create the corresponding service and publish it in the context of
// the contributor bundle.
try
{
- JettyBootstrapActivator.registerWebapplication(bundle,warFolderRelativePath,contextPath);
+ JettyBootstrapActivator.registerWebapplication(bundle, warFolderRelativePath, contextPath);
return true;
}
catch (Throwable 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 track this bundle.
+ LOG.warn("Starting the web-bundle " + bundle.getSymbolicName() + " threw an exception.", e);
+ return true;// maybe it did not work maybe it did. safer to
+ // track this bundle.
}
}
else if (dic.get(OSGiWebappConstants.JETTY_CONTEXT_FILE_PATH) != null)
{
- String contextFileRelativePath = (String)dic.get(OSGiWebappConstants.JETTY_CONTEXT_FILE_PATH);
+ String contextFileRelativePath = (String) dic.get(OSGiWebappConstants.JETTY_CONTEXT_FILE_PATH);
if (contextFileRelativePath == null)
{
// nothing to register here.
@@ -187,7 +185,7 @@ public class WebBundleTrackerCustomizer implements BundleTrackerCustomizer {
{
try
{
- JettyBootstrapActivator.registerContext(bundle,path.trim());
+ JettyBootstrapActivator.registerContext(bundle, path.trim());
}
catch (Throwable e)
{
@@ -203,8 +201,8 @@ public class WebBundleTrackerCustomizer implements BundleTrackerCustomizer {
// (draft) of the spec: just a couple of posts on the
// world-wide-web.
URL rfc66Webxml = bundle.getEntry("/WEB-INF/web.xml");
- if (rfc66Webxml == null && dic.get(OSGiWebappConstants.RFC66_WEB_CONTEXTPATH) == null)
- {
+ if (rfc66Webxml == null && dic.get(OSGiWebappConstants.RFC66_WEB_CONTEXTPATH) == null)
+ {
return false;// no webapp in here
}
// this is risky: should we make sure that there is no classes and
@@ -215,42 +213,41 @@ public class WebBundleTrackerCustomizer implements BundleTrackerCustomizer {
// pointing to files and folders inside WEB-INF. We should
// filter-out
// META-INF too
- String rfc66ContextPath = getWebContextPath(bundle,dic,rfc66Webxml==null);
+ String rfc66ContextPath = getWebContextPath(bundle, dic, rfc66Webxml == null);
try
{
- JettyBootstrapActivator.registerWebapplication(bundle,".",rfc66ContextPath);
+ JettyBootstrapActivator.registerWebapplication(bundle, ".", rfc66ContextPath);
return true;
}
catch (Throwable e)
{
// TODO Auto-generated catch block
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.
}
}
}
private String getWebContextPath(Bundle bundle, Dictionary, ?> dic, boolean webinfWebxmlExists)
{
- String rfc66ContextPath = (String)dic.get(OSGiWebappConstants.RFC66_WEB_CONTEXTPATH);
+ String rfc66ContextPath = (String) dic.get(OSGiWebappConstants.RFC66_WEB_CONTEXTPATH);
if (rfc66ContextPath == null)
{
- if (!webinfWebxmlExists) {
- return null;
- }
+ if (!webinfWebxmlExists) { return null; }
// extract from the last token of the bundle's location:
// (really ?
// could consider processing the symbolic name as an alternative
// the location will often reflect the version.
// maybe this is relevant when the file is a war)
String location = bundle.getLocation();
- String toks[] = location.replace('\\','/').split("/");
+ String toks[] = location.replace('\\', '/').split("/");
rfc66ContextPath = toks[toks.length - 1];
// remove .jar, .war etc:
int lastDot = rfc66ContextPath.lastIndexOf('.');
if (lastDot != -1)
{
- rfc66ContextPath = rfc66ContextPath.substring(0,lastDot);
+ rfc66ContextPath = rfc66ContextPath.substring(0, lastDot);
}
}
if (!rfc66ContextPath.startsWith("/"))
@@ -259,7 +256,7 @@ public class WebBundleTrackerCustomizer implements BundleTrackerCustomizer {
}
return rfc66ContextPath;
}
-
+
private void unregister(Bundle bundle)
{
// nothing to do: when the bundle is stopped, each one of its service
@@ -268,7 +265,4 @@ public class WebBundleTrackerCustomizer implements BundleTrackerCustomizer {
// webapps registered in that bundle.
}
-
-
-
}
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 73b127cd637..7858e574243 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
@@ -25,6 +25,7 @@ import java.util.zip.ZipFile;
import org.eclipse.jetty.osgi.boot.utils.BundleFileLocatorHelper;
import org.eclipse.jetty.util.URIUtil;
+import org.eclipse.jetty.util.resource.Resource;
import org.eclipse.jetty.util.resource.FileResource;
import org.osgi.framework.Bundle;
@@ -43,11 +44,13 @@ public class DefaultFileLocatorHelper implements BundleFileLocatorHelper
// The url nuxeo and felix return is created directly from the File so it
// should work.
private static Field BUNDLE_ENTRY_FIELD = null;
+
private static Field FILE_FIELD = null;
private static Field BUNDLE_FILE_FIELD_FOR_DIR_ZIP_BUNDLE_ENTRY = null;// ZipBundleFile
- // inside
- // DirZipBundleEntry
+
+ // inside
+ // DirZipBundleEntry
private static Field ZIP_FILE_FILED_FOR_ZIP_BUNDLE_FILE = null;// ZipFile
@@ -56,8 +59,7 @@ public class DefaultFileLocatorHelper implements BundleFileLocatorHelper
* spirit of OSGi but quite necessary to support self-contained webapps and
* other situations.
*
- * @param bundle
- * The bundle
+ * @param bundle The bundle
* @return Its installation location as a file.
* @throws Exception
*/
@@ -67,19 +69,23 @@ 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
- // situations. Do use the FileResource to transform the URL into a File: URL#toURI is broken
- return new FileResource(url).getFile().getParentFile().getParentFile();
+ // situations. Do use the FileResource to transform the URL into a
+ // File: URL#toURI is broken
+ return new FileResource(url).getFile().getParentFile().getParentFile();
}
else if (url.getProtocol().equals("bundleentry"))
{
// say hello to equinox who has its own protocol.
// we use introspection like there is no tomorrow to get access to
// the File
+
URLConnection con = url.openConnection();
+ con.setUseCaches(Resource.getDefaultUseCaches()); //work around problems where url connections cache references to jars
+
if (BUNDLE_ENTRY_FIELD == null)
{
BUNDLE_ENTRY_FIELD = con.getClass().getDeclaredField("bundleEntry");
@@ -93,13 +99,16 @@ public class DefaultFileLocatorHelper implements BundleFileLocatorHelper
FILE_FIELD = bundleEntry.getClass().getDeclaredField("file");
FILE_FIELD.setAccessible(true);
}
- File f = (File)FILE_FIELD.get(bundleEntry);
+ File f = (File) FILE_FIELD.get(bundleEntry);
return f.getParentFile().getParentFile();
}
else if (bundleEntry.getClass().getName().equals("org.eclipse.osgi.baseadaptor.bundlefile.ZipBundleEntry"))
{
url = bundle.getEntry("/");
+
con = url.openConnection();
+ con.setDefaultUseCaches(Resource.getDefaultUseCaches());
+
if (BUNDLE_ENTRY_FIELD == null)
{// this one will be a DirZipBundleEntry
BUNDLE_ENTRY_FIELD = con.getClass().getDeclaredField("bundleEntry");
@@ -117,7 +126,7 @@ public class DefaultFileLocatorHelper implements BundleFileLocatorHelper
ZIP_FILE_FILED_FOR_ZIP_BUNDLE_FILE = zipBundleFile.getClass().getDeclaredField("zipFile");
ZIP_FILE_FILED_FOR_ZIP_BUNDLE_FILE.setAccessible(true);
}
- ZipFile zipFile = (ZipFile)ZIP_FILE_FILED_FOR_ZIP_BUNDLE_FILE.get(zipBundleFile);
+ ZipFile zipFile = (ZipFile) ZIP_FILE_FILED_FOR_ZIP_BUNDLE_FILE.get(zipBundleFile);
return new File(zipFile.getName());
}
else if (bundleEntry.getClass().getName().equals("org.eclipse.osgi.baseadaptor.bundlefile.DirZipBundleEntry"))
@@ -130,7 +139,7 @@ public class DefaultFileLocatorHelper implements BundleFileLocatorHelper
{
// observed this on felix-2.0.0
String location = bundle.getLocation();
-// System.err.println("location " + location);
+ // System.err.println("location " + location);
if (location.startsWith("file:/"))
{
URI uri = new URI(URIUtil.encodePath(location));
@@ -138,27 +147,32 @@ public class DefaultFileLocatorHelper implements BundleFileLocatorHelper
}
else if (location.startsWith("file:"))
{
- //location defined in the BundleArchive m_bundleArchive
- //it is relative to relative to the BundleArchive's m_archiveRootDir
- File res = new File(location.substring("file:".length()));
- if (!res.exists())
- {
- return null;
-// Object bundleArchive = getFelixBundleArchive(bundle);
-// File archiveRoot = getFelixBundleArchiveRootDir(bundleArchive);
-// String currentLocation = getFelixBundleArchiveCurrentLocation(bundleArchive);
-// System.err.println("Got the archive root " + archiveRoot.getAbsolutePath()
-// + " current location " + currentLocation + " is directory ?");
-// res = new File(archiveRoot, currentLocation != null
-// ? currentLocation : location.substring("file:".length()));
- }
- return res;
+ // location defined in the BundleArchive m_bundleArchive
+ // it is relative to relative to the BundleArchive's
+ // m_archiveRootDir
+ File res = new File(location.substring("file:".length()));
+ if (!res.exists())
+ {
+ return null;
+ // Object bundleArchive = getFelixBundleArchive(bundle);
+ // File archiveRoot =
+ // getFelixBundleArchiveRootDir(bundleArchive);
+ // String currentLocation =
+ // getFelixBundleArchiveCurrentLocation(bundleArchive);
+ // System.err.println("Got the archive root " +
+ // archiveRoot.getAbsolutePath()
+ // + " current location " + currentLocation +
+ // " is directory ?");
+ // res = new File(archiveRoot, currentLocation != null
+ // ? currentLocation : location.substring("file:".length()));
+ }
+ return res;
}
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;
+ location = URLDecoder.decode(location.substring("reference:".length()), "UTF-8");
+ File file = new File(location.substring("file:".length()));
+ return file;
}
}
return null;
@@ -179,37 +193,40 @@ public class DefaultFileLocatorHelper implements BundleFileLocatorHelper
path = path.substring(1);
}
File bundleInstall = getBundleInstallLocation(bundle);
- File webapp = path != null && path.length() != 0?new File(bundleInstall,path):bundleInstall;
- if (!webapp.exists())
- {
- throw new IllegalArgumentException("Unable to locate " + path + " inside " + bundle.getSymbolicName() + " ("
- + (bundleInstall != null?bundleInstall.getAbsolutePath():" no_bundle_location ") + ")");
+ File webapp = path != null && path.length() != 0 ? new File(bundleInstall, path) : bundleInstall;
+ if (!webapp.exists())
+ {
+ throw new IllegalArgumentException("Unable to locate " + path
+ + " inside "
+ + bundle.getSymbolicName()
+ + " ("
+ + (bundleInstall != null ? bundleInstall.getAbsolutePath() : " no_bundle_location ")
+ + ")");
}
return webapp;
}
-
+
/**
- * Helper method equivalent to Bundle#getEntry(String entryPath) except that
- * it searches for entries in the fragments by using the Bundle#findEntries method.
- *
- * @param bundle
- * @param entryPath
- * @return null or all the entries found for that path.
- */
- public Enumeration