Skip to content
Permalink
Browse files
[JENKINS-23378] Servlet 3.1 support
Test harness now runs with Jetty 9.2
  • Loading branch information
kohsuke committed Feb 25, 2016
1 parent 5681958 commit eec94edfe6a4708ebb3ea068d94d7a8e6f37996e
11 pom.xml
@@ -88,9 +88,14 @@ THE SOFTWARE.
</exclusions>
</dependency>
<dependency>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty</artifactId>
<version>6.1.26</version>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-webapp</artifactId>
<version>9.2.15.v20160210</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-security</artifactId>
<version>9.2.15.v20160210</version>
</dependency>
<dependency>
<groupId>junit</groupId>
@@ -127,6 +127,17 @@
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.resolver.AbstractArtifactResolutionException;
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
import org.eclipse.jetty.http.MimeTypes;
import org.eclipse.jetty.security.HashLoginService;
import org.eclipse.jetty.security.LoginService;
import org.eclipse.jetty.server.HttpConfiguration;
import org.eclipse.jetty.server.HttpConnectionFactory;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.ServerConnector;
import org.eclipse.jetty.util.security.Password;
import org.eclipse.jetty.webapp.Configuration;
import org.eclipse.jetty.webapp.WebAppContext;
import org.eclipse.jetty.webapp.WebXmlConfiguration;
import org.jvnet.hudson.test.HudsonHomeLoader.CopyExisting;
import org.jvnet.hudson.test.recipes.Recipe;
import org.jvnet.hudson.test.recipes.Recipe.Runner;
@@ -140,14 +151,6 @@
import org.kohsuke.stapler.Stapler;
import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.StaplerResponse;
import org.mortbay.jetty.MimeTypes;
import org.mortbay.jetty.Server;
import org.mortbay.jetty.bio.SocketConnector;
import org.mortbay.jetty.security.HashUserRealm;
import org.mortbay.jetty.security.UserRealm;
import org.mortbay.jetty.webapp.Configuration;
import org.mortbay.jetty.webapp.WebAppContext;
import org.mortbay.jetty.webapp.WebXmlConfiguration;
import org.mozilla.javascript.tools.debugger.Dim;
import org.mozilla.javascript.tools.shell.Global;
import org.springframework.dao.DataAccessException;
@@ -505,27 +508,32 @@ public void setPluginManager(PluginManager pluginManager) {
* that we need for testing.
*/
protected ServletContext createWebServer() throws Exception {
server = new Server();
server = new Server(new ThreadPoolImpl(new ThreadPoolExecutor(10, 10, 10L, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>(),new ThreadFactory() {
public Thread newThread(Runnable r) {
Thread t = new Thread(r);
t.setName("Jetty Thread Pool");
return t;
}
})));

explodedWarDir = WarExploder.getExplodedDir();
WebAppContext context = new WebAppContext(explodedWarDir.getPath(), contextPath);
context.setResourceBase(explodedWarDir.getPath());
context.setClassLoader(getClass().getClassLoader());
context.setConfigurations(new Configuration[]{new WebXmlConfiguration(), new NoListenerConfiguration()});
context.setConfigurations(new Configuration[]{new WebXmlConfiguration()});
context.addBean(new NoListenerConfiguration(context));
server.setHandler(context);
context.setMimeTypes(MIME_TYPES);
context.getSecurityHandler().setLoginService(configureUserRealm());

SocketConnector connector = new SocketConnector();
connector.setHeaderBufferSize(12*1024); // use a bigger buffer as Stapler traces can get pretty large on deeply nested URL
ServerConnector connector = new ServerConnector(server);

HttpConfiguration config = connector.getConnectionFactory(HttpConnectionFactory.class).getHttpConfiguration();
// use a bigger buffer as Stapler traces can get pretty large on deeply nested URL
config.setRequestHeaderSize(12 * 1024);
connector.setHost("localhost");

server.setThreadPool(new ThreadPoolImpl(new ThreadPoolExecutor(10, 10, 10L, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>(),new ThreadFactory() {
public Thread newThread(Runnable r) {
Thread t = new Thread(r);
t.setName("Jetty Thread Pool");
return t;
}
})));
server.addConnector(connector);
server.addUserRealm(configureUserRealm());
server.start();

localPort = connector.getLocalPort();
@@ -536,16 +544,12 @@ public Thread newThread(Runnable r) {
/**
* Configures a security realm for a test.
*/
protected UserRealm configureUserRealm() {
HashUserRealm realm = new HashUserRealm();
protected LoginService configureUserRealm() {
HashLoginService realm = new HashLoginService();
realm.setName("default"); // this is the magic realm name to make it effective on everywhere
realm.put("alice","alice");
realm.put("bob","bob");
realm.put("charlie","charlie");

realm.addUserToRole("alice","female");
realm.addUserToRole("bob","male");
realm.addUserToRole("charlie","male");
realm.update("alice", new Password("alice"), new String[]{"female"});
realm.update("bob", new Password("bob"), new String[]{"male"});
realm.update("charlie", new Password("charlie"), new String[]{"male"});

return realm;
}
@@ -3,11 +3,11 @@
import hudson.Util;
import hudson.util.IOUtils;
import org.apache.commons.io.FileUtils;
import org.mortbay.jetty.Server;
import org.mortbay.jetty.bio.SocketConnector;
import org.mortbay.jetty.handler.ContextHandlerCollection;
import org.mortbay.jetty.servlet.Context;
import org.mortbay.jetty.servlet.ServletHolder;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.ServerConnector;
import org.eclipse.jetty.server.handler.ContextHandlerCollection;
import org.eclipse.jetty.servlet.ServletContextHandler;
import org.eclipse.jetty.servlet.ServletHolder;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
@@ -40,10 +40,10 @@ public JavaNetReverseProxy(File cacheFolder) throws Exception {
ContextHandlerCollection contexts = new ContextHandlerCollection();
server.setHandler(contexts);

Context root = new Context(contexts, "/", Context.SESSIONS);
ServletContextHandler root = new ServletContextHandler(contexts, "/", ServletContextHandler.SESSIONS);
root.addServlet(new ServletHolder(this), "/");

SocketConnector connector = new SocketConnector();
ServerConnector connector = new ServerConnector(server);
server.addConnector(connector);
server.start();

@@ -175,6 +175,17 @@
import org.apache.commons.io.IOUtils;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.resolver.AbstractArtifactResolutionException;
import org.eclipse.jetty.http.MimeTypes;
import org.eclipse.jetty.security.HashLoginService;
import org.eclipse.jetty.security.LoginService;
import org.eclipse.jetty.server.HttpConfiguration;
import org.eclipse.jetty.server.HttpConnectionFactory;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.ServerConnector;
import org.eclipse.jetty.util.security.Password;
import org.eclipse.jetty.webapp.Configuration;
import org.eclipse.jetty.webapp.WebAppContext;
import org.eclipse.jetty.webapp.WebXmlConfiguration;
import org.hamcrest.Matchers;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.not;
@@ -203,14 +214,6 @@
import org.kohsuke.stapler.Stapler;
import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.StaplerResponse;
import org.mortbay.jetty.MimeTypes;
import org.mortbay.jetty.Server;
import org.mortbay.jetty.bio.SocketConnector;
import org.mortbay.jetty.security.HashUserRealm;
import org.mortbay.jetty.security.UserRealm;
import org.mortbay.jetty.webapp.Configuration;
import org.mortbay.jetty.webapp.WebAppContext;
import org.mortbay.jetty.webapp.WebXmlConfiguration;
import org.mozilla.javascript.tools.debugger.Dim;
import org.mozilla.javascript.tools.shell.Global;
import org.springframework.dao.DataAccessException;
@@ -606,29 +609,32 @@ public File getWebAppRoot() throws Exception {
* that we need for testing.
*/
protected ServletContext createWebServer() throws Exception {
server = new Server();
server = new Server(new ThreadPoolImpl(new ThreadPoolExecutor(10, 10, 10L, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>(),new ThreadFactory() {
public Thread newThread(Runnable r) {
Thread t = new Thread(r);
t.setName("Jetty Thread Pool");
return t;
}
})));

WebAppContext context = new WebAppContext(WarExploder.getExplodedDir().getPath(), contextPath);
context.setClassLoader(getClass().getClassLoader());
context.setConfigurations(new Configuration[]{new WebXmlConfiguration(), new NoListenerConfiguration()});
context.setConfigurations(new Configuration[]{new WebXmlConfiguration()});
context.addBean(new NoListenerConfiguration(context));
server.setHandler(context);
context.setMimeTypes(MIME_TYPES);
context.getSecurityHandler().setLoginService(configureUserRealm());
context.setResourceBase(WarExploder.getExplodedDir().getPath());

SocketConnector connector = new SocketConnector();
connector.setHeaderBufferSize(12*1024); // use a bigger buffer as Stapler traces can get pretty large on deeply nested URL
ServerConnector connector = new ServerConnector(server);
HttpConfiguration config = connector.getConnectionFactory(HttpConnectionFactory.class).getHttpConfiguration();
// use a bigger buffer as Stapler traces can get pretty large on deeply nested URL
config.setRequestHeaderSize(12 * 1024);
connector.setHost("localhost");
if (System.getProperty("port")!=null)
connector.setPort(Integer.parseInt(System.getProperty("port")));

server.setThreadPool(new ThreadPoolImpl(new ThreadPoolExecutor(10, 10, 10L, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>(),new ThreadFactory() {
public Thread newThread(Runnable r) {
Thread t = new Thread(r);
t.setName("Jetty Thread Pool");
return t;
}
})));
server.addConnector(connector);
server.addUserRealm(configureUserRealm());
server.start();

localPort = connector.getLocalPort();
@@ -640,16 +646,12 @@ public Thread newThread(Runnable r) {
/**
* Configures a security realm for a test.
*/
public UserRealm configureUserRealm() {
HashUserRealm realm = new HashUserRealm();
protected LoginService configureUserRealm() {
HashLoginService realm = new HashLoginService();
realm.setName("default"); // this is the magic realm name to make it effective on everywhere
realm.put("alice","alice");
realm.put("bob","bob");
realm.put("charlie","charlie");

realm.addUserToRole("alice","female");
realm.addUserToRole("bob","male");
realm.addUserToRole("charlie","male");
realm.update("alice", new Password("alice"), new String[]{"female"});
realm.update("bob", new Password("bob"), new String[]{"male"});
realm.update("charlie", new Password("charlie"), new String[]{"male"});

return realm;
}
@@ -23,8 +23,9 @@
*/
package org.jvnet.hudson.test;

import org.mortbay.jetty.webapp.Configuration;
import org.mortbay.jetty.webapp.WebAppContext;
import org.eclipse.jetty.util.component.AbstractLifeCycle;
import org.eclipse.jetty.webapp.AbstractConfiguration;
import org.eclipse.jetty.webapp.WebAppContext;

import javax.servlet.ServletContextListener;

@@ -37,27 +38,15 @@
*
* @author Kohsuke Kawaguchi
*/
final class NoListenerConfiguration implements Configuration {
private WebAppContext context;
final class NoListenerConfiguration extends AbstractLifeCycle {
private final WebAppContext context;

public void setWebAppContext(WebAppContext context) {
NoListenerConfiguration(WebAppContext context) {
this.context = context;
}

public WebAppContext getWebAppContext() {
return context;
}

public void configureClassLoader() throws Exception {
}

public void configureDefaults() throws Exception {
}

public void configureWebApp() throws Exception {
@Override
protected void doStart() throws Exception {
context.setEventListeners(null);
}

public void deconfigureWebApp() throws Exception {
}
}
@@ -1,9 +1,10 @@
package org.jvnet.hudson.test;

import org.mortbay.component.AbstractLifeCycle;
import org.mortbay.thread.ThreadPool;
import org.eclipse.jetty.util.component.AbstractLifeCycle;
import org.eclipse.jetty.util.thread.ThreadPool;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.RejectedExecutionException;
import java.util.concurrent.TimeUnit;

/**
@@ -16,12 +17,12 @@ public ThreadPoolImpl(ExecutorService es) {
this.es = es;
}

public boolean dispatch(Runnable job) {
@Override
public void execute(Runnable job) {
if (!isRunning() || job==null)
return false;
throw new RejectedExecutionException();

es.submit(job);
return true;
}

public void join() throws InterruptedException {

0 comments on commit eec94ed

Please sign in to comment.