[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[jetty-commit] r1201 - in jetty/trunk: jetty-deploy/src/main/java/org/eclipse/jetty/deploy/providers jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/internal/webapp jetty-osgi/jetty-osgi-boot-jsp/src/main/java/org/eclipse/jetty/osgi/boot/jasper

Author: hmalphett
Date: 2010-01-17 22:13:27 -0500 (Sun, 17 Jan 2010)
New Revision: 1201

Modified:
   jetty/trunk/jetty-deploy/src/main/java/org/eclipse/jetty/deploy/providers/WebAppProvider.java
   jetty/trunk/jetty-osgi/jetty-osgi-boot-jsp/src/main/java/org/eclipse/jetty/osgi/boot/jasper/WebappRegistrationCustomizerImpl.java
   jetty/trunk/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/OSGiAppProvider.java
   jetty/trunk/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/internal/webapp/WebappRegistrationHelper.java
Log:
cleaned the workaround now that bug 294799 is fixed. added to OSGiAppProvieder the same parameters that WebAppProvider for configuration of WebAppContext

Modified: jetty/trunk/jetty-deploy/src/main/java/org/eclipse/jetty/deploy/providers/WebAppProvider.java
===================================================================
--- jetty/trunk/jetty-deploy/src/main/java/org/eclipse/jetty/deploy/providers/WebAppProvider.java	2010-01-16 02:09:35 UTC (rev 1200)
+++ jetty/trunk/jetty-deploy/src/main/java/org/eclipse/jetty/deploy/providers/WebAppProvider.java	2010-01-18 03:13:27 UTC (rev 1201)
@@ -81,24 +81,6 @@
     }
 
     /* ------------------------------------------------------------ */
-    /** Get the extractWars.
-     * @return the extractWars
-     */
-    public boolean isExtractWars()
-    {
-        return _extractWars;
-    }
-
-    /* ------------------------------------------------------------ */
-    /** Set the extractWars.
-     * @param extractWars the extractWars to set
-     */
-    public void setExtractWars(boolean extractWars)
-    {
-        _extractWars = extractWars;
-    }
-
-    /* ------------------------------------------------------------ */
     /** Get the parentLoaderPriority.
      * @return the parentLoaderPriority
      */

Modified: jetty/trunk/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/OSGiAppProvider.java
===================================================================
--- jetty/trunk/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/OSGiAppProvider.java	2010-01-16 02:09:35 UTC (rev 1200)
+++ jetty/trunk/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/OSGiAppProvider.java	2010-01-18 03:13:27 UTC (rev 1201)
@@ -22,6 +22,7 @@
 import org.eclipse.jetty.deploy.App;
 import org.eclipse.jetty.deploy.AppProvider;
 import org.eclipse.jetty.deploy.DeploymentManager;
+import org.eclipse.jetty.deploy.providers.ContextProvider;
 import org.eclipse.jetty.deploy.providers.ScanningAppProvider;
 import org.eclipse.jetty.server.handler.ContextHandler;
 import org.eclipse.jetty.util.resource.Resource;
@@ -44,6 +45,10 @@
 public class OSGiAppProvider extends ScanningAppProvider implements AppProvider
 {
     
+    private boolean _extractWars = false;
+    private boolean _parentLoaderPriority = false;
+    private String _defaultsDescriptor;
+	
 	/**
 	 * When a context file corresponds to a deployed bundle and is changed we
 	 * reload the corresponding bundle.
@@ -79,17 +84,27 @@
         return null;
 	}
 	
-	public OSGiAppProvider(File contextsDir) {
+	/**
+	 * Default OSGiAppProvider consutructed when none are defined in the jetty.xml
+	 * configuration.
+	 * @param contextsDir
+	 */
+	public OSGiAppProvider() {
 		super(new Filter());
 		((Filter)super._filenameFilter)._enclosedInstance = this;
-		try {
-			setMonitoredDir(Resource.newResource(contextsDir.toURI()));
-		} catch (IOException e) {
-			// TODO Auto-generated catch block
-			e.printStackTrace();
-		}
 	}
+
 	
+	/**
+	 * Default OSGiAppProvider consutructed when none are defined in the jetty.xml
+	 * configuration.
+	 * @param contextsDir
+	 */
+	public OSGiAppProvider(File contextsDir) throws IOException {
+		this();
+		setMonitoredDir(Resource.newResource(contextsDir.toURI()));
+	}
+	
     /**
      * Returns the ContextHandler that was created by WebappRegistractionHelper
      * @see AppProvider
@@ -176,5 +191,113 @@
         }
     }
     
+	////copied from WebAppProvider as the parameters are identical.
+    /* ------------------------------------------------------------ */
+    /** Get the extractWars.
+     * @return the extractWars
+     */
+    public boolean isExtractWars()
+    {
+        return _extractWars;
+    }
+
+    /* ------------------------------------------------------------ */
+    /** Set the extractWars.
+     * @param extractWars the extractWars to set
+     */
+    public void setExtractWars(boolean extractWars)
+    {
+        _extractWars = extractWars;
+    }
+
+    /* ------------------------------------------------------------ */
+    /** Get the parentLoaderPriority.
+     * @return the parentLoaderPriority
+     */
+    public boolean isParentLoaderPriority()
+    {
+        return _parentLoaderPriority;
+    }
+
+    /* ------------------------------------------------------------ */
+    /** Set the parentLoaderPriority.
+     * @param parentLoaderPriority the parentLoaderPriority to set
+     */
+    public void setParentLoaderPriority(boolean parentLoaderPriority)
+    {
+        _parentLoaderPriority = parentLoaderPriority;
+    }
+
+    /* ------------------------------------------------------------ */
+    /** Get the defaultsDescriptor.
+     * @return the defaultsDescriptor
+     */
+    public String getDefaultsDescriptor()
+    {
+        return _defaultsDescriptor;
+    }
+
+    /* ------------------------------------------------------------ */
+    /** Set the defaultsDescriptor.
+     * @param defaultsDescriptor the defaultsDescriptor to set
+     */
+    public void setDefaultsDescriptor(String defaultsDescriptor)
+    {
+        _defaultsDescriptor = defaultsDescriptor;
+    }
+
+    /**
+     * The context xml directory.
+     * In fact it is the directory watched by the scanner.
+     */
+    public File getContextXmlDirAsFile()
+    {
+        try {
+        	Resource monitoredDir = getMonitoredDir();
+        	if (monitoredDir == null)
+        		return null;
+			return monitoredDir.getFile();
+		} catch (IOException e) {
+			e.printStackTrace();
+			return null;
+		}
+    }
+
     
+    /* ------------------------------------------------------------ */
+    /**
+     * The context xml directory.
+     * In fact it is the directory watched by the scanner.
+     */
+    public String getContextXmlDir()
+    {
+        try {
+        	Resource monitoredDir = getMonitoredDir();
+        	if (monitoredDir == null)
+        		return null;
+			return monitoredDir.getFile().toURI().toString();
+		} catch (IOException e) {
+			e.printStackTrace();
+			return null;
+		}
+    }
+
+    /* ------------------------------------------------------------ */
+    /**
+     * Set the directory in which to look for context XML files.
+     * <p>
+     * If a webapp call "foo/" or "foo.war" is discovered in the monitored
+     * directory, then the ContextXmlDir is examined to see if a foo.xml
+     * file exists.  If it does, then this deployer will not deploy the webapp
+     * and the ContextProvider should be used to act on the foo.xml file.
+     * @see ContextProvider
+     * @param contextsDir
+     */
+    public void setContextXmlDir(String contextsDir)
+    {
+    	setMonitoredDir(contextsDir);
+    }
+
+	
+    
 }

Modified: jetty/trunk/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/internal/webapp/WebappRegistrationHelper.java
===================================================================
--- jetty/trunk/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/internal/webapp/WebappRegistrationHelper.java	2010-01-16 02:09:35 UTC (rev 1200)
+++ jetty/trunk/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/internal/webapp/WebappRegistrationHelper.java	2010-01-18 03:13:27 UTC (rev 1201)
@@ -20,7 +20,6 @@
 import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.io.InputStream;
-import java.lang.reflect.Field;
 import java.net.MalformedURLException;
 import java.net.URL;
 import java.net.URLClassLoader;
@@ -32,7 +31,9 @@
 import java.util.zip.ZipEntry;
 
 import org.eclipse.jetty.deploy.AppProvider;
+import org.eclipse.jetty.deploy.ContextDeployer;
 import org.eclipse.jetty.deploy.DeploymentManager;
+import org.eclipse.jetty.deploy.WebAppDeployer;
 import org.eclipse.jetty.osgi.boot.JettyBootstrapActivator;
 import org.eclipse.jetty.osgi.boot.OSGiAppProvider;
 import org.eclipse.jetty.osgi.boot.OSGiWebappConstants;
@@ -50,12 +51,9 @@
 import org.eclipse.jetty.server.handler.HandlerCollection;
 import org.eclipse.jetty.server.handler.RequestLogHandler;
 import org.eclipse.jetty.server.nio.SelectChannelConnector;
-import org.eclipse.jetty.util.AttributesMap;
 import org.eclipse.jetty.util.log.Log;
 import org.eclipse.jetty.util.log.Logger;
 import org.eclipse.jetty.util.resource.Resource;
-import org.eclipse.jetty.webapp.Configuration;
-import org.eclipse.jetty.webapp.JettyWebXmlConfiguration;
 import org.eclipse.jetty.webapp.WebAppContext;
 import org.eclipse.jetty.xml.XmlConfiguration;
 import org.osgi.framework.Bundle;
@@ -382,9 +380,18 @@
                     break;
                 }
             }
-            if (_provider == null) {
+            if (_provider == null)
+            {
             	//create it on the fly with reasonable default values.
-            	_provider = new OSGiAppProvider(getOSGiContextsHome());
+            	try
+            	{
+					_provider = new OSGiAppProvider();
+					_provider.setMonitoredDir(
+							Resource.newResource(getDefaultOSGiContextsHome(
+									new File(System.getProperty("jetty.home"))).toURI()));
+				} catch (IOException e) {
+					e.printStackTrace();
+				}
             	_deploymentManager.addAppProvider(_provider);
             }
         }
@@ -442,6 +449,7 @@
 
     /**
      * @See {@link WebAppDeployer#scan()}
+     * TODO: refacotr this into the createContext method of OSGiAppProvider.
      * 
      * @param webapp
      * @param contextPath
@@ -461,93 +469,11 @@
             // make sure we provide access to all the jetty bundles by going
             // through this bundle.
             OSGiWebappClassLoader composite = createWebappClassLoader(contributor);
-            // configure with access to all jetty classes and also all the
-            // classes
+            // configure with access to all jetty classes and also all the classes
             // that the contributor gives access to.
             Thread.currentThread().setContextClassLoader(composite);
 
-            // final WebXmlConfiguration webXml = new WebXmlConfiguration();
-            // webXml.configure(context);
-
-            final JettyWebXmlConfiguration jettyXml = new JettyWebXmlConfiguration()
-            {
-                // workaround for
-                // https://bugs.eclipse.org/bugs/show_bug.cgi?id=294799
-                // remove it when it is fixed.
-                /**
-                 * Configure Apply web-jetty.xml configuration
-                 * 
-                 * @see Configuration#configure(WebAppContext)
-                 */
-                public void configure(WebAppContext context) throws Exception
-                {
-                    // cannot configure if the _context is already started
-                    if (context.isStarted())
-                    {
-                        if (Log.isDebugEnabled())
-                        {
-                            Log.debug("Cannot configure webapp after it is started");
-                        }
-                        return;
-                    }
-
-                    if (Log.isDebugEnabled())
-                        Log.debug("Configuring web-jetty.xml");
-
-                    Resource web_inf = context.getWebInf();
-                    // handle any WEB-INF descriptors
-                    if (web_inf != null && web_inf.isDirectory())
-                    {
-                        // do jetty.xml file
-                        Resource jetty = web_inf.addPath("jetty7-web.xml");
-                        if (!jetty.exists())
-                            jetty = web_inf.addPath("jetty-web.xml");
-                        if (!jetty.exists())
-                            jetty = web_inf.addPath("web-jetty.xml");
-
-                        if (jetty.exists())
-                        {
-                            // No server classes while configuring
-                            String[] old_server_classes = context.getServerClasses();
-                            try
-                            {
-                                context.setServerClasses(null);
-                                if (Log.isDebugEnabled())
-                                    Log.debug("Configure: " + jetty);
-                                XmlConfiguration jetty_config = new XmlConfiguration(jetty.getURL());
-                                jetty_config.configure(context);
-//                                jetty_config.getProperties().add("jetty.home", );
-                            }
-                            finally
-                            {
-                                if (context.getServerClasses() == null)
-                                    context.setServerClasses(old_server_classes);
-                            }
-                        }
-                    }
-                }
-
-            };
-            // jettyXml.configure(context);
-
-            context = new WebAppContext(webapp.getAbsolutePath(),contextPath)
-            {
-                @Override
-                protected void loadConfigurations() throws Exception
-                {
-                    super.loadConfigurations();
-                    // now replace the default JettyWebXmlConfiguration by our
-                    // own.
-                    for (int i = 0; i < getConfigurations().length; i++)
-                    {
-                        if (getConfigurations()[i] instanceof JettyWebXmlConfiguration)
-                        {
-                            getConfigurations()[i] = jettyXml;
-                        }
-                    }
-                }
-            };
-            
+            context = new WebAppContext(webapp.getAbsolutePath(),contextPath);
             context.setExtraClasspath(extraClasspath);
 
             if (webXmlPath != null && webXmlPath.length() != 0)
@@ -567,6 +493,11 @@
                 }
             }
 
+            if (defaultWebXmlPath == null || defaultWebXmlPath.length() == 0)
+            {
+            	//use the one defined by the OSGiAppProvider.
+            	defaultWebXmlPath = _provider.getDefaultsDescriptor();
+            }
             if (defaultWebXmlPath != null && defaultWebXmlPath.length() != 0)
             {
                 File defaultWebXml = null;
@@ -583,14 +514,11 @@
                     context.setDefaultsDescriptor(defaultWebXml.getAbsolutePath());
                 }
             }
+            
+            //other parameters that might be defines on the OSGiAppProvider:
+            context.setParentLoaderPriority(_provider.isParentLoaderPriority());
 
             configureWebAppContext(context,contributor);
-
-            // ok now register this webapp. we checked when we started jetty
-            // that there
-            // was at least one such handler for webapps.
-//            _ctxtHandler.addHandler(context);
-
             configureWebappClassLoader(contributor,context,composite);
 
             // @see
@@ -600,7 +528,7 @@
             // through the webapp classloader.
             oldServerClasses = context.getServerClasses();
             context.setServerClasses(null);
-            _provider.addContext(context);//context.start();//we don't start the context ourselves anymore.
+            _provider.addContext(context);
 
             return context;
         }
@@ -629,11 +557,13 @@
     }
 
     /**
-     * @return The folder in which the context files of the osgi bundles are
-     *         located and watched. Or null when the system property
+     * @return The default folder in which the context files of the osgi bundles
+     *         are located and watched. Or null when the system property
      *         "jetty.osgi.contexts.home" is not defined.
+     *         If the configuration file defines the OSGiAppProvider's context.
+     *         This will not be taken into account.
      */
-    File getOSGiContextsHome()
+    File getDefaultOSGiContextsHome(File jettyHome)
     {
         String jettyContextsHome = System.getProperty("jetty.osgi.contexts.home");
         if (jettyContextsHome != null)
@@ -645,8 +575,13 @@
             }
             return contextsHome;
         }
-        return new File(System.getProperty("jetty.home") + "/contexts");
+        return new File(jettyHome, "/contexts");
     }
+    
+    File getOSGiContextsHome()
+    {
+    	return _provider.getContextXmlDirAsFile();
+    }
 
     /**
      * This type of registration relies on jetty's complete context xml file.
@@ -661,7 +596,7 @@
     public ContextHandler registerContext(Bundle contributor, String contextFileRelativePath, String extraClasspath, String overrideBundleInstallLocation)
             throws Exception
     {
-        File contextsHome = getOSGiContextsHome();
+        File contextsHome = _provider.getContextXmlDirAsFile();
         if (contextsHome != null)
         {
             File prodContextFile = new File(contextsHome,contributor.getSymbolicName() + "/" + contextFileRelativePath);

Modified: jetty/trunk/jetty-osgi/jetty-osgi-boot-jsp/src/main/java/org/eclipse/jetty/osgi/boot/jasper/WebappRegistrationCustomizerImpl.java
===================================================================
--- jetty/trunk/jetty-osgi/jetty-osgi-boot-jsp/src/main/java/org/eclipse/jetty/osgi/boot/jasper/WebappRegistrationCustomizerImpl.java	2010-01-16 02:09:35 UTC (rev 1200)
+++ jetty/trunk/jetty-osgi/jetty-osgi-boot-jsp/src/main/java/org/eclipse/jetty/osgi/boot/jasper/WebappRegistrationCustomizerImpl.java	2010-01-18 03:13:27 UTC (rev 1201)
@@ -41,14 +41,15 @@
     public WebappRegistrationCustomizerImpl()
     {
         fixupDtdResolution();
+        //sanity check:
         try
         {
             Class cl = getClass().getClassLoader().loadClass("org.apache.jasper.servlet.JspServlet");
-            System.err.println("found the jsp servlet: " + cl.getName());
+            //System.err.println("found the jsp servlet: " + cl.getName());
         }
         catch (ClassNotFoundException e)
         {
-            // TODO Auto-generated catch block
+        	System.err.println("Unable to locate the JspServlet: jsp support unavailable.");
             e.printStackTrace();
         }
     }