Merge remote-tracking branch 'origin/jetty-9.4.x'

This commit is contained in:
Joakim Erdfelt 2017-07-12 13:18:12 -07:00
commit a9c329859d
212 changed files with 12860 additions and 10146 deletions

4
.gitattributes vendored
View File

@ -1,4 +1,8 @@
*.sh eol=lf
*.bat eol=crlf
*.txt eol=lf
*.properties eol=lf
*.java eol=lf
*.xml eol=lf
Jenkinsfile eol=lf
*.js eol=lf

2
Jenkinsfile vendored
View File

@ -53,7 +53,7 @@ node {
withEnv(mvnEnv) {
timeout(time: 90, unit: 'MINUTES') {
// Run test phase / ignore test failures
sh "mvn -B install -Dmaven.test.failure.ignore=true"
sh "mvn -B install -Dmaven.test.failure.ignore=true -Prun-its"
// Report failures in the jenkins UI
step([$class: 'JUnitResultArchiver',
testResults: '**/target/surefire-reports/TEST-*.xml'])

View File

@ -94,313 +94,313 @@
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>apache-jsp</artifactId>
<version>9.4.6-SNAPSHOT</version>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>apache-jstl</artifactId>
<version>9.4.6-SNAPSHOT</version>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-alpn-client</artifactId>
<version>9.4.6-SNAPSHOT</version>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-alpn-java-client</artifactId>
<version>9.4.6-SNAPSHOT</version>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-alpn-java-server</artifactId>
<version>9.4.6-SNAPSHOT</version>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-alpn-server</artifactId>
<version>9.4.6-SNAPSHOT</version>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-annotations</artifactId>
<version>9.4.6-SNAPSHOT</version>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-ant</artifactId>
<version>9.4.6-SNAPSHOT</version>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.cdi</groupId>
<artifactId>cdi-core</artifactId>
<version>9.4.6-SNAPSHOT</version>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.cdi</groupId>
<artifactId>cdi-full-servlet</artifactId>
<version>9.4.6-SNAPSHOT</version>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.cdi</groupId>
<artifactId>cdi-servlet</artifactId>
<version>9.4.6-SNAPSHOT</version>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.cdi</groupId>
<artifactId>cdi-websocket</artifactId>
<version>9.4.6-SNAPSHOT</version>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-client</artifactId>
<version>9.4.6-SNAPSHOT</version>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-continuation</artifactId>
<version>9.4.6-SNAPSHOT</version>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-deploy</artifactId>
<version>9.4.6-SNAPSHOT</version>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-distribution</artifactId>
<version>9.4.6-SNAPSHOT</version>
<version>${project.version}</version>
<type>zip</type>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.fcgi</groupId>
<artifactId>jetty-fcgi-client</artifactId>
<version>9.4.6-SNAPSHOT</version>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.fcgi</groupId>
<artifactId>jetty-fcgi-server</artifactId>
<version>9.4.6-SNAPSHOT</version>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.gcloud</groupId>
<artifactId>jetty-gcloud-session-manager</artifactId>
<version>9.4.6-SNAPSHOT</version>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-home</artifactId>
<version>9.4.6-SNAPSHOT</version>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-http</artifactId>
<version>9.4.6-SNAPSHOT</version>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.http2</groupId>
<artifactId>http2-client</artifactId>
<version>9.4.6-SNAPSHOT</version>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.http2</groupId>
<artifactId>http2-common</artifactId>
<version>9.4.6-SNAPSHOT</version>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.http2</groupId>
<artifactId>http2-hpack</artifactId>
<version>9.4.6-SNAPSHOT</version>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.http2</groupId>
<artifactId>http2-http-client-transport</artifactId>
<version>9.4.6-SNAPSHOT</version>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.http2</groupId>
<artifactId>http2-server</artifactId>
<version>9.4.6-SNAPSHOT</version>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-http-spi</artifactId>
<version>9.4.6-SNAPSHOT</version>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-infinispan</artifactId>
<version>9.4.6-SNAPSHOT</version>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-hazelcast</artifactId>
<version>9.4.6-SNAPSHOT</version>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-io</artifactId>
<version>9.4.6-SNAPSHOT</version>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-jaas</artifactId>
<version>9.4.6-SNAPSHOT</version>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-jaspi</artifactId>
<version>9.4.6-SNAPSHOT</version>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-jmx</artifactId>
<version>9.4.6-SNAPSHOT</version>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-jndi</artifactId>
<version>9.4.6-SNAPSHOT</version>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.memcached</groupId>
<artifactId>jetty-memcached-sessions</artifactId>
<version>9.4.6-SNAPSHOT</version>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-monitor</artifactId>
<version>9.4.6-SNAPSHOT</version>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-nosql</artifactId>
<version>9.4.6-SNAPSHOT</version>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.osgi</groupId>
<artifactId>jetty-osgi-boot</artifactId>
<version>9.4.6-SNAPSHOT</version>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.osgi</groupId>
<artifactId>jetty-osgi-boot-jsp</artifactId>
<version>9.4.6-SNAPSHOT</version>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.osgi</groupId>
<artifactId>jetty-osgi-boot-warurl</artifactId>
<version>9.4.6-SNAPSHOT</version>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.osgi</groupId>
<artifactId>jetty-httpservice</artifactId>
<version>9.4.6-SNAPSHOT</version>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-plus</artifactId>
<version>9.4.6-SNAPSHOT</version>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-proxy</artifactId>
<version>9.4.6-SNAPSHOT</version>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-quickstart</artifactId>
<version>9.4.6-SNAPSHOT</version>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-rewrite</artifactId>
<version>9.4.6-SNAPSHOT</version>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-security</artifactId>
<version>9.4.6-SNAPSHOT</version>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-server</artifactId>
<version>9.4.6-SNAPSHOT</version>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-servlet</artifactId>
<version>9.4.6-SNAPSHOT</version>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-servlets</artifactId>
<version>9.4.6-SNAPSHOT</version>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-spring</artifactId>
<version>9.4.6-SNAPSHOT</version>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-unixsocket</artifactId>
<version>9.4.6-SNAPSHOT</version>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-util</artifactId>
<version>9.4.6-SNAPSHOT</version>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-util-ajax</artifactId>
<version>9.4.6-SNAPSHOT</version>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-webapp</artifactId>
<version>9.4.6-SNAPSHOT</version>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.websocket</groupId>
<artifactId>javax-websocket-client-impl</artifactId>
<version>9.4.6-SNAPSHOT</version>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.websocket</groupId>
<artifactId>javax-websocket-server-impl</artifactId>
<version>9.4.6-SNAPSHOT</version>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.websocket</groupId>
<artifactId>websocket-api</artifactId>
<version>9.4.6-SNAPSHOT</version>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.websocket</groupId>
<artifactId>websocket-client</artifactId>
<version>9.4.6-SNAPSHOT</version>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.websocket</groupId>
<artifactId>websocket-common</artifactId>
<version>9.4.6-SNAPSHOT</version>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.websocket</groupId>
<artifactId>websocket-server</artifactId>
<version>9.4.6-SNAPSHOT</version>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>websocket-servlet</artifactId>
<version>9.4.6-SNAPSHOT</version>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-xml</artifactId>
<version>9.4.6-SNAPSHOT</version>
<version>${project.version}</version>
</dependency>
</dependencies>
</dependencyManagement>

View File

@ -10,7 +10,6 @@
<url>http://www.eclipse.org/jetty</url>
<packaging>pom</packaging>
<properties>
<weld.version>2.2.9.Final</weld.version>
</properties>
<dependencies>

View File

@ -10,7 +10,6 @@
<url>http://www.eclipse.org/jetty</url>
<packaging>jar</packaging>
<properties>
<weld.version>2.2.9.Final</weld.version>
<bundle-symbolic-name>${project.groupId}.servlet</bundle-symbolic-name>
</properties>
<build>

View File

@ -10,7 +10,6 @@
<url>http://www.eclipse.org/jetty</url>
<packaging>jar</packaging>
<properties>
<weld.version>2.2.9.Final</weld.version>
<bundle-symbolic-name>${project.groupId}.websocket</bundle-symbolic-name>
</properties>

View File

@ -18,7 +18,9 @@
package org.eclipse.jetty.cdi.websocket;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import javax.enterprise.inject.spi.Bean;
import javax.enterprise.inject.spi.BeanManager;
@ -26,90 +28,74 @@ import javax.enterprise.inject.spi.CDI;
import org.eclipse.jetty.cdi.core.AnyLiteral;
import org.eclipse.jetty.cdi.core.ScopedInstance;
import org.eclipse.jetty.util.component.ContainerLifeCycle;
import org.eclipse.jetty.util.component.LifeCycle;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;
import org.eclipse.jetty.websocket.api.Session;
import org.eclipse.jetty.websocket.common.WebSocketSession;
import org.eclipse.jetty.websocket.common.scopes.WebSocketContainerScope;
import org.eclipse.jetty.websocket.common.scopes.WebSocketSessionScope;
public class WebSocketCdiListener extends AbstractContainerListener
public class WebSocketCdiListener extends AbstractContainerListener implements WebSocketSession.Listener
{
static final Logger LOG = Log.getLogger(WebSocketCdiListener.class);
private Map<String, ScopedInstance<WebSocketScopeContext>> instances = new ConcurrentHashMap<>();
@SuppressWarnings(
{ "rawtypes", "unchecked" })
{"rawtypes", "unchecked"})
public static <T> ScopedInstance<T> newInstance(Class<T> clazz)
{
BeanManager bm = CDI.current().getBeanManager();
ScopedInstance sbean = new ScopedInstance();
Set<Bean<?>> beans = bm.getBeans(clazz,AnyLiteral.INSTANCE);
Set<Bean<?>> beans = bm.getBeans(clazz, AnyLiteral.INSTANCE);
if (beans.size() > 0)
{
sbean.bean = beans.iterator().next();
sbean.creationalContext = bm.createCreationalContext(sbean.bean);
sbean.instance = bm.getReference(sbean.bean,clazz,sbean.creationalContext);
sbean.instance = bm.getReference(sbean.bean, clazz, sbean.creationalContext);
return sbean;
}
else
{
throw new RuntimeException(String.format("Can't find class %s",clazz));
throw new RuntimeException(String.format("Can't find class %s", clazz));
}
}
public static class ContainerListener extends AbstractContainerListener
@Override
public void onCreated(WebSocketSession session)
{
private static final Logger LOG = Log.getLogger(WebSocketCdiListener.ContainerListener.class);
private final WebSocketContainerScope container;
private final ScopedInstance<WebSocketScopeContext> wsScope;
String id = toId(session);
public ContainerListener(WebSocketContainerScope container)
ScopedInstance<WebSocketScopeContext> wsScope = newInstance(WebSocketScopeContext.class);
wsScope.instance.create();
wsScope.instance.begin();
wsScope.instance.setSession(session);
instances.put(id, wsScope);
}
@Override
public void onOpened(WebSocketSession session)
{
// do nothing
}
@Override
public void onClosed(WebSocketSession session)
{
String id = toId(session);
ScopedInstance<WebSocketScopeContext> wsScope = instances.remove(id);
if (wsScope != null)
{
this.container = container;
this.wsScope = newInstance(WebSocketScopeContext.class);
this.wsScope.instance.create();
wsScope.instance.end();
wsScope.instance.destroy();
wsScope.destroy();
}
}
@Override
public void lifeCycleStarted(LifeCycle event)
{
if (event == container)
{
if (LOG.isDebugEnabled())
{
LOG.debug("starting websocket container [{}]",event);
}
wsScope.instance.begin();
return;
}
if (event instanceof WebSocketSessionScope)
{
if (LOG.isDebugEnabled())
{
LOG.debug("starting websocket session [{}]",event);
}
wsScope.instance.setSession((Session)event);
return;
}
}
@Override
public void lifeCycleStopped(LifeCycle event)
{
if (event == container)
{
if (LOG.isDebugEnabled())
{
LOG.debug("stopped websocket container [{}]",event);
}
this.wsScope.instance.end();
this.wsScope.instance.destroy();
this.wsScope.destroy();
}
}
private String toId(WebSocketSession session)
{
return session.getRemoteAddress().toString() + ">" + session.getLocalAddress().toString();
}
@Override
@ -119,19 +105,11 @@ public class WebSocketCdiListener extends AbstractContainerListener
{
if (LOG.isDebugEnabled())
{
LOG.debug("started websocket container [{}]",event);
}
ContainerListener listener = new ContainerListener((WebSocketContainerScope)event);
if (event instanceof ContainerLifeCycle)
{
ContainerLifeCycle container = (ContainerLifeCycle)event;
container.addLifeCycleListener(listener);
container.addEventListener(listener);
}
else
{
throw new RuntimeException("Unable to setup CDI against non-container: " + event.getClass().getName());
LOG.debug("started websocket container [{}]", event);
}
WebSocketContainerScope webSocketContainerScope = (WebSocketContainerScope) event;
webSocketContainerScope.addSessionListener(this);
}
}
}

View File

@ -21,15 +21,17 @@ package org.eclipse.jetty.cdi.websocket;
import static org.junit.Assert.assertTrue;
import java.io.IOException;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.TimeUnit;
import org.eclipse.jetty.toolchain.test.EventQueue;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;
import org.eclipse.jetty.websocket.api.Session;
import org.eclipse.jetty.websocket.api.WebSocketAdapter;
import org.eclipse.jetty.websocket.api.annotations.WebSocket;
import org.eclipse.jetty.websocket.common.util.TextUtil;
@WebSocket
public class CheckSocket extends WebSocketAdapter
@ -37,7 +39,7 @@ public class CheckSocket extends WebSocketAdapter
private static final Logger LOG = Log.getLogger(CheckSocket.class);
private CountDownLatch closeLatch = new CountDownLatch(1);
private CountDownLatch openLatch = new CountDownLatch(1);
private EventQueue<String> textMessages = new EventQueue<>();
private BlockingQueue<String> textMessages = new LinkedBlockingDeque<>();
public void awaitClose(int timeout, TimeUnit timeunit) throws InterruptedException
{
@ -49,7 +51,7 @@ public class CheckSocket extends WebSocketAdapter
assertTrue("Timeout waiting for open",openLatch.await(timeout,timeunit));
}
public EventQueue<String> getTextMessages()
public BlockingQueue<String> getTextMessages()
{
return textMessages;
}
@ -81,7 +83,7 @@ public class CheckSocket extends WebSocketAdapter
public void onWebSocketText(String message)
{
LOG.debug("TEXT: {}",message);
textMessages.add(message);
textMessages.offer(message);
}
public void sendText(String msg) throws IOException
@ -90,6 +92,11 @@ public class CheckSocket extends WebSocketAdapter
{
getRemote().sendString(msg);
}
else
{
LOG.warn("Not connected, cannot send {}", TextUtil.quote(msg));
LOG.debug("Session: {}", getSession());
}
}
public void close(int statusCode, String reason)

View File

@ -23,13 +23,13 @@ import static org.junit.Assert.assertThat;
import java.io.File;
import java.net.URI;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import javax.websocket.server.ServerContainer;
import org.eclipse.jetty.cdi.servlet.EmbeddedCdiHandler;
import org.eclipse.jetty.cdi.websocket.CheckSocket;
import org.eclipse.jetty.cdi.websocket.cdiapp.InfoSocket;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.ServerConnector;
import org.eclipse.jetty.toolchain.test.MavenTestingUtils;
@ -37,7 +37,9 @@ import org.eclipse.jetty.util.log.JettyLogHandler;
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.websocket.api.Session;
import org.eclipse.jetty.websocket.api.StatusCode;
import org.eclipse.jetty.websocket.api.util.WSURI;
import org.eclipse.jetty.websocket.client.WebSocketClient;
import org.eclipse.jetty.websocket.jsr356.server.deploy.WebSocketServerContainerInitializer;
import org.junit.AfterClass;
@ -76,18 +78,11 @@ public class BasicAppTest
// Add some websockets
ServerContainer container = WebSocketServerContainerInitializer.configureContext(context);
container.addEndpoint(EchoSocket.class);
container.addEndpoint(InfoSocket.class);
server.start();
String host = connector.getHost();
if (host == null)
{
host = "localhost";
}
int port = connector.getLocalPort();
serverHttpURI = new URI(String.format("http://%s:%d/",host,port));
serverWebsocketURI = new URI(String.format("ws://%s:%d/",host,port));
serverHttpURI = server.getURI().resolve("/");
serverWebsocketURI = WSURI.toWebsocket(serverHttpURI);
}
@AfterClass
@ -111,18 +106,16 @@ public class BasicAppTest
{
client.start();
CheckSocket socket = new CheckSocket();
client.connect(socket,serverWebsocketURI.resolve("/echo"));
Future<Session> futureSession = client.connect(socket,serverWebsocketURI.resolve("/echo"));
socket.awaitOpen(2,TimeUnit.SECONDS);
socket.sendText("Hello World");
socket.close(StatusCode.NORMAL,"Test complete");
socket.awaitClose(2,TimeUnit.SECONDS);
assertThat("Messages received",socket.getTextMessages().size(),is(1));
String response = socket.getTextMessages().poll();
System.err.println(response);
Session session = futureSession.get(5, TimeUnit.SECONDS);
session.getRemote().sendString("Hello World");
String response = socket.getTextMessages().poll(5, TimeUnit.SECONDS);
assertThat("Message[0]",response,is("Hello World"));
socket.close(StatusCode.NORMAL,"Test complete");
socket.awaitClose(5,TimeUnit.SECONDS);
}
finally
{

View File

@ -27,6 +27,7 @@ import javax.websocket.server.ServerEndpoint;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;
import org.eclipse.jetty.websocket.common.util.TextUtil;
@ServerEndpoint("/echo")
public class EchoSocket
@ -52,6 +53,7 @@ public class EchoSocket
@OnMessage
public String onMessage(String msg)
{
LOG.debug("onMessage({})", TextUtil.quote(msg));
return msg;
}
}

View File

@ -21,6 +21,7 @@ package org.eclipse.jetty.cdi.websocket.cdiapp;
import static org.hamcrest.Matchers.allOf;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.notNullValue;
import static org.junit.Assert.assertThat;
import java.io.File;
@ -141,9 +142,7 @@ public class CdiAppTest
socket.close(StatusCode.NORMAL,"Test complete");
socket.awaitClose(2,TimeUnit.SECONDS);
assertThat("Messages received",socket.getTextMessages().size(),is(1));
String response = socket.getTextMessages().poll();
System.err.println(response);
String response = socket.getTextMessages().poll(5, TimeUnit.SECONDS);
assertThat("Message[0]",response,
allOf(
@ -170,14 +169,14 @@ public class CdiAppTest
socket.awaitOpen(2,TimeUnit.SECONDS);
socket.sendText("data|stuff");
String response = socket.getTextMessages().poll(5, TimeUnit.SECONDS);
assertThat("Message[0]",response,containsString("Hello there stuff"));
response = socket.getTextMessages().poll(5, TimeUnit.SECONDS);
assertThat("Message[1]",response,notNullValue());
socket.close(StatusCode.NORMAL,"Test complete");
socket.awaitClose(2,TimeUnit.SECONDS);
assertThat("Messages received",socket.getTextMessages().size(),is(2));
String response = socket.getTextMessages().poll();
System.out.println("[0]" + response);
assertThat("Message[0]",response,containsString("Hello there stuff"));
System.out.println("[1]" + socket.getTextMessages().poll());
}
finally
{

View File

@ -20,7 +20,6 @@ package org.eclipse.jetty.cdi.websocket.cdiapp;
import javax.inject.Inject;
import org.eclipse.jetty.cdi.websocket.annotation.WebSocketScope;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;
import org.eclipse.jetty.websocket.api.Session;
@ -30,8 +29,7 @@ public class DataMaker
private static final Logger LOG = Log.getLogger(DataMaker.class);
@Inject
@WebSocketScope
private Session session;
public Session session;
public void processMessage(String msg)
{

View File

@ -22,7 +22,6 @@ import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.logging.Level;
import javax.enterprise.context.SessionScoped;
import javax.inject.Inject;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpSession;
@ -38,15 +37,14 @@ public class InfoSocket
{
private static final java.util.logging.Logger LOG = java.util.logging.Logger.getLogger(InfoSocket.class.getName());
@SessionScoped
@Inject
private HttpSession httpSession;
public HttpSession httpSession;
@Inject
private ServletContext servletContext;
public ServletContext servletContext;
@Inject
private DataMaker dataMaker;
public DataMaker dataMaker;
private Session session;

View File

@ -20,14 +20,12 @@ package org.eclipse.jetty.cdi.websocket.wsscope;
import javax.inject.Inject;
import org.eclipse.jetty.cdi.websocket.annotation.WebSocketScope;
import org.eclipse.jetty.websocket.api.Session;
public class BogusSocket
{
@Inject
@WebSocketScope
private Session session;
public Session session;
public Session getSession()
{

View File

@ -20,7 +20,7 @@
<module>cdi-full-servlet</module>
<module>cdi-websocket</module>
<module>test-cdi-webapp</module>
<!-- needs to be fixed still
<!-- deprecated
<module>test-cdi-it</module>
-->
</modules>

View File

@ -93,11 +93,7 @@ public class SessionInfoIT
socket.session.getBasicRemote().sendText("info");
socket.messages.awaitEventCount(1,2,TimeUnit.SECONDS);
System.out.printf("socket.messages.size = %s%n",socket.messages.size());
String msg = socket.messages.poll();
System.out.printf("Message is [%s]%n",msg);
assertThat("Message", msg, containsString("HttpSession = HttpSession"));
socket.session.getBasicRemote().sendText("close");

View File

@ -0,0 +1,183 @@
//
// ========================================================================
// Copyright (c) 1995-2017 Mort Bay Consulting Pty. Ltd.
// ------------------------------------------------------------------------
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
// and Apache License v2.0 which accompanies this distribution.
//
// The Eclipse Public License is available at
// http://www.eclipse.org/legal/epl-v10.html
//
// The Apache License v2.0 is available at
// http://www.opensource.org/licenses/apache2.0.php
//
// You may elect to redistribute this code under either of these licenses.
// ========================================================================
//
package org.eclipse.jetty.client;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.SocketAddress;
import java.net.SocketException;
import java.nio.channels.SelectableChannel;
import java.nio.channels.SelectionKey;
import java.nio.channels.SocketChannel;
import java.util.Map;
import org.eclipse.jetty.client.api.Connection;
import org.eclipse.jetty.io.EndPoint;
import org.eclipse.jetty.io.ManagedSelector;
import org.eclipse.jetty.io.SelectorManager;
import org.eclipse.jetty.io.SocketChannelEndPoint;
import org.eclipse.jetty.io.ssl.SslClientConnectionFactory;
import org.eclipse.jetty.util.Promise;
import org.eclipse.jetty.util.annotation.ManagedAttribute;
public abstract class AbstractConnectorHttpClientTransport extends AbstractHttpClientTransport
{
private final int selectors;
private SelectorManager selectorManager;
protected AbstractConnectorHttpClientTransport(int selectors)
{
this.selectors = selectors;
}
@ManagedAttribute(value = "The number of selectors", readonly = true)
public int getSelectors()
{
return selectors;
}
@Override
protected void doStart() throws Exception
{
HttpClient httpClient = getHttpClient();
selectorManager = newSelectorManager(httpClient);
selectorManager.setConnectTimeout(httpClient.getConnectTimeout());
addBean(selectorManager);
super.doStart();
}
@Override
protected void doStop() throws Exception
{
super.doStop();
removeBean(selectorManager);
}
@Override
public void connect(InetSocketAddress address, Map<String, Object> context)
{
SocketChannel channel = null;
try
{
channel = SocketChannel.open();
HttpDestination destination = (HttpDestination)context.get(HTTP_DESTINATION_CONTEXT_KEY);
HttpClient client = destination.getHttpClient();
SocketAddress bindAddress = client.getBindAddress();
if (bindAddress != null)
channel.bind(bindAddress);
configure(client, channel);
context.put(SslClientConnectionFactory.SSL_PEER_HOST_CONTEXT_KEY, destination.getHost());
context.put(SslClientConnectionFactory.SSL_PEER_PORT_CONTEXT_KEY, destination.getPort());
if (client.isConnectBlocking())
{
channel.socket().connect(address, (int)client.getConnectTimeout());
channel.configureBlocking(false);
selectorManager.accept(channel, context);
}
else
{
channel.configureBlocking(false);
if (channel.connect(address))
selectorManager.accept(channel, context);
else
selectorManager.connect(channel, context);
}
}
// Must catch all exceptions, since some like
// UnresolvedAddressException are not IOExceptions.
catch (Throwable x)
{
// If IPv6 is not deployed, a generic SocketException "Network is unreachable"
// exception is being thrown, so we attempt to provide a better error message.
if (x.getClass() == SocketException.class)
x = new SocketException("Could not connect to " + address).initCause(x);
try
{
if (channel != null)
channel.close();
}
catch (IOException xx)
{
LOG.ignore(xx);
}
finally
{
connectFailed(context, x);
}
}
}
protected void connectFailed(Map<String, Object> context, Throwable x)
{
if (LOG.isDebugEnabled())
LOG.debug("Could not connect to {}", context.get(HTTP_DESTINATION_CONTEXT_KEY));
@SuppressWarnings("unchecked")
Promise<Connection> promise = (Promise<Connection>)context.get(HTTP_CONNECTION_PROMISE_CONTEXT_KEY);
promise.failed(x);
}
protected void configure(HttpClient client, SocketChannel channel) throws IOException
{
channel.socket().setTcpNoDelay(client.isTCPNoDelay());
}
protected SelectorManager newSelectorManager(HttpClient client)
{
return new ClientSelectorManager(client, getSelectors());
}
protected class ClientSelectorManager extends SelectorManager
{
private final HttpClient client;
protected ClientSelectorManager(HttpClient client, int selectors)
{
super(client.getExecutor(), client.getScheduler(), selectors);
this.client = client;
}
@Override
protected EndPoint newEndPoint(SelectableChannel channel, ManagedSelector selector, SelectionKey key)
{
SocketChannelEndPoint endp = new SocketChannelEndPoint(channel, selector, key, getScheduler());
endp.setIdleTimeout(client.getIdleTimeout());
return endp;
}
@Override
public org.eclipse.jetty.io.Connection newConnection(SelectableChannel channel, EndPoint endPoint, Object attachment) throws IOException
{
@SuppressWarnings("unchecked")
Map<String, Object> context = (Map<String, Object>)attachment;
HttpDestination destination = (HttpDestination)context.get(HTTP_DESTINATION_CONTEXT_KEY);
return destination.getClientConnectionFactory().newConnection(endPoint, context);
}
@Override
protected void connectionFailed(SelectableChannel channel, Throwable x, Object attachment)
{
@SuppressWarnings("unchecked")
Map<String, Object> context = (Map<String, Object>)attachment;
connectFailed(context, x);
}
}
}

View File

@ -18,24 +18,6 @@
package org.eclipse.jetty.client;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.SocketAddress;
import java.net.SocketException;
import java.nio.channels.SelectableChannel;
import java.nio.channels.SelectionKey;
import java.nio.channels.SocketChannel;
import java.util.Map;
import org.eclipse.jetty.client.api.Connection;
import org.eclipse.jetty.io.EndPoint;
import org.eclipse.jetty.io.ManagedSelector;
import org.eclipse.jetty.io.SelectChannelEndPoint;
import org.eclipse.jetty.io.SelectorManager;
import org.eclipse.jetty.io.SocketChannelEndPoint;
import org.eclipse.jetty.io.ssl.SslClientConnectionFactory;
import org.eclipse.jetty.util.Promise;
import org.eclipse.jetty.util.annotation.ManagedAttribute;
import org.eclipse.jetty.util.annotation.ManagedObject;
import org.eclipse.jetty.util.component.ContainerLifeCycle;
import org.eclipse.jetty.util.log.Log;
@ -46,14 +28,8 @@ public abstract class AbstractHttpClientTransport extends ContainerLifeCycle imp
{
protected static final Logger LOG = Log.getLogger(HttpClientTransport.class);
private final int selectors;
private volatile HttpClient client;
private volatile SelectorManager selectorManager;
protected AbstractHttpClientTransport(int selectors)
{
this.selectors = selectors;
}
private HttpClient client;
private ConnectionPool.Factory factory;
protected HttpClient getHttpClient()
{
@ -66,137 +42,15 @@ public abstract class AbstractHttpClientTransport extends ContainerLifeCycle imp
this.client = client;
}
@ManagedAttribute(value = "The number of selectors", readonly = true)
public int getSelectors()
@Override
public ConnectionPool.Factory getConnectionPoolFactory()
{
return selectors;
return factory;
}
@Override
protected void doStart() throws Exception
public void setConnectionPoolFactory(ConnectionPool.Factory factory)
{
selectorManager = newSelectorManager(client);
selectorManager.setConnectTimeout(client.getConnectTimeout());
addBean(selectorManager);
super.doStart();
}
@Override
protected void doStop() throws Exception
{
super.doStop();
removeBean(selectorManager);
}
@Override
public void connect(InetSocketAddress address, Map<String, Object> context)
{
SocketChannel channel = null;
try
{
channel = SocketChannel.open();
HttpDestination destination = (HttpDestination)context.get(HTTP_DESTINATION_CONTEXT_KEY);
HttpClient client = destination.getHttpClient();
SocketAddress bindAddress = client.getBindAddress();
if (bindAddress != null)
channel.bind(bindAddress);
configure(client, channel);
context.put(SslClientConnectionFactory.SSL_PEER_HOST_CONTEXT_KEY, destination.getHost());
context.put(SslClientConnectionFactory.SSL_PEER_PORT_CONTEXT_KEY, destination.getPort());
if (client.isConnectBlocking())
{
channel.socket().connect(address, (int)client.getConnectTimeout());
channel.configureBlocking(false);
selectorManager.accept(channel, context);
}
else
{
channel.configureBlocking(false);
if (channel.connect(address))
selectorManager.accept(channel, context);
else
selectorManager.connect(channel, context);
}
}
// Must catch all exceptions, since some like
// UnresolvedAddressException are not IOExceptions.
catch (Throwable x)
{
// If IPv6 is not deployed, a generic SocketException "Network is unreachable"
// exception is being thrown, so we attempt to provide a better error message.
if (x.getClass() == SocketException.class)
x = new SocketException("Could not connect to " + address).initCause(x);
try
{
if (channel != null)
channel.close();
}
catch (IOException xx)
{
LOG.ignore(xx);
}
finally
{
connectFailed(context, x);
}
}
}
protected void connectFailed(Map<String, Object> context, Throwable x)
{
if (LOG.isDebugEnabled())
LOG.debug("Could not connect to {}", context.get(HTTP_DESTINATION_CONTEXT_KEY));
@SuppressWarnings("unchecked")
Promise<Connection> promise = (Promise<Connection>)context.get(HTTP_CONNECTION_PROMISE_CONTEXT_KEY);
promise.failed(x);
}
protected void configure(HttpClient client, SocketChannel channel) throws IOException
{
channel.socket().setTcpNoDelay(client.isTCPNoDelay());
}
protected SelectorManager newSelectorManager(HttpClient client)
{
return new ClientSelectorManager(client, selectors);
}
protected class ClientSelectorManager extends SelectorManager
{
private final HttpClient client;
protected ClientSelectorManager(HttpClient client, int selectors)
{
super(client.getExecutor(), client.getScheduler(), selectors);
this.client = client;
}
@Override
protected EndPoint newEndPoint(SelectableChannel channel, ManagedSelector selector, SelectionKey key)
{
SocketChannelEndPoint endp = new SocketChannelEndPoint(channel, selector, key, getScheduler());
endp.setIdleTimeout(client.getIdleTimeout());
return endp;
}
@Override
public org.eclipse.jetty.io.Connection newConnection(SelectableChannel channel, EndPoint endPoint, Object attachment) throws IOException
{
@SuppressWarnings("unchecked")
Map<String, Object> context = (Map<String, Object>)attachment;
HttpDestination destination = (HttpDestination)context.get(HTTP_DESTINATION_CONTEXT_KEY);
return destination.getClientConnectionFactory().newConnection(endPoint, context);
}
@Override
protected void connectionFailed(SelectableChannel channel, Throwable x, Object attachment)
{
@SuppressWarnings("unchecked")
Map<String, Object> context = (Map<String, Object>)attachment;
connectFailed(context, x);
}
this.factory = factory;
}
}

View File

@ -22,20 +22,73 @@ import java.io.Closeable;
import org.eclipse.jetty.client.api.Connection;
/**
* <p>Client-side connection pool abstraction.</p>
*/
public interface ConnectionPool extends Closeable
{
/**
* @param connection the connection to test
* @return whether the given connection is currently in use
*/
boolean isActive(Connection connection);
/**
* @return whether this ConnectionPool has no open connections
*/
boolean isEmpty();
/**
* @return whether this ConnectionPool has been closed
* @see #close()
*/
boolean isClosed();
/**
* <p>Returns an idle connection, if available, or schedules the opening
* of a new connection and returns {@code null}.</p>
*
* @return an available connection, or null
*/
Connection acquire();
/**
* <p>Returns the given connection, previously obtained via {@link #acquire()},
* back to this ConnectionPool.</p>
*
* @param connection the connection to release
* @return true if the connection has been released, false if the connection
* was not obtained from the this ConnectionPool
*/
boolean release(Connection connection);
/**
* <p>Removes the given connection from this ConnectionPool.</p>
*
* @param connection the connection to remove
* @return true if the connection was removed from this ConnectionPool
*/
boolean remove(Connection connection);
/**
* Closes this ConnectionPool.
*
* @see #isClosed()
*/
@Override
void close();
/**
* Factory for ConnectionPool instances.
*/
interface Factory
{
/**
* Creates a new ConnectionPool for the given destination.
*
* @param destination the destination to create the ConnectionPool for
* @return the newly created ConnectionPool
*/
ConnectionPool newConnectionPool(HttpDestination destination);
}
}

View File

@ -68,4 +68,14 @@ public interface HttpClientTransport extends ClientConnectionFactory
* @param context the context information to establish the connection
*/
public void connect(InetSocketAddress address, Map<String, Object> context);
/**
* @return the factory for ConnectionPool instances
*/
public ConnectionPool.Factory getConnectionPoolFactory();
/**
* @param factory the factory for ConnectionPool instances
*/
public void setConnectionPoolFactory(ConnectionPool.Factory factory);
}

View File

@ -114,7 +114,10 @@ public abstract class HttpDestination extends ContainerLifeCycle implements Dest
removeBean(connectionPool);
}
protected abstract ConnectionPool newConnectionPool(HttpClient client);
protected ConnectionPool newConnectionPool(HttpClient client)
{
return client.getTransport().getConnectionPoolFactory().newConnectionPool(this);
}
protected Queue<HttpExchange> newExchangeQueue(HttpClient client)
{

View File

@ -25,12 +25,6 @@ public abstract class MultiplexHttpDestination extends HttpDestination
super(client, origin);
}
protected ConnectionPool newConnectionPool(HttpClient client)
{
return new MultiplexConnectionPool(this, client.getMaxConnectionsPerDestination(), this,
client.getMaxRequestsQueuedPerDestination());
}
public int getMaxRequestsPerConnection()
{
ConnectionPool connectionPool = getConnectionPool();

View File

@ -24,9 +24,4 @@ public abstract class PoolingHttpDestination extends HttpDestination
{
super(client, origin);
}
protected ConnectionPool newConnectionPool(HttpClient client)
{
return new DuplexConnectionPool(this, client.getMaxConnectionsPerDestination(), this);
}
}

View File

@ -21,7 +21,8 @@ package org.eclipse.jetty.client.http;
import java.io.IOException;
import java.util.Map;
import org.eclipse.jetty.client.AbstractHttpClientTransport;
import org.eclipse.jetty.client.AbstractConnectorHttpClientTransport;
import org.eclipse.jetty.client.DuplexConnectionPool;
import org.eclipse.jetty.client.HttpDestination;
import org.eclipse.jetty.client.Origin;
import org.eclipse.jetty.client.api.Connection;
@ -30,7 +31,7 @@ import org.eclipse.jetty.util.Promise;
import org.eclipse.jetty.util.annotation.ManagedObject;
@ManagedObject("The HTTP/1.1 client transport")
public class HttpClientTransportOverHTTP extends AbstractHttpClientTransport
public class HttpClientTransportOverHTTP extends AbstractConnectorHttpClientTransport
{
public HttpClientTransportOverHTTP()
{
@ -40,6 +41,7 @@ public class HttpClientTransportOverHTTP extends AbstractHttpClientTransport
public HttpClientTransportOverHTTP(int selectors)
{
super(selectors);
setConnectionPoolFactory(destination -> new DuplexConnectionPool(destination, getHttpClient().getMaxConnectionsPerDestination(), destination));
}
@Override

View File

@ -29,7 +29,6 @@ import javax.servlet.http.HttpServletResponse;
import org.eclipse.jetty.client.api.ContentResponse;
import org.eclipse.jetty.client.api.Request;
import org.eclipse.jetty.client.http.HttpClientTransportOverHTTP;
import org.eclipse.jetty.client.http.HttpDestinationOverHTTP;
import org.eclipse.jetty.client.util.FutureResponseListener;
import org.eclipse.jetty.http.HttpHeader;
import org.eclipse.jetty.http.HttpHeaderValue;
@ -50,7 +49,11 @@ public class ValidatingConnectionPoolTest extends AbstractHttpClientServerTest
@Override
protected void startClient() throws Exception
{
startClient(new ValidatingHttpClientTransportOverHTTP(1000));
long timeout = 1000;
HttpClientTransportOverHTTP transport = new HttpClientTransportOverHTTP(1);
transport.setConnectionPoolFactory(destination ->
new ValidatingConnectionPool(destination, destination.getHttpClient().getMaxConnectionsPerDestination(), destination, destination.getHttpClient().getScheduler(), timeout));
startClient(transport);
}
@Test
@ -177,28 +180,4 @@ public class ValidatingConnectionPoolTest extends AbstractHttpClientServerTest
ContentResponse response2 = listener2.get(5, TimeUnit.SECONDS);
Assert.assertEquals(200, response2.getStatus());
}
private static class ValidatingHttpClientTransportOverHTTP extends HttpClientTransportOverHTTP
{
private final long timeout;
public ValidatingHttpClientTransportOverHTTP(long timeout)
{
super(1);
this.timeout = timeout;
}
@Override
public HttpDestination newHttpDestination(Origin origin)
{
return new HttpDestinationOverHTTP(getHttpClient(), origin)
{
@Override
protected DuplexConnectionPool newConnectionPool(HttpClient client)
{
return new ValidatingConnectionPool(this, client.getMaxConnectionsPerDestination(), this, client.getScheduler(), timeout);
}
};
}
}
}

View File

@ -136,7 +136,7 @@ jetty-distribution-{VERSION}/
....
It might seem strange or undesirable to unpack the first portion of the jetty-distribution directory name too.
But starting with Jetty 9.1 the split between `${jetty.home}` and `${jetty.base}` allows for easier upgrades of Jetty itself while isolating your webapp specific configuration.
But starting with Jetty 9 the split between `${jetty.home}` and `${jetty.base}` allows for easier upgrades of Jetty itself while isolating your webapp specific configuration.
For more information on the Jetty home and base concepts see the section on managing a Jetty installation <<startup-base-and-home, earlier in this Chapter.>>
The `/opt/jetty/temp` directory is created as a durable place for Jetty to use for temp and working directories.
@ -156,16 +156,17 @@ While this is still supported, we encourage you to setup a proper `${jetty.base}
# cd /opt/web/mybase/
[/opt/web/mybase]# ls
[/opt/web/mybase]# java -jar /opt/jetty/jetty-distribution-{VERSION}/start.jar \
--add-to-start=deploy,http,logging
WARNING: deploy initialised in ${jetty.base}/start.ini (appended)
WARNING: deploy enabled in ${jetty.base}/start.ini
WARNING: server initialised in ${jetty.base}/start.ini (appended)
WARNING: server enabled in ${jetty.base}/start.ini
WARNING: http initialised in ${jetty.base}/start.ini (appended)
WARNING: http enabled in ${jetty.base}/start.ini
WARNING: server enabled in ${jetty.base}/start.ini
WARNING: logging initialised in ${jetty.base}/start.ini (appended)
WARNING: logging enabled in ${jetty.base}/start.ini
--add-to-start=deploy,http,console-capture
INFO : webapp transitively enabled, ini template available with --add-to-start=webapp
INFO : server transitively enabled, ini template available with --add-to-start=server
INFO : security transitively enabled
INFO : servlet transitively enabled
INFO : console-capture initialized in ${jetty.base}/start.ini
INFO : http initialized in ${jetty.base}/start.ini
INFO : deploy initialized in ${jetty.base}/start.ini
MKDIR : ${jetty.base}/logs
MKDIR : ${jetty.base}/webapps
INFO : Base directory was modified
[/opt/web/mybase]# ls -F
start.ini webapps/
....
@ -178,10 +179,12 @@ http::
This sets up a single Connector that listens for basic HTTP requests.
+
See the created `start.ini` for configuring this connector.
logging::
console-capture::
When running Jetty as a service it is very important to have logging enabled.
This module will enable the basic STDOUT and STDERR capture logging to the `/opt/web/mybase/logs/` directory.
Additionally, the `webapp`, `server`, `security` and `servlet` modules were enabled as they are dependencies for other modules.
See xref:start-jar[] for more details and options on setting up and configuring a `${jetty.base}` directory.
Copy your war file into place.
@ -238,7 +241,7 @@ JAVA_OPTIONS = -Djetty.state=/opt/web/mybase/jetty.state
-Djetty.home=/opt/jetty/jetty-distribution-{VERSION}
-Djetty.base=/opt/web/mybase
-Djava.io.tmpdir=/opt/jetty/temp
JETTY_ARGS = jetty-logging.xml jetty-started.xml
JETTY_ARGS = console-capture.xml jetty-started.xml
RUN_CMD = /usr/bin/java
-Djetty.state=/opt/web/mybase/jetty.state
-Djetty.logs=/opt/web/mybase/logs
@ -246,11 +249,11 @@ RUN_CMD = /usr/bin/java
-Djetty.base=/opt/web/mybase
-Djava.io.tmpdir=/opt/jetty/temp
-jar /opt/jetty/jetty-distribution-{VERSION}/start.jar
jetty-logging.xml
console-capture.xml
jetty-started.xml
....
You now have a configured `${jetty.base}` in `/opt/web/mybase` and a jetty-distribution in `/opt/jetty/jetty-distribution-{VERSION}`, along with the service level files necessary to start the service.
You now have a configured `${jetty.base}` in `/opt/web/mybase` and a `${jetty.home}` in `/opt/jetty/jetty-distribution-{VERSION}`, along with the service level files necessary to start the service.
Test the service to make sure it starts up and runs successfully.
@ -268,4 +271,4 @@ USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
jetty 2958 5.3 0.1 11179176 53984 ? Sl 12:46 0:00 /usr/bin/java -Djetty...
....
You should now have your server running. Try it out
You should now have your server running.

View File

@ -41,6 +41,8 @@ link:{GITBROWSEURL}/jetty-server/src/main/config/etc/jetty-ssl.xml[`jetty-ssl.xm
On it's own, this connector is not functional and requires one or more of the following files to also be configured to add link:{JDURL}/org/eclipse/jetty/server/ConnectionFactory.html[`ConnectionFactories`] to make the connector functional.
link:{GITBROWSEURL}/jetty-server/src/main/config/etc/jetty-https.xml[`jetty-https.xml`]::
Adds a link:{JDURL}/org/eclipse/jetty/server/HttpConnectionFactory.html[`HttpConnectionFactory`] to the link:{JDURL}/org/eclipse/jetty/server/ServerConnector.html[`ServerConnector`] configured by `jetty-ssl.xml` which combine to provide support for HTTPS.
link:{GITBROWSEURL}/jetty-server/src/main/config/etc/jetty-http-forwarded.xml[`jetty-http-forwarded.xml`]::
Adds a link:{JDURL}/org/eclipse/jetty/server/ForwardedRequestCustomizer.html[`ForwardedRequestCustomizer`]to the HTTP Connector to process forwarded-for style headers from a proxy.
link:{GITBROWSEURL}/jetty-http2/http2-server/src/main/config/etc/jetty-http2.xml[`jetty-http2.xml`]::
Adds a link:{JDURL}/org/eclipse/jetty/http2/server/HTTP2ServerConnectionFactory.html[`Http2ServerConnectionFactory`] to the link:{JDURL}/org/eclipse/jetty/server/ServerConnector.html[`ServerConnector`] configured by `jetty-ssl.xml` to support the http2 protocol. Also prepends either `protonego-alpn.xml` or `protonego-npn.xml` so that the next protocol can be negotiated, which allows the same SSL port to handle multiple protocols.
link:{GITBROWSEURL}/jetty-alpn/jetty-alpn-server/src/main/config/etc/jetty-alpn.xml[`jetty-alpn.xml`]::
@ -49,6 +51,12 @@ link:{GITBROWSEURL}/jetty-alpn/jetty-alpn-server/src/main/config/etc/jetty-alpn.
Typically connectors require very little configuration aside from setting the listening port (see link:#jetty-connectors-network-settings[Network Settings]), and enabling `X-Forwarded-For` customization when applicable. (see link:#jetty-connectors-http-configuration[HTTP Configuration]).
Additional settings are for expert configuration only.
____
[NOTE]
All the connectors discussed in this chapter can be enabled in the Jetty Distribution by enabling them via the module system.
Please refer to our chapter on link:#startup-modules[Managing Startup Modules] for more information.
____
==== Constructing a ServerConnector
The services a link:{JDURL}/org/eclipse/jetty/server/ServerConnector.html[`ServerConnector`] instance uses are set by constructor injection and once instantiated cannot be changed.

View File

@ -86,3 +86,33 @@ public class GoogleOnlyCookieStore extends HttpCookieStore
----
The example above will retain only cookies that come from the `google.com` domain or sub-domains.
==== Special Characters in Cookies
Jetty is compliant with link:https://tools.ietf.org/html/rfc6265[RFC6265], and as such care must be taken when setting a cookie value that includes special characters such as `;`.
Previously, Version=1 cookies defined in link:https://tools.ietf.org/html/rfc2109[RFC2109] (and continued in link:https://tools.ietf.org/html/rfc2965[RFC2965]) allowed for special/reserved characters to be enclosed within double quotes when declared in a `Set-Cookie` response header:
[source, java, subs="{sub-order}"]
----
Set-Cookie: foo="bar;baz";Version=1;Path="/secur"
----
This was added to the HTTP Response header as follows:
[source, java, subs="{sub-order}"]
----
Cookie cookie = new Cookie("foo", "bar;baz");
cookie.setPath("/secur");
response.addCookie(cookie);
----
The introduction of RFC6265 has rendered this approach no longer possible; users are now required to encode cookie values that use these special characters.
This can be done utilizing `javax.servlet.http.Cookie` as follows:
[source, java, subs="{sub-order}"]
----
Cookie cookie = new Cookie("foo", URLEncoder.encode("bar;baz", "utf-8"));
----
Jetty validates all cookie names and values being added to the `HttpServletResponse` via the `addCookie(Cookie)` method.
If an illegal value is discovered Jetty will throw an `IllegalArgumentException` with the details.

View File

@ -21,8 +21,11 @@ package org.eclipse.jetty.fcgi.client.http;
import java.io.IOException;
import java.util.Map;
import org.eclipse.jetty.client.AbstractHttpClientTransport;
import org.eclipse.jetty.client.AbstractConnectorHttpClientTransport;
import org.eclipse.jetty.client.DuplexConnectionPool;
import org.eclipse.jetty.client.HttpClient;
import org.eclipse.jetty.client.HttpDestination;
import org.eclipse.jetty.client.MultiplexConnectionPool;
import org.eclipse.jetty.client.Origin;
import org.eclipse.jetty.client.api.Connection;
import org.eclipse.jetty.client.api.Request;
@ -34,7 +37,7 @@ import org.eclipse.jetty.util.annotation.ManagedAttribute;
import org.eclipse.jetty.util.annotation.ManagedObject;
@ManagedObject("The FastCGI/1.0 client transport")
public class HttpClientTransportOverFCGI extends AbstractHttpClientTransport
public class HttpClientTransportOverFCGI extends AbstractConnectorHttpClientTransport
{
private final boolean multiplexed;
private final String scriptRoot;
@ -49,6 +52,14 @@ public class HttpClientTransportOverFCGI extends AbstractHttpClientTransport
super(selectors);
this.multiplexed = multiplexed;
this.scriptRoot = scriptRoot;
setConnectionPoolFactory(destination ->
{
HttpClient httpClient = getHttpClient();
int maxConnections = httpClient.getMaxConnectionsPerDestination();
return isMultiplexed() ?
new MultiplexConnectionPool(destination, maxConnections, destination, httpClient.getMaxRequestsQueuedPerDestination()) :
new DuplexConnectionPool(destination, maxConnections, destination);
});
}
public boolean isMultiplexed()

View File

@ -45,23 +45,23 @@ import org.eclipse.jetty.proxy.AsyncProxyServlet;
* Specific implementation of {@link org.eclipse.jetty.proxy.AsyncProxyServlet.Transparent} for FastCGI.
* <p>
* This servlet accepts a HTTP request and transforms it into a FastCGI request
* that is sent to the FastCGI server specified in the <code>proxyTo</code>
* that is sent to the FastCGI server specified in the {@code proxyTo}
* init-param.
* <p>
* This servlet accepts two additional init-params:
* <ul>
* <li><code>scriptRoot</code>, mandatory, that must be set to the directory where
* <li>{@code scriptRoot}, mandatory, that must be set to the directory where
* the application that must be served via FastCGI is installed and corresponds to
* the FastCGI DOCUMENT_ROOT parameter</li>
* <li><code>scriptPattern</code>, optional, defaults to <code>(.+?\.php)</code>,
* <li>{@code scriptPattern}, optional, defaults to {@code (.+?\.php)},
* that specifies a regular expression with at least 1 and at most 2 groups that specify
* respectively:
* <ul>
* <li>the FastCGI SCRIPT_NAME parameter</li>
* <li>the FastCGI PATH_INFO parameter</li>
* </ul></li>
* <li><code>fastCGI.HTTPS</code>, optional, defaults to false, that specifies whether
* to force the FastCGI <code>HTTPS</code> parameter to the value <code>on</code></li>
* <li>{@code fastCGI.HTTPS}, optional, defaults to false, that specifies whether
* to force the FastCGI {@code HTTPS} parameter to the value {@code on}</li>
* </ul>
*
* @see TryFilesFilter
@ -111,7 +111,11 @@ public class FastCGIProxyServlet extends AsyncProxyServlet.Transparent
String scriptRoot = config.getInitParameter(SCRIPT_ROOT_INIT_PARAM);
if (scriptRoot == null)
throw new IllegalArgumentException("Mandatory parameter '" + SCRIPT_ROOT_INIT_PARAM + "' not configured");
return new HttpClient(new ProxyHttpClientTransportOverFCGI(scriptRoot), null);
int selectors = Math.max(1, Runtime.getRuntime().availableProcessors() / 2);
String value = config.getInitParameter("selectors");
if (value != null)
selectors = Integer.parseInt(value);
return new HttpClient(new ProxyHttpClientTransportOverFCGI(selectors, scriptRoot), null);
}
@Override
@ -238,9 +242,9 @@ public class FastCGIProxyServlet extends AsyncProxyServlet.Transparent
private class ProxyHttpClientTransportOverFCGI extends HttpClientTransportOverFCGI
{
public ProxyHttpClientTransportOverFCGI(String scriptRoot)
private ProxyHttpClientTransportOverFCGI(int selectors, String scriptRoot)
{
super(scriptRoot);
super(selectors, false, scriptRoot);
}
@Override

View File

@ -20,13 +20,10 @@ package org.eclipse.jetty.fcgi.server;
import java.util.concurrent.atomic.AtomicLong;
import org.eclipse.jetty.client.DuplexConnectionPool;
import org.eclipse.jetty.client.HttpClient;
import org.eclipse.jetty.client.HttpDestination;
import org.eclipse.jetty.client.HttpClientTransport;
import org.eclipse.jetty.client.LeakTrackingConnectionPool;
import org.eclipse.jetty.client.Origin;
import org.eclipse.jetty.fcgi.client.http.HttpClientTransportOverFCGI;
import org.eclipse.jetty.fcgi.client.http.HttpDestinationOverFCGI;
import org.eclipse.jetty.http.HttpScheme;
import org.eclipse.jetty.io.LeakTrackingByteBufferPool;
import org.eclipse.jetty.io.MappedByteBufferPool;
@ -72,28 +69,16 @@ public abstract class AbstractHttpClientServerTest
QueuedThreadPool executor = new QueuedThreadPool();
executor.setName(executor.getName() + "-client");
client = new HttpClient(new HttpClientTransportOverFCGI(1, false, "")
HttpClientTransport transport = new HttpClientTransportOverFCGI(1, false, "");
transport.setConnectionPoolFactory(destination -> new LeakTrackingConnectionPool(destination, client.getMaxConnectionsPerDestination(), destination)
{
@Override
public HttpDestination newHttpDestination(Origin origin)
protected void leaked(LeakDetector.LeakInfo leakInfo)
{
return new HttpDestinationOverFCGI(client, origin)
{
@Override
protected DuplexConnectionPool newConnectionPool(HttpClient client)
{
return new LeakTrackingConnectionPool(this, client.getMaxConnectionsPerDestination(), this)
{
@Override
protected void leaked(LeakDetector.LeakInfo leakInfo)
{
connectionLeaks.incrementAndGet();
}
};
}
};
connectionLeaks.incrementAndGet();
}
}, null);
});
client = new HttpClient(transport, null);
client.setExecutor(executor);
clientBufferPool = new LeakTrackingByteBufferPool(new MappedByteBufferPool.Tagged());
client.setByteBufferPool(clientBufferPool);

View File

@ -475,23 +475,11 @@
<artifactId>jetty-spring</artifactId>
<version>${project.version}</version>
</dependency>
<!--
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-overlay-deployer</artifactId>
<version>${project.version}</version>
</dependency>
-->
<dependency>
<groupId>org.eclipse.jetty.cdi</groupId>
<artifactId>cdi-servlet</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.cdi</groupId>
<artifactId>cdi-websocket</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-jaas</artifactId>

View File

@ -24,9 +24,10 @@ import java.util.HashMap;
import java.util.Map;
import org.eclipse.jetty.alpn.client.ALPNClientConnectionFactory;
import org.eclipse.jetty.client.AbstractHttpClientTransport;
import org.eclipse.jetty.client.HttpClient;
import org.eclipse.jetty.client.HttpClientTransport;
import org.eclipse.jetty.client.HttpDestination;
import org.eclipse.jetty.client.MultiplexConnectionPool;
import org.eclipse.jetty.client.Origin;
import org.eclipse.jetty.client.ProxyConfiguration;
import org.eclipse.jetty.client.api.Connection;
@ -42,20 +43,23 @@ import org.eclipse.jetty.io.EndPoint;
import org.eclipse.jetty.util.Promise;
import org.eclipse.jetty.util.annotation.ManagedAttribute;
import org.eclipse.jetty.util.annotation.ManagedObject;
import org.eclipse.jetty.util.component.ContainerLifeCycle;
import org.eclipse.jetty.util.ssl.SslContextFactory;
@ManagedObject("The HTTP/2 client transport")
public class HttpClientTransportOverHTTP2 extends ContainerLifeCycle implements HttpClientTransport
public class HttpClientTransportOverHTTP2 extends AbstractHttpClientTransport
{
private final HTTP2Client client;
private ClientConnectionFactory connectionFactory;
private HttpClient httpClient;
private boolean useALPN = true;
public HttpClientTransportOverHTTP2(HTTP2Client client)
{
this.client = client;
setConnectionPoolFactory(destination ->
{
HttpClient httpClient = getHttpClient();
return new MultiplexConnectionPool(destination, httpClient.getMaxConnectionsPerDestination(), destination, httpClient.getMaxRequestsQueuedPerDestination());
});
}
@ManagedAttribute(value = "The number of selectors", readonly = true)
@ -79,6 +83,7 @@ public class HttpClientTransportOverHTTP2 extends ContainerLifeCycle implements
{
if (!client.isStarted())
{
HttpClient httpClient = getHttpClient();
client.setExecutor(httpClient.getExecutor());
client.setScheduler(httpClient.getScheduler());
client.setByteBufferPool(httpClient.getByteBufferPool());
@ -104,34 +109,23 @@ public class HttpClientTransportOverHTTP2 extends ContainerLifeCycle implements
removeBean(client);
}
protected HttpClient getHttpClient()
{
return httpClient;
}
@Override
public void setHttpClient(HttpClient client)
{
httpClient = client;
}
@Override
public HttpDestination newHttpDestination(Origin origin)
{
return new HttpDestinationOverHTTP2(httpClient, origin);
return new HttpDestinationOverHTTP2(getHttpClient(), origin);
}
@Override
public void connect(InetSocketAddress address, Map<String, Object> context)
{
client.setConnectTimeout(httpClient.getConnectTimeout());
client.setConnectTimeout(getHttpClient().getConnectTimeout());
SessionListenerPromise listenerPromise = new SessionListenerPromise(context);
HttpDestinationOverHTTP2 destination = (HttpDestinationOverHTTP2)context.get(HTTP_DESTINATION_CONTEXT_KEY);
SslContextFactory sslContextFactory = null;
if (HttpScheme.HTTPS.is(destination.getScheme()))
sslContextFactory = httpClient.getSslContextFactory();
sslContextFactory = getHttpClient().getSslContextFactory();
client.connect(sslContextFactory, address, listenerPromise, listenerPromise, context);
}
@ -139,7 +133,7 @@ public class HttpClientTransportOverHTTP2 extends ContainerLifeCycle implements
@Override
public org.eclipse.jetty.io.Connection newConnection(EndPoint endPoint, Map<String, Object> context) throws IOException
{
endPoint.setIdleTimeout(httpClient.getIdleTimeout());
endPoint.setIdleTimeout(getHttpClient().getIdleTimeout());
ClientConnectionFactory factory = connectionFactory;
HttpDestinationOverHTTP2 destination = (HttpDestinationOverHTTP2)context.get(HTTP_DESTINATION_CONTEXT_KEY);

View File

@ -13,6 +13,9 @@
<mavenVersion>3.0.3</mavenVersion>
<pluginToolsVersion>3.4</pluginToolsVersion>
<bundle-symbolic-name>${project.groupId}.maven.plugin</bundle-symbolic-name>
<it.debug>false</it.debug>
<jetty.stopKey>FOOBEER</jetty.stopKey>
<jetty.jvmArgs></jetty.jvmArgs>
</properties>
<build>
<plugins>
@ -153,6 +156,12 @@
<artifactId>javax.transaction-api</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-client</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<reporting>
<plugins>
@ -177,4 +186,79 @@
</plugin>
</plugins>
</reporting>
<profiles>
<profile>
<id>run-its</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-invoker-plugin</artifactId>
<version>3.0.1-SNAPSHOT</version>
<executions>
<execution>
<id>integration-test</id>
<goals>
<goal>install</goal>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
<configuration>
<debug>${it.debug}</debug>
<addTestClassPath>true</addTestClassPath>
<projectsDirectory>src/it</projectsDirectory>
<cloneProjectsTo>${project.build.directory}/it</cloneProjectsTo>
<pomIncludes>
<pomInclude>*/pom.xml</pomInclude>
</pomIncludes>
<localRepositoryPath>${project.build.directory}/local-repo</localRepositoryPath>
<settingsFile>src/it/settings.xml</settingsFile>
<scriptVariables>
<jettyStopKey>${jetty.stopKey}</jettyStopKey>
<jettyStopPort>${jetty.stopPort}</jettyStopPort>
<jettyRunPort>${jetty.runPort}</jettyRunPort>
</scriptVariables>
<goals>
<goal>clean</goal>
</goals>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<id>reserve-ports</id>
<phase>pre-integration-test</phase>
<goals>
<goal>reserve-network-port</goal>
</goals>
<configuration>
<portNames>
<portName>jetty.stopPort</portName>
<portName>jetty.runPort</portName>
</portNames>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<pluginRepositories>
<pluginRepository>
<id>apache.snaphots</id>
<url>https://repository.apache.org/content/repositories/snapshots</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
</project>

View File

@ -0,0 +1 @@
invoker.goals = test -fae

View File

@ -0,0 +1,50 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.eclipse.jetty.its.jetty-run-forked-mojo-it</groupId>
<artifactId>jetty-simple-project</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>jetty-simple-base</artifactId>
<packaging>jar</packaging>
<name>Jetty :: Simple :: Base</name>
<dependencies>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<type>jar</type>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.toolchain</groupId>
<artifactId>jetty-perf-helper</artifactId>
<version>1.0.5</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.8.1</version>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,45 @@
//
// ========================================================================
// Copyright (c) 1995-2017 Mort Bay Consulting Pty. Ltd.
// ------------------------------------------------------------------------
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
// and Apache License v2.0 which accompanies this distribution.
//
// The Eclipse Public License is available at
// http://www.eclipse.org/legal/epl-v10.html
//
// The Apache License v2.0 is available at
// http://www.opensource.org/licenses/apache2.0.php
//
// You may elect to redistribute this code under either of these licenses.
// ========================================================================
//
package org.eclipse.jetty.its.jetty_run_mojo_it;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
/**
*
*/
@WebServlet("/hello")
public class HelloServlet
extends HttpServlet
{
@Override
protected void doGet( HttpServletRequest req, HttpServletResponse resp )
throws ServletException, IOException
{
String who = req.getParameter( "name" );
resp.getWriter().write( "hello " + (who == null ? "unknown" : who) );
}
}

View File

@ -0,0 +1,41 @@
//
// ========================================================================
// Copyright (c) 1995-2017 Mort Bay Consulting Pty. Ltd.
// ------------------------------------------------------------------------
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
// and Apache License v2.0 which accompanies this distribution.
//
// The Eclipse Public License is available at
// http://www.eclipse.org/legal/epl-v10.html
//
// The Apache License v2.0 is available at
// http://www.opensource.org/licenses/apache2.0.php
//
// You may elect to redistribute this code under either of these licenses.
// ========================================================================
//
package org.eclipse.jetty.its.jetty_run_mojo_it;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
public class PingServlet
extends HttpServlet
{
@Override
protected void doGet( HttpServletRequest req, HttpServletResponse resp )
throws ServletException, IOException
{
String who = req.getParameter( "name" );
resp.getWriter().write( "pong " + (who == null ? "unknown" : who) );
}
}

View File

@ -0,0 +1,32 @@
<?xml version="1.0" encoding="UTF-8"?>
<web-fragment
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-fragment_3_1.xsd"
version="3.1">
<name>FragmentA</name>
<ordering>
<after><others/></after>
</ordering>
<servlet>
<servlet-name>Ping</servlet-name>
<servlet-class>org.eclipse.jetty.its.jetty_run_mojo_it.PingServlet</servlet-class>
<init-param>
<param-name>extra1</param-name><param-value>123</param-value>
</init-param>
<init-param>
<param-name>extra2</param-name><param-value>345</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>Ping</servlet-name>
<url-pattern>/ping</url-pattern>
</servlet-mapping>
</web-fragment>

View File

@ -0,0 +1,137 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.eclipse.jetty.its.jetty-run-forked-mojo-it</groupId>
<artifactId>jetty-simple-project</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>jetty-simple-webapp</artifactId>
<packaging>war</packaging>
<name>Jetty :: Simple :: Webapp</name>
<properties>
<jetty.runPort>@jetty.runPort@</jetty.runPort>
<jetty.jvmArgs>@jetty.jvmArgs@</jetty.jvmArgs>
</properties>
<dependencies>
<dependency>
<groupId>org.eclipse.jetty.its.jetty-run-forked-mojo-it</groupId>
<artifactId>jetty-simple-base</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-servlet</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-client</artifactId>
<version>@project.version@</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>${maven-war-plugin-version}</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.20</version>
<configuration>
<systemPropertyVariables>
<jetty.runPort>@jetty.runPort@</jetty.runPort>
</systemPropertyVariables>
</configuration>
</plugin>
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<configuration>
<stopPort>@jetty.stopPort@</stopPort>
<stopKey>@jetty.stopKey@</stopKey>
</configuration>
<executions>
<execution>
<id>start-jetty</id>
<phase>test-compile</phase>
<goals>
<goal>run-forked</goal>
</goals>
<configuration>
<nonBlocking>true</nonBlocking>
<waitForChild>false</waitForChild>
<jettyXml>${project.build.directory}/config/jetty.xml</jettyXml>
<jvmArgs>${jetty.jvmArgs}</jvmArgs>
</configuration>
</execution>
<!--
<execution>
<id>stop-jetty</id>
<phase>test</phase>
<goals>
<goal>stop</goal>
</goals>
</execution>
-->
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
<executions>
<execution>
<id>copy-resources-jetty</id>
<phase>generate-resources</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/config</outputDirectory>
<resources>
<resource>
<directory>${basedir}/src/config/</directory>
<filtering>true</filtering>
<includes>
<include>**/**</include>
</includes>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

View File

@ -0,0 +1,33 @@
<?xml version="1.0"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure_9_0.dtd">
<Configure id="Server" class="org.eclipse.jetty.server.Server">
<New id="httpConfig" class="org.eclipse.jetty.server.HttpConfiguration">
<Set name="secureScheme">https</Set>
<Set name="securePort"><Property name="jetty.secure.port" default="8443" /></Set>
<Set name="outputBufferSize">32768</Set>
<Set name="requestHeaderSize">8192</Set>
<Set name="responseHeaderSize">8192</Set>
<Set name="headerCacheSize">512</Set>
</New>
<Call name="addConnector">
<Arg>
<New class="org.eclipse.jetty.server.ServerConnector">
<Arg name="server"><Ref refid="Server" /></Arg>
<Arg name="factories">
<Array type="org.eclipse.jetty.server.ConnectionFactory">
<Item>
<New class="org.eclipse.jetty.server.HttpConnectionFactory">
<Arg name="config"><Ref refid="httpConfig" /></Arg>
</New>
</Item>
</Array>
</Arg>
<Set name="host"><Property name="jetty.host" /></Set>
<Set name="port"><Property name="jetty.port" default="${jetty.runPort}" /></Set>
<Set name="idleTimeout">30000</Set>
</New>
</Arg>
</Call>
</Configure>

View File

@ -0,0 +1,7 @@
<?xml version="1.0"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
version="3.1">
<display-name>Jetty Simple Webapp run-mojo-it</display-name>
</web-app>

View File

@ -0,0 +1,58 @@
//
// ========================================================================
// Copyright (c) 1995-2017 Mort Bay Consulting Pty. Ltd.
// ------------------------------------------------------------------------
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
// and Apache License v2.0 which accompanies this distribution.
//
// The Eclipse Public License is available at
// http://www.eclipse.org/legal/epl-v10.html
//
// The Apache License v2.0 is available at
// http://www.opensource.org/licenses/apache2.0.php
//
// You may elect to redistribute this code under either of these licenses.
// ========================================================================
//
package org.eclipse.jetty.its.jetty_run_mojo_it;
import org.eclipse.jetty.client.HttpClient;
import org.junit.Assert;
import org.junit.Test;
/**
*
*/
public class TestHelloServlet
{
@Test
public void hello_servlet()
throws Exception
{
int port = Integer.getInteger( "jetty.runPort" );
System.out.println( "port used:" + port );
HttpClient httpClient = new HttpClient();
try
{
httpClient.start();
String response = httpClient.GET( "http://localhost:" + port + "/hello?name=beer" ).getContentAsString();
System.out.println( "httpResponse:" + response );
Assert.assertEquals( "hello beer", response.trim() );
response = httpClient.GET( "http://localhost:" + port + "/ping?name=beer" ).getContentAsString();
System.out.println( "httpResponse:" + response );
Assert.assertEquals( "pong beer", response.trim() );
}
finally
{
httpClient.stop();
}
}
}

View File

@ -0,0 +1,90 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.eclipse.jetty.its.jetty-run-forked-mojo-it</groupId>
<artifactId>jetty-simple-project</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<name>Jetty :: Simple</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<maven-war-plugin-version>3.0.0</maven-war-plugin-version>
<jetty.version>@project.version@</jetty.version>
</properties>
<modules>
<module>jetty-simple-base</module>
<module>jetty-simple-webapp</module>
</modules>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.eclipse.jetty.its.jetty-run-forked-mojo-it</groupId>
<artifactId>jetty-simple-base</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
<type>jar</type>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.21</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.5</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-servlet</artifactId>
<version>${jetty.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<target>1.8</target>
<source>1.8</source>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.1</version>
</plugin>
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>${jetty.version}</version>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>

View File

@ -0,0 +1,13 @@
System.out.println( "running postbuild.groovy port " + jettyStopPort + ", key:" + jettyStopKey )
int port = Integer.parseInt( jettyStopPort )
Socket s=new Socket(InetAddress.getByName("127.0.0.1"),port )
s.setSoLinger(false, 0)
OutputStream out=s.getOutputStream()
out.write(( jettyStopKey +"\r\nforcestop\r\n").getBytes())
out.flush()
s.close()

View File

@ -0,0 +1 @@
invoker.goals = test

View File

@ -0,0 +1,50 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.eclipse.jetty.its.jetty-run-mojo-it</groupId>
<artifactId>jetty-simple-project</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>jetty-simple-base</artifactId>
<packaging>jar</packaging>
<name>Jetty :: Simple :: Base</name>
<dependencies>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<type>jar</type>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.toolchain</groupId>
<artifactId>jetty-perf-helper</artifactId>
<version>1.0.5</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.8.1</version>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,45 @@
//
// ========================================================================
// Copyright (c) 1995-2017 Mort Bay Consulting Pty. Ltd.
// ------------------------------------------------------------------------
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
// and Apache License v2.0 which accompanies this distribution.
//
// The Eclipse Public License is available at
// http://www.eclipse.org/legal/epl-v10.html
//
// The Apache License v2.0 is available at
// http://www.opensource.org/licenses/apache2.0.php
//
// You may elect to redistribute this code under either of these licenses.
// ========================================================================
//
package org.eclipse.jetty.its.jetty_run_mojo_it;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
/**
*
*/
@WebServlet("/hello")
public class HelloServlet
extends HttpServlet
{
@Override
protected void doGet( HttpServletRequest req, HttpServletResponse resp )
throws ServletException, IOException
{
String who = req.getParameter( "name" );
resp.getWriter().write( "hello " + (who == null ? "unknown" : who) );
}
}

View File

@ -0,0 +1,41 @@
//
// ========================================================================
// Copyright (c) 1995-2017 Mort Bay Consulting Pty. Ltd.
// ------------------------------------------------------------------------
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
// and Apache License v2.0 which accompanies this distribution.
//
// The Eclipse Public License is available at
// http://www.eclipse.org/legal/epl-v10.html
//
// The Apache License v2.0 is available at
// http://www.opensource.org/licenses/apache2.0.php
//
// You may elect to redistribute this code under either of these licenses.
// ========================================================================
//
package org.eclipse.jetty.its.jetty_run_mojo_it;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
public class PingServlet
extends HttpServlet
{
@Override
protected void doGet( HttpServletRequest req, HttpServletResponse resp )
throws ServletException, IOException
{
String who = req.getParameter( "name" );
resp.getWriter().write( "pong " + (who == null ? "unknown" : who) );
}
}

View File

@ -0,0 +1,32 @@
<?xml version="1.0" encoding="UTF-8"?>
<web-fragment
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-fragment_3_1.xsd"
version="3.1">
<name>FragmentA</name>
<ordering>
<after><others/></after>
</ordering>
<servlet>
<servlet-name>Ping</servlet-name>
<servlet-class>org.eclipse.jetty.its.jetty_run_mojo_it.PingServlet</servlet-class>
<init-param>
<param-name>extra1</param-name><param-value>123</param-value>
</init-param>
<init-param>
<param-name>extra2</param-name><param-value>345</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>Ping</servlet-name>
<url-pattern>/ping</url-pattern>
</servlet-mapping>
</web-fragment>

View File

@ -0,0 +1,93 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.eclipse.jetty.its.jetty-run-mojo-it</groupId>
<artifactId>jetty-simple-project</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>jetty-simple-webapp</artifactId>
<packaging>war</packaging>
<name>Jetty :: Simple :: Webapp</name>
<dependencies>
<dependency>
<groupId>org.eclipse.jetty.its.jetty-run-mojo-it</groupId>
<artifactId>jetty-simple-base</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-servlet</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-client</artifactId>
<version>@project.version@</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>${maven-war-plugin-version}</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.20</version>
<configuration>
<systemPropertyVariables>
<jetty.runPort>@jetty.runPort@</jetty.runPort>
</systemPropertyVariables>
</configuration>
</plugin>
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<executions>
<execution>
<id>start-jetty</id>
<phase>test-compile</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<nonBlocking>true</nonBlocking>
<httpConnector>
<port>@jetty.runPort@</port>
</httpConnector>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

View File

@ -0,0 +1,7 @@
<?xml version="1.0"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
version="3.1">
<display-name>Jetty Simple Webapp run-mojo-it</display-name>
</web-app>

View File

@ -0,0 +1,59 @@
//
// ========================================================================
// Copyright (c) 1995-2017 Mort Bay Consulting Pty. Ltd.
// ------------------------------------------------------------------------
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
// and Apache License v2.0 which accompanies this distribution.
//
// The Eclipse Public License is available at
// http://www.eclipse.org/legal/epl-v10.html
//
// The Apache License v2.0 is available at
// http://www.opensource.org/licenses/apache2.0.php
//
// You may elect to redistribute this code under either of these licenses.
// ========================================================================
//
package org.eclipse.jetty.its.jetty_run_mojo_it;
import org.eclipse.jetty.client.HttpClient;
import org.junit.Assert;
import org.junit.Test;
/**
*
*/
public class TestHelloServlet
{
@Test
public void hello_servlet()
throws Exception
{
int port = Integer.getInteger( "jetty.runPort" );
System.out.println( "port used:" + port );
HttpClient httpClient = new HttpClient();
try
{
httpClient.start();
String response = httpClient.GET( "http://localhost:" + port + "/hello?name=beer" ).getContentAsString();
System.out.println( "httpResponse:" + response );
Assert.assertEquals( "hello beer", response.trim() );
response = httpClient.GET( "http://localhost:" + port + "/ping?name=beer" ).getContentAsString();
System.out.println( "httpResponse:" + response );
Assert.assertEquals( "pong beer", response.trim() );
}
finally
{
httpClient.stop();
}
}
}

View File

@ -0,0 +1,90 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.eclipse.jetty.its.jetty-run-mojo-it</groupId>
<artifactId>jetty-simple-project</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<name>Jetty :: Simple</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<maven-war-plugin-version>3.0.0</maven-war-plugin-version>
<jetty.version>@project.version@</jetty.version>
</properties>
<modules>
<module>jetty-simple-base</module>
<module>jetty-simple-webapp</module>
</modules>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.eclipse.jetty.its.jetty-run-mojo-it</groupId>
<artifactId>jetty-simple-base</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
<type>jar</type>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.21</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.5</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-servlet</artifactId>
<version>${jetty.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<target>1.8</target>
<source>1.8</source>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.1</version>
</plugin>
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>${jetty.version}</version>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>

View File

@ -0,0 +1,2 @@
invoker.goals = verify
#test-compile failsafe:integration-test

View File

@ -0,0 +1,50 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.eclipse.jetty.its.jetty-run-war-exploded-mojo-it</groupId>
<artifactId>jetty-simple-project</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>jetty-simple-base</artifactId>
<packaging>jar</packaging>
<name>Jetty :: Simple :: Base</name>
<dependencies>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<type>jar</type>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.toolchain</groupId>
<artifactId>jetty-perf-helper</artifactId>
<version>1.0.5</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.8.1</version>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,45 @@
//
// ========================================================================
// Copyright (c) 1995-2017 Mort Bay Consulting Pty. Ltd.
// ------------------------------------------------------------------------
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
// and Apache License v2.0 which accompanies this distribution.
//
// The Eclipse Public License is available at
// http://www.eclipse.org/legal/epl-v10.html
//
// The Apache License v2.0 is available at
// http://www.opensource.org/licenses/apache2.0.php
//
// You may elect to redistribute this code under either of these licenses.
// ========================================================================
//
package org.eclipse.jetty.its.jetty_run_mojo_it;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
/**
*
*/
@WebServlet("/hello")
public class HelloServlet
extends HttpServlet
{
@Override
protected void doGet( HttpServletRequest req, HttpServletResponse resp )
throws ServletException, IOException
{
String who = req.getParameter( "name" );
resp.getWriter().write( "hello " + (who == null ? "unknown" : who) );
}
}

View File

@ -0,0 +1,41 @@
//
// ========================================================================
// Copyright (c) 1995-2017 Mort Bay Consulting Pty. Ltd.
// ------------------------------------------------------------------------
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
// and Apache License v2.0 which accompanies this distribution.
//
// The Eclipse Public License is available at
// http://www.eclipse.org/legal/epl-v10.html
//
// The Apache License v2.0 is available at
// http://www.opensource.org/licenses/apache2.0.php
//
// You may elect to redistribute this code under either of these licenses.
// ========================================================================
//
package org.eclipse.jetty.its.jetty_run_mojo_it;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
public class PingServlet
extends HttpServlet
{
@Override
protected void doGet( HttpServletRequest req, HttpServletResponse resp )
throws ServletException, IOException
{
String who = req.getParameter( "name" );
resp.getWriter().write( "pong " + (who == null ? "unknown" : who) );
}
}

View File

@ -0,0 +1,32 @@
<?xml version="1.0" encoding="UTF-8"?>
<web-fragment
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-fragment_3_1.xsd"
version="3.1">
<name>FragmentA</name>
<ordering>
<after><others/></after>
</ordering>
<servlet>
<servlet-name>Ping</servlet-name>
<servlet-class>org.eclipse.jetty.its.jetty_run_mojo_it.PingServlet</servlet-class>
<init-param>
<param-name>extra1</param-name><param-value>123</param-value>
</init-param>
<init-param>
<param-name>extra2</param-name><param-value>345</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>Ping</servlet-name>
<url-pattern>/ping</url-pattern>
</servlet-mapping>
</web-fragment>

View File

@ -0,0 +1,121 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.eclipse.jetty.its.jetty-run-war-exploded-mojo-it</groupId>
<artifactId>jetty-simple-project</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>jetty-simple-webapp</artifactId>
<packaging>war</packaging>
<name>Jetty :: Simple :: Webapp</name>
<dependencies>
<dependency>
<groupId>org.eclipse.jetty.its.jetty-run-war-exploded-mojo-it</groupId>
<artifactId>jetty-simple-base</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-servlet</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-client</artifactId>
<version>@project.version@</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>${maven-war-plugin-version}</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.20</version>
<configuration>
<skip>true</skip>
<systemPropertyVariables>
<jetty.runPort>@jetty.runPort@</jetty.runPort>
</systemPropertyVariables>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.20</version>
<configuration>
<systemPropertyVariables>
<jetty.runPort>@jetty.runPort@</jetty.runPort>
</systemPropertyVariables>
<includes>
<include>**/*TestHelloServlet*</include>
</includes>
</configuration>
<executions>
<execution>
<id>integration-test</id>
<goals>
<goal>integration-test</goal>
</goals>
</execution>
<execution>
<id>verify</id>
<goals>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<executions>
<execution>
<id>start-jetty</id>
<phase>test-compile</phase>
<goals>
<goal>run-exploded</goal>
</goals>
<configuration>
<nonBlocking>true</nonBlocking>
<httpConnector>
<port>@jetty.runPort@</port>
</httpConnector>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

View File

@ -0,0 +1,7 @@
<?xml version="1.0"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
version="3.1">
<display-name>Jetty Simple Webapp run-mojo-it</display-name>
</web-app>

View File

@ -0,0 +1,59 @@
//
// ========================================================================
// Copyright (c) 1995-2017 Mort Bay Consulting Pty. Ltd.
// ------------------------------------------------------------------------
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
// and Apache License v2.0 which accompanies this distribution.
//
// The Eclipse Public License is available at
// http://www.eclipse.org/legal/epl-v10.html
//
// The Apache License v2.0 is available at
// http://www.opensource.org/licenses/apache2.0.php
//
// You may elect to redistribute this code under either of these licenses.
// ========================================================================
//
package org.eclipse.jetty.its.jetty_run_mojo_it;
import org.eclipse.jetty.client.HttpClient;
import org.junit.Assert;
import org.junit.Test;
/**
*
*/
public class TestHelloServlet
{
@Test
public void hello_servlet()
throws Exception
{
int port = Integer.getInteger( "jetty.runPort" );
System.out.println( "port used:" + port );
HttpClient httpClient = new HttpClient();
try
{
httpClient.start();
String response = httpClient.GET( "http://localhost:" + port + "/hello?name=beer" ).getContentAsString();
System.out.println( "httpResponse:" + response );
Assert.assertEquals( "hello beer", response.trim() );
response = httpClient.GET( "http://localhost:" + port + "/ping?name=beer" ).getContentAsString();
System.out.println( "httpResponse:" + response );
Assert.assertEquals( "pong beer", response.trim() );
}
finally
{
httpClient.stop();
}
}
}

View File

@ -0,0 +1,90 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.eclipse.jetty.its.jetty-run-war-exploded-mojo-it</groupId>
<artifactId>jetty-simple-project</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<name>Jetty :: Simple</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<maven-war-plugin-version>3.0.0</maven-war-plugin-version>
<jetty.version>@project.version@</jetty.version>
</properties>
<modules>
<module>jetty-simple-base</module>
<module>jetty-simple-webapp</module>
</modules>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.eclipse.jetty.its.jetty-run-war-exploded-mojo-it</groupId>
<artifactId>jetty-simple-base</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
<type>jar</type>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.21</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.5</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-servlet</artifactId>
<version>${jetty.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<target>1.8</target>
<source>1.8</source>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.1</version>
</plugin>
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>${jetty.version}</version>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>

View File

@ -0,0 +1,2 @@
invoker.goals = verify
#test-compile failsafe:integration-test

View File

@ -0,0 +1,50 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.eclipse.jetty.its.jetty-run-war-mojo-it</groupId>
<artifactId>jetty-simple-project</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>jetty-simple-base</artifactId>
<packaging>jar</packaging>
<name>Jetty :: Simple :: Base</name>
<dependencies>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<type>jar</type>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.toolchain</groupId>
<artifactId>jetty-perf-helper</artifactId>
<version>1.0.5</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.8.1</version>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,45 @@
//
// ========================================================================
// Copyright (c) 1995-2017 Mort Bay Consulting Pty. Ltd.
// ------------------------------------------------------------------------
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
// and Apache License v2.0 which accompanies this distribution.
//
// The Eclipse Public License is available at
// http://www.eclipse.org/legal/epl-v10.html
//
// The Apache License v2.0 is available at
// http://www.opensource.org/licenses/apache2.0.php
//
// You may elect to redistribute this code under either of these licenses.
// ========================================================================
//
package org.eclipse.jetty.its.jetty_run_mojo_it;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
/**
*
*/
@WebServlet("/hello")
public class HelloServlet
extends HttpServlet
{
@Override
protected void doGet( HttpServletRequest req, HttpServletResponse resp )
throws ServletException, IOException
{
String who = req.getParameter( "name" );
resp.getWriter().write( "hello " + (who == null ? "unknown" : who) );
}
}

View File

@ -0,0 +1,41 @@
//
// ========================================================================
// Copyright (c) 1995-2017 Mort Bay Consulting Pty. Ltd.
// ------------------------------------------------------------------------
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
// and Apache License v2.0 which accompanies this distribution.
//
// The Eclipse Public License is available at
// http://www.eclipse.org/legal/epl-v10.html
//
// The Apache License v2.0 is available at
// http://www.opensource.org/licenses/apache2.0.php
//
// You may elect to redistribute this code under either of these licenses.
// ========================================================================
//
package org.eclipse.jetty.its.jetty_run_mojo_it;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
public class PingServlet
extends HttpServlet
{
@Override
protected void doGet( HttpServletRequest req, HttpServletResponse resp )
throws ServletException, IOException
{
String who = req.getParameter( "name" );
resp.getWriter().write( "pong " + (who == null ? "unknown" : who) );
}
}

View File

@ -0,0 +1,32 @@
<?xml version="1.0" encoding="UTF-8"?>
<web-fragment
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-fragment_3_1.xsd"
version="3.1">
<name>FragmentA</name>
<ordering>
<after><others/></after>
</ordering>
<servlet>
<servlet-name>Ping</servlet-name>
<servlet-class>org.eclipse.jetty.its.jetty_run_mojo_it.PingServlet</servlet-class>
<init-param>
<param-name>extra1</param-name><param-value>123</param-value>
</init-param>
<init-param>
<param-name>extra2</param-name><param-value>345</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>Ping</servlet-name>
<url-pattern>/ping</url-pattern>
</servlet-mapping>
</web-fragment>

View File

@ -0,0 +1,121 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.eclipse.jetty.its.jetty-run-war-mojo-it</groupId>
<artifactId>jetty-simple-project</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>jetty-simple-webapp</artifactId>
<packaging>war</packaging>
<name>Jetty :: Simple :: Webapp</name>
<dependencies>
<dependency>
<groupId>org.eclipse.jetty.its.jetty-run-war-mojo-it</groupId>
<artifactId>jetty-simple-base</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-servlet</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-client</artifactId>
<version>@project.version@</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>${maven-war-plugin-version}</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.20</version>
<configuration>
<skip>true</skip>
<systemPropertyVariables>
<jetty.runPort>@jetty.runPort@</jetty.runPort>
</systemPropertyVariables>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.20</version>
<configuration>
<systemPropertyVariables>
<jetty.runPort>@jetty.runPort@</jetty.runPort>
</systemPropertyVariables>
<includes>
<include>**/*TestHelloServlet*</include>
</includes>
</configuration>
<executions>
<execution>
<id>integration-test</id>
<goals>
<goal>integration-test</goal>
</goals>
</execution>
<execution>
<id>verify</id>
<goals>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<executions>
<execution>
<id>start-jetty</id>
<phase>test-compile</phase>
<goals>
<goal>run-war</goal>
</goals>
<configuration>
<nonBlocking>true</nonBlocking>
<httpConnector>
<port>@jetty.runPort@</port>
</httpConnector>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

View File

@ -0,0 +1,7 @@
<?xml version="1.0"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
version="3.1">
<display-name>Jetty Simple Webapp run-mojo-it</display-name>
</web-app>

View File

@ -0,0 +1,59 @@
//
// ========================================================================
// Copyright (c) 1995-2017 Mort Bay Consulting Pty. Ltd.
// ------------------------------------------------------------------------
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
// and Apache License v2.0 which accompanies this distribution.
//
// The Eclipse Public License is available at
// http://www.eclipse.org/legal/epl-v10.html
//
// The Apache License v2.0 is available at
// http://www.opensource.org/licenses/apache2.0.php
//
// You may elect to redistribute this code under either of these licenses.
// ========================================================================
//
package org.eclipse.jetty.its.jetty_run_mojo_it;
import org.eclipse.jetty.client.HttpClient;
import org.junit.Assert;
import org.junit.Test;
/**
*
*/
public class TestHelloServlet
{
@Test
public void hello_servlet()
throws Exception
{
int port = Integer.getInteger( "jetty.runPort" );
System.out.println( "port used:" + port );
HttpClient httpClient = new HttpClient();
try
{
httpClient.start();
String response = httpClient.GET( "http://localhost:" + port + "/hello?name=beer" ).getContentAsString();
System.out.println( "httpResponse:" + response );
Assert.assertEquals( "hello beer", response.trim() );
response = httpClient.GET( "http://localhost:" + port + "/ping?name=beer" ).getContentAsString();
System.out.println( "httpResponse:" + response );
Assert.assertEquals( "pong beer", response.trim() );
}
finally
{
httpClient.stop();
}
}
}

View File

@ -0,0 +1,90 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.eclipse.jetty.its.jetty-run-war-mojo-it</groupId>
<artifactId>jetty-simple-project</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<name>Jetty :: Simple</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<maven-war-plugin-version>3.0.0</maven-war-plugin-version>
<jetty.version>@project.version@</jetty.version>
</properties>
<modules>
<module>jetty-simple-base</module>
<module>jetty-simple-webapp</module>
</modules>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.eclipse.jetty.its.jetty-run-war-mojo-it</groupId>
<artifactId>jetty-simple-base</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
<type>jar</type>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.21</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.5</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-servlet</artifactId>
<version>${jetty.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<target>1.8</target>
<source>1.8</source>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.1</version>
</plugin>
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>${jetty.version}</version>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>

View File

@ -0,0 +1 @@
invoker.goals = test

View File

@ -0,0 +1,50 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.eclipse.jetty.its.jetty-start-mojo-it</groupId>
<artifactId>jetty-simple-project</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>jetty-simple-base</artifactId>
<packaging>jar</packaging>
<name>Jetty :: Simple :: Base</name>
<dependencies>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<type>jar</type>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.toolchain</groupId>
<artifactId>jetty-perf-helper</artifactId>
<version>1.0.5</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.8.1</version>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,45 @@
//
// ========================================================================
// Copyright (c) 1995-2017 Mort Bay Consulting Pty. Ltd.
// ------------------------------------------------------------------------
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
// and Apache License v2.0 which accompanies this distribution.
//
// The Eclipse Public License is available at
// http://www.eclipse.org/legal/epl-v10.html
//
// The Apache License v2.0 is available at
// http://www.opensource.org/licenses/apache2.0.php
//
// You may elect to redistribute this code under either of these licenses.
// ========================================================================
//
package org.eclipse.jetty.its.jetty_run_mojo_it;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
/**
*
*/
@WebServlet("/hello")
public class HelloServlet
extends HttpServlet
{
@Override
protected void doGet( HttpServletRequest req, HttpServletResponse resp )
throws ServletException, IOException
{
String who = req.getParameter( "name" );
resp.getWriter().write( "hello " + (who == null ? "unknown" : who) );
}
}

View File

@ -0,0 +1,41 @@
//
// ========================================================================
// Copyright (c) 1995-2017 Mort Bay Consulting Pty. Ltd.
// ------------------------------------------------------------------------
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
// and Apache License v2.0 which accompanies this distribution.
//
// The Eclipse Public License is available at
// http://www.eclipse.org/legal/epl-v10.html
//
// The Apache License v2.0 is available at
// http://www.opensource.org/licenses/apache2.0.php
//
// You may elect to redistribute this code under either of these licenses.
// ========================================================================
//
package org.eclipse.jetty.its.jetty_run_mojo_it;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
public class PingServlet
extends HttpServlet
{
@Override
protected void doGet( HttpServletRequest req, HttpServletResponse resp )
throws ServletException, IOException
{
String who = req.getParameter( "name" );
resp.getWriter().write( "pong " + (who == null ? "unknown" : who) );
}
}

View File

@ -0,0 +1,32 @@
<?xml version="1.0" encoding="UTF-8"?>
<web-fragment
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-fragment_3_1.xsd"
version="3.1">
<name>FragmentA</name>
<ordering>
<after><others/></after>
</ordering>
<servlet>
<servlet-name>Ping</servlet-name>
<servlet-class>org.eclipse.jetty.its.jetty_run_mojo_it.PingServlet</servlet-class>
<init-param>
<param-name>extra1</param-name><param-value>123</param-value>
</init-param>
<init-param>
<param-name>extra2</param-name><param-value>345</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>Ping</servlet-name>
<url-pattern>/ping</url-pattern>
</servlet-mapping>
</web-fragment>

View File

@ -0,0 +1,92 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.eclipse.jetty.its.jetty-start-mojo-it</groupId>
<artifactId>jetty-simple-project</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>jetty-simple-webapp</artifactId>
<packaging>war</packaging>
<name>Jetty :: Simple :: Webapp</name>
<dependencies>
<dependency>
<groupId>org.eclipse.jetty.its.jetty-start-mojo-it</groupId>
<artifactId>jetty-simple-base</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-servlet</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-client</artifactId>
<version>@project.version@</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>${maven-war-plugin-version}</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.20</version>
<configuration>
<systemPropertyVariables>
<jetty.runPort>@jetty.runPort@</jetty.runPort>
</systemPropertyVariables>
</configuration>
</plugin>
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<executions>
<execution>
<id>start-jetty</id>
<phase>test-compile</phase>
<goals>
<goal>start</goal>
</goals>
<configuration>
<httpConnector>
<port>@jetty.runPort@</port>
</httpConnector>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

View File

@ -0,0 +1,7 @@
<?xml version="1.0"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
version="3.1">
<display-name>Jetty Simple Webapp run-mojo-it</display-name>
</web-app>

View File

@ -0,0 +1,59 @@
//
// ========================================================================
// Copyright (c) 1995-2017 Mort Bay Consulting Pty. Ltd.
// ------------------------------------------------------------------------
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
// and Apache License v2.0 which accompanies this distribution.
//
// The Eclipse Public License is available at
// http://www.eclipse.org/legal/epl-v10.html
//
// The Apache License v2.0 is available at
// http://www.opensource.org/licenses/apache2.0.php
//
// You may elect to redistribute this code under either of these licenses.
// ========================================================================
//
package org.eclipse.jetty.its.jetty_run_mojo_it;
import org.eclipse.jetty.client.HttpClient;
import org.junit.Assert;
import org.junit.Test;
/**
*
*/
public class TestHelloServlet
{
@Test
public void hello_servlet()
throws Exception
{
int port = Integer.getInteger( "jetty.runPort" );
System.out.println( "port used:" + port );
HttpClient httpClient = new HttpClient();
try
{
httpClient.start();
String response = httpClient.GET( "http://localhost:" + port + "/hello?name=beer" ).getContentAsString();
System.out.println( "httpResponse:" + response );
Assert.assertEquals( "hello beer", response.trim() );
response = httpClient.GET( "http://localhost:" + port + "/ping?name=beer" ).getContentAsString();
System.out.println( "httpResponse:" + response );
Assert.assertEquals( "pong beer", response.trim() );
}
finally
{
httpClient.stop();
}
}
}

View File

@ -0,0 +1,90 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.eclipse.jetty.its.jetty-start-mojo-it</groupId>
<artifactId>jetty-simple-project</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<name>Jetty :: Simple</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<maven-war-plugin-version>3.0.0</maven-war-plugin-version>
<jetty.version>@project.version@</jetty.version>
</properties>
<modules>
<module>jetty-simple-base</module>
<module>jetty-simple-webapp</module>
</modules>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.eclipse.jetty.its.jetty-start-mojo-it</groupId>
<artifactId>jetty-simple-base</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
<type>jar</type>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.21</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.5</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-servlet</artifactId>
<version>${jetty.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<target>1.8</target>
<source>1.8</source>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.1</version>
</plugin>
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>${jetty.version}</version>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>

View File

@ -0,0 +1,36 @@
<?xml version="1.0" encoding="UTF-8"?>
<settings>
<profiles>
<profile>
<id>it-repo</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<repositories>
<repository>
<id>local.central</id>
<url>@localRepositoryUrl@</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>local.central</id>
<url>@localRepositoryUrl@</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
</settings>

View File

@ -21,9 +21,13 @@ package org.eclipse.jetty.maven.plugin;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLClassLoader;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Enumeration;
@ -36,11 +40,14 @@ import org.apache.maven.artifact.Artifact;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.project.MavenProject;
import org.codehaus.plexus.util.FileUtils;
import org.eclipse.jetty.security.LoginService;
import org.eclipse.jetty.server.NetworkConnector;
import org.eclipse.jetty.server.RequestLog;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.ServerConnector;
import org.eclipse.jetty.server.ShutdownMonitor;
import org.eclipse.jetty.server.handler.ContextHandler;
import org.eclipse.jetty.server.handler.ContextHandlerCollection;
@ -273,9 +280,6 @@ public abstract class AbstractJettyMojo extends AbstractMojo
protected ServerSupport serverSupport;
/**
* <p>
* Determines whether or not the server blocks when started. The default
@ -287,8 +291,9 @@ public abstract class AbstractJettyMojo extends AbstractMojo
* If true, the server will not block the execution of subsequent code. This
* is the behaviour of the jetty:start and default behaviour of the jetty:deploy goals.
* </p>
* @parameter default-value="false"
*/
protected boolean nonblocking = false;
protected boolean nonBlocking = false;
public abstract void restartWebApp(boolean reconfigureScanner) throws Exception;
@ -429,11 +434,13 @@ public abstract class AbstractJettyMojo extends AbstractMojo
// if a <httpConnector> was specified in the pom, use it
if (httpConnector != null)
{
// check that its port was set
if (httpConnector.getPort() <= 0)
{
//use any jetty.http.port settings provided
String tmp = System.getProperty(MavenServerConnector.PORT_SYSPROPERTY, System.getProperty("jetty.port", MavenServerConnector.DEFAULT_PORT_STR));
String tmp = System.getProperty(MavenServerConnector.PORT_SYSPROPERTY, //
System.getProperty("jetty.port", MavenServerConnector.DEFAULT_PORT_STR));
httpConnector.setPort(Integer.parseInt(tmp.trim()));
}
httpConnector.setServer(server);
@ -459,7 +466,7 @@ public abstract class AbstractJettyMojo extends AbstractMojo
// start Jetty
this.server.start();
getLog().info("Started Jetty Server");
getLog().info( "Started Jetty Server" );
if ( dumpOnStart )
{
@ -478,10 +485,11 @@ public abstract class AbstractJettyMojo extends AbstractMojo
startConsoleScanner();
// keep the thread going if not in daemon mode
if (!nonblocking )
if (!nonBlocking )
{
server.join();
}
}
catch (Exception e)
{
@ -489,7 +497,7 @@ public abstract class AbstractJettyMojo extends AbstractMojo
}
finally
{
if (!nonblocking )
if (!nonBlocking )
{
getLog().info("Jetty server exiting.");
}
@ -504,7 +512,7 @@ public abstract class AbstractJettyMojo extends AbstractMojo
ShutdownMonitor monitor = ShutdownMonitor.getInstance();
monitor.setPort(stopPort);
monitor.setKey(stopKey);
monitor.setExitVm(!nonblocking);
monitor.setExitVm(!nonBlocking );
}
}

View File

@ -61,7 +61,7 @@ public class JettyDeployWar extends JettyRunWarMojo
@Override
public void execute() throws MojoExecutionException, MojoFailureException
{
nonblocking = daemon;
nonBlocking = daemon;
super.execute();
}
@ -72,7 +72,7 @@ public class JettyDeployWar extends JettyRunWarMojo
{
super.finishConfigurationBeforeStart();
//only stop the server at shutdown if we are blocking
server.setStopAtShutdown(!nonblocking);
server.setStopAtShutdown(!nonBlocking );
}
}

View File

@ -18,6 +18,17 @@
package org.eclipse.jetty.maven.plugin;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugin.descriptor.PluginDescriptor;
import org.eclipse.jetty.annotations.AnnotationConfiguration;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.util.IO;
import org.eclipse.jetty.util.resource.Resource;
import org.eclipse.jetty.util.resource.ResourceCollection;
import org.eclipse.jetty.util.thread.QueuedThreadPool;
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.File;
@ -40,17 +51,6 @@ import java.util.Properties;
import java.util.Random;
import java.util.Set;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugin.descriptor.PluginDescriptor;
import org.eclipse.jetty.annotations.AnnotationConfiguration;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.util.IO;
import org.eclipse.jetty.util.resource.Resource;
import org.eclipse.jetty.util.resource.ResourceCollection;
import org.eclipse.jetty.util.thread.QueuedThreadPool;
/**
* This goal is used to deploy your unassembled webapp into a forked JVM.
@ -171,7 +171,14 @@ public class JettyRunForkedMojo extends JettyRunMojo
}
/**
* we o
*/
// protected MavenProject getProjectReferences( Artifact artifact, MavenProject project )
// {
//
// return null;
// }
/**
* ConsoleStreamer
@ -349,7 +356,7 @@ public class JettyRunForkedMojo extends JettyRunMojo
builder.directory(project.getBasedir());
if (PluginLog.getLog().isDebugEnabled())
PluginLog.getLog().debug(Arrays.toString(cmd.toArray()));
PluginLog.getLog().debug("Forked cli:"+Arrays.toString(cmd.toArray()));
PluginLog.getLog().info("Forked process starting");
@ -510,6 +517,19 @@ public class JettyRunForkedMojo extends JettyRunMojo
props.put("testClasses.dir", webApp.getTestClasses().getAbsolutePath());
}
if ( !webApp.getClassPathFiles().isEmpty() )
{
StringBuilder stringBuilder = new StringBuilder();
for ( File dependency : webApp.getClassPathFiles() )
{
if (dependency.isDirectory())
{
stringBuilder.append( dependency.getCanonicalPath() ).append( '|' );
}
}
props.put( "projects.classes.dir", stringBuilder.toString() );
}
//web-inf lib
List<File> deps = webApp.getWebInfLib();
StringBuffer strbuff = new StringBuffer();
@ -578,7 +598,7 @@ public class JettyRunForkedMojo extends JettyRunMojo
List<Artifact> warArtifacts = new ArrayList<Artifact>();
for ( Iterator<Artifact> iter = project.getArtifacts().iterator(); iter.hasNext(); )
{
Artifact artifact = (Artifact) iter.next();
Artifact artifact = iter.next();
if (artifact.getType().equals("war"))
warArtifacts.add(artifact);

View File

@ -18,17 +18,6 @@
package org.eclipse.jetty.maven.plugin;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.project.MavenProject;
import org.codehaus.plexus.util.StringUtils;
import org.eclipse.jetty.util.PathWatcher;
import org.eclipse.jetty.util.PathWatcher.PathWatchEvent;
import org.eclipse.jetty.util.resource.Resource;
import org.eclipse.jetty.webapp.WebAppContext;
import java.io.File;
import java.io.IOException;
import java.net.URL;
@ -41,6 +30,17 @@ import java.util.Iterator;
import java.util.List;
import java.util.Set;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.project.MavenProject;
import org.codehaus.plexus.util.StringUtils;
import org.eclipse.jetty.util.PathWatcher;
import org.eclipse.jetty.util.PathWatcher.PathWatchEvent;
import org.eclipse.jetty.util.resource.Resource;
import org.eclipse.jetty.webapp.WebAppContext;
/**
* This goal is used in-situ on a Maven project without first requiring that the project
* is assembled into a war, saving time during the development cycle.
@ -222,7 +222,7 @@ public class JettyRunMojo extends AbstractJettyMojo
{
getLog().info("Reload Mechanic: " + reload );
}
getLog().info( "nonBlocking:" + nonBlocking );
// check the classes to form a classpath with
try
@ -287,8 +287,6 @@ public class JettyRunMojo extends AbstractJettyMojo
//get copy of a list of war artifacts
Set<Artifact> matchedWarArtifacts = new HashSet<Artifact>();
//process any overlays and the war type artifacts
List<Overlay> overlays = new ArrayList<Overlay>();
for (OverlayConfig config:warPluginInfo.getMavenWarOverlayConfigs())
@ -367,7 +365,17 @@ public class JettyRunMojo extends AbstractJettyMojo
getLog().info("Webapp directory = " + webAppSourceDirectory.getCanonicalPath());
}
private static File toFile(Resource resource)
{
try
{
return resource.getFile();
}
catch ( IOException e )
{
throw new RuntimeException( e.getMessage(), e );
}
}
/**
@ -566,7 +574,7 @@ public class JettyRunMojo extends AbstractJettyMojo
*/
private List<File> getDependencyFiles()
{
List<File> dependencyFiles = new ArrayList<File>();
List<File> dependencyFiles = new ArrayList<>();
for ( Iterator<Artifact> iter = projectArtifacts.iterator(); iter.hasNext(); )
{
Artifact artifact = iter.next();
@ -596,7 +604,7 @@ public class JettyRunMojo extends AbstractJettyMojo
private List<File> getDependencyProjects()
{
List<File> dependencyFiles = new ArrayList<File>();
List<File> dependencyFiles = new ArrayList<>();
for ( Iterator<Artifact> iter = projectArtifacts.iterator(); iter.hasNext(); )
{
Artifact artifact = iter.next();
@ -626,7 +634,7 @@ public class JettyRunMojo extends AbstractJettyMojo
}
private MavenProject getProjectReferences( Artifact artifact, MavenProject project )
protected MavenProject getProjectReferences( Artifact artifact, MavenProject project )
{
if ( project.getProjectReferences() == null || project.getProjectReferences().isEmpty() )
{
@ -656,10 +664,10 @@ public class JettyRunMojo extends AbstractJettyMojo
if (warArtifacts != null)
return warArtifacts;
warArtifacts = new ArrayList<Artifact>();
warArtifacts = new ArrayList<>();
for ( Iterator<Artifact> iter = projectArtifacts.iterator(); iter.hasNext(); )
{
Artifact artifact = (Artifact) iter.next();
Artifact artifact = iter.next();
if (artifact.getType().equals("war") || artifact.getType().equals("zip"))
{
try

View File

@ -61,6 +61,10 @@ public class JettyRunWarMojo extends AbstractJettyMojo
*/
public void execute() throws MojoExecutionException, MojoFailureException
{
if ( !"war".equals( project.getPackaging() ) || skip )
{
return;
}
super.execute();
}

View File

@ -44,7 +44,7 @@ public class JettyStartMojo extends JettyRunMojo
@Override
public void execute() throws MojoExecutionException, MojoFailureException
{
nonblocking = true; //ensure that starting jetty won't hold up the thread
nonBlocking = true; //ensure that starting jetty won't hold up the thread
super.execute();
}

View File

@ -271,6 +271,11 @@ public class MavenServerConnector extends ContainerLifeCycle implements Connecto
return this.name;
}
public int getLocalPort()
{
return this.delegate.getLocalPort();
}
private void checkDelegate() throws IllegalStateException
{
if (this.delegate == null)

View File

@ -87,6 +87,10 @@ public class MavenWebInfConfiguration extends WebInfConfiguration
/**
* @see org.eclipse.jetty.webapp.WebInfConfiguration#deconfigure(org.eclipse.jetty.webapp.WebAppContext)
*/

View File

@ -165,7 +165,7 @@ public class ServerSupport
if (server == null)
return null;
return (ContextHandlerCollection)server.getChildHandlerByClass(ContextHandlerCollection.class);
return server.getChildHandlerByClass(ContextHandlerCollection.class);
}

View File

@ -22,7 +22,9 @@ import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.net.URL;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Enumeration;
import java.util.HashSet;
import java.util.Iterator;
@ -30,6 +32,8 @@ import java.util.List;
import java.util.Properties;
import java.util.Set;
import java.util.TreeMap;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import org.eclipse.jetty.server.Handler;
import org.eclipse.jetty.server.Server;
@ -174,31 +178,31 @@ public class Starter
//apply a properties file that defines the things that we configure in the jetty:run plugin:
// - the context path
String str = (String)props.get("context.path");
String str = props.getProperty("context.path");
if (str != null)
webApp.setContextPath(str);
// - web.xml
str = (String)props.get("web.xml");
str = props.getProperty("web.xml");
if (str != null)
webApp.setDescriptor(str);
str = (String)props.get("quickstart.web.xml");
str = props.getProperty("quickstart.web.xml");
if (str != null)
webApp.setQuickStartWebDescriptor(Resource.newResource(new File(str)));
// - the tmp directory
str = (String)props.getProperty("tmp.dir");
str = props.getProperty("tmp.dir");
if (str != null)
webApp.setTempDirectory(new File(str.trim()));
str = (String)props.getProperty("tmp.dir.persist");
str = props.getProperty("tmp.dir.persist");
if (str != null)
webApp.setPersistTempDirectory(Boolean.valueOf(str));
//Get the calculated base dirs which includes the overlays
str = (String)props.getProperty("base.dirs");
str = props.getProperty("base.dirs");
if (str != null && !"".equals(str.trim()))
{
ResourceCollection bases = new ResourceCollection(StringUtil.csvSplit(str));
@ -207,7 +211,7 @@ public class Starter
}
//Get the original base dirs without the overlays
str = (String)props.get("base.dirs.orig");
str = props.getProperty("base.dirs.orig");
if (str != null && !"".equals(str.trim()))
{
ResourceCollection bases = new ResourceCollection(StringUtil.csvSplit(str));
@ -215,9 +219,9 @@ public class Starter
}
//For overlays
str = (String)props.getProperty("maven.war.includes");
str = props.getProperty("maven.war.includes");
List<String> defaultWarIncludes = fromCSV(str);
str = (String)props.getProperty("maven.war.excludes");
str = props.getProperty("maven.war.excludes");
List<String> defaultWarExcludes = fromCSV(str);
//List of war artifacts
@ -246,7 +250,7 @@ public class Starter
Set<Artifact> matchedWars = new HashSet<Artifact>();
//process any overlays and the war type artifacts
List<Overlay> overlays = new ArrayList<Overlay>();
List<Overlay> overlays = new ArrayList<>();
for (OverlayConfig config:orderedConfigs.values())
{
//overlays can be individually skipped
@ -288,21 +292,20 @@ public class Starter
// - the equivalent of web-inf classes
str = (String)props.getProperty("classes.dir");
str = props.getProperty("classes.dir");
if (str != null && !"".equals(str.trim()))
{
webApp.setClasses(new File(str));
}
str = (String)props.getProperty("testClasses.dir");
str = props.getProperty("testClasses.dir");
if (str != null && !"".equals(str.trim()))
{
webApp.setTestClasses(new File(str));
}
// - the equivalent of web-inf lib
str = (String)props.getProperty("lib.jars");
str = props.getProperty("lib.jars");
if (str != null && !"".equals(str.trim()))
{
List<File> jars = new ArrayList<File>();
@ -312,6 +315,15 @@ public class Starter
webApp.setWebInfLib(jars);
}
str = props.getProperty( "projects.classes.dir" );
if (str != null && !"".equals(str.trim()))
{
List<File> classesDirectories = //
Arrays.stream(str.split( Pattern.quote("|") )) //
.map( s -> Paths.get( s).toFile() ).collect( Collectors.toList() );
webApp.getWebInfLib().addAll( classesDirectories );
}
}
public void getConfiguration (String[] args)

View File

@ -44,6 +44,7 @@ import org.eclipse.jetty.client.HttpClient;
import org.eclipse.jetty.client.ProtocolHandlers;
import org.eclipse.jetty.client.api.Request;
import org.eclipse.jetty.client.api.Response;
import org.eclipse.jetty.client.http.HttpClientTransportOverHTTP;
import org.eclipse.jetty.http.HttpField;
import org.eclipse.jetty.http.HttpHeader;
import org.eclipse.jetty.http.HttpHeaderValue;
@ -257,9 +258,14 @@ public abstract class AbstractProxyServlet extends HttpServlet
* <td>HttpClient's default</td>
* <td>The response buffer size, see {@link HttpClient#setResponseBufferSize(int)}</td>
* </tr>
* <tr>
* <td>selectors</td>
* <td>cores / 2</td>
* <td>The number of NIO selectors used by {@link HttpClient}</td>
* </tr>
* </tbody>
* </table>
*
* @see #newHttpClient()
* @return a {@link HttpClient} configured from the {@link #getServletConfig() servlet configuration}
* @throws ServletException if the {@link HttpClient} cannot be created
*/
@ -340,11 +346,17 @@ public abstract class AbstractProxyServlet extends HttpServlet
}
/**
* The servlet init parameter 'selectors' can be set for the number of
* selector threads to be used by the HttpClient.
* @return a new HttpClient instance
*/
protected HttpClient newHttpClient()
{
return new HttpClient();
int selectors = Math.max(1, Runtime.getRuntime().availableProcessors() / 2);
String value = getServletConfig().getInitParameter("selectors");
if (value != null)
selectors = Integer.parseInt(value);
return new HttpClient(new HttpClientTransportOverHTTP(selectors),null);
}
protected HttpClient getHttpClient()

View File

@ -379,6 +379,16 @@ public class LocalConnector extends AbstractConnector
}
}
/**
* Remaining output ByteBuffer after calls to {@link #getResponse()} or {@link #waitForResponse(boolean, long, TimeUnit)}
*
* @return the remaining response data buffer
*/
public ByteBuffer getResponseData()
{
return _responseData;
}
/**
* Wait for a response using a parser to detect the end of message
* @return Buffer containing full response or null for EOF;

View File

@ -266,7 +266,7 @@ public class ServerConnector extends AbstractNetworkConnector
* <p>Use it with xinetd/inetd, to launch an instance of Jetty on demand. The port
* used to access pages on the Jetty instance is the same as the port used to
* launch Jetty.</p>
*
* @see ServerConnector#openAcceptChannel()
* @param inheritChannel whether this connector uses a channel inherited from the JVM.
*/
public void setInheritChannel(boolean inheritChannel)
@ -274,41 +274,67 @@ public class ServerConnector extends AbstractNetworkConnector
_inheritChannel = inheritChannel;
}
/**
* Open the connector using the passed ServerSocketChannel.
* This open method can be called before starting the connector to pass it a ServerSocketChannel
* that will be used instead of one returned from {@link #openAcceptChannel()}
* @param acceptChannel the channel to use
* @throws IOException
*/
public void open(ServerSocketChannel acceptChannel) throws IOException
{
if (isStarted())
throw new IllegalStateException(getState());
updateBean(_acceptChannel,acceptChannel);
_acceptChannel = acceptChannel;
_localPort = _acceptChannel.socket().getLocalPort();
if (_localPort <= 0)
throw new IOException("Server channel not bound");
}
@Override
public void open() throws IOException
{
if (_acceptChannel == null)
{
ServerSocketChannel serverChannel = null;
if (isInheritChannel())
{
Channel channel = System.inheritedChannel();
if (channel instanceof ServerSocketChannel)
serverChannel = (ServerSocketChannel)channel;
else
LOG.warn("Unable to use System.inheritedChannel() [{}]. Trying a new ServerSocketChannel at {}:{}", channel, getHost(), getPort());
}
if (serverChannel == null)
{
serverChannel = ServerSocketChannel.open();
InetSocketAddress bindAddress = getHost() == null ? new InetSocketAddress(getPort()) : new InetSocketAddress(getHost(), getPort());
serverChannel.socket().setReuseAddress(getReuseAddress());
serverChannel.socket().bind(bindAddress, getAcceptQueueSize());
_localPort = serverChannel.socket().getLocalPort();
if (_localPort <= 0)
throw new IOException("Server channel not bound");
}
serverChannel.configureBlocking(true);
addBean(serverChannel);
_acceptChannel = serverChannel;
_acceptChannel = openAcceptChannel();
_acceptChannel.configureBlocking(true);
_localPort = _acceptChannel.socket().getLocalPort();
if (_localPort <= 0)
throw new IOException("Server channel not bound");
addBean(_acceptChannel);
}
}
/**
* Called by {@link #open()} to obtain the accepting channel.
* @return ServerSocketChannel used to accept connections.
* @throws IOException
*/
protected ServerSocketChannel openAcceptChannel() throws IOException
{
ServerSocketChannel serverChannel = null;
if (isInheritChannel())
{
Channel channel = System.inheritedChannel();
if (channel instanceof ServerSocketChannel)
serverChannel = (ServerSocketChannel)channel;
else
LOG.warn("Unable to use System.inheritedChannel() [{}]. Trying a new ServerSocketChannel at {}:{}", channel, getHost(), getPort());
}
if (serverChannel == null)
{
serverChannel = ServerSocketChannel.open();
InetSocketAddress bindAddress = getHost() == null ? new InetSocketAddress(getPort()) : new InetSocketAddress(getHost(), getPort());
serverChannel.socket().setReuseAddress(getReuseAddress());
serverChannel.socket().bind(bindAddress, getAcceptQueueSize());
}
return serverChannel;
}
@Override
public Future<Void> shutdown()
{

View File

@ -32,9 +32,11 @@ import java.io.InputStream;
import java.io.PrintWriter;
import java.lang.reflect.Field;
import java.net.HttpURLConnection;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.channels.ServerSocketChannel;
import java.nio.charset.StandardCharsets;
import java.util.Collection;
import java.util.concurrent.atomic.AtomicLong;
@ -52,8 +54,11 @@ import org.eclipse.jetty.toolchain.test.OS;
import org.eclipse.jetty.util.IO;
import org.eclipse.jetty.util.log.StacklessLogging;
import org.hamcrest.Matchers;
import org.junit.Assert;
import org.junit.Test;
import static org.hamcrest.Matchers.greaterThan;
import static org.junit.Assert.assertTrue;
public class ServerConnectorTest
{
public static class ReuseInfoHandler extends AbstractHandler
@ -265,5 +270,39 @@ public class ServerConnectorTest
{
server.stop();
}
}
@Test
public void testOpenWithServerSocketChannel() throws Exception
{
Server server = new Server();
ServerConnector connector = new ServerConnector(server);
server.addConnector(connector);
ServerSocketChannel channel = ServerSocketChannel.open();
channel.bind(new InetSocketAddress(0));
assertTrue(channel.isOpen());
int port = channel.socket().getLocalPort();
assertThat(port,greaterThan(0));
connector.open(channel);
assertThat(connector.getLocalPort(),is(port));
server.start();
assertThat(connector.getLocalPort(),is(port));
assertThat(connector.getTransport(),is(channel));
server.stop();
assertThat(connector.getTransport(),Matchers.nullValue());
}
}

View File

@ -19,6 +19,7 @@
package org.eclipse.jetty.servlet;
import static org.junit.Assert.assertTrue;
import static org.junit.Assume.assumeTrue;
import java.io.File;
import java.io.FileOutputStream;
@ -231,10 +232,7 @@ public class DefaultServletTest
createFile(index, "<h1>Hello Index</h1>");
File wackyDir = new File(resBase, "dir?");
if (!OS.IS_WINDOWS)
{
FS.ensureDirExists(wackyDir);
}
assumeTrue("FileSystem should support question dirs", wackyDir.mkdirs());
wackyDir = new File(resBase, "dir;");
assertTrue(wackyDir.mkdirs());
@ -266,13 +264,8 @@ public class DefaultServletTest
response = connector.getResponse("GET /context/dir?/ HTTP/1.0\r\n\r\n");
assertResponseContains("404", response);
if (!OS.IS_WINDOWS)
{
response = connector.getResponse("GET /context/dir%3F/ HTTP/1.0\r\n\r\n");
assertResponseContains("Directory: /context/dir?/<", response);
}
else
assertResponseContains("404", response);
response = connector.getResponse("GET /context/dir%3F/ HTTP/1.0\r\n\r\n");
assertResponseContains("Directory: /context/dir?/<", response);
response = connector.getResponse("GET /context/index.html HTTP/1.0\r\n\r\n");
assertResponseContains("Hello Index", response);
@ -421,7 +414,8 @@ public class DefaultServletTest
context.setBaseResource(Resource.newResource(resBase));
File dir = new File(resBase, "dir?");
assertTrue(dir.mkdirs());
assumeTrue("FileSystem should support question dirs", dir.mkdirs());
File index = new File(dir, "index.html");
createFile(index, "<h1>Hello Index</h1>");
@ -438,7 +432,6 @@ public class DefaultServletTest
assertResponseContains("Location: http://0.0.0.0/context/dir%3F/index.html", response);
}
@Test
public void testWelcomeServlet() throws Exception
{

View File

@ -19,6 +19,12 @@
package org.eclipse.jetty.util;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileWriter;
@ -35,12 +41,6 @@ import org.junit.Assert;
import org.junit.Ignore;
import org.junit.Test;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
public class BufferUtilTest
{
@Test
@ -346,7 +346,7 @@ public class BufferUtilTest
String data="Now is the time for all good men to come to the aid of the party";
File file = File.createTempFile("test",".txt");
file.deleteOnExit();
try(FileWriter out = new FileWriter(file);)
try(FileWriter out = new FileWriter(file))
{
out.write(data);
}

View File

@ -37,7 +37,6 @@ import java.util.concurrent.TimeUnit;
import org.eclipse.jetty.toolchain.test.FS;
import org.eclipse.jetty.toolchain.test.MavenTestingUtils;
import org.eclipse.jetty.util.resource.ResourceTest;
import org.hamcrest.Matchers;
import org.junit.Test;
@ -182,9 +181,9 @@ public class RolloverFileOutputStreamTest
}
@Test
public void testFilehandling() throws Exception
public void testFileHandling() throws Exception
{
File testDir = MavenTestingUtils.getTargetTestingDir(ResourceTest.class.getName());
File testDir = MavenTestingUtils.getTargetTestingDir(RolloverFileOutputStreamTest.class.getName() + "_testFileHandling");
Path testPath = testDir.toPath();
FS.ensureEmpty(testDir);
@ -290,7 +289,7 @@ public class RolloverFileOutputStreamTest
@Test
public void testRollover() throws Exception
{
File testDir = MavenTestingUtils.getTargetTestingDir(ResourceTest.class.getName());
File testDir = MavenTestingUtils.getTargetTestingDir(RolloverFileOutputStreamTest.class.getName() + "_testRollover");
FS.ensureEmpty(testDir);
ZoneId zone = toZoneId("Australia/Sydney");

View File

@ -19,14 +19,16 @@
package org.eclipse.jetty.util;
import org.eclipse.jetty.toolchain.test.JDK;
import org.hamcrest.Matchers;
import org.junit.Assert;
import org.junit.Test;
import static org.hamcrest.CoreMatchers.containsString;
import static org.junit.Assert.assertThat;
import java.nio.file.Path;
import java.nio.file.Paths;
import org.eclipse.jetty.toolchain.test.JDK;
import org.junit.Assert;
import org.junit.Test;
public class TypeUtilTest
{
@Test
@ -129,18 +131,19 @@ public class TypeUtilTest
public void testGetLocationOfClass() throws Exception
{
Path mavenRepoPath = Paths.get( System.getProperty( "mavenRepoPath" ) );
String mavenRepo = mavenRepoPath.toFile().getPath();
String mavenRepo = mavenRepoPath.toFile().getPath().replaceAll("\\\\", "/");
// Classes from maven dependencies
Assert.assertThat(TypeUtil.getLocationOfClass(Assert.class).toASCIIString(),Matchers.containsString(mavenRepo));
assertThat(TypeUtil.getLocationOfClass(Assert.class).toASCIIString(),containsString(mavenRepo));
// Class from project dependencies
Assert.assertThat(TypeUtil.getLocationOfClass(TypeUtil.class).toASCIIString(),Matchers.containsString("/classes/"));
assertThat(TypeUtil.getLocationOfClass(TypeUtil.class).toASCIIString(),containsString("/classes/"));
// Class from JVM core
String expectedJavaBase = "/rt.jar";
if(JDK.IS_9)
expectedJavaBase = "/java.base/";
Assert.assertThat(TypeUtil.getLocationOfClass(String.class).toASCIIString(),Matchers.containsString(expectedJavaBase));
assertThat(TypeUtil.getLocationOfClass(String.class).toASCIIString(),containsString(expectedJavaBase));
}
}

Some files were not shown because too many files have changed in this diff Show More