From 2e5bc754e4e6757656fe7fb003ad8613243f9c3c Mon Sep 17 00:00:00 2001 From: Hugues Malphettes Date: Tue, 26 Jan 2010 09:38:55 +0000 Subject: [PATCH] bug #299733 tweak to support JSF taglibs. ability to register additional tag-libs directly in jetty git-svn-id: svn+ssh://dev.eclipse.org/svnroot/rt/org.eclipse.jetty/jetty/trunk@1215 7e9141cc-0065-0410-87d8-b60c137991c4 --- .../WebappRegistrationCustomizerImpl.java | 30 +++++++++++++-- .../{jasper => jsp}/FragmentActivator.java | 12 +++++- .../webapp/WebappRegistrationHelper.java | 37 ++++++++++--------- 3 files changed, 56 insertions(+), 23 deletions(-) rename jetty-osgi/jetty-osgi-boot-jsp/src/main/java/org/eclipse/jetty/osgi/boot/{jasper => jsp}/FragmentActivator.java (68%) diff --git a/jetty-osgi/jetty-osgi-boot-jsp/src/main/java/org/eclipse/jetty/osgi/boot/jasper/WebappRegistrationCustomizerImpl.java b/jetty-osgi/jetty-osgi-boot-jsp/src/main/java/org/eclipse/jetty/osgi/boot/jasper/WebappRegistrationCustomizerImpl.java index 3ddd8c0e9ac..9073bd05396 100644 --- a/jetty-osgi/jetty-osgi-boot-jsp/src/main/java/org/eclipse/jetty/osgi/boot/jasper/WebappRegistrationCustomizerImpl.java +++ b/jetty-osgi/jetty-osgi-boot-jsp/src/main/java/org/eclipse/jetty/osgi/boot/jasper/WebappRegistrationCustomizerImpl.java @@ -19,11 +19,13 @@ import java.util.ArrayList; import javax.servlet.Servlet; import javax.servlet.jsp.JspContext; +import javax.servlet.jsp.JspFactory; import org.apache.jasper.Constants; import org.apache.jasper.compiler.Localizer; import org.apache.jasper.compiler.TldLocationsCache; import org.apache.jasper.xmlparser.ParserUtils; +import org.eclipse.jetty.osgi.boot.JettyBootstrapActivator; import org.eclipse.jetty.osgi.boot.utils.BundleFileLocatorHelper; import org.eclipse.jetty.osgi.boot.utils.WebappRegistrationCustomizer; import org.osgi.framework.Bundle; @@ -41,15 +43,37 @@ public class WebappRegistrationCustomizerImpl implements WebappRegistrationCusto public WebappRegistrationCustomizerImpl() { fixupDtdResolution(); - //sanity check: + try { + //sanity check: Class cl = getClass().getClassLoader().loadClass("org.apache.jasper.servlet.JspServlet"); //System.err.println("found the jsp servlet: " + cl.getName()); } - catch (ClassNotFoundException e) + catch (Exception e) { - System.err.println("Unable to locate the JspServlet: jsp support unavailable."); + System.err.println("Unable to locate the JspServlet: jsp support unavailable."); + e.printStackTrace(); + return; + } + try + { + //bug #299733 + JspFactory fact = JspFactory.getDefaultFactory(); + if (fact == null) + { //bug #299733 + //JspFactory does a simple Class.getForName("org.apache.jasper.runtime.JspFactoryImpl") + //however its bundles does not import the jasper package + //so it fails. let's help things out: + fact = (JspFactory)JettyBootstrapActivator.class.getClassLoader() + .loadClass("org.apache.jasper.runtime.JspFactoryImpl").newInstance(); + JspFactory.setDefaultFactory(fact); + } + + } + catch (Exception e) + { + System.err.println("Unable to set the JspFactory: jsp support incomplete."); e.printStackTrace(); } } diff --git a/jetty-osgi/jetty-osgi-boot-jsp/src/main/java/org/eclipse/jetty/osgi/boot/jasper/FragmentActivator.java b/jetty-osgi/jetty-osgi-boot-jsp/src/main/java/org/eclipse/jetty/osgi/boot/jsp/FragmentActivator.java similarity index 68% rename from jetty-osgi/jetty-osgi-boot-jsp/src/main/java/org/eclipse/jetty/osgi/boot/jasper/FragmentActivator.java rename to jetty-osgi/jetty-osgi-boot-jsp/src/main/java/org/eclipse/jetty/osgi/boot/jsp/FragmentActivator.java index 086eb08943a..c96a5fbc21f 100644 --- a/jetty-osgi/jetty-osgi-boot-jsp/src/main/java/org/eclipse/jetty/osgi/boot/jasper/FragmentActivator.java +++ b/jetty-osgi/jetty-osgi-boot-jsp/src/main/java/org/eclipse/jetty/osgi/boot/jsp/FragmentActivator.java @@ -10,8 +10,10 @@ // http://www.opensource.org/licenses/apache2.0.php // You may elect to redistribute this code under either of these licenses. // ======================================================================== -package org.eclipse.jetty.osgi.boot.jasper; +package org.eclipse.jetty.osgi.boot.jsp; +import org.eclipse.jetty.osgi.boot.internal.webapp.WebappRegistrationHelper; +import org.eclipse.jetty.osgi.boot.jasper.WebappRegistrationCustomizerImpl; import org.osgi.framework.BundleActivator; import org.osgi.framework.BundleContext; @@ -20,6 +22,12 @@ import org.osgi.framework.BundleContext; * Called by the main org.eclipse.jetty.osgi.boot bundle. * Please note: this is not a real BundleActivator. Simply something called back by * the host bundle. + *

+ * 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. + *

*/ public class FragmentActivator implements BundleActivator { @@ -27,7 +35,7 @@ public class FragmentActivator implements BundleActivator * */ public void start(BundleContext context) throws Exception { - System.err.println("hello from jasper boot fragment"); + WebappRegistrationHelper.JSP_REGISTRATION_HELPERS.add(new WebappRegistrationCustomizerImpl()); } /** 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 336401bc25b..093f7dfc6f4 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 @@ -23,9 +23,12 @@ import java.io.InputStream; import java.net.MalformedURLException; import java.net.URL; import java.net.URLClassLoader; +import java.util.ArrayList; +import java.util.Collection; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Set; import java.util.StringTokenizer; import java.util.jar.JarFile; import java.util.zip.ZipEntry; @@ -77,7 +80,7 @@ import org.xml.sax.SAXParseException; *
  • support for jarred webapps is somewhat limited.
  • * */ -class WebappRegistrationHelper +public class WebappRegistrationHelper { private static Logger __logger = Log.getLogger(WebappRegistrationHelper.class.getName()); @@ -101,8 +104,12 @@ class WebappRegistrationHelper * 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. + *

    + * 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 WebappRegistrationCustomizer JSP_REGISTRATION_HELPER = null; + public static Collection JSP_REGISTRATION_HELPERS = new ArrayList(); private Server _server; private ContextHandlerCollection _ctxtHandler; @@ -137,17 +144,6 @@ class WebappRegistrationHelper if (!INITIALIZED) { INITIALIZED = true; - // setup the custom WebappRegistrationCustomizer - try - { - Class cl = Class.forName(WebappRegistrationCustomizer.CLASS_NAME); - JSP_REGISTRATION_HELPER = (WebappRegistrationCustomizer)cl.newInstance(); - } - catch (Throwable t) - { - // System.err.println("no jsp/jasper support"); - // System.exit(1); - } // setup the custom BundleClassLoaderHelper try { @@ -771,15 +767,20 @@ class WebappRegistrationHelper */ private URL[] getJarsWithTlds() throws Exception { - if (JSP_REGISTRATION_HELPER != null) + ArrayList res = new ArrayList(); + for (WebappRegistrationCustomizer regCustomizer : JSP_REGISTRATION_HELPERS) { - return JSP_REGISTRATION_HELPER.getJarsWithTlds(BUNDLE_FILE_LOCATOR_HELPER); + URL[] urls = regCustomizer.getJarsWithTlds(BUNDLE_FILE_LOCATOR_HELPER); + for (URL url : urls) + { + if (!res.contains(url)) + res.add(url); + } } + if (!res.isEmpty()) + return res.toArray(new URL[res.size()]); else - { return null; - } - } /**