Merge branch 'master' of ssh://git.eclipse.org/gitroot/jetty/org.eclipse.jetty.project
This commit is contained in:
commit
154daa524a
|
@ -42,6 +42,7 @@ import org.codehaus.plexus.util.FileUtils;
|
||||||
import org.eclipse.jetty.security.LoginService;
|
import org.eclipse.jetty.security.LoginService;
|
||||||
import org.eclipse.jetty.server.Connector;
|
import org.eclipse.jetty.server.Connector;
|
||||||
import org.eclipse.jetty.server.RequestLog;
|
import org.eclipse.jetty.server.RequestLog;
|
||||||
|
import org.eclipse.jetty.server.Server;
|
||||||
import org.eclipse.jetty.server.ShutdownMonitor;
|
import org.eclipse.jetty.server.ShutdownMonitor;
|
||||||
import org.eclipse.jetty.server.handler.ContextHandler;
|
import org.eclipse.jetty.server.handler.ContextHandler;
|
||||||
import org.eclipse.jetty.server.handler.ContextHandlerCollection;
|
import org.eclipse.jetty.server.handler.ContextHandlerCollection;
|
||||||
|
@ -61,11 +62,7 @@ import org.eclipse.jetty.xml.XmlConfiguration;
|
||||||
*/
|
*/
|
||||||
public abstract class AbstractJettyMojo extends AbstractMojo
|
public abstract class AbstractJettyMojo extends AbstractMojo
|
||||||
{
|
{
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public String PORT_SYSPROPERTY = "jetty.port";
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Whether or not to include dependencies on the plugin's classpath with <scope>provided</scope>
|
* Whether or not to include dependencies on the plugin's classpath with <scope>provided</scope>
|
||||||
|
@ -277,8 +274,9 @@ public abstract class AbstractJettyMojo extends AbstractMojo
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A wrapper for the Server object
|
* A wrapper for the Server object
|
||||||
|
* @parameter
|
||||||
*/
|
*/
|
||||||
protected JettyServer server = new JettyServer();
|
protected Server server;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -304,6 +302,10 @@ public abstract class AbstractJettyMojo extends AbstractMojo
|
||||||
*/
|
*/
|
||||||
protected Thread consoleScanner;
|
protected Thread consoleScanner;
|
||||||
|
|
||||||
|
protected ServerSupport serverSupport;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
|
@ -451,11 +453,13 @@ public abstract class AbstractJettyMojo extends AbstractMojo
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public void applyJettyXml() throws Exception
|
public void applyJettyXml() throws Exception
|
||||||
{
|
{
|
||||||
if (getJettyXmlFiles() == null)
|
Server tmp = ServerSupport.applyXmlConfigurations(server, getJettyXmlFiles());
|
||||||
return;
|
if (server == null)
|
||||||
|
server = tmp;
|
||||||
this.server.applyXmlConfigurations(getJettyXmlFiles());
|
|
||||||
|
if (server == null)
|
||||||
|
server = new Server();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -469,6 +473,9 @@ public abstract class AbstractJettyMojo extends AbstractMojo
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
getLog().debug("Starting Jetty Server ...");
|
getLog().debug("Starting Jetty Server ...");
|
||||||
|
|
||||||
|
//make sure Jetty does not use URLConnection caches with the plugin
|
||||||
|
Resource.setDefaultUseCaches(false);
|
||||||
|
|
||||||
configureMonitor();
|
configureMonitor();
|
||||||
|
|
||||||
|
@ -477,7 +484,7 @@ public abstract class AbstractJettyMojo extends AbstractMojo
|
||||||
//apply any config from a jetty.xml file first which is able to
|
//apply any config from a jetty.xml file first which is able to
|
||||||
//be overwritten by config in the pom.xml
|
//be overwritten by config in the pom.xml
|
||||||
applyJettyXml ();
|
applyJettyXml ();
|
||||||
|
|
||||||
// if a <httpConnector> was specified in the pom, use it
|
// if a <httpConnector> was specified in the pom, use it
|
||||||
if (httpConnector != null)
|
if (httpConnector != null)
|
||||||
{
|
{
|
||||||
|
@ -485,46 +492,21 @@ public abstract class AbstractJettyMojo extends AbstractMojo
|
||||||
if (httpConnector.getPort() <= 0)
|
if (httpConnector.getPort() <= 0)
|
||||||
{
|
{
|
||||||
//use any jetty.port settings provided
|
//use any jetty.port settings provided
|
||||||
String tmp = System.getProperty(PORT_SYSPROPERTY, MavenServerConnector.DEFAULT_PORT_STR);
|
String tmp = System.getProperty(MavenServerConnector.PORT_SYSPROPERTY, MavenServerConnector.DEFAULT_PORT_STR);
|
||||||
httpConnector.setPort(Integer.parseInt(tmp.trim()));
|
httpConnector.setPort(Integer.parseInt(tmp.trim()));
|
||||||
}
|
}
|
||||||
if (httpConnector.getServer() == null)
|
httpConnector.setServer(server);
|
||||||
httpConnector.setServer(this.server);
|
|
||||||
this.server.addConnector(httpConnector);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// if the user hasn't configured the connectors in a jetty.xml file so use a default one
|
ServerSupport.configureConnectors(server, httpConnector);
|
||||||
Connector[] connectors = this.server.getConnectors();
|
|
||||||
if (connectors == null|| connectors.length == 0)
|
|
||||||
{
|
|
||||||
//if <httpConnector> not configured in the pom, create one
|
|
||||||
if (httpConnector == null)
|
|
||||||
{
|
|
||||||
httpConnector = new MavenServerConnector();
|
|
||||||
//use any jetty.port settings provided
|
|
||||||
String tmp = System.getProperty(PORT_SYSPROPERTY, MavenServerConnector.DEFAULT_PORT_STR);
|
|
||||||
httpConnector.setPort(Integer.parseInt(tmp.trim()));
|
|
||||||
}
|
|
||||||
if (httpConnector.getServer() == null)
|
|
||||||
httpConnector.setServer(this.server);
|
|
||||||
this.server.setConnectors(new Connector[] {httpConnector});
|
|
||||||
}
|
|
||||||
|
|
||||||
//set up a RequestLog if one is provided
|
//set up a RequestLog if one is provided and the handle structure
|
||||||
if (this.requestLog != null)
|
ServerSupport.configureHandlers(server, this.requestLog);
|
||||||
this.server.setRequestLog(this.requestLog);
|
|
||||||
|
|
||||||
//set up the webapp and any context provided
|
|
||||||
this.server.configureHandlers();
|
|
||||||
configureWebApplication();
|
configureWebApplication();
|
||||||
this.server.addWebApplication(webApp);
|
ServerSupport.addWebApplication(server, webApp);
|
||||||
|
|
||||||
// set up security realms
|
// set up security realms
|
||||||
for (int i = 0; (this.loginServices != null) && i < this.loginServices.length; i++)
|
ServerSupport.configureLoginServices(server, loginServices);
|
||||||
{
|
|
||||||
getLog().debug(this.loginServices[i].getClass().getName() + ": "+ this.loginServices[i].toString());
|
|
||||||
this.server.addBean(this.loginServices[i]);
|
|
||||||
}
|
|
||||||
|
|
||||||
//do any other configuration required by the
|
//do any other configuration required by the
|
||||||
//particular Jetty version
|
//particular Jetty version
|
||||||
|
@ -534,7 +516,6 @@ public abstract class AbstractJettyMojo extends AbstractMojo
|
||||||
this.server.start();
|
this.server.start();
|
||||||
|
|
||||||
getLog().info("Started Jetty Server");
|
getLog().info("Started Jetty Server");
|
||||||
|
|
||||||
|
|
||||||
if ( dumpOnStart )
|
if ( dumpOnStart )
|
||||||
{
|
{
|
||||||
|
@ -580,6 +561,10 @@ public abstract class AbstractJettyMojo extends AbstractMojo
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Subclasses should invoke this to setup basic info
|
* Subclasses should invoke this to setup basic info
|
||||||
* on the webapp
|
* on the webapp
|
||||||
|
|
|
@ -94,9 +94,8 @@ public class JettyEffectiveWebXml extends JettyRunMojo
|
||||||
//apply any config from a jetty.xml file first to our "fake" server instance
|
//apply any config from a jetty.xml file first to our "fake" server instance
|
||||||
//TODO probably not necessary
|
//TODO probably not necessary
|
||||||
applyJettyXml ();
|
applyJettyXml ();
|
||||||
|
|
||||||
|
|
||||||
server.configureHandlers();
|
ServerSupport.configureHandlers(server, null);
|
||||||
|
|
||||||
//ensure config of the webapp based on settings in plugin
|
//ensure config of the webapp based on settings in plugin
|
||||||
configureWebApplication();
|
configureWebApplication();
|
||||||
|
@ -114,7 +113,7 @@ public class JettyEffectiveWebXml extends JettyRunMojo
|
||||||
|
|
||||||
webApp.setQuickStartWebDescriptor(descriptor);
|
webApp.setQuickStartWebDescriptor(descriptor);
|
||||||
|
|
||||||
server.addWebApplication(webApp);
|
ServerSupport.addWebApplication(server, webApp);
|
||||||
|
|
||||||
//if our server has a thread pool associated we can do any annotation scanning multithreaded,
|
//if our server has a thread pool associated we can do any annotation scanning multithreaded,
|
||||||
//otherwise scanning will be single threaded
|
//otherwise scanning will be single threaded
|
||||||
|
|
|
@ -46,6 +46,7 @@ import org.apache.maven.plugin.MojoFailureException;
|
||||||
import org.apache.maven.plugin.descriptor.PluginDescriptor;
|
import org.apache.maven.plugin.descriptor.PluginDescriptor;
|
||||||
import org.eclipse.jetty.annotations.AnnotationConfiguration;
|
import org.eclipse.jetty.annotations.AnnotationConfiguration;
|
||||||
import org.eclipse.jetty.quickstart.QuickStartDescriptorGenerator;
|
import org.eclipse.jetty.quickstart.QuickStartDescriptorGenerator;
|
||||||
|
import org.eclipse.jetty.server.Server;
|
||||||
import org.eclipse.jetty.util.IO;
|
import org.eclipse.jetty.util.IO;
|
||||||
import org.eclipse.jetty.util.resource.Resource;
|
import org.eclipse.jetty.util.resource.Resource;
|
||||||
import org.eclipse.jetty.util.resource.ResourceCollection;
|
import org.eclipse.jetty.util.resource.ResourceCollection;
|
||||||
|
@ -257,9 +258,11 @@ public class JettyRunForkedMojo extends JettyRunMojo
|
||||||
printSystemProperties();
|
printSystemProperties();
|
||||||
|
|
||||||
//do NOT apply the jettyXml configuration - as the jvmArgs may be needed for it to work
|
//do NOT apply the jettyXml configuration - as the jvmArgs may be needed for it to work
|
||||||
|
if (server == null)
|
||||||
|
server = new Server();
|
||||||
|
|
||||||
//ensure handler structure enabled
|
//ensure handler structure enabled
|
||||||
server.configureHandlers();
|
ServerSupport.configureHandlers(server, null);
|
||||||
|
|
||||||
//ensure config of the webapp based on settings in plugin
|
//ensure config of the webapp based on settings in plugin
|
||||||
configureWebApplication();
|
configureWebApplication();
|
||||||
|
@ -280,7 +283,7 @@ public class JettyRunForkedMojo extends JettyRunMojo
|
||||||
webApp.setQuickStartWebDescriptor(Resource.newResource(forkWebXml));
|
webApp.setQuickStartWebDescriptor(Resource.newResource(forkWebXml));
|
||||||
|
|
||||||
//add webapp to our fake server instance
|
//add webapp to our fake server instance
|
||||||
server.addWebApplication(webApp);
|
ServerSupport.addWebApplication(server, webApp);
|
||||||
|
|
||||||
//if our server has a thread pool associated we can do annotation scanning multithreaded,
|
//if our server has a thread pool associated we can do annotation scanning multithreaded,
|
||||||
//otherwise scanning will be single threaded
|
//otherwise scanning will be single threaded
|
||||||
|
|
|
@ -47,6 +47,8 @@ import org.eclipse.jetty.util.thread.Scheduler;
|
||||||
*/
|
*/
|
||||||
public class MavenServerConnector extends AbstractLifeCycle implements Connector
|
public class MavenServerConnector extends AbstractLifeCycle implements Connector
|
||||||
{
|
{
|
||||||
|
public static String PORT_SYSPROPERTY = "jetty.port";
|
||||||
|
|
||||||
public static final int DEFAULT_PORT = 8080;
|
public static final int DEFAULT_PORT = 8080;
|
||||||
public static final String DEFAULT_PORT_STR = String.valueOf(DEFAULT_PORT);
|
public static final String DEFAULT_PORT_STR = String.valueOf(DEFAULT_PORT);
|
||||||
public static final int DEFAULT_MAX_IDLE_TIME = 30000;
|
public static final int DEFAULT_MAX_IDLE_TIME = 30000;
|
||||||
|
|
|
@ -16,17 +16,20 @@
|
||||||
// ========================================================================
|
// ========================================================================
|
||||||
//
|
//
|
||||||
|
|
||||||
|
|
||||||
package org.eclipse.jetty.maven.plugin;
|
package org.eclipse.jetty.maven.plugin;
|
||||||
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.Enumeration;
|
import java.util.Enumeration;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.eclipse.jetty.security.LoginService;
|
||||||
|
import org.eclipse.jetty.server.Connector;
|
||||||
import org.eclipse.jetty.server.Handler;
|
import org.eclipse.jetty.server.Handler;
|
||||||
import org.eclipse.jetty.server.RequestLog;
|
import org.eclipse.jetty.server.RequestLog;
|
||||||
|
import org.eclipse.jetty.server.Server;
|
||||||
import org.eclipse.jetty.server.handler.ContextHandlerCollection;
|
import org.eclipse.jetty.server.handler.ContextHandlerCollection;
|
||||||
import org.eclipse.jetty.server.handler.DefaultHandler;
|
import org.eclipse.jetty.server.handler.DefaultHandler;
|
||||||
import org.eclipse.jetty.server.handler.HandlerCollection;
|
import org.eclipse.jetty.server.handler.HandlerCollection;
|
||||||
|
@ -35,54 +38,16 @@ import org.eclipse.jetty.util.resource.Resource;
|
||||||
import org.eclipse.jetty.webapp.WebAppContext;
|
import org.eclipse.jetty.webapp.WebAppContext;
|
||||||
import org.eclipse.jetty.xml.XmlConfiguration;
|
import org.eclipse.jetty.xml.XmlConfiguration;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* JettyServer
|
* ServerSupport
|
||||||
*
|
*
|
||||||
* Maven jetty plugin version of a wrapper for the Server class.
|
* Helps configure the Server instance.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class JettyServer extends org.eclipse.jetty.server.Server
|
public class ServerSupport
|
||||||
{
|
{
|
||||||
private RequestLog requestLog;
|
|
||||||
private ContextHandlerCollection contexts;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public JettyServer()
|
|
||||||
{
|
|
||||||
super();
|
|
||||||
//make sure Jetty does not use URLConnection caches with the plugin
|
|
||||||
Resource.setDefaultUseCaches(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public void setRequestLog (RequestLog requestLog)
|
|
||||||
{
|
|
||||||
this.requestLog = requestLog;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @see org.eclipse.jetty.server.Server#doStart()
|
|
||||||
*/
|
|
||||||
public void doStart() throws Exception
|
|
||||||
{
|
|
||||||
super.doStart();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @see org.eclipse.jetty.server.handler.HandlerCollection#addHandler(org.eclipse.jetty.server.Handler)
|
|
||||||
*/
|
|
||||||
public void addWebApplication(WebAppContext webapp) throws Exception
|
|
||||||
{
|
|
||||||
contexts.addHandler (webapp);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set up the handler structure to receive a webapp.
|
* Set up the handler structure to receive a webapp.
|
||||||
* Also put in a DefaultHandler so we get a nice page
|
* Also put in a DefaultHandler so we get a nice page
|
||||||
|
@ -90,22 +55,25 @@ public class JettyServer extends org.eclipse.jetty.server.Server
|
||||||
* context isn't at root.
|
* context isn't at root.
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public void configureHandlers () throws Exception
|
public static void configureHandlers (Server server, RequestLog requestLog) throws Exception
|
||||||
{
|
{
|
||||||
|
if (server == null)
|
||||||
|
throw new IllegalArgumentException ("Server is null");
|
||||||
|
|
||||||
DefaultHandler defaultHandler = new DefaultHandler();
|
DefaultHandler defaultHandler = new DefaultHandler();
|
||||||
RequestLogHandler requestLogHandler = new RequestLogHandler();
|
RequestLogHandler requestLogHandler = new RequestLogHandler();
|
||||||
if (this.requestLog != null)
|
if (requestLog != null)
|
||||||
requestLogHandler.setRequestLog(this.requestLog);
|
requestLogHandler.setRequestLog(requestLog);
|
||||||
|
|
||||||
contexts = (ContextHandlerCollection)super.getChildHandlerByClass(ContextHandlerCollection.class);
|
ContextHandlerCollection contexts = findContextHandlerCollection(server);
|
||||||
if (contexts==null)
|
if (contexts == null)
|
||||||
{
|
{
|
||||||
contexts = new ContextHandlerCollection();
|
contexts = new ContextHandlerCollection();
|
||||||
HandlerCollection handlers = (HandlerCollection)super.getChildHandlerByClass(HandlerCollection.class);
|
HandlerCollection handlers = (HandlerCollection)server.getChildHandlerByClass(HandlerCollection.class);
|
||||||
if (handlers==null)
|
if (handlers == null)
|
||||||
{
|
{
|
||||||
handlers = new HandlerCollection();
|
handlers = new HandlerCollection();
|
||||||
super.setHandler(handlers);
|
server.setHandler(handlers);
|
||||||
handlers.setHandlers(new Handler[]{contexts, defaultHandler, requestLogHandler});
|
handlers.setHandlers(new Handler[]{contexts, defaultHandler, requestLogHandler});
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -114,6 +82,87 @@ public class JettyServer extends org.eclipse.jetty.server.Server
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Configure at least one connector for the server
|
||||||
|
*
|
||||||
|
* @param server
|
||||||
|
* @param connector
|
||||||
|
*/
|
||||||
|
public static void configureConnectors (Server server, Connector connector)
|
||||||
|
{
|
||||||
|
if (server == null)
|
||||||
|
throw new IllegalArgumentException("Server is null");
|
||||||
|
|
||||||
|
//if a connector is provided, use it
|
||||||
|
if (connector != null)
|
||||||
|
{
|
||||||
|
server.addConnector(connector);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// if the user hasn't configured the connectors in a jetty.xml file so use a default one
|
||||||
|
Connector[] connectors = server.getConnectors();
|
||||||
|
if (connectors == null || connectors.length == 0)
|
||||||
|
{
|
||||||
|
//Make a new default connector
|
||||||
|
MavenServerConnector tmp = new MavenServerConnector();
|
||||||
|
//use any jetty.port settings provided
|
||||||
|
String port = System.getProperty(MavenServerConnector.PORT_SYSPROPERTY, MavenServerConnector.DEFAULT_PORT_STR);
|
||||||
|
tmp.setPort(Integer.parseInt(port.trim()));
|
||||||
|
tmp.setServer(server);
|
||||||
|
server.setConnectors(new Connector[] {tmp});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set up any security LoginServices provided.
|
||||||
|
*
|
||||||
|
* @param server
|
||||||
|
* @param loginServices
|
||||||
|
*/
|
||||||
|
public static void configureLoginServices (Server server, LoginService[] loginServices)
|
||||||
|
{
|
||||||
|
if (server == null)
|
||||||
|
throw new IllegalArgumentException ("Server is null");
|
||||||
|
|
||||||
|
if (loginServices != null)
|
||||||
|
{
|
||||||
|
for (LoginService loginService:loginServices)
|
||||||
|
{
|
||||||
|
PluginLog.getLog().debug(loginService.getClass().getName() + ": "+ loginService.toString());
|
||||||
|
server.addBean(loginService);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see org.eclipse.jetty.server.handler.HandlerCollection#addHandler(org.eclipse.jetty.server.Handler)
|
||||||
|
*/
|
||||||
|
public static void addWebApplication(Server server, WebAppContext webapp) throws Exception
|
||||||
|
{
|
||||||
|
if (server == null)
|
||||||
|
throw new IllegalArgumentException ("Server is null");
|
||||||
|
ContextHandlerCollection contexts = findContextHandlerCollection(server);
|
||||||
|
if (contexts == null)
|
||||||
|
throw new IllegalStateException("ContextHandlerCollection is null");
|
||||||
|
contexts.addHandler (webapp);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static ContextHandlerCollection findContextHandlerCollection (Server server)
|
||||||
|
{
|
||||||
|
if (server == null)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
return (ContextHandlerCollection)server.getChildHandlerByClass(ContextHandlerCollection.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Apply xml files to server startup, passing in ourselves as the
|
* Apply xml files to server startup, passing in ourselves as the
|
||||||
|
@ -122,13 +171,17 @@ public class JettyServer extends org.eclipse.jetty.server.Server
|
||||||
* @param files
|
* @param files
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public void applyXmlConfigurations (List<File> files)
|
public static Server applyXmlConfigurations (Server server, List<File> files)
|
||||||
throws Exception
|
throws Exception
|
||||||
{
|
{
|
||||||
if (files == null || files.isEmpty())
|
if (files == null || files.isEmpty())
|
||||||
return;
|
return server;
|
||||||
|
|
||||||
Map<String,Object> lastMap = Collections.singletonMap("Server", (Object)this);
|
Map<String,Object> lastMap = new HashMap<String,Object>();
|
||||||
|
|
||||||
|
if (server != null)
|
||||||
|
lastMap.put("Server", server);
|
||||||
|
|
||||||
|
|
||||||
for ( File xmlFile : files )
|
for ( File xmlFile : files )
|
||||||
{
|
{
|
||||||
|
@ -152,5 +205,8 @@ public class JettyServer extends org.eclipse.jetty.server.Server
|
||||||
xmlConfiguration.configure();
|
xmlConfiguration.configure();
|
||||||
lastMap = xmlConfiguration.getIdMap();
|
lastMap = xmlConfiguration.getIdMap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return (Server)lastMap.get("Server");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -33,6 +33,7 @@ import java.util.TreeMap;
|
||||||
|
|
||||||
import org.eclipse.jetty.server.Connector;
|
import org.eclipse.jetty.server.Connector;
|
||||||
import org.eclipse.jetty.server.Handler;
|
import org.eclipse.jetty.server.Handler;
|
||||||
|
import org.eclipse.jetty.server.Server;
|
||||||
import org.eclipse.jetty.server.ShutdownMonitor;
|
import org.eclipse.jetty.server.ShutdownMonitor;
|
||||||
import org.eclipse.jetty.server.handler.HandlerCollection;
|
import org.eclipse.jetty.server.handler.HandlerCollection;
|
||||||
import org.eclipse.jetty.util.log.Log;
|
import org.eclipse.jetty.util.log.Log;
|
||||||
|
@ -57,7 +58,7 @@ public class Starter
|
||||||
private List<File> jettyXmls; // list of jetty.xml config files to apply - Mandatory
|
private List<File> jettyXmls; // list of jetty.xml config files to apply - Mandatory
|
||||||
private File contextXml; //name of context xml file to configure the webapp - Mandatory
|
private File contextXml; //name of context xml file to configure the webapp - Mandatory
|
||||||
|
|
||||||
private JettyServer server = new JettyServer();
|
private Server server;
|
||||||
private JettyWebAppContext webApp;
|
private JettyWebAppContext webApp;
|
||||||
|
|
||||||
|
|
||||||
|
@ -121,34 +122,16 @@ public class Starter
|
||||||
public void configureJetty () throws Exception
|
public void configureJetty () throws Exception
|
||||||
{
|
{
|
||||||
LOG.debug("Starting Jetty Server ...");
|
LOG.debug("Starting Jetty Server ...");
|
||||||
|
Resource.setDefaultUseCaches(false);
|
||||||
|
|
||||||
//apply any configs from jetty.xml files first
|
//apply any configs from jetty.xml files first
|
||||||
applyJettyXml ();
|
applyJettyXml ();
|
||||||
|
|
||||||
// if the user hasn't configured a connector in the jetty.xml
|
//ensure there's a connector
|
||||||
//then use a default
|
ServerSupport.configureConnectors(server, null);
|
||||||
Connector[] connectors = this.server.getConnectors();
|
|
||||||
if (connectors == null|| connectors.length == 0)
|
|
||||||
{
|
|
||||||
//if a SystemProperty -Djetty.port=<portnum> has been supplied, use that as the default port
|
|
||||||
MavenServerConnector httpConnector = new MavenServerConnector();
|
|
||||||
httpConnector.setServer(this.server);
|
|
||||||
String tmp = System.getProperty(PORT_SYSPROPERTY, MavenServerConnector.DEFAULT_PORT_STR);
|
|
||||||
httpConnector.setPort(Integer.parseInt(tmp.trim()));
|
|
||||||
connectors = new Connector[] {httpConnector};
|
|
||||||
this.server.setConnectors(connectors);
|
|
||||||
}
|
|
||||||
|
|
||||||
//check that everything got configured, and if not, make the handlers
|
|
||||||
HandlerCollection handlers = (HandlerCollection) server.getChildHandlerByClass(HandlerCollection.class);
|
|
||||||
if (handlers == null)
|
|
||||||
{
|
|
||||||
handlers = new HandlerCollection();
|
|
||||||
server.setHandler(handlers);
|
|
||||||
}
|
|
||||||
|
|
||||||
//check if contexts already configured, create if not
|
//check if contexts already configured, create if not
|
||||||
this.server.configureHandlers();
|
ServerSupport.configureHandlers(server, null);
|
||||||
|
|
||||||
webApp = new JettyWebAppContext();
|
webApp = new JettyWebAppContext();
|
||||||
|
|
||||||
|
@ -176,7 +159,7 @@ public class Starter
|
||||||
xmlConfiguration.configure(webApp);
|
xmlConfiguration.configure(webApp);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.server.addWebApplication(webApp);
|
ServerSupport.addWebApplication(server, webApp);
|
||||||
|
|
||||||
if(stopPort>0 && stopKey!=null)
|
if(stopPort>0 && stopKey!=null)
|
||||||
{
|
{
|
||||||
|
@ -431,9 +414,12 @@ public class Starter
|
||||||
*/
|
*/
|
||||||
public void applyJettyXml() throws Exception
|
public void applyJettyXml() throws Exception
|
||||||
{
|
{
|
||||||
if (jettyXmls == null)
|
Server tmp = ServerSupport.applyXmlConfigurations(server, jettyXmls);
|
||||||
return;
|
if (server == null)
|
||||||
this.server.applyXmlConfigurations(jettyXmls);
|
server = tmp;
|
||||||
|
|
||||||
|
if (server == null)
|
||||||
|
server = new Server();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue