small cleanup no use to compute twice the jars with tlds.
git-svn-id: svn+ssh://dev.eclipse.org/svnroot/rt/org.eclipse.jetty/jetty/trunk@2028 7e9141cc-0065-0410-87d8-b60c137991c4
This commit is contained in:
parent
1511c6e9cc
commit
103bdc47c3
|
@ -25,7 +25,7 @@
|
|||
</goals>
|
||||
<configuration>
|
||||
<instructions>
|
||||
<Import-Package>!javax.net.*,*</Import-Package>
|
||||
<Import-Package>javax.net.*,*</Import-Package>
|
||||
</instructions>
|
||||
</configuration>
|
||||
</execution>
|
||||
|
|
|
@ -38,7 +38,7 @@
|
|||
</goals>
|
||||
<configuration>
|
||||
<instructions>
|
||||
<Import-Package>!javax.net.*,*</Import-Package>
|
||||
<Import-Package>javax.net.*,*</Import-Package>
|
||||
</instructions>
|
||||
</configuration>
|
||||
</execution>
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
</goals>
|
||||
<configuration>
|
||||
<instructions>
|
||||
<Import-Package>!javax.management.*,*</Import-Package>
|
||||
<Import-Package>javax.management.*,*</Import-Package>
|
||||
</instructions>
|
||||
</configuration>
|
||||
</execution>
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
</goals>
|
||||
<configuration>
|
||||
<instructions>
|
||||
<Import-Package>!javax.naming.*,*</Import-Package>
|
||||
<Import-Package>javax.naming.*,*</Import-Package>
|
||||
</instructions>
|
||||
</configuration>
|
||||
</execution>
|
||||
|
|
|
@ -14,12 +14,15 @@
|
|||
// ========================================================================
|
||||
package org.eclipse.jetty.osgi.boot;
|
||||
|
||||
import java.net.URL;
|
||||
import java.util.Dictionary;
|
||||
import java.util.Hashtable;
|
||||
import java.util.Properties;
|
||||
import java.util.StringTokenizer;
|
||||
|
||||
import org.eclipse.jetty.osgi.boot.internal.webapp.JettyContextHandlerExtender;
|
||||
import org.eclipse.jetty.osgi.boot.internal.serverfactory.JettyServersManagedFactory;
|
||||
import org.eclipse.jetty.osgi.boot.internal.webapp.JettyContextHandlerServiceTracker;
|
||||
import org.eclipse.jetty.osgi.boot.internal.webapp.WebBundleTrackerCustomizer;
|
||||
import org.eclipse.jetty.osgi.boot.utils.internal.PackageAdminServiceTracker;
|
||||
import org.eclipse.jetty.server.Server;
|
||||
import org.eclipse.jetty.server.handler.ContextHandler;
|
||||
|
@ -27,8 +30,13 @@ import org.eclipse.jetty.webapp.WebAppContext;
|
|||
import org.osgi.framework.Bundle;
|
||||
import org.osgi.framework.BundleActivator;
|
||||
import org.osgi.framework.BundleContext;
|
||||
import org.osgi.framework.FrameworkUtil;
|
||||
import org.osgi.framework.Constants;
|
||||
import org.osgi.framework.ServiceReference;
|
||||
import org.osgi.framework.ServiceRegistration;
|
||||
import org.osgi.service.cm.Configuration;
|
||||
import org.osgi.service.cm.ConfigurationAdmin;
|
||||
import org.osgi.service.cm.ManagedServiceFactory;
|
||||
import org.osgi.util.tracker.BundleTracker;
|
||||
|
||||
/**
|
||||
* Experiment: bootstrap jetty's complete distrib from an OSGi bundle. Progress:
|
||||
|
@ -65,6 +73,10 @@ public class JettyBootstrapActivator implements BundleActivator
|
|||
private Server _server;
|
||||
private JettyContextHandlerServiceTracker _jettyContextHandlerTracker;
|
||||
private PackageAdminServiceTracker _packageAdminServiceTracker;
|
||||
private BundleTracker _webBundleTracker;
|
||||
|
||||
private ServiceRegistration _jettyServerFactoryService;
|
||||
|
||||
|
||||
/**
|
||||
* Setup a new jetty Server, registers it as a service. Setup the Service
|
||||
|
@ -82,6 +94,14 @@ public class JettyBootstrapActivator implements BundleActivator
|
|||
// should activate.
|
||||
_packageAdminServiceTracker = new PackageAdminServiceTracker(context);
|
||||
|
||||
//Register the Jetty Server Factory as a ManagedServiceFactory:
|
||||
Properties jettyServerMgdFactoryServiceProps = new Properties();
|
||||
jettyServerMgdFactoryServiceProps.put("pid", OSGiWebappConstants.MANAGED_JETTY_SERVER_FACTORY_PID);
|
||||
_jettyServerFactoryService = context.registerService(
|
||||
ManagedServiceFactory.class.getName(), new JettyServersManagedFactory(),
|
||||
jettyServerMgdFactoryServiceProps);
|
||||
|
||||
|
||||
// todo: replace all this by the ManagedFactory so that we can start
|
||||
// multiple jetty servers.
|
||||
_server = new Server();
|
||||
|
@ -95,12 +115,10 @@ public class JettyBootstrapActivator implements BundleActivator
|
|||
// kind of nice not to so we can debug what is missing easily.
|
||||
context.addServiceListener(_jettyContextHandlerTracker,"(objectclass=" + ContextHandler.class.getName() + ")");
|
||||
|
||||
// now ready to support the Extender pattern:
|
||||
JettyContextHandlerExtender jettyContexHandlerExtender = new JettyContextHandlerExtender();
|
||||
context.addBundleListener(jettyContexHandlerExtender);
|
||||
|
||||
jettyContexHandlerExtender.init(context);
|
||||
|
||||
// now ready to support the Extender pattern:
|
||||
_webBundleTracker = new BundleTracker(context,
|
||||
Bundle.ACTIVE | Bundle.STOPPING, new WebBundleTrackerCustomizer());
|
||||
_webBundleTracker.open();
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -113,28 +131,55 @@ public class JettyBootstrapActivator implements BundleActivator
|
|||
{
|
||||
try
|
||||
{
|
||||
|
||||
if (_webBundleTracker != null)
|
||||
{
|
||||
_webBundleTracker.close();
|
||||
_webBundleTracker = null;
|
||||
}
|
||||
if (_jettyContextHandlerTracker != null)
|
||||
{
|
||||
_jettyContextHandlerTracker.stop();
|
||||
context.removeServiceListener(_jettyContextHandlerTracker);
|
||||
_jettyContextHandlerTracker = null;
|
||||
}
|
||||
if (_packageAdminServiceTracker != null)
|
||||
{
|
||||
_packageAdminServiceTracker.stop();
|
||||
context.removeServiceListener(_packageAdminServiceTracker);
|
||||
_packageAdminServiceTracker = null;
|
||||
}
|
||||
if (_registeredServer != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
_registeredServer.unregister();
|
||||
_registeredServer = null;
|
||||
}
|
||||
catch (IllegalArgumentException ill)
|
||||
{
|
||||
// already unregistered.
|
||||
}
|
||||
finally
|
||||
{
|
||||
_registeredServer = null;
|
||||
}
|
||||
}
|
||||
if (_jettyServerFactoryService != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
_jettyServerFactoryService.unregister();
|
||||
}
|
||||
catch (IllegalArgumentException ill)
|
||||
{
|
||||
// already unregistered.
|
||||
}
|
||||
finally
|
||||
{
|
||||
_jettyServerFactoryService = null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
finally
|
||||
{
|
||||
|
@ -232,5 +277,54 @@ public class JettyBootstrapActivator implements BundleActivator
|
|||
{
|
||||
// todo
|
||||
}
|
||||
|
||||
public static void createNewServer(Bundle contributor, String serverName, String urlsToJettyXml) throws Exception
|
||||
{
|
||||
ServiceReference configurationAdminReference =
|
||||
contributor.getBundleContext().getServiceReference( ConfigurationAdmin.class.getName() );
|
||||
|
||||
ConfigurationAdmin confAdmin = (ConfigurationAdmin) contributor.getBundleContext()
|
||||
.getService( configurationAdminReference );
|
||||
|
||||
Configuration configuration = confAdmin.createFactoryConfiguration(
|
||||
OSGiWebappConstants.MANAGED_JETTY_SERVER_FACTORY_PID, contributor.getLocation() );
|
||||
Dictionary properties = new Hashtable();
|
||||
properties.put(OSGiWebappConstants.MANAGED_JETTY_SERVER_NAME, serverName);
|
||||
|
||||
StringBuilder actualBundleUrls = new StringBuilder();
|
||||
StringTokenizer tokenizer = new StringTokenizer(urlsToJettyXml, ",", false);
|
||||
while (tokenizer.hasMoreTokens())
|
||||
{
|
||||
if (actualBundleUrls.length() != 0)
|
||||
{
|
||||
actualBundleUrls.append(",");
|
||||
}
|
||||
String token = tokenizer.nextToken();
|
||||
if (token.indexOf(':') != -1)
|
||||
{
|
||||
//a complete url. no change needed:
|
||||
actualBundleUrls.append(token);
|
||||
}
|
||||
else if (token.startsWith("/"))
|
||||
{
|
||||
//url relative to the contributor bundle:
|
||||
URL url = contributor.getEntry(token);
|
||||
if (url == null)
|
||||
{
|
||||
actualBundleUrls.append(token);
|
||||
}
|
||||
else
|
||||
{
|
||||
actualBundleUrls.append(url.toString());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
properties.put(OSGiWebappConstants.MANAGED_JETTY_JETTY_XML_URL, actualBundleUrls.toString());
|
||||
configuration.update(properties);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -75,4 +75,29 @@ public class OSGiWebappConstants
|
|||
* path is relative the file is resolved relatively to jettyhome.
|
||||
*/
|
||||
public static final String SYS_PROP_JETTY_ETC_FILES = "jetty.etc.files";
|
||||
|
||||
//for managed jetty instances, name of the configuration parameters
|
||||
/**
|
||||
* PID of the jetty servers's ManagedFactory
|
||||
*/
|
||||
public static final String MANAGED_JETTY_SERVER_FACTORY_PID = "org.eclipse.jetty.osgi.boot.managedserverfactory";
|
||||
|
||||
/**
|
||||
* The associated value of that configuration parameter is the name under which this
|
||||
* instance of the jetty server is tracked.
|
||||
* When a ContextHandler is deployed and it specifies the managedServerName property, it is deployed
|
||||
* on the corresponding jetty managed server or it throws an exception: jetty server not available.
|
||||
*/
|
||||
public static final String MANAGED_JETTY_SERVER_NAME = "managedServerName";
|
||||
|
||||
/**
|
||||
* List of URLs to the jetty.xml files that configure the server.
|
||||
*/
|
||||
public static final String MANAGED_JETTY_XML_CONFIG_URLS = SYS_PROP_JETTY_ETC_FILES;
|
||||
|
||||
/**
|
||||
* List of URLs to the folders where the legacy J2EE shared libraries are stored aka lib/ext, lib/jsp etc.
|
||||
*/
|
||||
public static final String MANAGED_JETTY_SHARED_LIB_URLS = "managedJettySharedLibUrls";
|
||||
|
||||
}
|
||||
|
|
|
@ -18,6 +18,7 @@ import java.util.Dictionary;
|
|||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.eclipse.jetty.osgi.boot.OSGiWebappConstants;
|
||||
import org.eclipse.jetty.server.Server;
|
||||
import org.osgi.service.cm.ConfigurationException;
|
||||
import org.osgi.service.cm.ManagedServiceFactory;
|
||||
|
@ -79,7 +80,18 @@ public class JettyServersManagedFactory implements ManagedServiceFactory
|
|||
*/
|
||||
public static final String JETTY_HTTPS_PORT = "jetty.http.port";
|
||||
|
||||
private Map<String, Server> _servers = new HashMap<String, Server>();
|
||||
/**
|
||||
* Servers indexed by PIDs. PIDs are generated by the ConfigurationAdmin service.
|
||||
*/
|
||||
private Map<String, Server> _serversIndexedByPID = new HashMap<String, Server>();
|
||||
/**
|
||||
* PID -> {@link OSGiWebappConstants#MANAGED_JETTY_SERVER_NAME}
|
||||
*/
|
||||
private Map<String, String> _serversNameIndexedByPID = new HashMap<String, String>();
|
||||
/**
|
||||
* {@link OSGiWebappConstants#MANAGED_JETTY_SERVER_NAME} -> PID
|
||||
*/
|
||||
private Map<String, String> _serversPIDIndexedByName = new HashMap<String, String>();
|
||||
|
||||
/**
|
||||
* Return a descriptive name of this factory.
|
||||
|
@ -93,24 +105,43 @@ public class JettyServersManagedFactory implements ManagedServiceFactory
|
|||
|
||||
public void updated(String pid, Dictionary properties) throws ConfigurationException
|
||||
{
|
||||
Server server = _servers.get(pid);
|
||||
Server server = getServerByPID(pid);
|
||||
deleted(pid);
|
||||
// do we need to collect the currently deployed http services and
|
||||
// webapps
|
||||
// to be able to re-deploy them later?
|
||||
// probably not. simply restart and see the various service trackers
|
||||
// do everything that is needed.
|
||||
|
||||
server = new Server();
|
||||
_serversIndexedByPID.put(pid, server);
|
||||
String name = (String)properties.get(OSGiWebappConstants.MANAGED_JETTY_SERVER_NAME);
|
||||
if (name == null)
|
||||
{
|
||||
throw new ConfigurationException(OSGiWebappConstants.MANAGED_JETTY_SERVER_NAME,
|
||||
"The name of the server is mandatory");
|
||||
}
|
||||
_serversNameIndexedByPID.put(pid, name);
|
||||
_serversPIDIndexedByName.put(name, pid);
|
||||
ServerInstanceWrapperHelper.start(server, pid, properties);
|
||||
}
|
||||
|
||||
public synchronized void deleted(String pid)
|
||||
{
|
||||
Server server = (Server)_servers.remove(pid);
|
||||
Server server = (Server)_serversIndexedByPID.remove(pid);
|
||||
String name = _serversNameIndexedByPID.remove(pid);
|
||||
if (name != null)
|
||||
{
|
||||
_serversPIDIndexedByName.remove(name);
|
||||
}
|
||||
else
|
||||
{
|
||||
//something incorrect going on.
|
||||
}
|
||||
if (server != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
server.stop();
|
||||
ServerInstanceWrapperHelper.stop(server, pid);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
@ -119,4 +150,15 @@ public class JettyServersManagedFactory implements ManagedServiceFactory
|
|||
}
|
||||
}
|
||||
|
||||
public synchronized Server getServerByPID(String pid)
|
||||
{
|
||||
return _serversIndexedByPID.get(pid);
|
||||
}
|
||||
|
||||
public synchronized Server getServerByName(String name)
|
||||
{
|
||||
String pid = _serversPIDIndexedByName.get(name);
|
||||
return pid != null ? _serversIndexedByPID.get(pid) : null;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -341,7 +341,7 @@ public class WebappRegistrationHelper
|
|||
try
|
||||
{
|
||||
URL[] jarsWithTlds = getJarsWithTlds();
|
||||
_commonParentClassLoaderForWebapps = jarsWithTlds == null?libExtClassLoader:new TldLocatableURLClassloader(libExtClassLoader,getJarsWithTlds());
|
||||
_commonParentClassLoaderForWebapps = jarsWithTlds == null?libExtClassLoader:new TldLocatableURLClassloader(libExtClassLoader,jarsWithTlds);
|
||||
}
|
||||
catch (MalformedURLException e)
|
||||
{
|
||||
|
|
|
@ -29,7 +29,7 @@
|
|||
<configuration>
|
||||
<instructions>
|
||||
<_versionpolicy> </_versionpolicy>
|
||||
<Import-Package>!javax.sql.*;!javax.security.*;!javax.naming.*;javax.servlet.*;version="[2.5,3.0)",javax.transaction.*;version="[1.1,1.2)",*</Import-Package>
|
||||
<Import-Package>javax.sql.*;javax.security.*;javax.naming.*;javax.servlet.*;version="[2.5,3.0)",javax.transaction.*;version="[1.1,1.2)",*</Import-Package>
|
||||
</instructions>
|
||||
</configuration>
|
||||
</execution>
|
||||
|
|
Loading…
Reference in New Issue