Merged branch 'jetty-10.0.x' into 'jetty-10.0.x-4058-autolock'.
This commit is contained in:
commit
f942cd4687
2
KEYS.txt
2
KEYS.txt
|
@ -2,6 +2,6 @@
|
|||
Jan Bartel <janb@mortbay.com> AED5 EE6C 45D0 FE8D 5D1B 164F 27DE D4BF 6216 DB8F
|
||||
Jesse McConnell <jesse.mcconnell@gmail.com> 2A68 4B57 436A 81FA 8706 B53C 61C3 351A 438A 3B7D
|
||||
Joakim Erdfelt <joakim.erdfelt@gmail.com> 5989 BAF7 6217 B843 D66B E55B 2D0E 1FB8 FE4B 68B4
|
||||
Joakim Erdfelt <joakim@apache.org> B59B 67FD 7904 9843 67F9 3180 0818 D9D6 8FB6 7BAC
|
||||
Joakim Erdfelt <joakime@apache.org> B59B 67FD 7904 9843 67F9 3180 0818 D9D6 8FB6 7BAC
|
||||
Joakim Erdfelt <joakim@erdfelt.com> BFBB 21C2 46D7 7768 3628 7A48 A04E 0C74 ABB3 5FEA
|
||||
Simone Bordet <simone.bordet@gmail.com> 8B09 6546 B1A8 F026 56B1 5D3B 1677 D141 BCF3 584D
|
||||
|
|
|
@ -79,6 +79,7 @@ jetty-10.0.0-alpha0 - 11 July 2019
|
|||
+ 2095 Remove FastCGI multiplexing
|
||||
+ 2103 Server should open connectors early in start sequence
|
||||
+ 2108 Update licence headers and plugin for 2018
|
||||
+ 2140 Infinispan and hazelcast changes to scavenge zombie expired sessions.
|
||||
+ 2172 Support javax.websocket 1.1
|
||||
+ 2175 Refactor WebSocket close handling
|
||||
+ 2191 JPMS Support
|
||||
|
@ -289,6 +290,7 @@ jetty-9.4.18.v20190429 - 29 April 2019
|
|||
+ 3609 Fix infinispan start module dependencies
|
||||
|
||||
jetty-9.4.17.v20190418 - 18 April 2019
|
||||
+ 2140 Infinispan and hazelcast changes to scavenge zombie expired sessions.
|
||||
+ 3464 Split SslContextFactory into Client and Server
|
||||
+ 3549 Directory Listing on Windows reveals Resource Base path
|
||||
+ 3555 DefaultHandler Reveals Base Resource Path of each Context
|
||||
|
|
|
@ -132,7 +132,32 @@
|
|||
<dependency>
|
||||
<groupId>org.eclipse.jetty.toolchain</groupId>
|
||||
<artifactId>jetty-test-helper</artifactId>
|
||||
<!-- scope>test</scope-->
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty.websocket</groupId>
|
||||
<artifactId>jetty-websocket-client</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-distribution</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<type>tar.gz</type>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<configuration>
|
||||
<useManifestOnlyJar>false</useManifestOnlyJar>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
|
|
|
@ -22,7 +22,6 @@ import java.io.IOException;
|
|||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import javax.servlet.AsyncContext;
|
||||
import javax.servlet.ReadListener;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.ServletInputStream;
|
||||
import javax.servlet.ServletOutputStream;
|
||||
import javax.servlet.WriteListener;
|
||||
|
@ -35,7 +34,7 @@ public class AsyncEchoServlet extends HttpServlet
|
|||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Override
|
||||
protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
|
||||
protected void service(HttpServletRequest request, HttpServletResponse response) throws IOException
|
||||
{
|
||||
AsyncContext asyncContext = request.startAsync(request, response);
|
||||
asyncContext.setTimeout(0);
|
||||
|
|
|
@ -20,6 +20,8 @@ package org.eclipse.jetty.embedded;
|
|||
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.util.Collections;
|
||||
import javax.servlet.ServletContext;
|
||||
import javax.servlet.http.HttpServlet;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
@ -45,12 +47,28 @@ public class DumpServlet extends HttpServlet
|
|||
out.println("pathInfo=" + request.getPathInfo());
|
||||
out.println("session=" + request.getSession(true).getId());
|
||||
|
||||
ServletContext servletContext = getServletContext();
|
||||
|
||||
String r = request.getParameter("resource");
|
||||
if (r != null)
|
||||
{
|
||||
out.println("resource(" + r + ")=" + getServletContext().getResource(r));
|
||||
out.println("resource(" + r + ")=" + servletContext.getResource(r));
|
||||
}
|
||||
|
||||
Collections.list(request.getAttributeNames())
|
||||
.stream()
|
||||
.filter((name) -> name.startsWith("X-"))
|
||||
.sorted()
|
||||
.forEach((name) ->
|
||||
out.println("request.attribute[" + name + "]=" + request.getAttribute(name)));
|
||||
|
||||
Collections.list(servletContext.getAttributeNames())
|
||||
.stream()
|
||||
.filter((name) -> name.startsWith("X-"))
|
||||
.sorted()
|
||||
.forEach((name) ->
|
||||
out.println("servletContext.attribute[" + name + "]=" + servletContext.getAttribute(name)));
|
||||
|
||||
out.println("</pre>");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,12 +28,12 @@ import org.eclipse.jetty.servlet.ServletContextHandler;
|
|||
|
||||
public class ExampleServer
|
||||
{
|
||||
public static void main(String[] args) throws Exception
|
||||
public static Server createServer(int port)
|
||||
{
|
||||
Server server = new Server();
|
||||
|
||||
ServerConnector connector = new ServerConnector(server);
|
||||
connector.setPort(8080);
|
||||
connector.setPort(port);
|
||||
server.setConnectors(new Connector[]{connector});
|
||||
|
||||
ServletContextHandler context = new ServletContextHandler();
|
||||
|
@ -45,6 +45,13 @@ public class ExampleServer
|
|||
handlers.setHandlers(new Handler[]{context, new DefaultHandler()});
|
||||
server.setHandler(handlers);
|
||||
|
||||
return server;
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception
|
||||
{
|
||||
int port = ExampleUtil.getPort(args, "jetty.http.port", 8080);
|
||||
Server server = createServer(port);
|
||||
server.start();
|
||||
server.join();
|
||||
}
|
||||
|
|
|
@ -18,21 +18,31 @@
|
|||
|
||||
package org.eclipse.jetty.embedded;
|
||||
|
||||
import org.eclipse.jetty.server.Server;
|
||||
import org.eclipse.jetty.util.resource.Resource;
|
||||
import org.eclipse.jetty.xml.XmlConfiguration;
|
||||
|
||||
/**
|
||||
* Configures and Starts a Jetty server from an XML declaration.
|
||||
* <p>
|
||||
* See <a href="https://raw.githubusercontent.com/eclipse/jetty.project/master/examples/embedded/src/main/resources/exampleserver.xml">exampleserver.xml</a>
|
||||
* </p>
|
||||
*/
|
||||
public class ExampleServerXml
|
||||
{
|
||||
public static void main(String[] args) throws Exception
|
||||
public static Server createServer(int port) throws Exception
|
||||
{
|
||||
// Find Jetty XML (in classpath) that configures and starts Server.
|
||||
// See src/main/resources/exampleserver.xml
|
||||
Resource serverXml = Resource.newSystemResource("exampleserver.xml");
|
||||
XmlConfiguration.main(serverXml.getFile().getAbsolutePath());
|
||||
XmlConfiguration xml = new XmlConfiguration(serverXml);
|
||||
xml.getProperties().put("http.port", Integer.toString(port));
|
||||
Server server = (Server)xml.configure();
|
||||
return server;
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception
|
||||
{
|
||||
int port = ExampleUtil.getPort(args, "jetty.http.port", 8080);
|
||||
Server server = createServer(port);
|
||||
server.start();
|
||||
server.join();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,86 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2019 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.embedded;
|
||||
|
||||
import org.eclipse.jetty.util.StringUtil;
|
||||
|
||||
public class ExampleUtil
|
||||
{
|
||||
/**
|
||||
* Get a port, possibly configured from Command line or System property.
|
||||
*
|
||||
* @param args the command line arguments
|
||||
* @param propertyName the property name
|
||||
* @param defValue the default value
|
||||
* @return the configured port
|
||||
*/
|
||||
public static int getPort(String[] args, String propertyName, int defValue)
|
||||
{
|
||||
for (String arg : args)
|
||||
{
|
||||
if (arg.startsWith(propertyName + "="))
|
||||
{
|
||||
String value = arg.substring(propertyName.length() + 2);
|
||||
int port = toInt(value);
|
||||
if (isValidPort(port))
|
||||
return port;
|
||||
}
|
||||
}
|
||||
|
||||
String value = System.getProperty(propertyName);
|
||||
int port = toInt(value);
|
||||
if (isValidPort(port))
|
||||
return port;
|
||||
|
||||
return defValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if port is in the valid range to be used.
|
||||
*
|
||||
* @param port the port to test
|
||||
* @return true if valid
|
||||
*/
|
||||
private static boolean isValidPort(int port)
|
||||
{
|
||||
return (port >= 0) && (port <= 65535);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse an int, ignoring any {@link NumberFormatException}
|
||||
*
|
||||
* @param value the string value to parse
|
||||
* @return the int (if parsed), or -1 if not parsed.
|
||||
*/
|
||||
private static int toInt(String value)
|
||||
{
|
||||
if (StringUtil.isBlank(value))
|
||||
return -1;
|
||||
|
||||
try
|
||||
{
|
||||
return Integer.parseInt(value);
|
||||
}
|
||||
catch (NumberFormatException ignored)
|
||||
{
|
||||
// ignored
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -58,17 +58,24 @@ import org.eclipse.jetty.util.resource.Resource;
|
|||
*/
|
||||
public class FastFileServer
|
||||
{
|
||||
public static void main(String[] args) throws Exception
|
||||
public static Server createServer(int port, File resourceBase)
|
||||
{
|
||||
Server server = new Server(8080);
|
||||
Server server = new Server(port);
|
||||
|
||||
HandlerList handlers = new HandlerList();
|
||||
handlers.setHandlers(new Handler[]{
|
||||
new FastFileHandler(new File(System.getProperty("user.dir"))),
|
||||
new FastFileHandler(resourceBase),
|
||||
new DefaultHandler()
|
||||
});
|
||||
server.setHandler(handlers);
|
||||
return server;
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception
|
||||
{
|
||||
int port = ExampleUtil.getPort(args, "jetty.http.port", 8080);
|
||||
File directory = new File(System.getProperty("user.dir"));
|
||||
Server server = createServer(port, directory);
|
||||
server.start();
|
||||
server.join();
|
||||
}
|
||||
|
|
|
@ -18,11 +18,16 @@
|
|||
|
||||
package org.eclipse.jetty.embedded;
|
||||
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
|
||||
import org.eclipse.jetty.server.Handler;
|
||||
import org.eclipse.jetty.server.Server;
|
||||
import org.eclipse.jetty.server.handler.DefaultHandler;
|
||||
import org.eclipse.jetty.server.handler.HandlerList;
|
||||
import org.eclipse.jetty.server.handler.ResourceHandler;
|
||||
import org.eclipse.jetty.util.resource.PathResource;
|
||||
import org.eclipse.jetty.util.resource.Resource;
|
||||
|
||||
/**
|
||||
* Simple Jetty FileServer.
|
||||
|
@ -30,12 +35,12 @@ import org.eclipse.jetty.server.handler.ResourceHandler;
|
|||
*/
|
||||
public class FileServer
|
||||
{
|
||||
public static void main(String[] args) throws Exception
|
||||
public static Server createServer(int port, Resource baseResource) throws Exception
|
||||
{
|
||||
// Create a basic Jetty server object that will listen on port 8080. Note that if you set this to port 0
|
||||
// then a randomly available port will be assigned that you can either look in the logs for the port,
|
||||
// or programmatically obtain it for use in test cases.
|
||||
final Server server = new Server(8080);
|
||||
Server server = new Server(port);
|
||||
|
||||
// Create the ResourceHandler. It is the object that will actually handle the request for a given file. It is
|
||||
// a Jetty Handler object so it is suitable for chaining with other handlers as you will see in other examples.
|
||||
|
@ -45,13 +50,24 @@ public class FileServer
|
|||
// In this example it is the current directory but it can be configured to anything that the jvm has access to.
|
||||
resourceHandler.setDirectoriesListed(true);
|
||||
resourceHandler.setWelcomeFiles(new String[]{"index.html"});
|
||||
resourceHandler.setResourceBase(".");
|
||||
resourceHandler.setBaseResource(baseResource);
|
||||
|
||||
// Add the ResourceHandler to the server.
|
||||
HandlerList handlers = new HandlerList();
|
||||
handlers.setHandlers(new Handler[]{resourceHandler, new DefaultHandler()});
|
||||
server.setHandler(handlers);
|
||||
|
||||
return server;
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception
|
||||
{
|
||||
int port = ExampleUtil.getPort(args, "jetty.http.port", 8080);
|
||||
Path userDir = Paths.get(System.getProperty("user.dir"));
|
||||
PathResource pathResource = new PathResource(userDir);
|
||||
|
||||
Server server = createServer(port, pathResource);
|
||||
|
||||
// Start things up! By using the server.join() the server thread will join with the current thread.
|
||||
// See "http://docs.oracle.com/javase/1.5.0/docs/api/java/lang/Thread.html#join()" for more details.
|
||||
server.start();
|
||||
|
|
|
@ -18,6 +18,9 @@
|
|||
|
||||
package org.eclipse.jetty.embedded;
|
||||
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
|
||||
import org.eclipse.jetty.server.Server;
|
||||
import org.eclipse.jetty.util.resource.Resource;
|
||||
import org.eclipse.jetty.xml.XmlConfiguration;
|
||||
|
@ -28,17 +31,25 @@ import org.eclipse.jetty.xml.XmlConfiguration;
|
|||
* This server is identical to {@link FileServer}, except that it is configured
|
||||
* via an {@link XmlConfiguration} config file that does the identical work.
|
||||
* </p>
|
||||
* <p>
|
||||
* See <a href="https://raw.githubusercontent.com/eclipse/jetty.project/master/examples/embedded/src/main/resources/fileserver.xml">fileserver.xml</a>
|
||||
* </p>
|
||||
*/
|
||||
public class FileServerXml
|
||||
{
|
||||
public static void main(String[] args) throws Exception
|
||||
public static Server createServer(int port, Path baseResource) throws Exception
|
||||
{
|
||||
// Find Jetty XML (in classpath) that configures and starts Server.
|
||||
// See src/main/resources/fileserver.xml
|
||||
Resource fileServerXml = Resource.newSystemResource("fileserver.xml");
|
||||
XmlConfiguration configuration = new XmlConfiguration(fileServerXml);
|
||||
Server server = (Server)configuration.configure();
|
||||
configuration.getProperties().put("http.port", Integer.toString(port));
|
||||
configuration.getProperties().put("fileserver.baseresource", baseResource.toAbsolutePath().toString());
|
||||
return (Server)configuration.configure();
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception
|
||||
{
|
||||
int port = ExampleUtil.getPort(args, "jetty.http.port", 8080);
|
||||
Path userDir = Paths.get(System.getProperty("user.dir"));
|
||||
Server server = createServer(port, userDir);
|
||||
server.start();
|
||||
server.join();
|
||||
}
|
||||
|
|
|
@ -51,7 +51,8 @@ public class HelloWorld extends AbstractHandler
|
|||
|
||||
public static void main(String[] args) throws Exception
|
||||
{
|
||||
Server server = new Server(8080);
|
||||
int port = ExampleUtil.getPort(args, "jetty.http.port", 8080);
|
||||
Server server = new Server(port);
|
||||
server.setHandler(new HelloWorld());
|
||||
|
||||
server.start();
|
||||
|
|
|
@ -18,9 +18,12 @@
|
|||
|
||||
package org.eclipse.jetty.embedded;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.lang.management.ManagementFactory;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.EnumSet;
|
||||
|
@ -56,12 +59,15 @@ import org.eclipse.jetty.servlet.DefaultServlet;
|
|||
import org.eclipse.jetty.servlet.ServletContextHandler;
|
||||
import org.eclipse.jetty.servlet.ServletHolder;
|
||||
import org.eclipse.jetty.servlets.PushCacheFilter;
|
||||
import org.eclipse.jetty.util.resource.PathResource;
|
||||
import org.eclipse.jetty.util.ssl.SslContextFactory;
|
||||
|
||||
public class Http2Server
|
||||
{
|
||||
public static void main(String... args) throws Exception
|
||||
{
|
||||
int port = ExampleUtil.getPort(args, "jetty.http.port", 8080);
|
||||
int securePort = ExampleUtil.getPort(args, "jetty.https.port", 8443);
|
||||
Server server = new Server();
|
||||
|
||||
MBeanContainer mbContainer = new MBeanContainer(
|
||||
|
@ -69,10 +75,11 @@ public class Http2Server
|
|||
server.addBean(mbContainer);
|
||||
|
||||
ServletContextHandler context = new ServletContextHandler(server, "/", ServletContextHandler.SESSIONS);
|
||||
String docroot = "src/main/resources/docroot";
|
||||
if (!new File(docroot).exists())
|
||||
docroot = "examples/embedded/src/main/resources/docroot";
|
||||
context.setResourceBase(docroot);
|
||||
Path docroot = Paths.get("src/main/resources/docroot");
|
||||
if (!Files.exists(docroot))
|
||||
throw new FileNotFoundException(docroot.toString());
|
||||
|
||||
context.setBaseResource(new PathResource(docroot));
|
||||
context.addFilter(PushCacheFilter.class, "/*", EnumSet.of(DispatcherType.REQUEST));
|
||||
// context.addFilter(PushSessionCacheFilter.class,"/*",EnumSet.of(DispatcherType.REQUEST));
|
||||
context.addFilter(PushedTilesFilter.class, "/*", EnumSet.of(DispatcherType.REQUEST));
|
||||
|
@ -83,21 +90,21 @@ public class Http2Server
|
|||
// HTTP Configuration
|
||||
HttpConfiguration httpConfig = new HttpConfiguration();
|
||||
httpConfig.setSecureScheme("https");
|
||||
httpConfig.setSecurePort(8443);
|
||||
httpConfig.setSecurePort(securePort);
|
||||
httpConfig.setSendXPoweredBy(true);
|
||||
httpConfig.setSendServerVersion(true);
|
||||
|
||||
// HTTP Connector
|
||||
ServerConnector http = new ServerConnector(server, new HttpConnectionFactory(httpConfig), new HTTP2CServerConnectionFactory(httpConfig));
|
||||
http.setPort(8080);
|
||||
http.setPort(port);
|
||||
server.addConnector(http);
|
||||
|
||||
// SSL Context Factory for HTTPS and HTTP/2
|
||||
String jettyDistro = System.getProperty("jetty.distro", "../../jetty-distribution/target/distribution");
|
||||
if (!new File(jettyDistro).exists())
|
||||
jettyDistro = "jetty-distribution/target/distribution";
|
||||
Path keystorePath = Paths.get("src/main/resources/etc/keystore").toAbsolutePath();
|
||||
if (!Files.exists(keystorePath))
|
||||
throw new FileNotFoundException(keystorePath.toString());
|
||||
SslContextFactory.Server sslContextFactory = new SslContextFactory.Server();
|
||||
sslContextFactory.setKeyStorePath(jettyDistro + "/demo-base/etc/keystore");
|
||||
sslContextFactory.setKeyStorePath(keystorePath.toString());
|
||||
sslContextFactory.setKeyStorePassword("OBF:1vny1zlo1x8e1vnw1vn61x8g1zlu1vn4");
|
||||
sslContextFactory.setKeyManagerPassword("OBF:1u2u1wml1z7s1z7a1wnl1u2g");
|
||||
sslContextFactory.setCipherComparator(HTTP2Cipher.COMPARATOR);
|
||||
|
@ -119,7 +126,7 @@ public class Http2Server
|
|||
// HTTP/2 Connector
|
||||
ServerConnector http2Connector =
|
||||
new ServerConnector(server, ssl, alpn, h2, new HttpConnectionFactory(httpsConfig));
|
||||
http2Connector.setPort(8443);
|
||||
http2Connector.setPort(securePort);
|
||||
server.addConnector(http2Connector);
|
||||
|
||||
server.start();
|
||||
|
|
|
@ -18,7 +18,11 @@
|
|||
|
||||
package org.eclipse.jetty.embedded;
|
||||
|
||||
import org.eclipse.jetty.server.Handler;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
|
||||
import org.eclipse.jetty.server.Server;
|
||||
import org.eclipse.jetty.server.handler.DefaultHandler;
|
||||
import org.eclipse.jetty.server.handler.HandlerList;
|
||||
|
@ -28,24 +32,36 @@ import org.eclipse.jetty.servlet.ServletHolder;
|
|||
import org.eclipse.jetty.util.resource.Resource;
|
||||
|
||||
/**
|
||||
*
|
||||
* Example of serving content from a JAR file.
|
||||
* The JAR file in this example does not belong to any Classpath.
|
||||
*/
|
||||
public class JarServer
|
||||
{
|
||||
public static void main(String[] args) throws Exception
|
||||
public static Server createServer(int port) throws Exception
|
||||
{
|
||||
final Server server = new Server(8080);
|
||||
Server server = new Server(port);
|
||||
|
||||
Path jarFile = Paths.get("src/main/other/content.jar");
|
||||
if (!Files.exists(jarFile))
|
||||
throw new FileNotFoundException(jarFile.toString());
|
||||
|
||||
ServletContextHandler context = new ServletContextHandler();
|
||||
Resource.setDefaultUseCaches(true);
|
||||
Resource base = Resource.newResource("jar:file:src/main/resources/content.jar!/");
|
||||
Resource base = Resource.newResource("jar:" + jarFile.toAbsolutePath().toUri().toASCIIString() + "!/");
|
||||
context.setBaseResource(base);
|
||||
context.addServlet(new ServletHolder(new DefaultServlet()), "/");
|
||||
|
||||
HandlerList handlers = new HandlerList();
|
||||
handlers.setHandlers(new Handler[]{context, new DefaultHandler()});
|
||||
handlers.addHandler(context);
|
||||
handlers.addHandler(new DefaultHandler());
|
||||
server.setHandler(handlers);
|
||||
return server;
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception
|
||||
{
|
||||
int port = ExampleUtil.getPort(args, "jetty.http.port", 8080);
|
||||
Server server = createServer(port);
|
||||
server.start();
|
||||
server.join();
|
||||
}
|
||||
|
|
|
@ -18,8 +18,9 @@
|
|||
|
||||
package org.eclipse.jetty.embedded;
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
|
||||
import org.eclipse.jetty.util.StringUtil;
|
||||
import org.eclipse.jetty.util.log.Log;
|
||||
|
@ -41,54 +42,80 @@ public class JettyDistribution
|
|||
static
|
||||
{
|
||||
Path distro = asJettyDistribution(System.getProperty("jetty.home"));
|
||||
LOG.debug("JettyDistribution(prop(jetty.home)) = " + distro);
|
||||
if (distro == null)
|
||||
{
|
||||
distro = asJettyDistribution(System.getenv().get("JETTY_HOME"));
|
||||
LOG.debug("JettyDistribution(env(JETTY_HOME)) = " + distro);
|
||||
}
|
||||
|
||||
if (distro == null)
|
||||
{
|
||||
try
|
||||
{
|
||||
Path working = new File(".").getAbsoluteFile().getCanonicalFile().toPath();
|
||||
Path working = Paths.get(System.getProperty("user.dir"));
|
||||
LOG.debug("JettyDistribution(prop(user.dir)) = " + working);
|
||||
while (distro == null && working != null)
|
||||
{
|
||||
distro = asJettyDistribution(working.resolve("jetty-distribution/target/distribution").toString());
|
||||
working = working.getParent();
|
||||
}
|
||||
LOG.debug("JettyDistribution(working.resolve(...)) = " + distro);
|
||||
}
|
||||
catch (Throwable th)
|
||||
{
|
||||
LOG.warn(th);
|
||||
}
|
||||
}
|
||||
|
||||
if (distro == null)
|
||||
{
|
||||
LOG.info("JettyDistribution() FAILURE: NOT FOUND");
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG.debug("JettyDistribution() FOUND = " + distro);
|
||||
}
|
||||
DISTRIBUTION = distro;
|
||||
}
|
||||
|
||||
private static Path asJettyDistribution(String test)
|
||||
private static Path asJettyDistribution(String jettyHome)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (StringUtil.isBlank(test))
|
||||
if (jettyHome == null)
|
||||
{
|
||||
LOG.info("asJettyDistribution {} is blank", test);
|
||||
return null;
|
||||
}
|
||||
|
||||
File dir = new File(test);
|
||||
if (!dir.exists() || !dir.isDirectory())
|
||||
if (StringUtil.isBlank(jettyHome))
|
||||
{
|
||||
LOG.info("asJettyDistribution {} is not a directory", test);
|
||||
LOG.debug("asJettyDistribution {} is blank", jettyHome);
|
||||
return null;
|
||||
}
|
||||
|
||||
File demoBase = new File(dir, "demo-base");
|
||||
if (!demoBase.exists() || !demoBase.isDirectory())
|
||||
Path dir = Paths.get(jettyHome);
|
||||
if (!Files.exists(dir))
|
||||
{
|
||||
LOG.info("asJettyDistribution {} has no demo-base", test);
|
||||
LOG.debug("asJettyDistribution {} does not exist", jettyHome);
|
||||
return null;
|
||||
}
|
||||
|
||||
LOG.info("asJettyDistribution {}", dir);
|
||||
return dir.getAbsoluteFile().getCanonicalFile().toPath();
|
||||
if (!Files.isDirectory(dir))
|
||||
{
|
||||
LOG.debug("asJettyDistribution {} is not a directory", jettyHome);
|
||||
return null;
|
||||
}
|
||||
|
||||
Path demoBase = dir.resolve("demo-base");
|
||||
if (!Files.exists(demoBase) || !Files.isDirectory(demoBase))
|
||||
{
|
||||
LOG.debug("asJettyDistribution {} has no demo-base", jettyHome);
|
||||
return null;
|
||||
}
|
||||
|
||||
LOG.debug("asJettyDistribution {}", dir);
|
||||
return dir.toAbsolutePath();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
@ -97,9 +124,16 @@ public class JettyDistribution
|
|||
return null;
|
||||
}
|
||||
|
||||
public static Path get()
|
||||
{
|
||||
if (DISTRIBUTION == null)
|
||||
throw new RuntimeException("jetty-distribution not found");
|
||||
return DISTRIBUTION;
|
||||
}
|
||||
|
||||
public static Path resolve(String path)
|
||||
{
|
||||
return DISTRIBUTION.resolve(path);
|
||||
return get().resolve(path);
|
||||
}
|
||||
|
||||
public static void main(String... arg)
|
||||
|
|
|
@ -18,12 +18,16 @@
|
|||
|
||||
package org.eclipse.jetty.embedded;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.lang.management.ManagementFactory;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
|
||||
import org.eclipse.jetty.annotations.AnnotationConfiguration;
|
||||
import org.eclipse.jetty.deploy.DeploymentManager;
|
||||
import org.eclipse.jetty.deploy.PropertiesConfigurationManager;
|
||||
import org.eclipse.jetty.deploy.bindings.DebugListenerBinding;
|
||||
import org.eclipse.jetty.deploy.providers.WebAppProvider;
|
||||
import org.eclipse.jetty.http.HttpVersion;
|
||||
import org.eclipse.jetty.jmx.MBeanContainer;
|
||||
|
@ -35,6 +39,7 @@ import org.eclipse.jetty.rewrite.handler.ValidUrlRule;
|
|||
import org.eclipse.jetty.security.HashLoginService;
|
||||
import org.eclipse.jetty.server.AsyncRequestLogWriter;
|
||||
import org.eclipse.jetty.server.CustomRequestLog;
|
||||
import org.eclipse.jetty.server.DebugListener;
|
||||
import org.eclipse.jetty.server.Handler;
|
||||
import org.eclipse.jetty.server.HttpConfiguration;
|
||||
import org.eclipse.jetty.server.HttpConnectionFactory;
|
||||
|
@ -59,21 +64,21 @@ import org.eclipse.jetty.webapp.Configurations;
|
|||
*/
|
||||
public class LikeJettyXml
|
||||
{
|
||||
public static void main(String[] args) throws Exception
|
||||
public static Server createServer(int port, int securePort, boolean addDebugListener) throws Exception
|
||||
{
|
||||
// Path to as-built jetty-distribution directory
|
||||
String jettyHomeBuild = JettyDistribution.DISTRIBUTION.toString();
|
||||
Path jettyHomeBuild = JettyDistribution.get();
|
||||
|
||||
// Find jetty home and base directories
|
||||
String homePath = System.getProperty("jetty.home", jettyHomeBuild);
|
||||
File homeDir = new File(homePath);
|
||||
String homePath = System.getProperty("jetty.home", jettyHomeBuild.toString());
|
||||
Path homeDir = Paths.get(homePath);
|
||||
|
||||
String basePath = System.getProperty("jetty.base", homeDir + "/demo-base");
|
||||
File baseDir = new File(basePath);
|
||||
String basePath = System.getProperty("jetty.base", homeDir.resolve("demo-base").toString());
|
||||
Path baseDir = Paths.get(basePath);
|
||||
|
||||
// Configure jetty.home and jetty.base system properties
|
||||
String jettyHome = homeDir.getAbsolutePath();
|
||||
String jettyBase = baseDir.getAbsolutePath();
|
||||
String jettyHome = homeDir.toAbsolutePath().toString();
|
||||
String jettyBase = baseDir.toAbsolutePath().toString();
|
||||
System.setProperty("jetty.home", jettyHome);
|
||||
System.setProperty("jetty.base", jettyBase);
|
||||
|
||||
|
@ -91,7 +96,7 @@ public class LikeJettyXml
|
|||
// HTTP Configuration
|
||||
HttpConfiguration httpConfig = new HttpConfiguration();
|
||||
httpConfig.setSecureScheme("https");
|
||||
httpConfig.setSecurePort(8443);
|
||||
httpConfig.setSecurePort(securePort);
|
||||
httpConfig.setOutputBufferSize(32768);
|
||||
httpConfig.setRequestHeaderSize(8192);
|
||||
httpConfig.setResponseHeaderSize(8192);
|
||||
|
@ -105,11 +110,6 @@ public class LikeJettyXml
|
|||
handlers.setHandlers(new Handler[]{contexts, new DefaultHandler()});
|
||||
server.setHandler(handlers);
|
||||
|
||||
// Extra options
|
||||
server.setDumpAfterStart(true);
|
||||
server.setDumpBeforeStop(false);
|
||||
server.setStopAtShutdown(true);
|
||||
|
||||
// === jetty-jmx.xml ===
|
||||
MBeanContainer mbContainer = new MBeanContainer(
|
||||
ManagementFactory.getPlatformMBeanServer());
|
||||
|
@ -118,24 +118,21 @@ public class LikeJettyXml
|
|||
// === jetty-http.xml ===
|
||||
ServerConnector http = new ServerConnector(server,
|
||||
new HttpConnectionFactory(httpConfig));
|
||||
http.setPort(8080);
|
||||
http.setPort(port);
|
||||
http.setIdleTimeout(30000);
|
||||
server.addConnector(http);
|
||||
|
||||
// === jetty-https.xml ===
|
||||
// SSL Context Factory
|
||||
Path keystorePath = Paths.get("src/main/resources/etc/keystore").toAbsolutePath();
|
||||
if (!Files.exists(keystorePath))
|
||||
throw new FileNotFoundException(keystorePath.toString());
|
||||
SslContextFactory.Server sslContextFactory = new SslContextFactory.Server();
|
||||
sslContextFactory.setKeyStorePath(jettyHome + "/../../../jetty-server/src/test/config/etc/keystore");
|
||||
sslContextFactory.setKeyStorePath(keystorePath.toString());
|
||||
sslContextFactory.setKeyStorePassword("OBF:1vny1zlo1x8e1vnw1vn61x8g1zlu1vn4");
|
||||
sslContextFactory.setKeyManagerPassword("OBF:1u2u1wml1z7s1z7a1wnl1u2g");
|
||||
sslContextFactory.setTrustStorePath(jettyHome + "/../../../jetty-server/src/test/config/etc/keystore");
|
||||
sslContextFactory.setTrustStorePath(keystorePath.toString());
|
||||
sslContextFactory.setTrustStorePassword("OBF:1vny1zlo1x8e1vnw1vn61x8g1zlu1vn4");
|
||||
sslContextFactory.setExcludeCipherSuites("SSL_RSA_WITH_DES_CBC_SHA",
|
||||
"SSL_DHE_RSA_WITH_DES_CBC_SHA", "SSL_DHE_DSS_WITH_DES_CBC_SHA",
|
||||
"SSL_RSA_EXPORT_WITH_RC4_40_MD5",
|
||||
"SSL_RSA_EXPORT_WITH_DES40_CBC_SHA",
|
||||
"SSL_DHE_RSA_EXPORT_WITH_DES40_CBC_SHA",
|
||||
"SSL_DHE_DSS_EXPORT_WITH_DES40_CBC_SHA");
|
||||
|
||||
// SSL HTTP Configuration
|
||||
HttpConfiguration httpsConfig = new HttpConfiguration(httpConfig);
|
||||
|
@ -145,14 +142,17 @@ public class LikeJettyXml
|
|||
ServerConnector sslConnector = new ServerConnector(server,
|
||||
new SslConnectionFactory(sslContextFactory, HttpVersion.HTTP_1_1.asString()),
|
||||
new HttpConnectionFactory(httpsConfig));
|
||||
sslConnector.setPort(8443);
|
||||
sslConnector.setPort(securePort);
|
||||
server.addConnector(sslConnector);
|
||||
|
||||
// === jetty-deploy.xml ===
|
||||
DeploymentManager deployer = new DeploymentManager();
|
||||
//DebugListener debug = new DebugListener(System.out,true,true,true);
|
||||
// server.addBean(debug);
|
||||
// deployer.addLifeCycleBinding(new DebugListenerBinding(debug));
|
||||
if (addDebugListener)
|
||||
{
|
||||
DebugListener debug = new DebugListener(System.err, true, true, true);
|
||||
server.addBean(debug);
|
||||
deployer.addLifeCycleBinding(new DebugListenerBinding(debug));
|
||||
}
|
||||
deployer.setContexts(contexts);
|
||||
deployer.setContextAttribute(
|
||||
"org.eclipse.jetty.server.webapp.ContainerIncludeJarPattern",
|
||||
|
@ -208,6 +208,20 @@ public class LikeJettyXml
|
|||
login.setHotReload(false);
|
||||
server.addBean(login);
|
||||
|
||||
return server;
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception
|
||||
{
|
||||
int port = ExampleUtil.getPort(args, "jetty.http.port", 8080);
|
||||
int securePort = ExampleUtil.getPort(args, "jetty.https.port", 8443);
|
||||
Server server = createServer(port, securePort, true);
|
||||
|
||||
// Extra options
|
||||
server.setDumpAfterStart(true);
|
||||
server.setDumpBeforeStop(false);
|
||||
server.setStopAtShutdown(true);
|
||||
|
||||
// Start the server
|
||||
server.start();
|
||||
server.join();
|
||||
|
|
|
@ -18,8 +18,10 @@
|
|||
|
||||
package org.eclipse.jetty.embedded;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
|
||||
import org.eclipse.jetty.http.HttpVersion;
|
||||
import org.eclipse.jetty.server.Connector;
|
||||
|
@ -36,23 +38,13 @@ import org.eclipse.jetty.util.ssl.SslContextFactory;
|
|||
*/
|
||||
public class ManyConnectors
|
||||
{
|
||||
public static void main(String[] args) throws Exception
|
||||
public static Server createServer(int plainPort, int securePort) throws Exception
|
||||
{
|
||||
// Since this example shows off SSL configuration, we need a keystore
|
||||
// with the appropriate key. These lookup of jetty.home is purely a hack
|
||||
// to get access to a keystore that we use in many unit tests and should
|
||||
// probably be a direct path to your own keystore.
|
||||
|
||||
String jettyDistKeystore = "../../jetty-distribution/target/distribution/demo-base/etc/test-keystore";
|
||||
String keystorePath = System.getProperty("example.keystore", jettyDistKeystore);
|
||||
File keystoreFile = new File(keystorePath);
|
||||
if (!keystoreFile.exists())
|
||||
{
|
||||
keystorePath = "jetty-distribution/target/distribution/demo-base/etc/keystore";
|
||||
keystoreFile = new File(keystorePath);
|
||||
if (!keystoreFile.exists())
|
||||
throw new FileNotFoundException(keystoreFile.getAbsolutePath());
|
||||
}
|
||||
// with the appropriate key.
|
||||
Path keystorePath = Paths.get("src/main/resources/etc/keystore").toAbsolutePath();
|
||||
if (!Files.exists(keystorePath))
|
||||
throw new FileNotFoundException(keystorePath.toString());
|
||||
|
||||
// Create a basic jetty server object without declaring the port. Since
|
||||
// we are configuring connectors directly we'll be setting ports on
|
||||
|
@ -67,7 +59,7 @@ public class ManyConnectors
|
|||
// done. The port for secured communication is also set here.
|
||||
HttpConfiguration httpConfig = new HttpConfiguration();
|
||||
httpConfig.setSecureScheme("https");
|
||||
httpConfig.setSecurePort(8443);
|
||||
httpConfig.setSecurePort(securePort);
|
||||
httpConfig.setOutputBufferSize(32768);
|
||||
|
||||
// HTTP connector
|
||||
|
@ -77,7 +69,7 @@ public class ManyConnectors
|
|||
// configure an idle timeout.
|
||||
ServerConnector http = new ServerConnector(server,
|
||||
new HttpConnectionFactory(httpConfig));
|
||||
http.setPort(8080);
|
||||
http.setPort(plainPort);
|
||||
http.setIdleTimeout(30000);
|
||||
|
||||
// SSL Context Factory for HTTPS
|
||||
|
@ -88,7 +80,7 @@ public class ManyConnectors
|
|||
// keystore to be used.
|
||||
|
||||
SslContextFactory.Server sslContextFactory = new SslContextFactory.Server();
|
||||
sslContextFactory.setKeyStorePath(keystoreFile.getAbsolutePath());
|
||||
sslContextFactory.setKeyStorePath(keystorePath.toString());
|
||||
sslContextFactory.setKeyStorePassword("OBF:1vny1zlo1x8e1vnw1vn61x8g1zlu1vn4");
|
||||
sslContextFactory.setKeyManagerPassword("OBF:1u2u1wml1z7s1z7a1wnl1u2g");
|
||||
|
||||
|
@ -118,7 +110,7 @@ public class ManyConnectors
|
|||
ServerConnector https = new ServerConnector(server,
|
||||
new SslConnectionFactory(sslContextFactory, HttpVersion.HTTP_1_1.asString()),
|
||||
new HttpConnectionFactory(httpsConfig));
|
||||
https.setPort(8443);
|
||||
https.setPort(securePort);
|
||||
https.setIdleTimeout(500000);
|
||||
|
||||
// Here you see the server having multiple connectors registered with
|
||||
|
@ -132,7 +124,14 @@ public class ManyConnectors
|
|||
|
||||
// Set a handler
|
||||
server.setHandler(new HelloHandler());
|
||||
return server;
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception
|
||||
{
|
||||
int port = ExampleUtil.getPort(args, "jetty.http.port", 8080);
|
||||
int securePort = ExampleUtil.getPort(args, "jetty.https.port", 8443);
|
||||
Server server = createServer(port, securePort);
|
||||
// Start the server
|
||||
server.start();
|
||||
server.dumpStdErr();
|
||||
|
|
|
@ -18,39 +18,42 @@
|
|||
|
||||
package org.eclipse.jetty.embedded;
|
||||
|
||||
import org.eclipse.jetty.server.Handler;
|
||||
import org.eclipse.jetty.server.Server;
|
||||
import org.eclipse.jetty.server.handler.ContextHandler;
|
||||
import org.eclipse.jetty.server.handler.ContextHandlerCollection;
|
||||
|
||||
public class ManyContexts
|
||||
{
|
||||
public static void main(String[] args) throws Exception
|
||||
public static Server createServer(int port)
|
||||
{
|
||||
final Server server = new Server(8080);
|
||||
Server server = new Server(port);
|
||||
|
||||
ContextHandler context = new ContextHandler("/");
|
||||
context.setContextPath("/");
|
||||
context.setHandler(new HelloHandler("Root Hello"));
|
||||
|
||||
ContextHandler contextFR = new ContextHandler("/fr");
|
||||
contextFR.setHandler(new HelloHandler("Bonjoir"));
|
||||
contextFR.setHandler(new HelloHandler("Bonjour"));
|
||||
|
||||
ContextHandler contextIT = new ContextHandler("/it");
|
||||
contextIT.setHandler(new HelloHandler("Bongiorno"));
|
||||
contextIT.setHandler(new HelloHandler("Buongiorno"));
|
||||
|
||||
ContextHandler contextV = new ContextHandler("/");
|
||||
contextV.setVirtualHosts(new String[]{"127.0.0.2"});
|
||||
contextV.setHandler(new HelloHandler("Virtual Hello"));
|
||||
|
||||
ContextHandlerCollection contexts = new ContextHandlerCollection();
|
||||
contexts.setHandlers(new Handler[]{
|
||||
context, contextFR, contextIT,
|
||||
contextV
|
||||
});
|
||||
ContextHandlerCollection contexts = new ContextHandlerCollection(
|
||||
context, contextFR, contextIT, contextV
|
||||
);
|
||||
|
||||
server.setHandler(contexts);
|
||||
return server;
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception
|
||||
{
|
||||
int port = ExampleUtil.getPort(args, "jetty.http.port", 8080);
|
||||
Server server = createServer(port);
|
||||
server.start();
|
||||
server.dumpStdErr();
|
||||
server.join();
|
||||
|
|
|
@ -30,6 +30,8 @@ import org.eclipse.jetty.server.Handler;
|
|||
import org.eclipse.jetty.server.Request;
|
||||
import org.eclipse.jetty.server.Server;
|
||||
import org.eclipse.jetty.server.handler.AbstractHandler;
|
||||
import org.eclipse.jetty.server.handler.ContextHandler;
|
||||
import org.eclipse.jetty.server.handler.ContextHandlerCollection;
|
||||
import org.eclipse.jetty.server.handler.DefaultHandler;
|
||||
import org.eclipse.jetty.server.handler.HandlerCollection;
|
||||
import org.eclipse.jetty.server.handler.HandlerList;
|
||||
|
@ -99,20 +101,23 @@ public class ManyHandlers
|
|||
HttpServletResponse response) throws IOException,
|
||||
ServletException
|
||||
{
|
||||
request.setAttribute("welcome", "Hello");
|
||||
response.setHeader("X-Welcome", "Greetings from WelcomeWrapHandler");
|
||||
super.handle(target, baseRequest, request, response);
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception
|
||||
public static Server createServer(int port) throws IOException
|
||||
{
|
||||
final Server server = new Server(8080);
|
||||
Server server = new Server(port);
|
||||
|
||||
// create the handlers
|
||||
final Handler param = new ParamHandler();
|
||||
final HandlerWrapper wrapper = new WelcomeWrapHandler();
|
||||
final Handler hello = new HelloHandler();
|
||||
final Handler dft = new DefaultHandler();
|
||||
Handler param = new ParamHandler();
|
||||
HandlerWrapper wrapper = new WelcomeWrapHandler();
|
||||
Handler hello = new HelloHandler();
|
||||
GzipHandler gzipHandler = new GzipHandler();
|
||||
gzipHandler.setMinGzipSize(10);
|
||||
gzipHandler.addIncludedMimeTypes("text/plain");
|
||||
gzipHandler.addIncludedMimeTypes("text/html");
|
||||
|
||||
// configure request logging
|
||||
File requestLogFile = File.createTempFile("demo", "log");
|
||||
|
@ -120,16 +125,47 @@ public class ManyHandlers
|
|||
server.setRequestLog(ncsaLog);
|
||||
|
||||
// create the handler collections
|
||||
HandlerCollection handlers = new HandlerCollection();
|
||||
HandlerList list = new HandlerList();
|
||||
HandlerList handlers = new HandlerList();
|
||||
|
||||
// link them all together
|
||||
// wrap contexts around specific handlers
|
||||
wrapper.setHandler(hello);
|
||||
list.setHandlers(new Handler[]{param, new GzipHandler()});
|
||||
handlers.setHandlers(new Handler[]{list, dft});
|
||||
ContextHandler helloContext = new ContextHandler("/hello");
|
||||
helloContext.setHandler(wrapper);
|
||||
|
||||
ContextHandler paramContext = new ContextHandler("/params");
|
||||
paramContext.setHandler(param);
|
||||
|
||||
ContextHandlerCollection contexts = new ContextHandlerCollection(helloContext, paramContext);
|
||||
|
||||
// Wrap Contexts with GZIP
|
||||
gzipHandler.setHandler(contexts);
|
||||
|
||||
// Set the top level Handler List
|
||||
handlers.addHandler(gzipHandler);
|
||||
handlers.addHandler(new DefaultHandler());
|
||||
server.setHandler(handlers);
|
||||
|
||||
/* At this point you have the following handler hierarchy.
|
||||
*
|
||||
* Server.handler:
|
||||
* HandlerList
|
||||
* \- GzipHandler
|
||||
* | \- ContextHandlerCollection
|
||||
* | \- ContextHandler ("/hello")
|
||||
* | | \- WelcomeWrapHandler
|
||||
* | | \- HelloHandler
|
||||
* | \- ContextHandler ("/params")
|
||||
* | \- ParamHandler
|
||||
* \- DefaultHandler
|
||||
*/
|
||||
|
||||
return server;
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception
|
||||
{
|
||||
int port = ExampleUtil.getPort(args, "jetty.http.port", 8080);
|
||||
Server server = createServer(port);
|
||||
server.start();
|
||||
server.join();
|
||||
}
|
||||
|
|
|
@ -29,9 +29,9 @@ import org.eclipse.jetty.servlet.ServletHolder;
|
|||
|
||||
public class ManyServletContexts
|
||||
{
|
||||
public static void main(String[] args) throws Exception
|
||||
public static Server createServer(int port)
|
||||
{
|
||||
Server server = new Server(8080);
|
||||
Server server = new Server(port);
|
||||
|
||||
// Setup JMX
|
||||
MBeanContainer mbContainer = new MBeanContainer(
|
||||
|
@ -48,7 +48,7 @@ public class ManyServletContexts
|
|||
// Add servlets to root context
|
||||
root.addServlet(new ServletHolder(new HelloServlet("Hello")), "/");
|
||||
root.addServlet(new ServletHolder(new HelloServlet("Ciao")), "/it/*");
|
||||
root.addServlet(new ServletHolder(new HelloServlet("Bonjoir")), "/fr/*");
|
||||
root.addServlet(new ServletHolder(new HelloServlet("Bonjour")), "/fr/*");
|
||||
|
||||
// Configure context "/other" for servlets
|
||||
ServletContextHandler other = new ServletContextHandler(contexts,
|
||||
|
@ -57,6 +57,13 @@ public class ManyServletContexts
|
|||
other.addServlet(DefaultServlet.class.getCanonicalName(), "/");
|
||||
other.addServlet(new ServletHolder(new HelloServlet("YO!")), "*.yo");
|
||||
|
||||
return server;
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception
|
||||
{
|
||||
int port = ExampleUtil.getPort(args, "jetty.http.port", 8080);
|
||||
Server server = createServer(port);
|
||||
server.start();
|
||||
server.dumpStdErr();
|
||||
server.join();
|
||||
|
|
|
@ -19,7 +19,6 @@
|
|||
package org.eclipse.jetty.embedded;
|
||||
|
||||
import java.io.IOException;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServlet;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
@ -29,13 +28,13 @@ import org.eclipse.jetty.servlet.ServletHandler;
|
|||
|
||||
public class MinimalServlets
|
||||
{
|
||||
public static void main(String[] args) throws Exception
|
||||
|
||||
public static Server createServer(int port)
|
||||
{
|
||||
// Create a basic jetty server object that will listen on port 8080.
|
||||
// Note that if you set this to port 0 then a randomly available port
|
||||
// will be assigned that you can either look in the logs for the port,
|
||||
// or programmatically obtain it for use in test cases.
|
||||
Server server = new Server(8080);
|
||||
Server server = new Server(port);
|
||||
|
||||
// The ServletHandler is a dead simple way to create a context handler
|
||||
// that is backed by an instance of a Servlet.
|
||||
|
@ -51,13 +50,20 @@ public class MinimalServlets
|
|||
// through a web.xml @WebServlet annotation, or anything similar.
|
||||
handler.addServletWithMapping(HelloServlet.class, "/*");
|
||||
|
||||
return server;
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception
|
||||
{
|
||||
// Create a basic jetty server object that will listen on port 8080.
|
||||
int port = ExampleUtil.getPort(args, "jetty.http.port", 8080);
|
||||
Server server = createServer(port);
|
||||
|
||||
// Start things up!
|
||||
server.start();
|
||||
|
||||
// The use of server.join() the will make the current thread join and
|
||||
// wait until the server is done executing.
|
||||
// See
|
||||
// http://docs.oracle.com/javase/7/docs/api/java/lang/Thread.html#join()
|
||||
// wait until the server thread is done executing.
|
||||
server.join();
|
||||
}
|
||||
|
||||
|
@ -66,11 +72,11 @@ public class MinimalServlets
|
|||
{
|
||||
@Override
|
||||
protected void doGet(HttpServletRequest request,
|
||||
HttpServletResponse response) throws ServletException,
|
||||
IOException
|
||||
HttpServletResponse response) throws IOException
|
||||
{
|
||||
response.setContentType("text/html");
|
||||
response.setStatus(HttpServletResponse.SC_OK);
|
||||
response.setContentType("text/html");
|
||||
response.setCharacterEncoding("utf-8");
|
||||
response.getWriter().println("<h1>Hello from HelloServlet</h1>");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,7 +26,7 @@ import org.eclipse.jetty.server.ServerConnector;
|
|||
*/
|
||||
public class OneConnector
|
||||
{
|
||||
public static void main(String[] args) throws Exception
|
||||
public static Server createServer(int port) throws Exception
|
||||
{
|
||||
// The Server
|
||||
Server server = new Server();
|
||||
|
@ -34,7 +34,7 @@ public class OneConnector
|
|||
// HTTP connector
|
||||
ServerConnector http = new ServerConnector(server);
|
||||
http.setHost("localhost");
|
||||
http.setPort(8080);
|
||||
http.setPort(port);
|
||||
http.setIdleTimeout(30000);
|
||||
|
||||
// Set the connector
|
||||
|
@ -42,6 +42,13 @@ public class OneConnector
|
|||
|
||||
// Set a handler
|
||||
server.setHandler(new HelloHandler());
|
||||
return server;
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception
|
||||
{
|
||||
int port = ExampleUtil.getPort(args, "jetty.http.port", 8080);
|
||||
Server server = createServer(port);
|
||||
|
||||
// Start the server
|
||||
server.start();
|
||||
|
|
|
@ -23,9 +23,9 @@ import org.eclipse.jetty.server.handler.ContextHandler;
|
|||
|
||||
public class OneContext
|
||||
{
|
||||
public static void main(String[] args) throws Exception
|
||||
public static Server createServer(int port)
|
||||
{
|
||||
Server server = new Server(8080);
|
||||
Server server = new Server(port);
|
||||
|
||||
// Add a single handler on context "/hello"
|
||||
ContextHandler context = new ContextHandler();
|
||||
|
@ -35,6 +35,13 @@ public class OneContext
|
|||
// Can be accessed using http://localhost:8080/hello
|
||||
|
||||
server.setHandler(context);
|
||||
return server;
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception
|
||||
{
|
||||
int port = ExampleUtil.getPort(args, "jetty.http.port", 8080);
|
||||
Server server = createServer(port);
|
||||
|
||||
// Start the server
|
||||
server.start();
|
||||
|
|
|
@ -22,11 +22,17 @@ import org.eclipse.jetty.server.Server;
|
|||
|
||||
public class OneHandler
|
||||
{
|
||||
public static Server createServer(int port)
|
||||
{
|
||||
Server server = new Server(port);
|
||||
server.setHandler(new HelloHandler());
|
||||
return server;
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception
|
||||
{
|
||||
Server server = new Server(8080);
|
||||
server.setHandler(new HelloHandler());
|
||||
|
||||
int port = ExampleUtil.getPort(args, "jetty.http.port", 8080);
|
||||
Server server = createServer(port);
|
||||
server.start();
|
||||
server.join();
|
||||
}
|
||||
|
|
|
@ -19,8 +19,9 @@
|
|||
package org.eclipse.jetty.embedded;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.EnumSet;
|
||||
import javax.servlet.DispatcherType;
|
||||
import javax.servlet.Filter;
|
||||
import javax.servlet.FilterChain;
|
||||
import javax.servlet.FilterConfig;
|
||||
|
@ -31,38 +32,59 @@ import javax.servlet.ServletRequest;
|
|||
import javax.servlet.ServletRequestEvent;
|
||||
import javax.servlet.ServletRequestListener;
|
||||
import javax.servlet.ServletResponse;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.eclipse.jetty.server.Server;
|
||||
import org.eclipse.jetty.servlet.DefaultServlet;
|
||||
import org.eclipse.jetty.servlet.ListenerHolder;
|
||||
import org.eclipse.jetty.servlet.ServletContextHandler;
|
||||
import org.eclipse.jetty.servlet.ServletHolder;
|
||||
import org.eclipse.jetty.util.resource.PathResource;
|
||||
import org.eclipse.jetty.util.resource.Resource;
|
||||
|
||||
import static javax.servlet.DispatcherType.ASYNC;
|
||||
import static javax.servlet.DispatcherType.REQUEST;
|
||||
|
||||
public class OneServletContext
|
||||
{
|
||||
public static void main(String[] args) throws Exception
|
||||
public static Server createServer(int port, Resource baseResource)
|
||||
{
|
||||
Server server = new Server(8080);
|
||||
Server server = new Server(port);
|
||||
|
||||
ServletContextHandler context = new ServletContextHandler(
|
||||
ServletContextHandler.SESSIONS);
|
||||
ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
|
||||
context.setContextPath("/");
|
||||
context.setResourceBase(System.getProperty("java.io.tmpdir"));
|
||||
context.setBaseResource(baseResource);
|
||||
server.setHandler(context);
|
||||
|
||||
// Add dump servlet
|
||||
context.addServlet(
|
||||
context.addServlet(DumpServlet.class, "/dump/*"),
|
||||
"*.dump");
|
||||
// add hello servlet
|
||||
context.addServlet(HelloServlet.class, "/hello/*");
|
||||
|
||||
// Add dump servlet on multiple url-patterns
|
||||
ServletHolder debugHolder = new ServletHolder("debug", DumpServlet.class);
|
||||
context.addServlet(debugHolder, "/dump/*");
|
||||
context.addServlet(debugHolder, "*.dump");
|
||||
|
||||
// add default servlet (for error handling and static resources)
|
||||
context.addServlet(DefaultServlet.class, "/");
|
||||
|
||||
context.addFilter(TestFilter.class, "/*", EnumSet.of(DispatcherType.REQUEST));
|
||||
context.addFilter(TestFilter.class, "/test", EnumSet.of(DispatcherType.REQUEST, DispatcherType.ASYNC));
|
||||
context.addFilter(TestFilter.class, "*.test", EnumSet.of(DispatcherType.REQUEST, DispatcherType.INCLUDE, DispatcherType.FORWARD));
|
||||
// sprinkle in a few filters to demonstrate behaviors
|
||||
context.addFilter(TestFilter.class, "/test/*", EnumSet.of(REQUEST));
|
||||
context.addFilter(TestFilter.class, "*.test", EnumSet.of(REQUEST, ASYNC));
|
||||
|
||||
// and a few listeners to show other ways of working with servlets
|
||||
context.getServletHandler().addListener(new ListenerHolder(InitListener.class));
|
||||
context.getServletHandler().addListener(new ListenerHolder(RequestListener.class));
|
||||
|
||||
return server;
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception
|
||||
{
|
||||
int port = ExampleUtil.getPort(args, "jetty.http.port", 8080);
|
||||
Path tempDir = Paths.get(System.getProperty("java.io.tmpdir"));
|
||||
|
||||
Server server = createServer(port, new PathResource(tempDir));
|
||||
|
||||
server.start();
|
||||
server.dumpStdErr();
|
||||
server.join();
|
||||
|
@ -71,14 +93,18 @@ public class OneServletContext
|
|||
public static class TestFilter implements Filter
|
||||
{
|
||||
@Override
|
||||
public void init(FilterConfig filterConfig) throws ServletException
|
||||
public void init(FilterConfig filterConfig)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException
|
||||
{
|
||||
if (response instanceof HttpServletResponse)
|
||||
{
|
||||
HttpServletResponse httpServletResponse = (HttpServletResponse)response;
|
||||
httpServletResponse.setHeader("X-TestFilter", "true");
|
||||
}
|
||||
chain.doFilter(request, response);
|
||||
}
|
||||
|
||||
|
@ -94,6 +120,7 @@ public class OneServletContext
|
|||
@Override
|
||||
public void contextInitialized(ServletContextEvent sce)
|
||||
{
|
||||
sce.getServletContext().setAttribute("X-Init", "true");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -105,15 +132,14 @@ public class OneServletContext
|
|||
public static class RequestListener implements ServletRequestListener
|
||||
{
|
||||
@Override
|
||||
public void requestDestroyed(ServletRequestEvent sre)
|
||||
public void requestInitialized(ServletRequestEvent sre)
|
||||
{
|
||||
|
||||
sre.getServletRequest().setAttribute("X-ReqListener", "true");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void requestInitialized(ServletRequestEvent sre)
|
||||
public void requestDestroyed(ServletRequestEvent sre)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,9 +28,10 @@ import org.eclipse.jetty.servlet.ServletContextHandler;
|
|||
|
||||
public class OneServletContextJmxStats
|
||||
{
|
||||
public static void main(String[] args) throws Exception
|
||||
public static Server createServer(int port)
|
||||
{
|
||||
Server server = new Server(8080);
|
||||
Server server = new Server(port);
|
||||
|
||||
// Add JMX tracking to Server
|
||||
server.addBean(new MBeanContainer(ManagementFactory
|
||||
.getPlatformMBeanServer()));
|
||||
|
@ -45,6 +46,13 @@ public class OneServletContextJmxStats
|
|||
|
||||
// Add Connector Statistics tracking to all connectors
|
||||
ServerConnectionStatistics.addToAllConnectors(server);
|
||||
return server;
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception
|
||||
{
|
||||
int port = ExampleUtil.getPort(args, "jetty.http.port", 8080);
|
||||
Server server = createServer(port);
|
||||
|
||||
server.start();
|
||||
server.join();
|
||||
|
|
|
@ -18,24 +18,29 @@
|
|||
|
||||
package org.eclipse.jetty.embedded;
|
||||
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
|
||||
import org.eclipse.jetty.server.Server;
|
||||
import org.eclipse.jetty.server.session.DefaultSessionCache;
|
||||
import org.eclipse.jetty.server.session.NullSessionDataStore;
|
||||
import org.eclipse.jetty.server.session.SessionCache;
|
||||
import org.eclipse.jetty.server.session.SessionHandler;
|
||||
import org.eclipse.jetty.servlet.ServletContextHandler;
|
||||
import org.eclipse.jetty.util.resource.PathResource;
|
||||
import org.eclipse.jetty.util.resource.Resource;
|
||||
|
||||
public class OneServletContextWithSession
|
||||
{
|
||||
public static void main(String[] args) throws Exception
|
||||
public static Server createServer(int port, Resource baseResource)
|
||||
{
|
||||
Server server = new Server(8080);
|
||||
Server server = new Server(port);
|
||||
|
||||
// Create a ServletContext, with a session handler enabled.
|
||||
ServletContextHandler context = new ServletContextHandler(
|
||||
ServletContextHandler.SESSIONS);
|
||||
context.setContextPath("/");
|
||||
context.setResourceBase(System.getProperty("java.io.tmpdir"));
|
||||
context.setBaseResource(baseResource);
|
||||
server.setHandler(context);
|
||||
|
||||
// Access the SessionHandler from the context.
|
||||
|
@ -55,6 +60,15 @@ public class OneServletContextWithSession
|
|||
// Servlet to read/set the greeting stored in the session.
|
||||
// Can be accessed using http://localhost:8080/hello
|
||||
context.addServlet(HelloSessionServlet.class, "/");
|
||||
return server;
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception
|
||||
{
|
||||
int port = ExampleUtil.getPort(args, "jetty.http.port", 8080);
|
||||
Path dir = Paths.get(System.getProperty("user.dir"));
|
||||
PathResource baseResource = new PathResource(dir);
|
||||
Server server = createServer(port, baseResource);
|
||||
|
||||
server.start();
|
||||
server.dumpStdErr();
|
||||
|
|
|
@ -19,27 +19,20 @@
|
|||
package org.eclipse.jetty.embedded;
|
||||
|
||||
import java.io.File;
|
||||
import java.lang.management.ManagementFactory;
|
||||
|
||||
import org.eclipse.jetty.jmx.MBeanContainer;
|
||||
import org.eclipse.jetty.server.Server;
|
||||
import org.eclipse.jetty.webapp.Configurations;
|
||||
import org.eclipse.jetty.webapp.WebAppContext;
|
||||
|
||||
public class OneWebApp
|
||||
{
|
||||
public static void main(String[] args) throws Exception
|
||||
public static Server createServer(int port)
|
||||
{
|
||||
// Create a basic jetty server object that will listen on port 8080.
|
||||
// Note that if you set this to port 0 then a randomly available port
|
||||
// will be assigned that you can either look in the logs for the port,
|
||||
// or programmatically obtain it for use in test cases.
|
||||
Server server = new Server(8080);
|
||||
|
||||
// Setup JMX
|
||||
MBeanContainer mbContainer = new MBeanContainer(
|
||||
ManagementFactory.getPlatformMBeanServer());
|
||||
server.addBean(mbContainer);
|
||||
Server server = new Server(port);
|
||||
|
||||
// The WebAppContext is the entity that controls the environment in
|
||||
// which a web application lives and breathes. In this example the
|
||||
|
@ -56,6 +49,13 @@ public class OneWebApp
|
|||
// A WebAppContext is a ContextHandler as well so it needs to be set to
|
||||
// the server so it is aware of where to send the appropriate requests.
|
||||
server.setHandler(webapp);
|
||||
return server;
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception
|
||||
{
|
||||
int port = ExampleUtil.getPort(args, "jetty.http.port", 8080);
|
||||
Server server = createServer(port);
|
||||
|
||||
Configurations.setServerDefault(server);
|
||||
|
||||
|
@ -66,7 +66,6 @@ public class OneWebApp
|
|||
|
||||
// The use of server.join() the will make the current thread join and
|
||||
// wait until the server is done executing.
|
||||
// See http://docs.oracle.com/javase/7/docs/api/java/lang/Thread.html#join()
|
||||
server.join();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,49 +18,45 @@
|
|||
|
||||
package org.eclipse.jetty.embedded;
|
||||
|
||||
import java.io.File;
|
||||
import java.lang.management.ManagementFactory;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.net.URL;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
|
||||
import org.eclipse.jetty.annotations.AnnotationConfiguration;
|
||||
import org.eclipse.jetty.jmx.MBeanContainer;
|
||||
import org.eclipse.jetty.security.HashLoginService;
|
||||
import org.eclipse.jetty.server.Server;
|
||||
import org.eclipse.jetty.util.resource.PathResource;
|
||||
import org.eclipse.jetty.webapp.WebAppContext;
|
||||
|
||||
public class OneWebAppWithJsp
|
||||
{
|
||||
public static void main(String[] args) throws Exception
|
||||
public static Server createServer(int port) throws FileNotFoundException
|
||||
{
|
||||
// Create a basic jetty server object that will listen on port 8080.
|
||||
// Note that if you set this to port 0 then
|
||||
// a randomly available port will be assigned that you can either look
|
||||
// in the logs for the port,
|
||||
// or programmatically obtain it for use in test cases.
|
||||
Server server = new Server(8080);
|
||||
|
||||
// Setup JMX
|
||||
MBeanContainer mbContainer = new MBeanContainer(
|
||||
ManagementFactory.getPlatformMBeanServer());
|
||||
server.addBean(mbContainer);
|
||||
Server server = new Server(port);
|
||||
|
||||
// The WebAppContext is the entity that controls the environment in
|
||||
// which a web application lives and
|
||||
// breathes. In this example the context path is being set to "/" so it
|
||||
// which a web application lives and breathes.
|
||||
// In this example the context path is being set to "/" so it
|
||||
// is suitable for serving root context
|
||||
// requests and then we see it setting the location of the war. A whole
|
||||
// host of other configurations are
|
||||
// requests and then we see it setting the location of the war.
|
||||
// A whole host of other configurations are
|
||||
// available, ranging from configuring to support annotation scanning in
|
||||
// the webapp (through
|
||||
// PlusConfiguration) to choosing where the webapp will unpack itself.
|
||||
// the webapp (through PlusConfiguration), to choosing where
|
||||
// the webapp will unpack itself.
|
||||
WebAppContext webapp = new WebAppContext();
|
||||
webapp.setContextPath("/");
|
||||
File warFile = new File(
|
||||
"jetty-distribution/target/distribution/demo-base/webapps/test.war");
|
||||
if (!warFile.exists())
|
||||
Path warFile = JettyDistribution.resolve("demo-base/webapps/test.war");
|
||||
if (!Files.exists(warFile))
|
||||
{
|
||||
throw new RuntimeException("Unable to find WAR File: " + warFile.getAbsolutePath());
|
||||
throw new FileNotFoundException(warFile.toString());
|
||||
}
|
||||
webapp.setWar(warFile.getAbsolutePath());
|
||||
webapp.setWarResource(new PathResource(warFile));
|
||||
webapp.setExtractWAR(true);
|
||||
|
||||
// This webapp will use jsps and jstl. We need to enable the
|
||||
|
@ -89,19 +85,32 @@ public class OneWebAppWithJsp
|
|||
// its own we register it as a bean with the Jetty server object so it
|
||||
// can be started and stopped according to the lifecycle of the server
|
||||
// itself.
|
||||
String realmResourceName = "etc/realm.properties";
|
||||
ClassLoader classLoader = OneWebAppWithJsp.class.getClassLoader();
|
||||
URL realmProps = classLoader.getResource(realmResourceName);
|
||||
if (realmProps == null)
|
||||
throw new FileNotFoundException("Unable to find " + realmResourceName);
|
||||
|
||||
HashLoginService loginService = new HashLoginService();
|
||||
loginService.setName("Test Realm");
|
||||
loginService.setConfig("examples/embedded/src/test/resources/realm.properties");
|
||||
loginService.setConfig(realmProps.toExternalForm());
|
||||
server.addBean(loginService);
|
||||
|
||||
// Start things up!
|
||||
return server;
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception
|
||||
{
|
||||
int port = ExampleUtil.getPort(args, "jetty.http.port", 8080);
|
||||
Server server = createServer(port);
|
||||
|
||||
// Start things up!
|
||||
server.start();
|
||||
|
||||
server.dumpStdErr();
|
||||
|
||||
// The use of server.join() the will make the current thread join and
|
||||
// wait until the server is done executing.
|
||||
// See http://docs.oracle.com/javase/7/docs/api/java/lang/Thread.html#join()
|
||||
server.join();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,11 +27,13 @@ import org.eclipse.jetty.servlet.ServletHolder;
|
|||
|
||||
public class ProxyServer
|
||||
{
|
||||
public static void main(String[] args) throws Exception
|
||||
public static Server createServer(int port)
|
||||
{
|
||||
Server server = new Server();
|
||||
|
||||
// Establish listening connector
|
||||
ServerConnector connector = new ServerConnector(server);
|
||||
connector.setPort(8888);
|
||||
connector.setPort(port);
|
||||
server.addConnector(connector);
|
||||
|
||||
// Setup proxy handler to handle CONNECT methods
|
||||
|
@ -45,6 +47,15 @@ public class ProxyServer
|
|||
proxyServlet.setInitParameter("blackList", "www.eclipse.org");
|
||||
context.addServlet(proxyServlet, "/*");
|
||||
|
||||
return server;
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception
|
||||
{
|
||||
int port = ExampleUtil.getPort(args, "jetty.http.port", 8080);
|
||||
Server server = createServer(port);
|
||||
|
||||
server.start();
|
||||
server.join();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,27 +18,29 @@
|
|||
|
||||
package org.eclipse.jetty.embedded;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.eclipse.jetty.rewrite.RewriteCustomizer;
|
||||
import org.eclipse.jetty.rewrite.handler.CompactPathRule;
|
||||
import org.eclipse.jetty.rewrite.handler.RewriteRegexRule;
|
||||
import org.eclipse.jetty.server.HttpConfiguration;
|
||||
import org.eclipse.jetty.server.HttpConnectionFactory;
|
||||
import org.eclipse.jetty.server.Server;
|
||||
import org.eclipse.jetty.servlet.ServletContextHandler;
|
||||
|
||||
public class RewriteServer
|
||||
{
|
||||
public static void main(String[] args) throws Exception
|
||||
public static Server createServer(int port)
|
||||
{
|
||||
Server server = new Server(8080);
|
||||
|
||||
HttpConfiguration config = server.getConnectors()[0].getConnectionFactory(HttpConnectionFactory.class).getHttpConfiguration();
|
||||
Server server = new Server(port);
|
||||
|
||||
RewriteCustomizer rewrite = new RewriteCustomizer();
|
||||
config.addCustomizer(rewrite);
|
||||
rewrite.addRule(new CompactPathRule());
|
||||
rewrite.addRule(new RewriteRegexRule("(.*)foo(.*)", "$1FOO$2"));
|
||||
|
||||
Arrays.stream(server.getConnectors())
|
||||
.forEach((connector) -> connector.getConnectionFactory(HttpConnectionFactory.class)
|
||||
.getHttpConfiguration().addCustomizer(rewrite));
|
||||
|
||||
ServletContextHandler context = new ServletContextHandler(
|
||||
ServletContextHandler.SESSIONS);
|
||||
context.setContextPath("/");
|
||||
|
@ -46,6 +48,14 @@ public class RewriteServer
|
|||
|
||||
context.addServlet(DumpServlet.class, "/*");
|
||||
|
||||
return server;
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception
|
||||
{
|
||||
int port = ExampleUtil.getPort(args, "jetty.http.port", 8080);
|
||||
Server server = createServer(port);
|
||||
|
||||
server.start();
|
||||
server.join();
|
||||
}
|
||||
|
|
|
@ -18,6 +18,8 @@
|
|||
|
||||
package org.eclipse.jetty.embedded;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
import java.net.URL;
|
||||
import java.util.Collections;
|
||||
|
||||
import org.eclipse.jetty.security.ConstraintMapping;
|
||||
|
@ -30,13 +32,13 @@ import org.eclipse.jetty.util.security.Constraint;
|
|||
|
||||
public class SecuredHelloHandler
|
||||
{
|
||||
public static void main(String[] args) throws Exception
|
||||
public static Server createServer(int port) throws FileNotFoundException
|
||||
{
|
||||
// Create a basic jetty server object that will listen on port 8080.
|
||||
// Note that if you set this to port 0 then a randomly available port
|
||||
// will be assigned that you can either look in the logs for the port,
|
||||
// or programmatically obtain it for use in test cases.
|
||||
Server server = new Server(8080);
|
||||
Server server = new Server(port);
|
||||
|
||||
// Since this example is for our test webapp, we need to setup a
|
||||
// LoginService so this shows how to create a very simple hashmap based
|
||||
|
@ -46,8 +48,14 @@ public class SecuredHelloHandler
|
|||
// started and stopped according to the lifecycle of the server itself.
|
||||
// In this example the name can be whatever you like since we are not
|
||||
// dealing with webapp realms.
|
||||
String realmResourceName = "etc/realm.properties";
|
||||
ClassLoader classLoader = SecuredHelloHandler.class.getClassLoader();
|
||||
URL realmProps = classLoader.getResource(realmResourceName);
|
||||
if (realmProps == null)
|
||||
throw new FileNotFoundException("Unable to find " + realmResourceName);
|
||||
|
||||
LoginService loginService = new HashLoginService("MyRealm",
|
||||
"src/test/resources/realm.properties");
|
||||
realmProps.toExternalForm());
|
||||
server.addBean(loginService);
|
||||
|
||||
// A security handler is a jetty handler that secures content behind a
|
||||
|
@ -68,7 +76,7 @@ public class SecuredHelloHandler
|
|||
constraint.setRoles(new String[]{"user", "admin"});
|
||||
|
||||
// Binds a url pattern with the previously created constraint. The roles
|
||||
// for this constraing mapping are mined from the Constraint itself
|
||||
// for this constraint mapping are mined from the Constraint itself
|
||||
// although methods exist to declare and bind roles separately as well.
|
||||
ConstraintMapping mapping = new ConstraintMapping();
|
||||
mapping.setPathSpec("/*");
|
||||
|
@ -92,13 +100,19 @@ public class SecuredHelloHandler
|
|||
// chain the hello handler into the security handler
|
||||
security.setHandler(hh);
|
||||
|
||||
return server;
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception
|
||||
{
|
||||
int port = ExampleUtil.getPort(args, "jetty.http.port", 8080);
|
||||
Server server = createServer(port);
|
||||
|
||||
// Start things up!
|
||||
server.start();
|
||||
|
||||
// The use of server.join() the will make the current thread join and
|
||||
// wait until the server is done executing.
|
||||
// See
|
||||
// http://docs.oracle.com/javase/7/docs/api/java/lang/Thread.html#join()
|
||||
server.join();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,6 +19,9 @@
|
|||
package org.eclipse.jetty.embedded;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.net.URL;
|
||||
import javax.naming.NamingException;
|
||||
|
||||
import org.eclipse.jetty.annotations.AnnotationConfiguration;
|
||||
import org.eclipse.jetty.plus.jndi.EnvEntry;
|
||||
|
@ -36,10 +39,10 @@ import org.eclipse.jetty.webapp.WebAppContext;
|
|||
*/
|
||||
public class ServerWithAnnotations
|
||||
{
|
||||
public static final void main(String[] args) throws Exception
|
||||
public static Server createServer(int port) throws NamingException, FileNotFoundException
|
||||
{
|
||||
// Create the server
|
||||
final Server server = new Server(8080);
|
||||
Server server = new Server(port);
|
||||
|
||||
// Create a WebApp
|
||||
WebAppContext webapp = new WebAppContext();
|
||||
|
@ -60,7 +63,7 @@ public class ServerWithAnnotations
|
|||
new Transaction(new com.acme.MockUserTransaction());
|
||||
|
||||
// Define an env entry with webapp scope.
|
||||
// THIS ENTRY IS OVERRIDEN BY THE ENTRY IN jetty-env.xml
|
||||
// THIS ENTRY IS OVERRIDDEN BY THE ENTRY IN jetty-env.xml
|
||||
new EnvEntry(webapp, "maxAmount", 100d, true);
|
||||
|
||||
// Register a mock DataSource scoped to the webapp
|
||||
|
@ -70,10 +73,23 @@ public class ServerWithAnnotations
|
|||
server.addBean(new NamingDump());
|
||||
|
||||
// Configure a LoginService
|
||||
String realmResourceName = "etc/realm.properties";
|
||||
ClassLoader classLoader = ServerWithAnnotations.class.getClassLoader();
|
||||
URL realmProps = classLoader.getResource(realmResourceName);
|
||||
if (realmProps == null)
|
||||
throw new FileNotFoundException("Unable to find " + realmResourceName);
|
||||
|
||||
HashLoginService loginService = new HashLoginService();
|
||||
loginService.setName("Test Realm");
|
||||
loginService.setConfig("examples/embedded/src/test/resources/realm.properties");
|
||||
loginService.setConfig(realmProps.toExternalForm());
|
||||
server.addBean(loginService);
|
||||
return server;
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception
|
||||
{
|
||||
int port = ExampleUtil.getPort(args, "jetty.http.port", 8080);
|
||||
Server server = createServer(port);
|
||||
|
||||
server.start();
|
||||
server.dumpStdErr();
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
package org.eclipse.jetty.embedded;
|
||||
|
||||
import java.lang.management.ManagementFactory;
|
||||
import java.net.MalformedURLException;
|
||||
import javax.management.remote.JMXServiceURL;
|
||||
|
||||
import org.eclipse.jetty.jmx.ConnectorServer;
|
||||
|
@ -26,17 +27,16 @@ import org.eclipse.jetty.jmx.MBeanContainer;
|
|||
import org.eclipse.jetty.server.Server;
|
||||
|
||||
/**
|
||||
* The simplest possible Jetty server.
|
||||
* A Jetty Server with JMX enabled for remote connections
|
||||
*/
|
||||
public class ServerWithJMX
|
||||
{
|
||||
public static void main(String[] args) throws Exception
|
||||
public static Server createServer(int port) throws MalformedURLException
|
||||
{
|
||||
// === jetty-jmx.xml ===
|
||||
Server server = new Server(port);
|
||||
|
||||
MBeanContainer mbContainer = new MBeanContainer(
|
||||
ManagementFactory.getPlatformMBeanServer());
|
||||
|
||||
Server server = new Server(8080);
|
||||
server.addBean(mbContainer);
|
||||
|
||||
ConnectorServer jmx = new ConnectorServer(
|
||||
|
@ -48,6 +48,14 @@ public class ServerWithJMX
|
|||
"org.eclipse.jetty.jmx:name=rmiconnectorserver");
|
||||
server.addBean(jmx);
|
||||
|
||||
return server;
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception
|
||||
{
|
||||
int port = ExampleUtil.getPort(args, "jetty.http.port", 8080);
|
||||
Server server = createServer(port);
|
||||
|
||||
server.start();
|
||||
server.dumpStdErr();
|
||||
server.join();
|
||||
|
|
|
@ -18,12 +18,14 @@
|
|||
|
||||
package org.eclipse.jetty.embedded;
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Properties;
|
||||
import javax.naming.NamingException;
|
||||
|
||||
import org.eclipse.jetty.plus.webapp.EnvConfiguration;
|
||||
import org.eclipse.jetty.plus.webapp.PlusConfiguration;
|
||||
import org.eclipse.jetty.server.Server;
|
||||
import org.eclipse.jetty.util.resource.PathResource;
|
||||
import org.eclipse.jetty.webapp.WebAppContext;
|
||||
|
||||
/**
|
||||
|
@ -31,18 +33,16 @@ import org.eclipse.jetty.webapp.WebAppContext;
|
|||
*/
|
||||
public class ServerWithJNDI
|
||||
{
|
||||
public static void main(String[] args) throws Exception
|
||||
public static Server createServer(int port) throws NamingException
|
||||
{
|
||||
|
||||
// Create the server
|
||||
Server server = new Server(8080);
|
||||
Server server = new Server(port);
|
||||
|
||||
// Create a WebApp
|
||||
WebAppContext webapp = new WebAppContext();
|
||||
webapp.setContextPath("/");
|
||||
File warFile = new File(
|
||||
"../../jetty-distribution/target/distribution/demo-base/webapps/test-jndi.war");
|
||||
webapp.setWar(warFile.getAbsolutePath());
|
||||
Path testJndiWar = JettyDistribution.resolve("demo-base/webapps/test-jndi.war");
|
||||
webapp.setWarResource(new PathResource(testJndiWar));
|
||||
server.setHandler(webapp);
|
||||
|
||||
// Enable parsing of jndi-related parts of web.xml and jetty-env.xml
|
||||
|
@ -74,7 +74,7 @@ public class ServerWithJNDI
|
|||
// Note that the last arg of "true" means that this definition for
|
||||
// "wiggle" would override an entry of the
|
||||
// same name in web.xml
|
||||
new org.eclipse.jetty.plus.jndi.EnvEntry(webapp, "wiggle", 100D, true);
|
||||
new org.eclipse.jetty.plus.jndi.EnvEntry(webapp, "wiggle", 100d, true);
|
||||
|
||||
// Register a reference to a mail service scoped to the webapp.
|
||||
// This must be linked to the webapp by an entry in web.xml:
|
||||
|
@ -84,7 +84,8 @@ public class ServerWithJNDI
|
|||
// <res-auth>Container</res-auth>
|
||||
// </resource-ref>
|
||||
// At runtime the webapp accesses this as java:comp/env/mail/Session
|
||||
org.eclipse.jetty.jndi.factories.MailSessionReference mailref = new org.eclipse.jetty.jndi.factories.MailSessionReference();
|
||||
org.eclipse.jetty.jndi.factories.MailSessionReference mailref =
|
||||
new org.eclipse.jetty.jndi.factories.MailSessionReference();
|
||||
mailref.setUser("CHANGE-ME");
|
||||
mailref.setPassword("CHANGE-ME");
|
||||
Properties props = new Properties();
|
||||
|
@ -106,6 +107,13 @@ public class ServerWithJNDI
|
|||
// java:comp/env/jdbc/mydatasource
|
||||
new org.eclipse.jetty.plus.jndi.Resource(
|
||||
webapp, "jdbc/mydatasource", new com.acme.MockDataSource());
|
||||
return server;
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception
|
||||
{
|
||||
int port = ExampleUtil.getPort(args, "jetty.http.port", 8080);
|
||||
Server server = createServer(port);
|
||||
|
||||
server.start();
|
||||
server.join();
|
||||
|
|
|
@ -25,11 +25,20 @@ import org.eclipse.jetty.server.Server;
|
|||
*/
|
||||
public class SimplestServer
|
||||
{
|
||||
public static Server createServer(int port)
|
||||
{
|
||||
Server server = new Server(port);
|
||||
// This has a connector listening on port specified
|
||||
// and no handlers, meaning all requests will result
|
||||
// in a 404 response
|
||||
return server;
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception
|
||||
{
|
||||
Server server = new Server(8080);
|
||||
int port = ExampleUtil.getPort(args, "jetty.http.port", 8080);
|
||||
Server server = createServer(port);
|
||||
server.start();
|
||||
server.dumpStdErr();
|
||||
server.join();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,16 +18,14 @@
|
|||
|
||||
package org.eclipse.jetty.embedded;
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.file.Paths;
|
||||
|
||||
import org.eclipse.jetty.server.Connector;
|
||||
import org.eclipse.jetty.server.Handler;
|
||||
import org.eclipse.jetty.server.Server;
|
||||
import org.eclipse.jetty.server.ServerConnector;
|
||||
import org.eclipse.jetty.server.handler.ContextHandler;
|
||||
import org.eclipse.jetty.server.handler.ContextHandlerCollection;
|
||||
import org.eclipse.jetty.server.handler.ResourceHandler;
|
||||
import org.eclipse.jetty.toolchain.test.MavenTestingUtils;
|
||||
import org.eclipse.jetty.util.resource.PathResource;
|
||||
import org.eclipse.jetty.util.resource.Resource;
|
||||
|
||||
/**
|
||||
|
@ -37,59 +35,68 @@ import org.eclipse.jetty.util.resource.Resource;
|
|||
*/
|
||||
public class SplitFileServer
|
||||
{
|
||||
public static void main(String[] args) throws Exception
|
||||
public static Server createServer(int port, Resource baseResource0, Resource baseResource1)
|
||||
{
|
||||
// Create the Server object and a corresponding ServerConnector and then
|
||||
// set the port for the connector. In this example the server will
|
||||
// listen on port 8090. If you set this to port 0 then when the server
|
||||
// listen on port 8080. If you set this to port 0 then when the server
|
||||
// has been started you can called connector.getLocalPort() to
|
||||
// programmatically get the port the server started on.
|
||||
Server server = new Server();
|
||||
ServerConnector connector = new ServerConnector(server);
|
||||
connector.setPort(8090);
|
||||
server.setConnectors(new Connector[]{connector});
|
||||
connector.setPort(port);
|
||||
server.addConnector(connector);
|
||||
|
||||
// Create a Context Handler and ResourceHandler. The ContextHandler is
|
||||
// getting set to "/" path but this could be anything you like for
|
||||
// builing out your url. Note how we are setting the ResourceBase using
|
||||
// building out your url. Note how we are setting the ResourceBase using
|
||||
// our jetty maven testing utilities to get the proper resource
|
||||
// directory, you needn't use these, you simply need to supply the paths
|
||||
// you are looking to serve content from.
|
||||
ResourceHandler rh0 = new ResourceHandler();
|
||||
rh0.setDirectoriesListed(false);
|
||||
|
||||
ContextHandler context0 = new ContextHandler();
|
||||
context0.setContextPath("/");
|
||||
File dir0 = MavenTestingUtils.getTestResourceDir("dir0");
|
||||
context0.setBaseResource(Resource.newResource(dir0));
|
||||
context0.setBaseResource(baseResource0);
|
||||
context0.setHandler(rh0);
|
||||
|
||||
// Rinse and repeat the previous item, only specifying a different
|
||||
// resource base.
|
||||
ResourceHandler rh1 = new ResourceHandler();
|
||||
rh1.setDirectoriesListed(false);
|
||||
|
||||
ContextHandler context1 = new ContextHandler();
|
||||
context1.setContextPath("/");
|
||||
File dir1 = MavenTestingUtils.getTestResourceDir("dir1");
|
||||
context1.setBaseResource(Resource.newResource(dir1));
|
||||
context1.setBaseResource(baseResource1);
|
||||
context1.setHandler(rh1);
|
||||
|
||||
// Create a ContextHandlerCollection and set the context handlers to it.
|
||||
// This will let jetty process urls against the declared contexts in
|
||||
// order to match up content.
|
||||
ContextHandlerCollection contexts = new ContextHandlerCollection();
|
||||
contexts.setHandlers(new Handler[]{context0, context1});
|
||||
|
||||
ContextHandlerCollection contexts = new ContextHandlerCollection(
|
||||
context0, context1
|
||||
);
|
||||
server.setHandler(contexts);
|
||||
return server;
|
||||
}
|
||||
|
||||
// Start things up!
|
||||
server.start();
|
||||
public static void main(String[] args) throws Exception
|
||||
{
|
||||
int port = ExampleUtil.getPort(args, "jetty.http.port", 8080);
|
||||
Resource resource0 = new PathResource(Paths.get("src/test/resources/dir0"));
|
||||
Resource resource1 = new PathResource(Paths.get("src/test/resources/dir1"));
|
||||
|
||||
Server server = createServer(port, resource0, resource1);
|
||||
|
||||
// Dump the server state
|
||||
System.out.println(server.dump());
|
||||
server.setDumpAfterStart(true);
|
||||
|
||||
// Start things up!
|
||||
server.start();
|
||||
|
||||
// The use of server.join() the will make the current thread join and
|
||||
// wait until the server is done executing.
|
||||
// See http://docs.oracle.com/javase/7/docs/api/java/lang/Thread.html#join()
|
||||
server.join();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -46,25 +46,37 @@ public class WebSocketJsrServer
|
|||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception
|
||||
public static Server createServer(int port)
|
||||
{
|
||||
final Server server = new Server(8080);
|
||||
Server server = new Server(port);
|
||||
|
||||
HandlerList handlers = new HandlerList();
|
||||
|
||||
ServletContextHandler contextHandler = new ServletContextHandler(
|
||||
ServletContextHandler.SESSIONS);
|
||||
contextHandler.setContextPath("/");
|
||||
handlers.addHandler(contextHandler);
|
||||
ServletContextHandler context = new ServletContextHandler();
|
||||
context.setContextPath("/");
|
||||
handlers.addHandler(context);
|
||||
|
||||
// Enable javax.websocket configuration for the context
|
||||
JavaxWebSocketServletContainerInitializer.configure(context,
|
||||
(servletContext, serverContainer) ->
|
||||
{
|
||||
// Add your websocket to the javax.websocket.server.ServerContainer
|
||||
serverContainer.addEndpoint(EchoJsrSocket.class);
|
||||
}
|
||||
);
|
||||
|
||||
handlers.addHandler(new DefaultHandler());
|
||||
server.setHandler(handlers);
|
||||
|
||||
// Enable javax.websocket configuration for the context
|
||||
JavaxWebSocketServletContainerInitializer.configure(contextHandler, (context, container) ->
|
||||
container.addEndpoint(EchoJsrSocket.class));
|
||||
return server;
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception
|
||||
{
|
||||
int port = ExampleUtil.getPort(args, "jetty.http.port", 8080);
|
||||
Server server = createServer(port);
|
||||
|
||||
server.start();
|
||||
contextHandler.dumpStdErr();
|
||||
server.join();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,13 +20,13 @@ package org.eclipse.jetty.embedded;
|
|||
|
||||
import org.eclipse.jetty.server.Server;
|
||||
import org.eclipse.jetty.servlet.ServletContextHandler;
|
||||
import org.eclipse.jetty.servlet.ServletHolder;
|
||||
import org.eclipse.jetty.websocket.api.Session;
|
||||
import org.eclipse.jetty.websocket.api.WriteCallback;
|
||||
import org.eclipse.jetty.websocket.api.annotations.OnWebSocketMessage;
|
||||
import org.eclipse.jetty.websocket.api.annotations.WebSocket;
|
||||
import org.eclipse.jetty.websocket.server.JettyWebSocketServlet;
|
||||
import org.eclipse.jetty.websocket.server.JettyWebSocketServletFactory;
|
||||
import org.eclipse.jetty.websocket.server.config.JettyWebSocketServletContainerInitializer;
|
||||
|
||||
/**
|
||||
* Example of setting up a Jetty WebSocket server
|
||||
|
@ -61,20 +61,29 @@ public class WebSocketServer
|
|||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception
|
||||
public static Server createServer(int port)
|
||||
{
|
||||
Server server = new Server(8080);
|
||||
Server server = new Server(port);
|
||||
|
||||
ServletContextHandler context = new ServletContextHandler(
|
||||
ServletContextHandler.SESSIONS);
|
||||
ServletContextHandler context = new ServletContextHandler();
|
||||
context.setContextPath("/");
|
||||
server.setHandler(context);
|
||||
|
||||
// Add the echo socket servlet to the /echo path map
|
||||
context.addServlet(new ServletHolder(EchoServlet.class), "/echo");
|
||||
context.addServlet(EchoServlet.class, "/echo");
|
||||
|
||||
// Configure context to support WebSocket
|
||||
JettyWebSocketServletContainerInitializer.configure(context, null);
|
||||
|
||||
return server;
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception
|
||||
{
|
||||
int port = ExampleUtil.getPort(args, "jetty.http.port", 8080);
|
||||
Server server = createServer(port);
|
||||
|
||||
server.start();
|
||||
context.dumpStdErr();
|
||||
server.join();
|
||||
}
|
||||
}
|
||||
|
|
Binary file not shown.
|
@ -0,0 +1,20 @@
|
|||
Bag Attributes
|
||||
friendlyName: jetty
|
||||
localKeyID: 54 69 6D 65 20 31 34 32 33 31 39 38 30 39 33 31 31 35
|
||||
Key Attributes: <No Attributes>
|
||||
-----BEGIN PRIVATE KEY-----
|
||||
MIICdgIBADANBgkqhkiG9w0BAQEFAASCAmAwggJcAgEAAoGBAIPh4Q0t4xklXTzX
|
||||
N2VAb47r5n7idAupp4CTNEhhT6lS70iA+A8i4+0lSEHWAogvd9jl3H7SvScr30QM
|
||||
4ieC0JCGSOwGc8f+yqKrO56PPd5OuqW380BJ0r74jJczU9CcsuavHD7e6mRLUnmj
|
||||
xM20NSxrcicMiPUHY1mJZtN9swtxAgMBAAECgYADS9P6Jll0uXBZIu/pgfDH27GJ
|
||||
HlPULstW9VbrMDNzgfUlFMQebLrRpIrnyleJ29Xc//HA4beEkR4lb0T/w88+pEkt
|
||||
7fhYeqRLPIfpDOgzloynnsoPcd8f/PypbimQrNLmBiG1178nVcy4Yoh5lYVIJwtU
|
||||
3VriqDlvAfTLrrx8AQJBAMLWuh27Hb8xs3LRg4UD7hcv8tJejstm08Y+czRz7cO0
|
||||
RENa3aDjGFSegc+IUfdez7BP8uDw+PwE+jybmTvaliECQQCtR/anCY1WS28/bKvy
|
||||
lmIwoI15eraBdVFkN0Hfxh+9PfR3rMD5uyvukT5GgTtY/XxADyafSTaipDJiZHJI
|
||||
EitRAkBjeCBYYVjUbVlBuvi8Bb+dktsSzzdzXDGtueAy3SR7jyJyiIcxRf775Fg9
|
||||
TUkbUwoQ5yAF+sACWcAvBPj796JBAkAEZEeHEkHnxv+pztpIyrDwZJFRW9/WRh/q
|
||||
90+PGVlilXhltBYr/idt43Z9mPblGX+VrAyhitx8oMa6IauX0gYRAkEAgnyVeXrD
|
||||
jDLUZRA3P8Gu27k1k6GjbTYiUz3HKCz2/6+MZ2MK2qqwafgqocji029Q6dHdPD7a
|
||||
4QnRlvraUnyQLA==
|
||||
-----END PRIVATE KEY-----
|
|
@ -0,0 +1,20 @@
|
|||
#
|
||||
# This file defines users passwords and roles for a HashUserRealm
|
||||
#
|
||||
# The format is
|
||||
# <username>: <password>[,<rolename> ...]
|
||||
#
|
||||
# Passwords may be clear text, obfuscated or checksummed. The class
|
||||
# org.eclipse.jetty.util.security.Password should be used to generate obfuscated
|
||||
# passwords or password checksums
|
||||
#
|
||||
# If DIGEST Authentication is used, the password must be in a recoverable
|
||||
# format, either plain text or OBF:.
|
||||
#
|
||||
jetty:MD5:164c88b302622e17050af52c89945d44,user
|
||||
admin:CRYPT:adpexzg3FUZAk,server-administrator,content-administrator,admin,user
|
||||
other:OBF:1xmk1w261u9r1w1c1xmq,user
|
||||
plain:plain,user
|
||||
user:password,user
|
||||
# This entry is for digest auth. The credential is a MD5 hash of username:realmname:password
|
||||
digest:MD5:6e120743ad67abfbc385bc2bb754e297,user
|
|
@ -8,7 +8,9 @@
|
|||
<Item>
|
||||
<New class="org.eclipse.jetty.server.ServerConnector">
|
||||
<Arg><Ref refid="ExampleServer"/></Arg>
|
||||
<Set name="port">8080</Set>
|
||||
<Set name="port">
|
||||
<Property name="http.port" default="8080" />
|
||||
</Set>
|
||||
</New>
|
||||
</Item>
|
||||
</Array>
|
||||
|
|
|
@ -7,7 +7,9 @@
|
|||
<Arg>
|
||||
<New class="org.eclipse.jetty.server.ServerConnector">
|
||||
<Arg><Ref refid="FileServer"/></Arg>
|
||||
<Set name="port">8080</Set>
|
||||
<Set name="port">
|
||||
<Property name="http.port" default="8080" />
|
||||
</Set>
|
||||
</New>
|
||||
</Arg>
|
||||
</Call>
|
||||
|
@ -22,7 +24,9 @@
|
|||
<Set name="welcomeFiles">
|
||||
<Array type="String"><Item>index.html</Item></Array>
|
||||
</Set>
|
||||
<Set name="resourceBase">.</Set>
|
||||
<Set name="resourceBase">
|
||||
<Property name="fileserver.baseresource" default="." />
|
||||
</Set>
|
||||
</New>
|
||||
</Item>
|
||||
<Item>
|
||||
|
|
|
@ -0,0 +1,64 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2019 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.embedded;
|
||||
|
||||
import org.eclipse.jetty.client.HttpClient;
|
||||
import org.eclipse.jetty.client.api.ContentResponse;
|
||||
import org.eclipse.jetty.client.http.HttpClientTransportOverHTTP;
|
||||
import org.eclipse.jetty.io.ClientConnector;
|
||||
import org.eclipse.jetty.util.ssl.SslContextFactory;
|
||||
import org.eclipse.jetty.util.thread.QueuedThreadPool;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
|
||||
public abstract class AbstractEmbeddedTest
|
||||
{
|
||||
public HttpClient client;
|
||||
|
||||
@BeforeEach
|
||||
public void startClient() throws Exception
|
||||
{
|
||||
SslContextFactory.Client sslContextFactory = new SslContextFactory.Client();
|
||||
sslContextFactory.setTrustAll(true);
|
||||
|
||||
ClientConnector clientConnector = new ClientConnector();
|
||||
clientConnector.setSelectors(1);
|
||||
clientConnector.setSslContextFactory(sslContextFactory);
|
||||
|
||||
QueuedThreadPool clientThreads = new QueuedThreadPool();
|
||||
clientThreads.setName("client");
|
||||
|
||||
clientConnector.setExecutor(clientThreads);
|
||||
|
||||
client = new HttpClient(new HttpClientTransportOverHTTP(clientConnector));
|
||||
client.start();
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
public void stopClient() throws Exception
|
||||
{
|
||||
client.stop();
|
||||
}
|
||||
|
||||
protected void dumpResponseHeaders(ContentResponse response)
|
||||
{
|
||||
System.out.printf("%s %s %s%n", response.getVersion(), response.getStatus(), response.getReason());
|
||||
System.out.println(response.getHeaders());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,90 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2019 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.embedded;
|
||||
|
||||
import java.net.URI;
|
||||
|
||||
import org.eclipse.jetty.client.api.ContentResponse;
|
||||
import org.eclipse.jetty.client.util.StringContentProvider;
|
||||
import org.eclipse.jetty.http.HttpMethod;
|
||||
import org.eclipse.jetty.http.HttpStatus;
|
||||
import org.eclipse.jetty.server.Server;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
|
||||
public class ExampleServerTest extends AbstractEmbeddedTest
|
||||
{
|
||||
private Server server;
|
||||
|
||||
@BeforeEach
|
||||
public void startServer() throws Exception
|
||||
{
|
||||
server = ExampleServer.createServer(0);
|
||||
server.start();
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
public void stopServer() throws Exception
|
||||
{
|
||||
server.stop();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetHello() throws Exception
|
||||
{
|
||||
URI uri = server.getURI().resolve("/hello");
|
||||
|
||||
ContentResponse response = client.newRequest(uri)
|
||||
.method(HttpMethod.GET)
|
||||
.send();
|
||||
assertThat("HTTP Response Status", response.getStatus(), is(HttpStatus.OK_200));
|
||||
|
||||
// dumpResponseHeaders(response);
|
||||
|
||||
// test response content
|
||||
String responseBody = response.getContentAsString();
|
||||
assertThat("Response Content", responseBody, containsString("Hello"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetEcho() throws Exception
|
||||
{
|
||||
URI uri = server.getURI().resolve("/echo/a/greeting");
|
||||
|
||||
String postBody = "Greetings from " + ExampleServerTest.class;
|
||||
ContentResponse response = client.newRequest(uri)
|
||||
.method(HttpMethod.POST)
|
||||
.content(new StringContentProvider(postBody))
|
||||
.send();
|
||||
|
||||
// Check the response status code
|
||||
assertThat("HTTP Response Status", response.getStatus(), is(HttpStatus.OK_200));
|
||||
|
||||
// dumpResponseHeaders(response);
|
||||
|
||||
// test response content
|
||||
String responseBody = response.getContentAsString();
|
||||
assertThat("Response Content", responseBody, containsString(postBody));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,67 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2019 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.embedded;
|
||||
|
||||
import java.net.URI;
|
||||
|
||||
import org.eclipse.jetty.client.api.ContentResponse;
|
||||
import org.eclipse.jetty.http.HttpMethod;
|
||||
import org.eclipse.jetty.http.HttpStatus;
|
||||
import org.eclipse.jetty.server.Server;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
|
||||
public class ExampleServerXmlTest extends AbstractEmbeddedTest
|
||||
{
|
||||
private Server server;
|
||||
|
||||
@BeforeEach
|
||||
public void startServer() throws Exception
|
||||
{
|
||||
server = ExampleServerXml.createServer(0);
|
||||
server.start();
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
public void stopServer() throws Exception
|
||||
{
|
||||
server.stop();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetHello() throws Exception
|
||||
{
|
||||
URI uri = server.getURI().resolve("/hello");
|
||||
ContentResponse response = client.newRequest(uri)
|
||||
.method(HttpMethod.GET)
|
||||
.send();
|
||||
assertThat("HTTP Response Status", response.getStatus(), is(HttpStatus.OK_200));
|
||||
|
||||
// dumpResponseHeaders(response);
|
||||
|
||||
// test response content
|
||||
String responseBody = response.getContentAsString();
|
||||
assertThat("Response Content", responseBody, containsString("Hello"));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,92 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2019 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.embedded;
|
||||
|
||||
import java.io.BufferedWriter;
|
||||
import java.net.URI;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
|
||||
import org.eclipse.jetty.client.api.ContentResponse;
|
||||
import org.eclipse.jetty.http.HttpFields;
|
||||
import org.eclipse.jetty.http.HttpMethod;
|
||||
import org.eclipse.jetty.http.HttpStatus;
|
||||
import org.eclipse.jetty.server.Server;
|
||||
import org.eclipse.jetty.toolchain.test.jupiter.WorkDir;
|
||||
import org.eclipse.jetty.toolchain.test.jupiter.WorkDirExtension;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
|
||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
|
||||
@ExtendWith(WorkDirExtension.class)
|
||||
public class FastFileServerTest extends AbstractEmbeddedTest
|
||||
{
|
||||
private static final String TEXT_CONTENT = "I am an old man and I have known a great " +
|
||||
"many troubles, but most of them never happened. - Mark Twain";
|
||||
public WorkDir workDir;
|
||||
private Server server;
|
||||
|
||||
@BeforeEach
|
||||
public void startServer() throws Exception
|
||||
{
|
||||
Path baseDir = workDir.getEmptyPathDir();
|
||||
|
||||
Path textFile = baseDir.resolve("simple.txt");
|
||||
try (BufferedWriter writer = Files.newBufferedWriter(textFile, UTF_8))
|
||||
{
|
||||
writer.write(TEXT_CONTENT);
|
||||
}
|
||||
|
||||
server = FastFileServer.createServer(0, baseDir.toFile());
|
||||
server.start();
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
public void stopServer() throws Exception
|
||||
{
|
||||
server.stop();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetSimpleText() throws Exception
|
||||
{
|
||||
URI uri = server.getURI().resolve("/simple.txt");
|
||||
ContentResponse response = client.newRequest(uri)
|
||||
.method(HttpMethod.GET)
|
||||
.send();
|
||||
assertThat("HTTP Response Status", response.getStatus(), is(HttpStatus.OK_200));
|
||||
|
||||
// dumpResponseHeaders(response);
|
||||
|
||||
HttpFields responseHeaders = response.getHeaders();
|
||||
|
||||
assertThat("Content-Type", responseHeaders.get("Content-Type"), is("text/plain"));
|
||||
assertThat("Content-Length", responseHeaders.getLongField("Content-Length"),
|
||||
is((long)TEXT_CONTENT.length()));
|
||||
|
||||
// test response content
|
||||
String responseBody = response.getContentAsString();
|
||||
assertThat("Response body", responseBody, is(TEXT_CONTENT));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,93 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2019 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.embedded;
|
||||
|
||||
import java.io.BufferedWriter;
|
||||
import java.net.URI;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
|
||||
import org.eclipse.jetty.client.api.ContentResponse;
|
||||
import org.eclipse.jetty.http.HttpFields;
|
||||
import org.eclipse.jetty.http.HttpMethod;
|
||||
import org.eclipse.jetty.http.HttpStatus;
|
||||
import org.eclipse.jetty.server.Server;
|
||||
import org.eclipse.jetty.toolchain.test.jupiter.WorkDir;
|
||||
import org.eclipse.jetty.toolchain.test.jupiter.WorkDirExtension;
|
||||
import org.eclipse.jetty.util.resource.PathResource;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
|
||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
|
||||
@ExtendWith(WorkDirExtension.class)
|
||||
public class FileServerTest extends AbstractEmbeddedTest
|
||||
{
|
||||
private static final String TEXT_CONTENT = "I am an old man and I have known a great " +
|
||||
"many troubles, but most of them never happened. - Mark Twain";
|
||||
public WorkDir workDir;
|
||||
private Server server;
|
||||
|
||||
@BeforeEach
|
||||
public void startServer() throws Exception
|
||||
{
|
||||
Path baseDir = workDir.getEmptyPathDir();
|
||||
|
||||
Path textFile = baseDir.resolve("simple.txt");
|
||||
try (BufferedWriter writer = Files.newBufferedWriter(textFile, UTF_8))
|
||||
{
|
||||
writer.write(TEXT_CONTENT);
|
||||
}
|
||||
|
||||
server = FileServer.createServer(0, new PathResource(baseDir));
|
||||
server.start();
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
public void stopServer() throws Exception
|
||||
{
|
||||
server.stop();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetSimpleText() throws Exception
|
||||
{
|
||||
URI uri = server.getURI().resolve("/simple.txt");
|
||||
ContentResponse response = client.newRequest(uri)
|
||||
.method(HttpMethod.GET)
|
||||
.send();
|
||||
assertThat("HTTP Response Status", response.getStatus(), is(HttpStatus.OK_200));
|
||||
|
||||
// dumpResponseHeaders(response);
|
||||
|
||||
HttpFields responseHeaders = response.getHeaders();
|
||||
|
||||
assertThat("Content-Type", responseHeaders.get("Content-Type"), is("text/plain"));
|
||||
assertThat("Content-Length", responseHeaders.getLongField("Content-Length"),
|
||||
is((long)TEXT_CONTENT.length()));
|
||||
|
||||
// test response content
|
||||
String responseBody = response.getContentAsString();
|
||||
assertThat("Response body", responseBody, is(TEXT_CONTENT));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,92 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2019 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.embedded;
|
||||
|
||||
import java.io.BufferedWriter;
|
||||
import java.net.URI;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
|
||||
import org.eclipse.jetty.client.api.ContentResponse;
|
||||
import org.eclipse.jetty.http.HttpFields;
|
||||
import org.eclipse.jetty.http.HttpMethod;
|
||||
import org.eclipse.jetty.http.HttpStatus;
|
||||
import org.eclipse.jetty.server.Server;
|
||||
import org.eclipse.jetty.toolchain.test.jupiter.WorkDir;
|
||||
import org.eclipse.jetty.toolchain.test.jupiter.WorkDirExtension;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
|
||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
|
||||
@ExtendWith(WorkDirExtension.class)
|
||||
public class FileServerXmlTest extends AbstractEmbeddedTest
|
||||
{
|
||||
private static final String TEXT_CONTENT = "I am an old man and I have known a great " +
|
||||
"many troubles, but most of them never happened. - Mark Twain";
|
||||
public WorkDir workDir;
|
||||
private Server server;
|
||||
|
||||
@BeforeEach
|
||||
public void startServer() throws Exception
|
||||
{
|
||||
Path baseDir = workDir.getEmptyPathDir();
|
||||
|
||||
Path textFile = baseDir.resolve("simple.txt");
|
||||
try (BufferedWriter writer = Files.newBufferedWriter(textFile, UTF_8))
|
||||
{
|
||||
writer.write(TEXT_CONTENT);
|
||||
}
|
||||
|
||||
server = FileServerXml.createServer(0, baseDir);
|
||||
server.start();
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
public void stopServer() throws Exception
|
||||
{
|
||||
server.stop();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetSimpleText() throws Exception
|
||||
{
|
||||
URI uri = server.getURI().resolve("/simple.txt");
|
||||
ContentResponse response = client.newRequest(uri)
|
||||
.method(HttpMethod.GET)
|
||||
.send();
|
||||
assertThat("HTTP Response Status", response.getStatus(), is(HttpStatus.OK_200));
|
||||
|
||||
// dumpResponseHeaders(response);
|
||||
|
||||
HttpFields responseHeaders = response.getHeaders();
|
||||
|
||||
assertThat("Content-Type", responseHeaders.get("Content-Type"), is("text/plain"));
|
||||
assertThat("Content-Length", responseHeaders.getLongField("Content-Length"),
|
||||
is((long)TEXT_CONTENT.length()));
|
||||
|
||||
// test response content
|
||||
String responseBody = response.getContentAsString();
|
||||
assertThat("Response body", responseBody, is(TEXT_CONTENT));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,83 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2019 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.embedded;
|
||||
|
||||
import java.net.URI;
|
||||
|
||||
import org.eclipse.jetty.client.api.ContentResponse;
|
||||
import org.eclipse.jetty.http.HttpMethod;
|
||||
import org.eclipse.jetty.http.HttpStatus;
|
||||
import org.eclipse.jetty.server.Server;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
|
||||
public class JarServerTest extends AbstractEmbeddedTest
|
||||
{
|
||||
private Server server;
|
||||
|
||||
@BeforeEach
|
||||
public void startServer() throws Exception
|
||||
{
|
||||
server = JarServer.createServer(0);
|
||||
server.start();
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
public void stopServer() throws Exception
|
||||
{
|
||||
server.stop();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetDir0Test0() throws Exception
|
||||
{
|
||||
URI uri = server.getURI().resolve("/dir0/test0.txt");
|
||||
ContentResponse response = client.newRequest(uri)
|
||||
.method(HttpMethod.GET)
|
||||
.send();
|
||||
assertThat("HTTP Response Status", response.getStatus(), is(HttpStatus.OK_200));
|
||||
|
||||
// dumpResponseHeaders(response);
|
||||
|
||||
// test response content
|
||||
String responseBody = response.getContentAsString();
|
||||
assertThat("Response Content", responseBody, containsString("test0"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetDir1Test1() throws Exception
|
||||
{
|
||||
URI uri = server.getURI().resolve("/dir1/test1.txt");
|
||||
ContentResponse response = client.newRequest(uri)
|
||||
.method(HttpMethod.GET)
|
||||
.send();
|
||||
assertThat("HTTP Response Status", response.getStatus(), is(HttpStatus.OK_200));
|
||||
|
||||
// dumpResponseHeaders(response);
|
||||
|
||||
// test response content
|
||||
String responseBody = response.getContentAsString();
|
||||
assertThat("Response Content", responseBody, containsString("test1"));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,97 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2019 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.embedded;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.Map;
|
||||
|
||||
import org.eclipse.jetty.client.api.ContentResponse;
|
||||
import org.eclipse.jetty.http.HttpMethod;
|
||||
import org.eclipse.jetty.http.HttpStatus;
|
||||
import org.eclipse.jetty.server.Server;
|
||||
import org.eclipse.jetty.util.component.LifeCycle;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.junit.jupiter.api.Assumptions.assumeTrue;
|
||||
|
||||
public class LikeJettyXmlTest extends AbstractEmbeddedTest
|
||||
{
|
||||
private Server server;
|
||||
private URI serverPlainUri;
|
||||
private URI serverSslUri;
|
||||
|
||||
@BeforeEach
|
||||
public void startServer() throws Exception
|
||||
{
|
||||
assumeTrue(JettyDistribution.DISTRIBUTION != null, "jetty-distribution not found");
|
||||
|
||||
server = LikeJettyXml.createServer(0, 0, false);
|
||||
server.start();
|
||||
|
||||
Map<String, Integer> ports = ServerUtil.fixDynamicPortConfigurations(server);
|
||||
|
||||
// Establish base URI's that use "localhost" to prevent tripping over
|
||||
// the "REMOTE ACCESS" warnings in demo-base
|
||||
serverPlainUri = URI.create("http://localhost:" + ports.get("plain") + "/");
|
||||
serverSslUri = URI.create("https://localhost:" + ports.get("secure") + "/");
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
public void stopServer() throws Exception
|
||||
{
|
||||
LifeCycle.stop(server);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetTest() throws Exception
|
||||
{
|
||||
URI uri = serverPlainUri.resolve("/test/");
|
||||
ContentResponse response = client.newRequest(uri)
|
||||
.method(HttpMethod.GET)
|
||||
.send();
|
||||
assertThat("HTTP Response Status", response.getStatus(), is(HttpStatus.OK_200));
|
||||
|
||||
// dumpResponseHeaders(response);
|
||||
|
||||
// test response content
|
||||
String responseBody = response.getContentAsString();
|
||||
assertThat("Response Content", responseBody, containsString("Hello"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetTestSsl() throws Exception
|
||||
{
|
||||
URI uri = serverSslUri.resolve("/test/");
|
||||
ContentResponse response = client.newRequest(uri)
|
||||
.method(HttpMethod.GET)
|
||||
.send();
|
||||
assertThat("HTTP Response Status", response.getStatus(), is(HttpStatus.OK_200));
|
||||
|
||||
// dumpResponseHeaders(response);
|
||||
|
||||
// test response content
|
||||
String responseBody = response.getContentAsString();
|
||||
assertThat("Response Content", responseBody, containsString("Hello"));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,95 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2019 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.embedded;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.Map;
|
||||
|
||||
import org.eclipse.jetty.client.api.ContentResponse;
|
||||
import org.eclipse.jetty.http.HttpMethod;
|
||||
import org.eclipse.jetty.http.HttpStatus;
|
||||
import org.eclipse.jetty.server.Server;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
|
||||
public class ManyConnectorsTest extends AbstractEmbeddedTest
|
||||
{
|
||||
private Server server;
|
||||
private URI serverPlainUri;
|
||||
private URI serverSslUri;
|
||||
|
||||
@BeforeEach
|
||||
public void startServer() throws Exception
|
||||
{
|
||||
server = ManyConnectors.createServer(0, 0);
|
||||
server.start();
|
||||
|
||||
Map<String, Integer> ports = ServerUtil.fixDynamicPortConfigurations(server);
|
||||
|
||||
// Establish base URI's that use "localhost" to prevent tripping over
|
||||
// the "REMOTE ACCESS" warnings in demo-base
|
||||
serverPlainUri = URI.create("http://localhost:" + ports.get("plain") + "/");
|
||||
serverSslUri = URI.create("https://localhost:" + ports.get("secure") + "/");
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
public void stopServer() throws Exception
|
||||
{
|
||||
server.stop();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPlainGetHello() throws Exception
|
||||
{
|
||||
URI uri = serverPlainUri.resolve("/hello");
|
||||
|
||||
ContentResponse response = client.newRequest(uri)
|
||||
.method(HttpMethod.GET)
|
||||
.send();
|
||||
assertThat("HTTP Response Status", response.getStatus(), is(HttpStatus.OK_200));
|
||||
|
||||
// dumpResponseHeaders(response);
|
||||
|
||||
// test response content
|
||||
String responseBody = response.getContentAsString();
|
||||
assertThat("Response Content", responseBody, containsString("Hello"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSecureGetHello() throws Exception
|
||||
{
|
||||
URI uri = serverSslUri.resolve("/hello");
|
||||
|
||||
ContentResponse response = client.newRequest(uri)
|
||||
.method(HttpMethod.GET)
|
||||
.send();
|
||||
assertThat("HTTP Response Status", response.getStatus(), is(HttpStatus.OK_200));
|
||||
|
||||
// dumpResponseHeaders(response);
|
||||
|
||||
// test response content
|
||||
String responseBody = response.getContentAsString();
|
||||
assertThat("Response Content", responseBody, containsString("Hello"));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,117 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2019 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.embedded;
|
||||
|
||||
import java.net.URI;
|
||||
|
||||
import org.eclipse.jetty.client.api.ContentResponse;
|
||||
import org.eclipse.jetty.http.HttpMethod;
|
||||
import org.eclipse.jetty.http.HttpStatus;
|
||||
import org.eclipse.jetty.server.Server;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
|
||||
public class ManyContextsTest extends AbstractEmbeddedTest
|
||||
{
|
||||
private Server server;
|
||||
|
||||
@BeforeEach
|
||||
public void startServer() throws Exception
|
||||
{
|
||||
server = ManyContexts.createServer(0);
|
||||
server.start();
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
public void stopServer() throws Exception
|
||||
{
|
||||
server.stop();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetRootHello() throws Exception
|
||||
{
|
||||
URI uri = server.getURI().resolve("/");
|
||||
ContentResponse response = client.newRequest(uri)
|
||||
.method(HttpMethod.GET)
|
||||
.send();
|
||||
assertThat("HTTP Response Status", response.getStatus(), is(HttpStatus.OK_200));
|
||||
|
||||
// dumpResponseHeaders(response);
|
||||
|
||||
// test response content
|
||||
String responseBody = response.getContentAsString();
|
||||
assertThat("Response Content", responseBody, containsString("Root Hello"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetFrenchHello() throws Exception
|
||||
{
|
||||
URI uri = server.getURI().resolve("/fr");
|
||||
ContentResponse response = client.newRequest(uri)
|
||||
.method(HttpMethod.GET)
|
||||
.send();
|
||||
assertThat("HTTP Response Status", response.getStatus(), is(HttpStatus.OK_200));
|
||||
|
||||
// dumpResponseHeaders(response);
|
||||
|
||||
// test response content
|
||||
String responseBody = response.getContentAsString();
|
||||
assertThat("Response Content", responseBody, containsString("Bonjour"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetItalianGoodMorning() throws Exception
|
||||
{
|
||||
URI uri = server.getURI().resolve("/it");
|
||||
ContentResponse response = client.newRequest(uri)
|
||||
.method(HttpMethod.GET)
|
||||
.send();
|
||||
assertThat("HTTP Response Status", response.getStatus(), is(HttpStatus.OK_200));
|
||||
|
||||
// dumpResponseHeaders(response);
|
||||
|
||||
// test response content
|
||||
String responseBody = response.getContentAsString();
|
||||
assertThat("Response Content", responseBody, containsString("Buongiorno"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetVirtualHostHello() throws Exception
|
||||
{
|
||||
int port = server.getURI().getPort();
|
||||
|
||||
URI uri = URI.create("http://127.0.0.2:" + port + "/");
|
||||
ContentResponse response = client.newRequest(uri)
|
||||
.method(HttpMethod.GET)
|
||||
.send();
|
||||
assertThat("HTTP Response Status", response.getStatus(), is(HttpStatus.OK_200));
|
||||
|
||||
// dumpResponseHeaders(response);
|
||||
|
||||
// test response content
|
||||
String responseBody = response.getContentAsString();
|
||||
assertThat("Response Content", responseBody, containsString("Virtual Hello"));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,105 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2019 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.embedded;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.Map;
|
||||
|
||||
import org.eclipse.jetty.client.api.ContentResponse;
|
||||
import org.eclipse.jetty.http.HttpHeader;
|
||||
import org.eclipse.jetty.http.HttpMethod;
|
||||
import org.eclipse.jetty.http.HttpStatus;
|
||||
import org.eclipse.jetty.server.Server;
|
||||
import org.eclipse.jetty.util.ajax.JSON;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
|
||||
public class ManyHandlersTest extends AbstractEmbeddedTest
|
||||
{
|
||||
private Server server;
|
||||
|
||||
@BeforeEach
|
||||
public void startServer() throws Exception
|
||||
{
|
||||
server = ManyHandlers.createServer(0);
|
||||
server.start();
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
public void stopServer() throws Exception
|
||||
{
|
||||
server.stop();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetParams() throws Exception
|
||||
{
|
||||
URI uri = server.getURI().resolve("/params?a=b&foo=bar");
|
||||
|
||||
ContentResponse response = client.newRequest(uri)
|
||||
.method(HttpMethod.GET)
|
||||
.header(HttpHeader.ACCEPT_ENCODING, "gzip")
|
||||
.send();
|
||||
assertThat("HTTP Response Status", response.getStatus(), is(HttpStatus.OK_200));
|
||||
|
||||
// dumpResponseHeaders(response);
|
||||
|
||||
// test gzip
|
||||
// Test that Gzip was used to produce the response
|
||||
String contentEncoding = response.getHeaders().get(HttpHeader.CONTENT_ENCODING);
|
||||
assertThat("Content-Encoding", contentEncoding, containsString("gzip"));
|
||||
|
||||
// test response content
|
||||
String responseBody = response.getContentAsString();
|
||||
Object jsonObj = JSON.parse(responseBody);
|
||||
Map jsonMap = (Map)jsonObj;
|
||||
assertThat("Response JSON keys.size", jsonMap.keySet().size(), is(2));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetHello() throws Exception
|
||||
{
|
||||
URI uri = server.getURI().resolve("/hello");
|
||||
ContentResponse response = client.newRequest(uri)
|
||||
.method(HttpMethod.GET)
|
||||
.header(HttpHeader.ACCEPT_ENCODING, "gzip")
|
||||
.send();
|
||||
assertThat("HTTP Response Status", response.getStatus(), is(HttpStatus.OK_200));
|
||||
|
||||
// dumpResponseHeaders(response);
|
||||
|
||||
// test gzip
|
||||
// Test that Gzip was used to produce the response
|
||||
String contentEncoding = response.getHeaders().get(HttpHeader.CONTENT_ENCODING);
|
||||
assertThat("Content-Encoding", contentEncoding, containsString("gzip"));
|
||||
|
||||
// test expected header from wrapper
|
||||
String welcome = response.getHeaders().get("X-Welcome");
|
||||
assertThat("X-Welcome header", welcome, containsString("Greetings from WelcomeWrapHandler"));
|
||||
|
||||
// test response content
|
||||
String responseBody = response.getContentAsString();
|
||||
assertThat("Response Content", responseBody, containsString("Hello"));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,115 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2019 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.embedded;
|
||||
|
||||
import java.net.URI;
|
||||
|
||||
import org.eclipse.jetty.client.api.ContentResponse;
|
||||
import org.eclipse.jetty.http.HttpMethod;
|
||||
import org.eclipse.jetty.http.HttpStatus;
|
||||
import org.eclipse.jetty.server.Server;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
|
||||
public class ManyServletContextsTest extends AbstractEmbeddedTest
|
||||
{
|
||||
private Server server;
|
||||
|
||||
@BeforeEach
|
||||
public void startServer() throws Exception
|
||||
{
|
||||
server = ManyServletContexts.createServer(0);
|
||||
server.start();
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
public void stopServer() throws Exception
|
||||
{
|
||||
server.stop();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetHello() throws Exception
|
||||
{
|
||||
URI uri = server.getURI().resolve("/hello");
|
||||
ContentResponse response = client.newRequest(uri)
|
||||
.method(HttpMethod.GET)
|
||||
.send();
|
||||
assertThat("HTTP Response Status", response.getStatus(), is(HttpStatus.OK_200));
|
||||
|
||||
// dumpResponseHeaders(response);
|
||||
|
||||
// test response content
|
||||
String responseBody = response.getContentAsString();
|
||||
assertThat("Response Content", responseBody, containsString("Hello"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetItalianHello() throws Exception
|
||||
{
|
||||
URI uri = server.getURI().resolve("/it/hello");
|
||||
ContentResponse response = client.newRequest(uri)
|
||||
.method(HttpMethod.GET)
|
||||
.send();
|
||||
assertThat("HTTP Response Status", response.getStatus(), is(HttpStatus.OK_200));
|
||||
|
||||
// dumpResponseHeaders(response);
|
||||
|
||||
// test response content
|
||||
String responseBody = response.getContentAsString();
|
||||
assertThat("Response Content", responseBody, containsString("Ciao"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetFrenchHello() throws Exception
|
||||
{
|
||||
URI uri = server.getURI().resolve("/fr/hello");
|
||||
ContentResponse response = client.newRequest(uri)
|
||||
.method(HttpMethod.GET)
|
||||
.send();
|
||||
assertThat("HTTP Response Status", response.getStatus(), is(HttpStatus.OK_200));
|
||||
|
||||
// dumpResponseHeaders(response);
|
||||
|
||||
// test response content
|
||||
String responseBody = response.getContentAsString();
|
||||
assertThat("Response Content", responseBody, containsString("Bonjour"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetOtherYo() throws Exception
|
||||
{
|
||||
URI uri = server.getURI().resolve("/other/hello.yo");
|
||||
ContentResponse response = client.newRequest(uri)
|
||||
.method(HttpMethod.GET)
|
||||
.send();
|
||||
assertThat("HTTP Response Status", response.getStatus(), is(HttpStatus.OK_200));
|
||||
|
||||
// dumpResponseHeaders(response);
|
||||
|
||||
// test response content
|
||||
String responseBody = response.getContentAsString();
|
||||
assertThat("Response Content", responseBody, containsString("YO!"));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,67 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2019 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.embedded;
|
||||
|
||||
import java.net.URI;
|
||||
|
||||
import org.eclipse.jetty.client.api.ContentResponse;
|
||||
import org.eclipse.jetty.http.HttpMethod;
|
||||
import org.eclipse.jetty.http.HttpStatus;
|
||||
import org.eclipse.jetty.server.Server;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
|
||||
public class MinimalServletsTest extends AbstractEmbeddedTest
|
||||
{
|
||||
private Server server;
|
||||
|
||||
@BeforeEach
|
||||
public void startServer() throws Exception
|
||||
{
|
||||
server = MinimalServlets.createServer(0);
|
||||
server.start();
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
public void stopServer() throws Exception
|
||||
{
|
||||
server.stop();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetHello() throws Exception
|
||||
{
|
||||
URI uri = server.getURI().resolve("/hello");
|
||||
ContentResponse response = client.newRequest(uri)
|
||||
.method(HttpMethod.GET)
|
||||
.send();
|
||||
assertThat("HTTP Response Status", response.getStatus(), is(HttpStatus.OK_200));
|
||||
|
||||
// dumpResponseHeaders(response);
|
||||
|
||||
// test response content
|
||||
String responseBody = response.getContentAsString();
|
||||
assertThat("Response Content", responseBody, containsString("Hello"));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,67 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2019 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.embedded;
|
||||
|
||||
import java.net.URI;
|
||||
|
||||
import org.eclipse.jetty.client.api.ContentResponse;
|
||||
import org.eclipse.jetty.http.HttpMethod;
|
||||
import org.eclipse.jetty.http.HttpStatus;
|
||||
import org.eclipse.jetty.server.Server;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
|
||||
public class OneConnectorTest extends AbstractEmbeddedTest
|
||||
{
|
||||
private Server server;
|
||||
|
||||
@BeforeEach
|
||||
public void startServer() throws Exception
|
||||
{
|
||||
server = OneConnector.createServer(0);
|
||||
server.start();
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
public void stopServer() throws Exception
|
||||
{
|
||||
server.stop();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetHello() throws Exception
|
||||
{
|
||||
URI uri = server.getURI().resolve("/hello");
|
||||
ContentResponse response = client.newRequest(uri)
|
||||
.method(HttpMethod.GET)
|
||||
.send();
|
||||
assertThat("HTTP Response Status", response.getStatus(), is(HttpStatus.OK_200));
|
||||
|
||||
// dumpResponseHeaders(response);
|
||||
|
||||
// test response content
|
||||
String responseBody = response.getContentAsString();
|
||||
assertThat("Response Content", responseBody, containsString("Hello"));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,67 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2019 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.embedded;
|
||||
|
||||
import java.net.URI;
|
||||
|
||||
import org.eclipse.jetty.client.api.ContentResponse;
|
||||
import org.eclipse.jetty.http.HttpMethod;
|
||||
import org.eclipse.jetty.http.HttpStatus;
|
||||
import org.eclipse.jetty.server.Server;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
|
||||
public class OneContextTest extends AbstractEmbeddedTest
|
||||
{
|
||||
private Server server;
|
||||
|
||||
@BeforeEach
|
||||
public void startServer() throws Exception
|
||||
{
|
||||
server = OneContext.createServer(0);
|
||||
server.start();
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
public void stopServer() throws Exception
|
||||
{
|
||||
server.stop();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetHello() throws Exception
|
||||
{
|
||||
URI uri = server.getURI().resolve("/hello");
|
||||
ContentResponse response = client.newRequest(uri)
|
||||
.method(HttpMethod.GET)
|
||||
.send();
|
||||
assertThat("HTTP Response Status", response.getStatus(), is(HttpStatus.OK_200));
|
||||
|
||||
// dumpResponseHeaders(response);
|
||||
|
||||
// test response content
|
||||
String responseBody = response.getContentAsString();
|
||||
assertThat("Response Content", responseBody, containsString("Hello"));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,67 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2019 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.embedded;
|
||||
|
||||
import java.net.URI;
|
||||
|
||||
import org.eclipse.jetty.client.api.ContentResponse;
|
||||
import org.eclipse.jetty.http.HttpMethod;
|
||||
import org.eclipse.jetty.http.HttpStatus;
|
||||
import org.eclipse.jetty.server.Server;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
|
||||
public class OneHandlerTest extends AbstractEmbeddedTest
|
||||
{
|
||||
private Server server;
|
||||
|
||||
@BeforeEach
|
||||
public void startServer() throws Exception
|
||||
{
|
||||
server = OneHandler.createServer(0);
|
||||
server.start();
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
public void stopServer() throws Exception
|
||||
{
|
||||
server.stop();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetHello() throws Exception
|
||||
{
|
||||
URI uri = server.getURI().resolve("/hello");
|
||||
ContentResponse response = client.newRequest(uri)
|
||||
.method(HttpMethod.GET)
|
||||
.send();
|
||||
assertThat("HTTP Response Status", response.getStatus(), is(HttpStatus.OK_200));
|
||||
|
||||
// dumpResponseHeaders(response);
|
||||
|
||||
// test response content
|
||||
String responseBody = response.getContentAsString();
|
||||
assertThat("Response Content", responseBody, containsString("Hello"));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,101 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2019 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.embedded;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.Set;
|
||||
import javax.management.MBeanServer;
|
||||
import javax.management.ObjectInstance;
|
||||
import javax.management.ObjectName;
|
||||
|
||||
import org.eclipse.jetty.client.api.ContentResponse;
|
||||
import org.eclipse.jetty.http.HttpMethod;
|
||||
import org.eclipse.jetty.http.HttpStatus;
|
||||
import org.eclipse.jetty.io.ConnectionStatistics;
|
||||
import org.eclipse.jetty.jmx.MBeanContainer;
|
||||
import org.eclipse.jetty.server.Server;
|
||||
import org.eclipse.jetty.toolchain.test.jupiter.WorkDirExtension;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.opentest4j.AssertionFailedError;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.allOf;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.greaterThanOrEqualTo;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.notNullValue;
|
||||
|
||||
@ExtendWith(WorkDirExtension.class)
|
||||
public class OneServletContextJmxStatsTest extends AbstractEmbeddedTest
|
||||
{
|
||||
private Server server;
|
||||
|
||||
@BeforeEach
|
||||
public void startServer() throws Exception
|
||||
{
|
||||
server = OneServletContextJmxStats.createServer(0);
|
||||
server.start();
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
public void stopServer() throws Exception
|
||||
{
|
||||
server.stop();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetDumpViaPathInfo() throws Exception
|
||||
{
|
||||
URI uri = server.getURI().resolve("/dump/something");
|
||||
ContentResponse response = client.newRequest(uri)
|
||||
.method(HttpMethod.GET)
|
||||
.send();
|
||||
assertThat("HTTP Response Status", response.getStatus(), is(HttpStatus.OK_200));
|
||||
|
||||
// dumpResponseHeaders(response);
|
||||
|
||||
// test response content
|
||||
String responseBody = response.getContentAsString();
|
||||
assertThat("Response Content", responseBody,
|
||||
allOf(
|
||||
containsString("DumpServlet"),
|
||||
containsString("servletPath=/dump"),
|
||||
containsString("pathInfo=/something")
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testJmxConnectStatsPresent() throws Exception
|
||||
{
|
||||
MBeanContainer mbeanContainer = server.getBean(MBeanContainer.class);
|
||||
MBeanServer mbeanServer = mbeanContainer.getMBeanServer();
|
||||
|
||||
String domain = ConnectionStatistics.class.getPackage().getName();
|
||||
Set<ObjectName> mbeanNames = mbeanServer.queryNames(ObjectName.getInstance(domain + ":type=connectionstatistics,*"), null);
|
||||
ObjectName connStatsName = mbeanNames.stream().findFirst().orElseThrow(AssertionFailedError::new);
|
||||
ObjectInstance mbeanConnStats = mbeanServer.getObjectInstance(connStatsName);
|
||||
Number connections = (Number)mbeanServer.getAttribute(connStatsName, "connections");
|
||||
assertThat("stats[connections]", connections, is(notNullValue()));
|
||||
assertThat("stats[connections]", connections.longValue(), greaterThanOrEqualTo(0L));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,158 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2019 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.embedded;
|
||||
|
||||
import java.io.BufferedWriter;
|
||||
import java.net.URI;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
|
||||
import org.eclipse.jetty.client.api.ContentResponse;
|
||||
import org.eclipse.jetty.http.HttpMethod;
|
||||
import org.eclipse.jetty.http.HttpStatus;
|
||||
import org.eclipse.jetty.server.Server;
|
||||
import org.eclipse.jetty.toolchain.test.jupiter.WorkDir;
|
||||
import org.eclipse.jetty.toolchain.test.jupiter.WorkDirExtension;
|
||||
import org.eclipse.jetty.util.resource.PathResource;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
|
||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.allOf;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
|
||||
@ExtendWith(WorkDirExtension.class)
|
||||
public class OneServletContextTest extends AbstractEmbeddedTest
|
||||
{
|
||||
private static final String TEXT_CONTENT = "The secret of getting ahead is getting started. - Mark Twain";
|
||||
public WorkDir workDir;
|
||||
private Server server;
|
||||
|
||||
@BeforeEach
|
||||
public void startServer() throws Exception
|
||||
{
|
||||
Path baseDir = workDir.getEmptyPathDir();
|
||||
|
||||
Path textFile = baseDir.resolve("simple.txt");
|
||||
try (BufferedWriter writer = Files.newBufferedWriter(textFile, UTF_8))
|
||||
{
|
||||
writer.write(TEXT_CONTENT);
|
||||
}
|
||||
|
||||
server = OneServletContext.createServer(0, new PathResource(baseDir));
|
||||
server.start();
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
public void stopServer() throws Exception
|
||||
{
|
||||
server.stop();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetHello() throws Exception
|
||||
{
|
||||
URI uri = server.getURI().resolve("/hello/there");
|
||||
ContentResponse response = client.newRequest(uri)
|
||||
.method(HttpMethod.GET)
|
||||
.send();
|
||||
assertThat("HTTP Response Status", response.getStatus(), is(HttpStatus.OK_200));
|
||||
|
||||
// dumpResponseHeaders(response);
|
||||
|
||||
// test response content
|
||||
String responseBody = response.getContentAsString();
|
||||
assertThat("Response Content", responseBody, containsString("Hello"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetDumpViaPathInfo() throws Exception
|
||||
{
|
||||
URI uri = server.getURI().resolve("/dump/something");
|
||||
ContentResponse response = client.newRequest(uri)
|
||||
.method(HttpMethod.GET)
|
||||
.send();
|
||||
assertThat("HTTP Response Status", response.getStatus(), is(HttpStatus.OK_200));
|
||||
|
||||
// dumpResponseHeaders(response);
|
||||
|
||||
// test response content
|
||||
String responseBody = response.getContentAsString();
|
||||
assertThat("Response Content", responseBody,
|
||||
allOf(
|
||||
containsString("DumpServlet"),
|
||||
containsString("servletPath=/dump"),
|
||||
containsString("pathInfo=/something")
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetDumpSuffix() throws Exception
|
||||
{
|
||||
URI uri = server.getURI().resolve("/another.dump");
|
||||
ContentResponse response = client.newRequest(uri)
|
||||
.method(HttpMethod.GET)
|
||||
.send();
|
||||
assertThat("HTTP Response Status", response.getStatus(), is(HttpStatus.OK_200));
|
||||
|
||||
// dumpResponseHeaders(response);
|
||||
|
||||
// test response content
|
||||
String responseBody = response.getContentAsString();
|
||||
assertThat("Response Content", responseBody,
|
||||
allOf(
|
||||
containsString("DumpServlet"),
|
||||
containsString("servletPath=/another.dump"),
|
||||
containsString("pathInfo=null")
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetTestDumpSuffix() throws Exception
|
||||
{
|
||||
URI uri = server.getURI().resolve("/test/another.dump");
|
||||
ContentResponse response = client.newRequest(uri)
|
||||
.method(HttpMethod.GET)
|
||||
.send();
|
||||
assertThat("HTTP Response Status", response.getStatus(), is(HttpStatus.OK_200));
|
||||
|
||||
// dumpResponseHeaders(response);
|
||||
|
||||
String filterResponseHeader = response.getHeaders().get("X-TestFilter");
|
||||
assertThat("X-TestFilter header", filterResponseHeader, is("true"));
|
||||
|
||||
// test response content
|
||||
String responseBody = response.getContentAsString();
|
||||
assertThat("Response Content", responseBody,
|
||||
allOf(
|
||||
containsString("DumpServlet"),
|
||||
containsString("servletPath=/test/another.dump"),
|
||||
containsString("pathInfo=null"),
|
||||
containsString("request.attribute[X-ReqListener]=true"),
|
||||
containsString("servletContext.attribute[X-Init]=true")
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,95 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2019 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.embedded;
|
||||
|
||||
import java.io.BufferedWriter;
|
||||
import java.net.URI;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
|
||||
import org.eclipse.jetty.client.api.ContentResponse;
|
||||
import org.eclipse.jetty.http.HttpHeader;
|
||||
import org.eclipse.jetty.http.HttpMethod;
|
||||
import org.eclipse.jetty.http.HttpStatus;
|
||||
import org.eclipse.jetty.server.Server;
|
||||
import org.eclipse.jetty.toolchain.test.jupiter.WorkDir;
|
||||
import org.eclipse.jetty.toolchain.test.jupiter.WorkDirExtension;
|
||||
import org.eclipse.jetty.util.resource.PathResource;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
|
||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.allOf;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
|
||||
@ExtendWith(WorkDirExtension.class)
|
||||
public class OneServletContextWithSessionTest extends AbstractEmbeddedTest
|
||||
{
|
||||
private static final String TEXT_CONTENT = "Do the right thing. It will gratify some people and astonish the rest. - Mark Twain";
|
||||
public WorkDir workDir;
|
||||
private Server server;
|
||||
|
||||
@BeforeEach
|
||||
public void startServer() throws Exception
|
||||
{
|
||||
Path baseDir = workDir.getEmptyPathDir();
|
||||
|
||||
Path textFile = baseDir.resolve("simple.txt");
|
||||
try (BufferedWriter writer = Files.newBufferedWriter(textFile, UTF_8))
|
||||
{
|
||||
writer.write(TEXT_CONTENT);
|
||||
}
|
||||
|
||||
server = OneServletContextWithSession.createServer(0, new PathResource(baseDir));
|
||||
server.start();
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
public void stopServer() throws Exception
|
||||
{
|
||||
server.stop();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetHello() throws Exception
|
||||
{
|
||||
URI uri = server.getURI().resolve("/");
|
||||
ContentResponse response = client.newRequest(uri)
|
||||
.method(HttpMethod.GET)
|
||||
.send();
|
||||
assertThat("HTTP Response Status", response.getStatus(), is(HttpStatus.OK_200));
|
||||
|
||||
// dumpResponseHeaders(response);
|
||||
String setCookieValue = response.getHeaders().get(HttpHeader.SET_COOKIE);
|
||||
assertThat("Set-Cookie value", setCookieValue, containsString("JSESSIONID="));
|
||||
|
||||
// test response content
|
||||
String responseBody = response.getContentAsString();
|
||||
assertThat("Response Content", responseBody,
|
||||
allOf(
|
||||
containsString("session.getId() = "),
|
||||
containsString("session.isNew() = true")
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,71 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2019 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.embedded;
|
||||
|
||||
import java.net.URI;
|
||||
|
||||
import org.eclipse.jetty.client.api.ContentResponse;
|
||||
import org.eclipse.jetty.http.HttpMethod;
|
||||
import org.eclipse.jetty.http.HttpStatus;
|
||||
import org.eclipse.jetty.server.Server;
|
||||
import org.eclipse.jetty.util.component.LifeCycle;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.junit.jupiter.api.Assumptions.assumeTrue;
|
||||
|
||||
public class OneWebAppTest extends AbstractEmbeddedTest
|
||||
{
|
||||
private Server server;
|
||||
|
||||
@BeforeEach
|
||||
public void startServer() throws Exception
|
||||
{
|
||||
assumeTrue(JettyDistribution.DISTRIBUTION != null, "jetty-distribution not found");
|
||||
|
||||
server = OneWebApp.createServer(0);
|
||||
server.start();
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
public void stopServer() throws Exception
|
||||
{
|
||||
LifeCycle.stop(server);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetAsyncRest() throws Exception
|
||||
{
|
||||
URI uri = server.getURI().resolve("/testAsync?items=mouse,beer,gnome");
|
||||
ContentResponse response = client.newRequest(uri)
|
||||
.method(HttpMethod.GET)
|
||||
.send();
|
||||
assertThat("HTTP Response Status", response.getStatus(), is(HttpStatus.OK_200));
|
||||
|
||||
// dumpResponseHeaders(response);
|
||||
|
||||
// test response content
|
||||
String responseBody = response.getContentAsString();
|
||||
assertThat("Response Content", responseBody, containsString("Asynchronous: mouse,beer,gnome"));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,112 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2019 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.embedded;
|
||||
|
||||
import java.net.URI;
|
||||
|
||||
import org.eclipse.jetty.client.api.ContentResponse;
|
||||
import org.eclipse.jetty.http.HttpMethod;
|
||||
import org.eclipse.jetty.http.HttpStatus;
|
||||
import org.eclipse.jetty.server.Server;
|
||||
import org.eclipse.jetty.util.component.LifeCycle;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.junit.jupiter.api.Assumptions.assumeTrue;
|
||||
|
||||
public class OneWebAppWithJspTest extends AbstractEmbeddedTest
|
||||
{
|
||||
private Server server;
|
||||
private URI serverLocalUri;
|
||||
|
||||
@BeforeEach
|
||||
public void startServer() throws Exception
|
||||
{
|
||||
assumeTrue(JettyDistribution.DISTRIBUTION != null, "jetty-distribution not found");
|
||||
|
||||
server = OneWebAppWithJsp.createServer(0);
|
||||
server.start();
|
||||
|
||||
// Use URI based on "localhost" to get past "REMOTE ACCESS!" protection of demo war
|
||||
serverLocalUri = URI.create("http://localhost:" + server.getURI().getPort() + "/");
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
public void stopServer() throws Exception
|
||||
{
|
||||
LifeCycle.stop(server);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetDumpInfo() throws Exception
|
||||
{
|
||||
URI uri = serverLocalUri.resolve("/dump/info");
|
||||
ContentResponse response = client.newRequest(uri)
|
||||
.method(HttpMethod.GET)
|
||||
.send();
|
||||
assertThat("HTTP Response Status", response.getStatus(), is(HttpStatus.OK_200));
|
||||
|
||||
// dumpResponseHeaders(response);
|
||||
|
||||
// test response content
|
||||
String responseBody = response.getContentAsString();
|
||||
assertThat("Response Content", responseBody, containsString("getProtocol: </th><td>HTTP/1.1"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetJspExpr() throws Exception
|
||||
{
|
||||
URI uri = serverLocalUri.resolve("/jsp/expr.jsp?A=1");
|
||||
ContentResponse response = client.newRequest(uri)
|
||||
.method(HttpMethod.GET)
|
||||
.send();
|
||||
assertThat("HTTP Response Status", response.getStatus(), is(HttpStatus.OK_200));
|
||||
|
||||
// dumpResponseHeaders(response);
|
||||
|
||||
// test response content
|
||||
String responseBody = response.getContentAsString();
|
||||
String userAgent = client.getUserAgentField().getValue();
|
||||
assertThat("Response Content", responseBody, containsString("<td>" + userAgent + "</td>"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetJstlExpr() throws Exception
|
||||
{
|
||||
URI uri = serverLocalUri.resolve("/jsp/jstl.jsp");
|
||||
ContentResponse response = client.newRequest(uri)
|
||||
.method(HttpMethod.GET)
|
||||
.send();
|
||||
assertThat("HTTP Response Status", response.getStatus(), is(HttpStatus.OK_200));
|
||||
|
||||
// dumpResponseHeaders(response);
|
||||
|
||||
// test response content
|
||||
String responseBody = response.getContentAsString();
|
||||
assertThat("Response Content", responseBody, containsString("<h1>JSTL Example</h1>"));
|
||||
for (int i = 1; i <= 10; i++)
|
||||
{
|
||||
assertThat("Reponse content (counting)", responseBody, containsString("" + i));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,72 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2019 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.embedded;
|
||||
|
||||
import java.net.URI;
|
||||
|
||||
import org.eclipse.jetty.client.HttpProxy;
|
||||
import org.eclipse.jetty.client.api.ContentResponse;
|
||||
import org.eclipse.jetty.http.HttpMethod;
|
||||
import org.eclipse.jetty.http.HttpStatus;
|
||||
import org.eclipse.jetty.server.Server;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
|
||||
public class ProxyServerTest extends AbstractEmbeddedTest
|
||||
{
|
||||
private Server server;
|
||||
|
||||
@BeforeEach
|
||||
public void startServer() throws Exception
|
||||
{
|
||||
server = ProxyServer.createServer(0);
|
||||
server.start();
|
||||
|
||||
URI uri = server.getURI();
|
||||
client.getProxyConfiguration().getProxies().add(new HttpProxy("localhost", uri.getPort()));
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
public void stopServer() throws Exception
|
||||
{
|
||||
server.stop();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetProxiedRFC() throws Exception
|
||||
{
|
||||
URI uri = URI.create("https://tools.ietf.org/rfc/rfc7230.txt");
|
||||
|
||||
ContentResponse response = client.newRequest(uri)
|
||||
.method(HttpMethod.GET)
|
||||
.send();
|
||||
assertThat("HTTP Response Status", response.getStatus(), is(HttpStatus.OK_200));
|
||||
|
||||
// dumpResponseHeaders(response);
|
||||
|
||||
// test response content
|
||||
String responseBody = response.getContentAsString();
|
||||
assertThat("Response Content", responseBody, containsString("Hypertext Transfer Protocol (HTTP/1.1): Message Syntax and Routing"));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,83 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2019 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.embedded;
|
||||
|
||||
import java.net.URI;
|
||||
|
||||
import org.eclipse.jetty.client.api.ContentResponse;
|
||||
import org.eclipse.jetty.http.HttpMethod;
|
||||
import org.eclipse.jetty.http.HttpStatus;
|
||||
import org.eclipse.jetty.server.Server;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
|
||||
public class RewriteServerTest extends AbstractEmbeddedTest
|
||||
{
|
||||
private Server server;
|
||||
|
||||
@BeforeEach
|
||||
public void startServer() throws Exception
|
||||
{
|
||||
server = RewriteServer.createServer(0);
|
||||
server.start();
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
public void stopServer() throws Exception
|
||||
{
|
||||
server.stop();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetRewriteFooInName() throws Exception
|
||||
{
|
||||
URI uri = server.getURI().resolve("/do-be-foo-be-do");
|
||||
ContentResponse response = client.newRequest(uri)
|
||||
.method(HttpMethod.GET)
|
||||
.send();
|
||||
assertThat("HTTP Response Status", response.getStatus(), is(HttpStatus.OK_200));
|
||||
|
||||
// dumpResponseHeaders(response);
|
||||
|
||||
// test response content
|
||||
String responseBody = response.getContentAsString();
|
||||
assertThat("Response Content", responseBody, containsString("requestURI=/do-be-FOO-be-do"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetRewriteFooInPath() throws Exception
|
||||
{
|
||||
URI uri = server.getURI().resolve("/do/be/foo/be/do.it");
|
||||
ContentResponse response = client.newRequest(uri)
|
||||
.method(HttpMethod.GET)
|
||||
.send();
|
||||
assertThat("HTTP Response Status", response.getStatus(), is(HttpStatus.OK_200));
|
||||
|
||||
// dumpResponseHeaders(response);
|
||||
|
||||
// test response content
|
||||
String responseBody = response.getContentAsString();
|
||||
assertThat("Response Content", responseBody, containsString("requestURI=/do/be/FOO/be/do.it"));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,85 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2019 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.embedded;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.Base64;
|
||||
|
||||
import org.eclipse.jetty.client.api.ContentResponse;
|
||||
import org.eclipse.jetty.http.HttpHeader;
|
||||
import org.eclipse.jetty.http.HttpMethod;
|
||||
import org.eclipse.jetty.http.HttpStatus;
|
||||
import org.eclipse.jetty.server.Server;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
|
||||
public class SecuredHelloHandlerTest extends AbstractEmbeddedTest
|
||||
{
|
||||
private Server server;
|
||||
|
||||
@BeforeEach
|
||||
public void startServer() throws Exception
|
||||
{
|
||||
server = SecuredHelloHandler.createServer(0);
|
||||
server.start();
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
public void stopServer() throws Exception
|
||||
{
|
||||
server.stop();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetWithoutAuth() throws Exception
|
||||
{
|
||||
URI uri = server.getURI().resolve("/hello");
|
||||
ContentResponse response = client.newRequest(uri)
|
||||
.method(HttpMethod.GET)
|
||||
.send();
|
||||
assertThat("HTTP Response Status", response.getStatus(), is(HttpStatus.UNAUTHORIZED_401));
|
||||
|
||||
// dumpResponseHeaders(response);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetWithAuth() throws Exception
|
||||
{
|
||||
URI uri = server.getURI().resolve("/hello");
|
||||
|
||||
String authEncoded = Base64.getEncoder().encodeToString("user:password".getBytes(UTF_8));
|
||||
ContentResponse response = client.newRequest(uri)
|
||||
.method(HttpMethod.GET)
|
||||
.header(HttpHeader.AUTHORIZATION, "Basic " + authEncoded)
|
||||
.send();
|
||||
assertThat("HTTP Response Status", response.getStatus(), is(HttpStatus.OK_200));
|
||||
|
||||
// dumpResponseHeaders(response);
|
||||
|
||||
// test response content
|
||||
String responseBody = response.getContentAsString();
|
||||
assertThat("Response Content", responseBody, containsString("<h1>Hello World</h1>"));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,88 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2019 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.embedded;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.eclipse.jetty.server.Connector;
|
||||
import org.eclipse.jetty.server.HttpConfiguration;
|
||||
import org.eclipse.jetty.server.HttpConnectionFactory;
|
||||
import org.eclipse.jetty.server.Server;
|
||||
import org.eclipse.jetty.server.ServerConnector;
|
||||
import org.eclipse.jetty.server.SslConnectionFactory;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
|
||||
public class ServerUtil
|
||||
{
|
||||
/**
|
||||
* Fix the HttpConfiguration entries for securePort after the dynamic ports have been bound.
|
||||
*
|
||||
* @param server the server to correct.
|
||||
*/
|
||||
public static Map<String, Integer> fixDynamicPortConfigurations(Server server)
|
||||
{
|
||||
// Fix ports in HttpConfiguration (since we are using dynamic port assignment for this testcase)
|
||||
HttpConfiguration plainHttpConfiguration = null;
|
||||
HttpConfiguration secureHttpConfiguration = null;
|
||||
int plainHttpPort = -1;
|
||||
int secureHttpPort = -1;
|
||||
|
||||
for (Connector connector : server.getConnectors())
|
||||
{
|
||||
if (connector instanceof ServerConnector)
|
||||
{
|
||||
ServerConnector serverConnector = (ServerConnector)connector;
|
||||
SslConnectionFactory sslConnectionFactory = serverConnector.getConnectionFactory(SslConnectionFactory.class);
|
||||
HttpConnectionFactory httpConnectionFactory = serverConnector.getConnectionFactory(HttpConnectionFactory.class);
|
||||
if (httpConnectionFactory != null)
|
||||
{
|
||||
HttpConfiguration configuration = httpConnectionFactory.getHttpConfiguration();
|
||||
if (sslConnectionFactory != null)
|
||||
{
|
||||
secureHttpConfiguration = configuration;
|
||||
secureHttpPort = serverConnector.getLocalPort();
|
||||
}
|
||||
else
|
||||
{
|
||||
plainHttpConfiguration = configuration;
|
||||
plainHttpPort = serverConnector.getLocalPort();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
assertNotNull(plainHttpConfiguration, "Plain HTTP Configuration");
|
||||
assertNotEquals(plainHttpPort, -1, "Dynamic Plain HTTP Port");
|
||||
|
||||
assertNotNull(secureHttpConfiguration, "Secure HTTP Configuration");
|
||||
assertNotEquals(secureHttpPort, -1, "Dynamic Secure Port");
|
||||
|
||||
plainHttpConfiguration.setSecurePort(secureHttpPort);
|
||||
secureHttpConfiguration.setSecurePort(secureHttpPort);
|
||||
|
||||
Map<String, Integer> ports = new HashMap<>();
|
||||
ports.put("plain", plainHttpPort);
|
||||
ports.put("secure", secureHttpPort);
|
||||
|
||||
return ports;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,70 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2019 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.embedded;
|
||||
|
||||
import java.net.URI;
|
||||
|
||||
import org.eclipse.jetty.client.api.ContentResponse;
|
||||
import org.eclipse.jetty.http.HttpStatus;
|
||||
import org.eclipse.jetty.server.Server;
|
||||
import org.eclipse.jetty.util.component.LifeCycle;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.not;
|
||||
import static org.junit.jupiter.api.Assumptions.assumeTrue;
|
||||
|
||||
public class ServerWithAnnotationsTest extends AbstractEmbeddedTest
|
||||
{
|
||||
private Server server;
|
||||
|
||||
@BeforeEach
|
||||
public void startServer() throws Exception
|
||||
{
|
||||
assumeTrue(JettyDistribution.DISTRIBUTION != null, "jetty-distribution not found");
|
||||
|
||||
server = ServerWithAnnotations.createServer(0);
|
||||
server.start();
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
public void stopServer() throws Exception
|
||||
{
|
||||
LifeCycle.stop(server);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetTest() throws Exception
|
||||
{
|
||||
URI uri = server.getURI().resolve("/test");
|
||||
ContentResponse response = client.GET(uri);
|
||||
assertThat("HTTP Response Status", response.getStatus(), is(HttpStatus.OK_200));
|
||||
|
||||
// dumpResponseHeaders(response);
|
||||
|
||||
// test response content
|
||||
String responseBody = response.getContentAsString();
|
||||
assertThat("Response Content", responseBody, containsString("maxAmount=55.0"));
|
||||
assertThat("Response Content", responseBody, not(containsString("<span class=\"fail\">")));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,62 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2019 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.embedded;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import javax.management.MBeanServer;
|
||||
import javax.management.ObjectName;
|
||||
|
||||
import org.eclipse.jetty.jmx.MBeanContainer;
|
||||
import org.eclipse.jetty.server.Server;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
public class ServerWithJMXTest extends AbstractEmbeddedTest
|
||||
{
|
||||
private Server server;
|
||||
|
||||
@BeforeEach
|
||||
public void startServer() throws Exception
|
||||
{
|
||||
server = ServerWithJMX.createServer(0);
|
||||
server.start();
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
public void stopServer() throws Exception
|
||||
{
|
||||
server.stop();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetTest() throws Exception
|
||||
{
|
||||
MBeanContainer mbeanContainer = server.getBean(MBeanContainer.class);
|
||||
MBeanServer mbeanServer = mbeanContainer.getMBeanServer();
|
||||
|
||||
String name = "org.eclipse.jetty.jmx:name=rmiconnectorserver,*";
|
||||
Set<ObjectName> mbeanNames = mbeanServer.queryNames(ObjectName.getInstance(name), null);
|
||||
Optional<ObjectName> rmiConnectorNameOptional = mbeanNames.stream().findFirst();
|
||||
assertTrue(rmiConnectorNameOptional.isPresent(), "Has RMI Connector Server");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,78 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2019 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.embedded;
|
||||
|
||||
import java.net.URI;
|
||||
|
||||
import org.eclipse.jetty.client.api.ContentResponse;
|
||||
import org.eclipse.jetty.http.HttpStatus;
|
||||
import org.eclipse.jetty.server.Server;
|
||||
import org.eclipse.jetty.util.component.LifeCycle;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.allOf;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.not;
|
||||
import static org.junit.jupiter.api.Assumptions.assumeTrue;
|
||||
|
||||
public class ServerWithJNDITest extends AbstractEmbeddedTest
|
||||
{
|
||||
private Server server;
|
||||
|
||||
@BeforeEach
|
||||
public void startServer() throws Exception
|
||||
{
|
||||
assumeTrue(JettyDistribution.DISTRIBUTION != null, "jetty-distribution not found");
|
||||
|
||||
server = ServerWithJNDI.createServer(0);
|
||||
server.start();
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
public void stopServer() throws Exception
|
||||
{
|
||||
LifeCycle.stop(server);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetTest() throws Exception
|
||||
{
|
||||
URI uri = server.getURI().resolve("/test");
|
||||
ContentResponse response = client.GET(uri);
|
||||
assertThat("HTTP Response Status", response.getStatus(), is(HttpStatus.OK_200));
|
||||
|
||||
// dumpResponseHeaders(response);
|
||||
|
||||
// test response content
|
||||
String responseBody = response.getContentAsString();
|
||||
assertThat("Response Content", responseBody,
|
||||
allOf(
|
||||
containsString("java:comp/env/woggle"),
|
||||
containsString("java:comp/env/gargle"),
|
||||
containsString("java:comp/env/wiggle")
|
||||
)
|
||||
);
|
||||
|
||||
assertThat("Response Content", responseBody, not(containsString("<span class=\"fail\">")));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,57 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2019 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.embedded;
|
||||
|
||||
import java.net.URI;
|
||||
|
||||
import org.eclipse.jetty.client.api.ContentResponse;
|
||||
import org.eclipse.jetty.http.HttpStatus;
|
||||
import org.eclipse.jetty.server.Server;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
|
||||
public class SimplestServerTest extends AbstractEmbeddedTest
|
||||
{
|
||||
private Server server;
|
||||
|
||||
@BeforeEach
|
||||
public void startServer() throws Exception
|
||||
{
|
||||
server = SimplestServer.createServer(0);
|
||||
server.start();
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
public void stopServer() throws Exception
|
||||
{
|
||||
server.stop();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetTest() throws Exception
|
||||
{
|
||||
URI uri = server.getURI().resolve("/test");
|
||||
ContentResponse response = client.GET(uri);
|
||||
assertThat("HTTP Response Status", response.getStatus(), is(HttpStatus.NOT_FOUND_404));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,95 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2019 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.embedded;
|
||||
|
||||
import java.net.URI;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
|
||||
import org.eclipse.jetty.client.api.ContentResponse;
|
||||
import org.eclipse.jetty.http.HttpStatus;
|
||||
import org.eclipse.jetty.server.Server;
|
||||
import org.eclipse.jetty.util.resource.PathResource;
|
||||
import org.eclipse.jetty.util.resource.Resource;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
|
||||
public class SplitFileServerTest extends AbstractEmbeddedTest
|
||||
{
|
||||
private Server server;
|
||||
|
||||
@BeforeEach
|
||||
public void startServer() throws Exception
|
||||
{
|
||||
Path path0 = Paths.get("src/test/resources/dir0");
|
||||
Path path1 = Paths.get("src/test/resources/dir1");
|
||||
Resource resource0 = new PathResource(path0);
|
||||
Resource resource1 = new PathResource(path1);
|
||||
|
||||
server = SplitFileServer.createServer(0, resource0, resource1);
|
||||
server.start();
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
public void stopServer() throws Exception
|
||||
{
|
||||
server.stop();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetTest0() throws Exception
|
||||
{
|
||||
URI uri = server.getURI().resolve("/test0.txt");
|
||||
ContentResponse response = client.GET(uri);
|
||||
assertThat("HTTP Response Status", response.getStatus(), is(HttpStatus.OK_200));
|
||||
|
||||
// dumpResponseHeaders(response);
|
||||
|
||||
// test response content
|
||||
String responseBody = response.getContentAsString();
|
||||
assertThat("Response Content", responseBody, containsString("test0"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetTest1() throws Exception
|
||||
{
|
||||
URI uri = server.getURI().resolve("/test1.txt");
|
||||
ContentResponse response = client.GET(uri);
|
||||
assertThat("HTTP Response Status", response.getStatus(), is(HttpStatus.OK_200));
|
||||
|
||||
// dumpResponseHeaders(response);
|
||||
|
||||
// test response content
|
||||
String responseBody = response.getContentAsString();
|
||||
assertThat("Response Content", responseBody, containsString("test1"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetTest2() throws Exception
|
||||
{
|
||||
URI uri = server.getURI().resolve("/test2.txt");
|
||||
ContentResponse response = client.GET(uri);
|
||||
assertThat("HTTP Response Status", response.getStatus(), is(HttpStatus.NOT_FOUND_404));
|
||||
}
|
||||
}
|
|
@ -1,31 +0,0 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2019 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.embedded;
|
||||
|
||||
import org.eclipse.jetty.xml.XmlConfiguration;
|
||||
|
||||
public class TestXml
|
||||
{
|
||||
public static void main(String[] args) throws Exception
|
||||
{
|
||||
System.setProperty("jetty.home", "../jetty-distribution/target/distribution");
|
||||
XmlConfiguration.main("../jetty-jmx/src/main/config/etc/jetty-jmx.xml",
|
||||
"../jetty-server/src/main/config/etc/jetty.xml");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,110 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2019 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.embedded;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
import javax.websocket.CloseReason;
|
||||
import javax.websocket.ContainerProvider;
|
||||
import javax.websocket.Endpoint;
|
||||
import javax.websocket.EndpointConfig;
|
||||
import javax.websocket.MessageHandler;
|
||||
import javax.websocket.Session;
|
||||
import javax.websocket.WebSocketContainer;
|
||||
|
||||
import org.eclipse.jetty.server.Server;
|
||||
import org.eclipse.jetty.util.component.LifeCycle;
|
||||
import org.eclipse.jetty.websocket.api.util.WSURI;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static java.util.concurrent.TimeUnit.SECONDS;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
|
||||
public class WebSocketJsrServerTest
|
||||
{
|
||||
private Server server;
|
||||
|
||||
@BeforeEach
|
||||
public void startServer() throws Exception
|
||||
{
|
||||
server = WebSocketJsrServer.createServer(0);
|
||||
server.start();
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
public void stopServer() throws Exception
|
||||
{
|
||||
server.stop();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetEcho() throws Exception
|
||||
{
|
||||
WebSocketContainer javaxWebSocketClient = ContainerProvider.getWebSocketContainer();
|
||||
javaxWebSocketClient.setDefaultMaxSessionIdleTimeout(2000);
|
||||
try
|
||||
{
|
||||
URI wsUri = WSURI.toWebsocket(server.getURI().resolve("/echo"));
|
||||
|
||||
TrackingClientEndpoint clientEndpoint = new TrackingClientEndpoint();
|
||||
|
||||
Session session = javaxWebSocketClient.connectToServer(clientEndpoint, wsUri);
|
||||
session.getBasicRemote().sendText("Hello World");
|
||||
|
||||
String response = clientEndpoint.messages.poll(2, SECONDS);
|
||||
assertThat("Response", response, is("Hello World"));
|
||||
}
|
||||
finally
|
||||
{
|
||||
LifeCycle.stop(javaxWebSocketClient);
|
||||
}
|
||||
}
|
||||
|
||||
public static class TrackingClientEndpoint extends Endpoint implements MessageHandler.Whole<String>
|
||||
{
|
||||
public LinkedBlockingQueue<String> messages = new LinkedBlockingQueue<>();
|
||||
|
||||
@Override
|
||||
public void onMessage(String message)
|
||||
{
|
||||
messages.offer(message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onOpen(Session session, EndpointConfig config)
|
||||
{
|
||||
session.addMessageHandler(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Session session, Throwable thr)
|
||||
{
|
||||
super.onError(session, thr);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClose(Session session, CloseReason closeReason)
|
||||
{
|
||||
super.onClose(session, closeReason);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,111 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2019 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.embedded;
|
||||
|
||||
import java.net.URI;
|
||||
import java.time.Duration;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
|
||||
import org.eclipse.jetty.server.Server;
|
||||
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.api.annotations.OnWebSocketClose;
|
||||
import org.eclipse.jetty.websocket.api.annotations.OnWebSocketError;
|
||||
import org.eclipse.jetty.websocket.api.annotations.OnWebSocketMessage;
|
||||
import org.eclipse.jetty.websocket.api.annotations.WebSocket;
|
||||
import org.eclipse.jetty.websocket.api.util.WSURI;
|
||||
import org.eclipse.jetty.websocket.client.WebSocketClient;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static java.util.concurrent.TimeUnit.SECONDS;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
|
||||
public class WebSocketServerTest
|
||||
{
|
||||
private Server server;
|
||||
|
||||
@BeforeEach
|
||||
public void startServer() throws Exception
|
||||
{
|
||||
server = WebSocketServer.createServer(0);
|
||||
server.start();
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
public void stopServer() throws Exception
|
||||
{
|
||||
server.stop();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetEcho() throws Exception
|
||||
{
|
||||
WebSocketClient webSocketClient = new WebSocketClient();
|
||||
webSocketClient.setIdleTimeout(Duration.ofSeconds(2));
|
||||
try
|
||||
{
|
||||
webSocketClient.start();
|
||||
URI wsUri = WSURI.toWebsocket(server.getURI().resolve("/echo"));
|
||||
|
||||
TrackingClientEndpoint clientEndpoint = new TrackingClientEndpoint();
|
||||
|
||||
Future<Session> sessionFut = webSocketClient.connect(clientEndpoint, wsUri);
|
||||
Session session = sessionFut.get(2, SECONDS);
|
||||
session.getRemote().sendString("Hello World");
|
||||
|
||||
String response = clientEndpoint.messages.poll(2, SECONDS);
|
||||
assertThat("Response", response, is("Hello World"));
|
||||
}
|
||||
finally
|
||||
{
|
||||
LifeCycle.stop(webSocketClient);
|
||||
}
|
||||
}
|
||||
|
||||
@WebSocket
|
||||
public static class TrackingClientEndpoint
|
||||
{
|
||||
private static final Logger LOG = Log.getLogger(TrackingClientEndpoint.class);
|
||||
public LinkedBlockingQueue<String> messages = new LinkedBlockingQueue<>();
|
||||
|
||||
@OnWebSocketMessage
|
||||
public void onMessage(String message)
|
||||
{
|
||||
messages.offer(message);
|
||||
}
|
||||
|
||||
@OnWebSocketError
|
||||
public void onError(Throwable cause)
|
||||
{
|
||||
LOG.warn(cause);
|
||||
}
|
||||
|
||||
@OnWebSocketClose
|
||||
public void onClose(int statusCode, String reason)
|
||||
{
|
||||
LOG.debug("Closed({}, {})", statusCode, reason);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
org.eclipse.jetty.util.log.class=org.eclipse.jetty.util.log.StdErrLog
|
||||
org.eclipse.jetty.LEVEL=WARN
|
||||
org.eclipse.jetty.embedded.JettyDistribution.LEVEL=DEBUG
|
||||
#org.eclipse.jetty.STACKS=true
|
||||
#org.eclipse.jetty.STACKS=false
|
||||
#org.eclipse.jetty.io.LEVEL=DEBUG
|
||||
#org.eclipse.jetty.io.ssl.LEVEL=DEBUG
|
||||
#org.eclipse.jetty.server.LEVEL=DEBUG
|
||||
#org.eclipse.jetty.servlets.LEVEL=DEBUG
|
||||
#org.eclipse.jetty.alpn.LEVEL=DEBUG
|
||||
#org.eclipse.jetty.jmx.LEVEL=DEBUG
|
|
@ -36,9 +36,9 @@
|
|||
</Arg>
|
||||
</Call> -->
|
||||
|
||||
<Call id="webappprovider" name="addAppProvider">
|
||||
<Call name="addAppProvider">
|
||||
<Arg>
|
||||
<New class="org.eclipse.jetty.deploy.providers.WebAppProvider">
|
||||
<New id="webappprovider" class="org.eclipse.jetty.deploy.providers.WebAppProvider">
|
||||
<Set name="monitoredDirName">
|
||||
<Property>
|
||||
<Name>jetty.deploy.monitoredPath</Name>
|
||||
|
|
|
@ -172,7 +172,7 @@ public class DeploymentManager extends ContainerLifeCycle
|
|||
for (AppProvider provider : providers)
|
||||
{
|
||||
if (_providers.add(provider))
|
||||
addBean(provider);
|
||||
addBean(provider, true);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -186,7 +186,7 @@ public class DeploymentManager extends ContainerLifeCycle
|
|||
if (isRunning())
|
||||
throw new IllegalStateException();
|
||||
_providers.add(provider);
|
||||
addBean(provider);
|
||||
addBean(provider, true);
|
||||
}
|
||||
|
||||
public void setLifeCycleBindings(Collection<AppLifeCycle.Binding> bindings)
|
||||
|
@ -523,6 +523,7 @@ public class DeploymentManager extends ContainerLifeCycle
|
|||
catch (Throwable t)
|
||||
{
|
||||
LOG.warn("Unable to reach node goal: " + nodeName, t);
|
||||
|
||||
// migrate to FAILED node
|
||||
Node failed = _lifecycle.getNodeByName(AppLifeCycle.FAILED);
|
||||
appentry.setLifeCycleNode(failed);
|
||||
|
|
|
@ -20,7 +20,6 @@ package org.eclipse.jetty.deploy;
|
|||
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.net.MalformedURLException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
@ -29,6 +28,7 @@ import org.eclipse.jetty.util.annotation.ManagedAttribute;
|
|||
import org.eclipse.jetty.util.annotation.ManagedObject;
|
||||
import org.eclipse.jetty.util.annotation.ManagedOperation;
|
||||
import org.eclipse.jetty.util.annotation.Name;
|
||||
import org.eclipse.jetty.util.component.Dumpable;
|
||||
import org.eclipse.jetty.util.resource.Resource;
|
||||
|
||||
/**
|
||||
|
@ -37,21 +37,33 @@ import org.eclipse.jetty.util.resource.Resource;
|
|||
* Supplies properties defined in a file.
|
||||
*/
|
||||
@ManagedObject("Configure deployed webapps via properties")
|
||||
public class PropertiesConfigurationManager implements ConfigurationManager
|
||||
public class PropertiesConfigurationManager implements ConfigurationManager, Dumpable
|
||||
{
|
||||
private String _properties;
|
||||
private final Map<String, String> _map = new HashMap<String, String>();
|
||||
private final Map<String, String> _map = new HashMap<>();
|
||||
|
||||
public PropertiesConfigurationManager(String properties)
|
||||
{
|
||||
if (properties != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
setFile(properties);
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public PropertiesConfigurationManager()
|
||||
{
|
||||
this(null);
|
||||
}
|
||||
|
||||
@ManagedAttribute("A file or URL of properties")
|
||||
public void setFile(String resource) throws MalformedURLException, IOException
|
||||
public void setFile(String resource) throws IOException
|
||||
{
|
||||
_properties = resource;
|
||||
_map.clear();
|
||||
|
@ -75,7 +87,7 @@ public class PropertiesConfigurationManager implements ConfigurationManager
|
|||
@Override
|
||||
public Map<String, String> getProperties()
|
||||
{
|
||||
return new HashMap<>(_map);
|
||||
return _map;
|
||||
}
|
||||
|
||||
private void loadProperties(String resource) throws FileNotFoundException, IOException
|
||||
|
@ -86,9 +98,25 @@ public class PropertiesConfigurationManager implements ConfigurationManager
|
|||
Properties properties = new Properties();
|
||||
properties.load(file.getInputStream());
|
||||
for (Map.Entry<Object, Object> entry : properties.entrySet())
|
||||
{
|
||||
_map.put(entry.getKey().toString(), String.valueOf(entry.getValue()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return String.format("%s@%x{%s}", this.getClass(), hashCode(), _properties);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String dump()
|
||||
{
|
||||
return Dumpable.dump(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dump(Appendable out, String indent) throws IOException
|
||||
{
|
||||
Dumpable.dumpObjects(out, indent, toString(), _map);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,7 +20,9 @@ package org.eclipse.jetty.deploy.bindings;
|
|||
|
||||
import org.eclipse.jetty.deploy.App;
|
||||
import org.eclipse.jetty.deploy.AppLifeCycle;
|
||||
import org.eclipse.jetty.deploy.AppProvider;
|
||||
import org.eclipse.jetty.deploy.graph.Node;
|
||||
import org.eclipse.jetty.deploy.providers.WebAppProvider;
|
||||
import org.eclipse.jetty.server.handler.ContextHandler;
|
||||
import org.eclipse.jetty.util.log.Log;
|
||||
import org.eclipse.jetty.util.log.Logger;
|
||||
|
@ -63,7 +65,7 @@ public class GlobalWebappConfigBinding implements AppLifeCycle.Binding
|
|||
{
|
||||
return new String[]{"deploying"};
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void processBinding(Node node, App app) throws Exception
|
||||
{
|
||||
|
@ -94,6 +96,13 @@ public class GlobalWebappConfigBinding implements AppLifeCycle.Binding
|
|||
XmlConfiguration jettyXmlConfig = new XmlConfiguration(globalContextSettings);
|
||||
Resource resource = Resource.newResource(app.getOriginId());
|
||||
app.getDeploymentManager().scope(jettyXmlConfig, resource);
|
||||
AppProvider appProvider = app.getAppProvider();
|
||||
if (appProvider instanceof WebAppProvider)
|
||||
{
|
||||
WebAppProvider webAppProvider = ((WebAppProvider)appProvider);
|
||||
if (webAppProvider.getConfigurationManager() != null)
|
||||
jettyXmlConfig.getProperties().putAll(webAppProvider.getConfigurationManager().getProperties());
|
||||
}
|
||||
WebAppClassLoader.runWithServerClassAccess(() ->
|
||||
{
|
||||
jettyXmlConfig.configure(context);
|
||||
|
|
|
@ -36,7 +36,7 @@ import org.eclipse.jetty.util.Scanner;
|
|||
import org.eclipse.jetty.util.annotation.ManagedAttribute;
|
||||
import org.eclipse.jetty.util.annotation.ManagedObject;
|
||||
import org.eclipse.jetty.util.annotation.ManagedOperation;
|
||||
import org.eclipse.jetty.util.component.AbstractLifeCycle;
|
||||
import org.eclipse.jetty.util.component.ContainerLifeCycle;
|
||||
import org.eclipse.jetty.util.log.Log;
|
||||
import org.eclipse.jetty.util.log.Logger;
|
||||
import org.eclipse.jetty.util.resource.Resource;
|
||||
|
@ -45,7 +45,7 @@ import org.eclipse.jetty.util.resource.Resource;
|
|||
*
|
||||
*/
|
||||
@ManagedObject("Abstract Provider for loading webapps")
|
||||
public abstract class ScanningAppProvider extends AbstractLifeCycle implements AppProvider
|
||||
public abstract class ScanningAppProvider extends ContainerLifeCycle implements AppProvider
|
||||
{
|
||||
private static final Logger LOG = Log.getLogger(ScanningAppProvider.class);
|
||||
|
||||
|
@ -81,11 +81,13 @@ public abstract class ScanningAppProvider extends AbstractLifeCycle implements A
|
|||
|
||||
protected ScanningAppProvider()
|
||||
{
|
||||
this(null);
|
||||
}
|
||||
|
||||
protected ScanningAppProvider(FilenameFilter filter)
|
||||
{
|
||||
_filenameFilter = filter;
|
||||
addBean(_appMap);
|
||||
}
|
||||
|
||||
protected void setFilenameFilter(FilenameFilter filter)
|
||||
|
@ -142,15 +144,19 @@ public abstract class ScanningAppProvider extends AbstractLifeCycle implements A
|
|||
_scanner.setFilenameFilter(_filenameFilter);
|
||||
_scanner.setReportDirs(true);
|
||||
_scanner.addListener(_scannerListener);
|
||||
_scanner.start();
|
||||
|
||||
addBean(_scanner);
|
||||
|
||||
super.doStart();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doStop() throws Exception
|
||||
{
|
||||
super.doStop();
|
||||
if (_scanner != null)
|
||||
{
|
||||
_scanner.stop();
|
||||
removeBean(_scanner);
|
||||
_scanner.removeListener(_scannerListener);
|
||||
_scanner = null;
|
||||
}
|
||||
|
@ -307,4 +313,10 @@ public abstract class ScanningAppProvider extends AbstractLifeCycle implements A
|
|||
);
|
||||
_scanner.scan();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return String.format("%s@%x%s", this.getClass(), hashCode(), _monitored);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -206,6 +206,7 @@ public class WebAppProvider extends ScanningAppProvider
|
|||
*/
|
||||
public void setConfigurationManager(ConfigurationManager configurationManager)
|
||||
{
|
||||
updateBean(_configurationManager, configurationManager);
|
||||
_configurationManager = configurationManager;
|
||||
}
|
||||
|
||||
|
|
|
@ -34,6 +34,7 @@ Once the `session-cache-hash` module has been enabled, you can view a list of al
|
|||
#jetty.session.saveOnInactiveEvict=false
|
||||
#jetty.session.saveOnCreate=false
|
||||
#jetty.session.removeUnloadableSessions=false
|
||||
#jetty.session.flushOnResponseCommit=false
|
||||
----
|
||||
|
||||
jetty.session.evictionPolicy::
|
||||
|
@ -63,6 +64,12 @@ jetty.session.removeUnloadableSessions::
|
|||
Boolean, default `false`.
|
||||
Controls whether a session that cannot be restored - for example because it is corrupted - from the `SessionDataStore` is deleted by the `SessionDataStore`.
|
||||
|
||||
jetty.session.flushOnResponseCommit::
|
||||
Boolean, default `false`.
|
||||
If true, if a session is "dirty" - ie its attributes have changed - it will be written to the backing store as the response is about to commit.
|
||||
This ensures that all subsequent requests whether to the same or different node will see the updated session data.
|
||||
If false, a dirty session will only be written to the backing store when the last simultaneous request for it leaves the session.
|
||||
|
||||
For more general information on the uses of these configuration properties, see link:#sessions-details[Session Components].
|
||||
|
||||
|
||||
|
@ -72,4 +79,21 @@ The `NullSessionCache` is a trivial implementation of the `SessionCache` that do
|
|||
You may need to use it if your clustering setup does not have a sticky load balancer, or if you want absolutely minimal support for sessions.
|
||||
If you use this in conjunction with the `NullSessionDataStore`, then sessions will neither be retained in memory nor persisted.
|
||||
|
||||
To enable the `NullSessionCache`, enable the `sesssion-cache-null` link:#startup-modules[module].
|
||||
To enable the `NullSessionCache`, enable the `sesssion-cache-null` link:#startup-modules[module].
|
||||
Configuration options are:
|
||||
|
||||
jetty.session.saveOnCreate::
|
||||
Boolean, default `false`.
|
||||
Controls whether a session that is newly created will be immediately saved to the `SessionDataStore` or lazily saved as the last request for the session exits.
|
||||
|
||||
jetty.session.removeUnloadableSessions::
|
||||
Boolean, default `false`.
|
||||
Controls whether a session that cannot be restored - for example because it is corrupted - from the `SessionDataStore` is deleted by the `SessionDataStore`.
|
||||
|
||||
jetty.session.flushOnResponseCommit::
|
||||
Boolean, default `false`.
|
||||
If true, if a session is "dirty" - ie its attributes have changed - it will be written to the backing store as the response is about to commit.
|
||||
This ensures that all subsequent requests whether to the same or different node will see the updated session data.
|
||||
If false, a dirty session will only be written to the backing store when the last simultaneous request for it leaves the session.
|
||||
|
||||
For more general information on the uses of these configuration properties, see link:#sessions-details[Session Components].
|
||||
|
|
|
@ -20,9 +20,14 @@ package org.eclipse.jetty.http.pathmap;
|
|||
|
||||
import org.eclipse.jetty.util.StringUtil;
|
||||
import org.eclipse.jetty.util.URIUtil;
|
||||
import org.eclipse.jetty.util.log.Log;
|
||||
import org.eclipse.jetty.util.log.Logger;
|
||||
|
||||
public class ServletPathSpec extends PathSpec
|
||||
{
|
||||
|
||||
private static final Logger LOG = Log.getLogger(ServletPathSpec.class);
|
||||
|
||||
/**
|
||||
* If a servlet or filter path mapping isn't a suffix mapping, ensure
|
||||
* it starts with '/'
|
||||
|
@ -213,13 +218,13 @@ public class ServletPathSpec extends PathSpec
|
|||
super.pathDepth = 0;
|
||||
char lastChar = servletPathSpec.charAt(specLength - 1);
|
||||
// prefix based
|
||||
if ((servletPathSpec.charAt(0) == '/') && (specLength > 1) && (lastChar == '*'))
|
||||
if (servletPathSpec.charAt(0) == '/' && servletPathSpec.endsWith("/*"))
|
||||
{
|
||||
this.group = PathSpecGroup.PREFIX_GLOB;
|
||||
this.prefix = servletPathSpec.substring(0, specLength - 2);
|
||||
}
|
||||
// suffix based
|
||||
else if (servletPathSpec.charAt(0) == '*')
|
||||
else if (servletPathSpec.charAt(0) == '*' && servletPathSpec.length() > 1)
|
||||
{
|
||||
this.group = PathSpecGroup.SUFFIX_GLOB;
|
||||
this.suffix = servletPathSpec.substring(2, specLength);
|
||||
|
@ -228,6 +233,11 @@ public class ServletPathSpec extends PathSpec
|
|||
{
|
||||
this.group = PathSpecGroup.EXACT;
|
||||
this.prefix = servletPathSpec;
|
||||
if (servletPathSpec.endsWith("*") )
|
||||
{
|
||||
LOG.warn("Suspicious URL pattern: '{}'; see sections 12.1 and 12.2 of the Servlet specification",
|
||||
servletPathSpec);
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < specLength; i++)
|
||||
|
@ -276,11 +286,6 @@ public class ServletPathSpec extends PathSpec
|
|||
{
|
||||
throw new IllegalArgumentException("Servlet Spec 12.2 violation: glob '*' can only exist at end of prefix based matches: bad spec \"" + servletPathSpec + "\"");
|
||||
}
|
||||
|
||||
if (idx < 1 || servletPathSpec.charAt(idx - 1) != '/')
|
||||
{
|
||||
throw new IllegalArgumentException("Servlet Spec 12.2 violation: suffix glob '*' can only exist after '/': bad spec \"" + servletPathSpec + "\"");
|
||||
}
|
||||
}
|
||||
else if (servletPathSpec.startsWith("*."))
|
||||
{
|
||||
|
|
|
@ -231,6 +231,8 @@ public class PathMappingsTest
|
|||
assertTrue(!new ServletPathSpec("/foo/*").matches("/bar/anything"), "!match /foo/*");
|
||||
assertTrue(new ServletPathSpec("*.foo").matches("anything.foo"), "match *.foo");
|
||||
assertTrue(!new ServletPathSpec("*.foo").matches("anything.bar"), "!match *.foo");
|
||||
assertTrue(new ServletPathSpec("/On*").matches("/On*"), "match /On*");
|
||||
assertTrue(!new ServletPathSpec("/On*").matches("/One"), "!match /One");
|
||||
|
||||
assertEquals("10", p.getMatch("/").getResource(), "match / with ''");
|
||||
|
||||
|
@ -287,7 +289,6 @@ public class PathMappingsTest
|
|||
@ValueSource(strings = {
|
||||
"*",
|
||||
"/foo/*/bar",
|
||||
"/foo*",
|
||||
"*/foo",
|
||||
"*.foo/*"
|
||||
})
|
||||
|
|
|
@ -43,6 +43,7 @@ import java.util.concurrent.RejectedExecutionException;
|
|||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
import org.eclipse.jetty.util.IO;
|
||||
import org.eclipse.jetty.util.component.ContainerLifeCycle;
|
||||
import org.eclipse.jetty.util.component.Dumpable;
|
||||
import org.eclipse.jetty.util.component.DumpableCollection;
|
||||
|
@ -122,12 +123,20 @@ public class ManagedSelector extends ContainerLifeCycle implements Dumpable
|
|||
start._started.await();
|
||||
}
|
||||
|
||||
protected void onSelectFailed(Throwable cause)
|
||||
{
|
||||
// override to change behavior
|
||||
}
|
||||
|
||||
public int size()
|
||||
{
|
||||
Selector s = _selector;
|
||||
if (s == null)
|
||||
return 0;
|
||||
return s.keys().size();
|
||||
Set<SelectionKey> keys = s.keys();
|
||||
if (keys == null)
|
||||
return 0;
|
||||
return keys.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -135,7 +144,7 @@ public class ManagedSelector extends ContainerLifeCycle implements Dumpable
|
|||
{
|
||||
// doStop might be called for a failed managedSelector,
|
||||
// We do not want to wait twice, so we only stop once for each start
|
||||
if (_started.compareAndSet(true, false))
|
||||
if (_started.compareAndSet(true, false) && _selector != null)
|
||||
{
|
||||
// Close connections, but only wait a single selector cycle for it to take effect
|
||||
CloseConnections closeConnections = new CloseConnections();
|
||||
|
@ -210,7 +219,7 @@ public class ManagedSelector extends ContainerLifeCycle implements Dumpable
|
|||
catch (RejectedExecutionException x)
|
||||
{
|
||||
if (task instanceof Closeable)
|
||||
closeNoExceptions((Closeable)task);
|
||||
IO.close((Closeable)task);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -246,17 +255,14 @@ public class ManagedSelector extends ContainerLifeCycle implements Dumpable
|
|||
}
|
||||
}
|
||||
|
||||
private static void closeNoExceptions(Closeable closeable)
|
||||
protected void endPointOpened(EndPoint endPoint)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (closeable != null)
|
||||
closeable.close();
|
||||
}
|
||||
catch (Throwable x)
|
||||
{
|
||||
LOG.ignore(x);
|
||||
}
|
||||
_selectorManager.endPointOpened(endPoint);
|
||||
}
|
||||
|
||||
protected void endPointClosed(EndPoint endPoint)
|
||||
{
|
||||
_selectorManager.endPointClosed(endPoint);
|
||||
}
|
||||
|
||||
private void createEndPoint(SelectableChannel channel, SelectionKey selectionKey) throws IOException
|
||||
|
@ -266,7 +272,7 @@ public class ManagedSelector extends ContainerLifeCycle implements Dumpable
|
|||
endPoint.setConnection(connection);
|
||||
selectionKey.attach(endPoint);
|
||||
endPoint.onOpen();
|
||||
_selectorManager.endPointOpened(endPoint);
|
||||
endPointOpened(endPoint);
|
||||
_selectorManager.connectionOpened(connection);
|
||||
if (LOG.isDebugEnabled())
|
||||
LOG.debug("Created {}", endPoint);
|
||||
|
@ -496,15 +502,19 @@ public class ManagedSelector extends ContainerLifeCycle implements Dumpable
|
|||
}
|
||||
catch (Throwable x)
|
||||
{
|
||||
IO.close(_selector);
|
||||
_selector = null;
|
||||
|
||||
if (isRunning())
|
||||
LOG.warn(x);
|
||||
{
|
||||
LOG.warn("Fatal select() failure", x);
|
||||
onSelectFailed(x);
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG.warn(x.toString());
|
||||
LOG.debug(x);
|
||||
}
|
||||
closeNoExceptions(_selector);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
@ -541,13 +551,13 @@ public class ManagedSelector extends ContainerLifeCycle implements Dumpable
|
|||
{
|
||||
LOG.debug("Ignoring cancelled key for channel {}", key.channel());
|
||||
if (attachment instanceof EndPoint)
|
||||
closeNoExceptions((EndPoint)attachment);
|
||||
IO.close((EndPoint)attachment);
|
||||
}
|
||||
catch (Throwable x)
|
||||
{
|
||||
LOG.warn("Could not process key for channel " + key.channel(), x);
|
||||
if (attachment instanceof EndPoint)
|
||||
closeNoExceptions((EndPoint)attachment);
|
||||
IO.close((EndPoint)attachment);
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -556,7 +566,7 @@ public class ManagedSelector extends ContainerLifeCycle implements Dumpable
|
|||
LOG.debug("Selector loop ignoring invalid key for channel {}", key.channel());
|
||||
Object attachment = key.attachment();
|
||||
if (attachment instanceof EndPoint)
|
||||
closeNoExceptions((EndPoint)attachment);
|
||||
IO.close((EndPoint)attachment);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
@ -661,7 +671,7 @@ public class ManagedSelector extends ContainerLifeCycle implements Dumpable
|
|||
}
|
||||
catch (Throwable x)
|
||||
{
|
||||
closeNoExceptions(_channel);
|
||||
IO.close(_channel);
|
||||
LOG.warn(x);
|
||||
}
|
||||
}
|
||||
|
@ -683,7 +693,7 @@ public class ManagedSelector extends ContainerLifeCycle implements Dumpable
|
|||
}
|
||||
catch (Throwable x)
|
||||
{
|
||||
closeNoExceptions(channel);
|
||||
IO.close(channel);
|
||||
LOG.warn("Accept failed for channel " + channel, x);
|
||||
}
|
||||
|
||||
|
@ -722,7 +732,7 @@ public class ManagedSelector extends ContainerLifeCycle implements Dumpable
|
|||
public void close()
|
||||
{
|
||||
LOG.debug("closed accept of {}", channel);
|
||||
closeNoExceptions(channel);
|
||||
IO.close(channel);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -735,7 +745,7 @@ public class ManagedSelector extends ContainerLifeCycle implements Dumpable
|
|||
}
|
||||
catch (Throwable x)
|
||||
{
|
||||
closeNoExceptions(channel);
|
||||
IO.close(channel);
|
||||
_selectorManager.onAcceptFailed(channel, x);
|
||||
LOG.debug(x);
|
||||
}
|
||||
|
@ -758,7 +768,7 @@ public class ManagedSelector extends ContainerLifeCycle implements Dumpable
|
|||
|
||||
protected void failed(Throwable failure)
|
||||
{
|
||||
closeNoExceptions(channel);
|
||||
IO.close(channel);
|
||||
LOG.warn(String.valueOf(failure));
|
||||
LOG.debug(failure);
|
||||
_selectorManager.onAcceptFailed(channel, failure);
|
||||
|
@ -808,7 +818,7 @@ public class ManagedSelector extends ContainerLifeCycle implements Dumpable
|
|||
if (failed.compareAndSet(false, true))
|
||||
{
|
||||
timeout.cancel();
|
||||
closeNoExceptions(channel);
|
||||
IO.close(channel);
|
||||
ManagedSelector.this._selectorManager.connectionFailed(channel, failure, attachment);
|
||||
}
|
||||
}
|
||||
|
@ -864,12 +874,12 @@ public class ManagedSelector extends ContainerLifeCycle implements Dumpable
|
|||
{
|
||||
if (_closed == null)
|
||||
{
|
||||
closeNoExceptions(closeable);
|
||||
IO.close(closeable);
|
||||
}
|
||||
else if (!_closed.contains(closeable))
|
||||
{
|
||||
_closed.add(closeable);
|
||||
closeNoExceptions(closeable);
|
||||
IO.close(closeable);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -894,12 +904,12 @@ public class ManagedSelector extends ContainerLifeCycle implements Dumpable
|
|||
{
|
||||
Object attachment = key.attachment();
|
||||
if (attachment instanceof EndPoint)
|
||||
closeNoExceptions((EndPoint)attachment);
|
||||
IO.close((EndPoint)attachment);
|
||||
}
|
||||
}
|
||||
|
||||
_selector = null;
|
||||
closeNoExceptions(selector);
|
||||
IO.close(selector);
|
||||
_stopped.countDown();
|
||||
}
|
||||
}
|
||||
|
@ -924,7 +934,7 @@ public class ManagedSelector extends ContainerLifeCycle implements Dumpable
|
|||
}
|
||||
catch (Throwable failure)
|
||||
{
|
||||
closeNoExceptions(_connect.channel);
|
||||
IO.close(_connect.channel);
|
||||
LOG.warn(String.valueOf(failure));
|
||||
LOG.debug(failure);
|
||||
_connect.failed(failure);
|
||||
|
@ -957,7 +967,7 @@ public class ManagedSelector extends ContainerLifeCycle implements Dumpable
|
|||
Connection connection = endPoint.getConnection();
|
||||
if (connection != null)
|
||||
_selectorManager.connectionClosed(connection, cause);
|
||||
_selectorManager.endPointClosed(endPoint);
|
||||
ManagedSelector.this.endPointClosed(endPoint);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -28,8 +28,9 @@ import org.apache.maven.plugins.annotations.Mojo;
|
|||
import org.apache.maven.plugins.annotations.Parameter;
|
||||
import org.apache.maven.plugins.annotations.ResolutionScope;
|
||||
import org.eclipse.jetty.annotations.AnnotationConfiguration;
|
||||
import org.eclipse.jetty.quickstart.QuickStartConfiguration;
|
||||
import org.eclipse.jetty.quickstart.QuickStartConfiguration.Mode;
|
||||
import org.eclipse.jetty.util.IO;
|
||||
import org.eclipse.jetty.util.component.LifeCycle;
|
||||
import org.eclipse.jetty.util.resource.Resource;
|
||||
import org.eclipse.jetty.util.thread.QueuedThreadPool;
|
||||
|
||||
|
@ -92,30 +93,23 @@ public class JettyEffectiveWebXml extends JettyRunMojo
|
|||
configureWebApplication();
|
||||
|
||||
//set the webapp up to do very little other than generate the quickstart-web.xml
|
||||
if (effectiveWebXml == null)
|
||||
{
|
||||
deleteOnExit = true;
|
||||
effectiveWebXml = new File(target, "effective-web.xml");
|
||||
effectiveWebXml.deleteOnExit();
|
||||
}
|
||||
Resource descriptor = Resource.newResource(effectiveWebXml);
|
||||
if (!effectiveWebXml.getParentFile().exists())
|
||||
effectiveWebXml.getParentFile().mkdirs();
|
||||
if (!effectiveWebXml.exists())
|
||||
effectiveWebXml.createNewFile();
|
||||
|
||||
webApp.setCopyWebDir(false);
|
||||
webApp.setCopyWebInf(false);
|
||||
webApp.setGenerateQuickStart(true);
|
||||
|
||||
//if the user didn't nominate a file to generate into, pick the name and
|
||||
//make sure that it is deleted on exit
|
||||
if (webApp.getQuickStartWebDescriptor() == null)
|
||||
{
|
||||
if (effectiveWebXml == null)
|
||||
{
|
||||
deleteOnExit = true;
|
||||
effectiveWebXml = new File(target, "effective-web.xml");
|
||||
effectiveWebXml.deleteOnExit();
|
||||
}
|
||||
|
||||
Resource descriptor = Resource.newResource(effectiveWebXml);
|
||||
|
||||
if (!effectiveWebXml.getParentFile().exists())
|
||||
effectiveWebXml.getParentFile().mkdirs();
|
||||
if (!effectiveWebXml.exists())
|
||||
effectiveWebXml.createNewFile();
|
||||
|
||||
webApp.setQuickStartWebDescriptor(descriptor);
|
||||
}
|
||||
webApp.addConfiguration(new QuickStartConfiguration());
|
||||
webApp.setAttribute(QuickStartConfiguration.MODE, Mode.GENERATE);
|
||||
webApp.setAttribute(QuickStartConfiguration.QUICKSTART_WEB_XML, descriptor);
|
||||
|
||||
ServerSupport.addWebApplication(server, webApp);
|
||||
|
||||
|
@ -158,7 +152,7 @@ public class JettyEffectiveWebXml extends JettyRunMojo
|
|||
try
|
||||
{
|
||||
//just show the result in the log
|
||||
getLog().info(IO.toString(webApp.getQuickStartWebDescriptor().getInputStream()));
|
||||
getLog().info(IO.toString(((Resource)webApp.getAttribute(QuickStartConfiguration.QUICKSTART_WEB_XML)).getInputStream()));
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
|
|
@ -43,6 +43,8 @@ import org.apache.maven.plugins.annotations.Mojo;
|
|||
import org.apache.maven.plugins.annotations.Parameter;
|
||||
import org.apache.maven.plugins.annotations.ResolutionScope;
|
||||
import org.eclipse.jetty.annotations.AnnotationConfiguration;
|
||||
import org.eclipse.jetty.quickstart.QuickStartConfiguration;
|
||||
import org.eclipse.jetty.quickstart.QuickStartConfiguration.Mode;
|
||||
import org.eclipse.jetty.server.Server;
|
||||
import org.eclipse.jetty.util.StringUtil;
|
||||
import org.eclipse.jetty.util.resource.Resource;
|
||||
|
@ -209,22 +211,19 @@ public class JettyRunForkedMojo extends JettyRunMojo
|
|||
configureWebApplication();
|
||||
|
||||
//set the webapp up to do very little other than generate the quickstart-web.xml
|
||||
if (forkWebXml == null)
|
||||
forkWebXml = new File(target, "fork-web.xml");
|
||||
|
||||
if (!forkWebXml.getParentFile().exists())
|
||||
forkWebXml.getParentFile().mkdirs();
|
||||
if (!forkWebXml.exists())
|
||||
forkWebXml.createNewFile();
|
||||
|
||||
webApp.addConfiguration(new MavenQuickStartConfiguration());
|
||||
webApp.setAttribute(QuickStartConfiguration.MODE, Mode.GENERATE);
|
||||
webApp.setAttribute(QuickStartConfiguration.QUICKSTART_WEB_XML, Resource.newResource(forkWebXml));
|
||||
webApp.setCopyWebDir(false);
|
||||
webApp.setCopyWebInf(false);
|
||||
webApp.setGenerateQuickStart(true);
|
||||
|
||||
if (webApp.getQuickStartWebDescriptor() == null)
|
||||
{
|
||||
if (forkWebXml == null)
|
||||
forkWebXml = new File(target, "fork-web.xml");
|
||||
|
||||
if (!forkWebXml.getParentFile().exists())
|
||||
forkWebXml.getParentFile().mkdirs();
|
||||
if (!forkWebXml.exists())
|
||||
forkWebXml.createNewFile();
|
||||
|
||||
webApp.setQuickStartWebDescriptor(Resource.newResource(forkWebXml));
|
||||
}
|
||||
webApp.setCopyWebInf(false);
|
||||
|
||||
//add webapp to our fake server instance
|
||||
ServerSupport.addWebApplication(server, webApp);
|
||||
|
@ -240,11 +239,10 @@ public class JettyRunForkedMojo extends JettyRunMojo
|
|||
//leave everything unpacked for the forked process to use
|
||||
webApp.setPersistTempDirectory(true);
|
||||
|
||||
File props = null;
|
||||
webApp.start(); //just enough to generate the quickstart
|
||||
|
||||
//save config of the webapp BEFORE we stop
|
||||
final File props = prepareConfiguration();
|
||||
|
||||
props = prepareConfiguration();
|
||||
webApp.stop();
|
||||
|
||||
if (tpool != null)
|
||||
|
@ -311,7 +309,7 @@ public class JettyRunForkedMojo extends JettyRunMojo
|
|||
|
||||
if (PluginLog.getLog().isDebugEnabled())
|
||||
PluginLog.getLog().debug("Forked cli:" + Arrays.toString(cmd.toArray()));
|
||||
|
||||
|
||||
PluginLog.getLog().info("Forked process starting");
|
||||
|
||||
//set up extra environment vars if there are any
|
||||
|
|
|
@ -34,7 +34,6 @@ import org.eclipse.jetty.annotations.AnnotationConfiguration;
|
|||
import org.eclipse.jetty.plus.webapp.EnvConfiguration;
|
||||
import org.eclipse.jetty.plus.webapp.PlusConfiguration;
|
||||
import org.eclipse.jetty.quickstart.QuickStartConfiguration;
|
||||
import org.eclipse.jetty.quickstart.QuickStartConfiguration.Mode;
|
||||
import org.eclipse.jetty.servlet.FilterHolder;
|
||||
import org.eclipse.jetty.servlet.FilterMapping;
|
||||
import org.eclipse.jetty.servlet.ServletHolder;
|
||||
|
@ -105,8 +104,6 @@ public class JettyWebAppContext extends WebAppContext
|
|||
*/
|
||||
private boolean _baseAppFirst = true;
|
||||
|
||||
private boolean _isGenerateQuickStart;
|
||||
|
||||
public JettyWebAppContext() throws Exception
|
||||
{
|
||||
super();
|
||||
|
@ -117,6 +114,8 @@ public class JettyWebAppContext extends WebAppContext
|
|||
addConfiguration(new EnvConfiguration());
|
||||
addConfiguration(new PlusConfiguration());
|
||||
addConfiguration(new AnnotationConfiguration());
|
||||
|
||||
setAttribute(QuickStartConfiguration.ORIGIN_ATTRIBUTE, "origin");
|
||||
}
|
||||
|
||||
public void setContainerIncludeJarPattern(String pattern)
|
||||
|
@ -210,27 +209,6 @@ public class JettyWebAppContext extends WebAppContext
|
|||
return attr == null ? null : attr.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggle whether or not the origin attribute will be generated into the
|
||||
* xml.
|
||||
*
|
||||
* @param generateOrigin if true then the origin of each xml element is
|
||||
* added, otherwise it is omitted.
|
||||
*/
|
||||
public void setGenerateOrigin(boolean generateOrigin)
|
||||
{
|
||||
setAttribute(QuickStartConfiguration.GENERATE_ORIGIN, generateOrigin);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true if the origin attribute will be generated, false otherwise
|
||||
*/
|
||||
public boolean isGenerateOrigin()
|
||||
{
|
||||
Object attr = getAttribute(QuickStartConfiguration.GENERATE_ORIGIN);
|
||||
return attr == null ? false : Boolean.valueOf(attr.toString());
|
||||
}
|
||||
|
||||
public List<Overlay> getOverlays()
|
||||
{
|
||||
return _overlays;
|
||||
|
@ -246,35 +224,6 @@ public class JettyWebAppContext extends WebAppContext
|
|||
return _baseAppFirst;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the file to use into which to generate the quickstart output.
|
||||
*
|
||||
* @param quickStartWebXml the full path to the file to use
|
||||
*/
|
||||
public void setQuickStartWebDescriptor(String quickStartWebXml) throws Exception
|
||||
{
|
||||
setQuickStartWebDescriptor(Resource.newResource(quickStartWebXml));
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the Resource to use into which to generate the quickstart output.
|
||||
*/
|
||||
protected void setQuickStartWebDescriptor(Resource quickStartWebXml)
|
||||
{
|
||||
setAttribute(QuickStartConfiguration.QUICKSTART_WEB_XML, quickStartWebXml.toString());
|
||||
}
|
||||
|
||||
public Resource getQuickStartWebDescriptor() throws Exception
|
||||
{
|
||||
Object o = getAttribute(QuickStartConfiguration.QUICKSTART_WEB_XML);
|
||||
if (o == null)
|
||||
return null;
|
||||
else if (o instanceof Resource)
|
||||
return (Resource)o;
|
||||
else
|
||||
return Resource.newResource((String)o);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is provided as a convenience for jetty maven plugin
|
||||
* configuration
|
||||
|
@ -307,41 +256,9 @@ public class JettyWebAppContext extends WebAppContext
|
|||
return _webInfClasses;
|
||||
}
|
||||
|
||||
/**
|
||||
* If true, a quickstart for the webapp is generated.
|
||||
*
|
||||
* @param quickStart if true the quickstart is generated, false otherwise
|
||||
*/
|
||||
public void setGenerateQuickStart(boolean quickStart)
|
||||
{
|
||||
_isGenerateQuickStart = quickStart;
|
||||
}
|
||||
|
||||
public boolean isGenerateQuickStart()
|
||||
{
|
||||
return _isGenerateQuickStart;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doStart() throws Exception
|
||||
{
|
||||
|
||||
// choose if this will be a quickstart or normal start
|
||||
if (!isGenerateQuickStart() && getQuickStartWebDescriptor() != null)
|
||||
{
|
||||
MavenQuickStartConfiguration quickStart = new MavenQuickStartConfiguration();
|
||||
quickStart.setMode(Mode.QUICKSTART);
|
||||
quickStart.setQuickStartWebXml(getQuickStartWebDescriptor());
|
||||
addConfiguration(quickStart);
|
||||
}
|
||||
else if (isGenerateQuickStart())
|
||||
{
|
||||
MavenQuickStartConfiguration quickStart = new MavenQuickStartConfiguration();
|
||||
quickStart.setMode(Mode.GENERATE);
|
||||
quickStart.setQuickStartWebXml(getQuickStartWebDescriptor());
|
||||
addConfiguration(quickStart);
|
||||
}
|
||||
|
||||
// Set up the pattern that tells us where the jars are that need
|
||||
// scanning
|
||||
|
||||
|
|
|
@ -18,15 +18,12 @@
|
|||
|
||||
package org.eclipse.jetty.maven.plugin;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import org.eclipse.jetty.quickstart.QuickStartConfiguration;
|
||||
import org.eclipse.jetty.util.IO;
|
||||
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.util.resource.ResourceCollection;
|
||||
import org.eclipse.jetty.webapp.WebAppClassLoader;
|
||||
import org.eclipse.jetty.webapp.WebAppContext;
|
||||
|
||||
/**
|
||||
|
@ -36,56 +33,6 @@ public class MavenQuickStartConfiguration extends QuickStartConfiguration
|
|||
{
|
||||
private static final Logger LOG = Log.getLogger(QuickStartConfiguration.class);
|
||||
|
||||
private Resource _quickStartWebXml; //the descriptor to use for starting/generating quickstart
|
||||
|
||||
public void setQuickStartWebXml(Resource quickStartWebXml)
|
||||
{
|
||||
_quickStartWebXml = quickStartWebXml;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Resource getQuickStartWebXml(WebAppContext context) throws Exception
|
||||
{
|
||||
if (_quickStartWebXml == null)
|
||||
return super.getQuickStartWebXml(context);
|
||||
|
||||
return _quickStartWebXml;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void preConfigure(WebAppContext context) throws Exception
|
||||
{
|
||||
//check that webapp is suitable for quick start
|
||||
if (context.getBaseResource() == null)
|
||||
throw new IllegalStateException("No location for webapp");
|
||||
|
||||
//look for quickstart-web.xml in WEB-INF of webapp
|
||||
Resource quickStartWebXml = getQuickStartWebXml(context);
|
||||
if (LOG.isDebugEnabled())
|
||||
LOG.debug("quickStartWebXml={}", quickStartWebXml);
|
||||
super.preConfigure(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void configure(WebAppContext context) throws Exception
|
||||
{
|
||||
JettyWebAppContext jwac = (JettyWebAppContext)context;
|
||||
|
||||
//put the classes dir and all dependencies into the classpath
|
||||
if (jwac.getClassPathFiles() != null)
|
||||
{
|
||||
if (LOG.isDebugEnabled())
|
||||
LOG.debug("Setting up classpath ...");
|
||||
for (File classPathFile : jwac.getClassPathFiles())
|
||||
{
|
||||
((WebAppClassLoader)context.getClassLoader()).addClassPath(classPathFile.getCanonicalPath());
|
||||
}
|
||||
}
|
||||
|
||||
//Set up the quickstart environment for the context
|
||||
super.configure(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deconfigure(WebAppContext context) throws Exception
|
||||
{
|
||||
|
|
|
@ -24,6 +24,7 @@ import java.util.HashMap;
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.eclipse.jetty.quickstart.QuickStartConfiguration;
|
||||
import org.eclipse.jetty.server.Handler;
|
||||
import org.eclipse.jetty.server.Server;
|
||||
import org.eclipse.jetty.server.ShutdownMonitor;
|
||||
|
@ -71,14 +72,9 @@ public class Starter
|
|||
|
||||
//configure webapp from properties file describing unassembled webapp
|
||||
configureWebApp();
|
||||
|
||||
//make it a quickstart if the quickstart-web.xml file exists
|
||||
if (webApp.getTempDirectory() != null)
|
||||
{
|
||||
File qs = new File(webApp.getTempDirectory(), "quickstart-web.xml");
|
||||
if (qs.exists() && qs.isFile())
|
||||
webApp.setQuickStartWebDescriptor(Resource.newResource(qs));
|
||||
}
|
||||
|
||||
webApp.addConfiguration(new QuickStartConfiguration());
|
||||
webApp.setAttribute(QuickStartConfiguration.MODE, QuickStartConfiguration.Mode.QUICKSTART);
|
||||
|
||||
ServerSupport.addWebApplication(server, webApp);
|
||||
|
||||
|
@ -232,7 +228,9 @@ public class Starter
|
|||
public static final void main(String[] args)
|
||||
{
|
||||
if (args == null)
|
||||
{
|
||||
System.exit(1);
|
||||
}
|
||||
|
||||
Starter starter = null;
|
||||
try
|
||||
|
|
|
@ -27,6 +27,7 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.eclipse.jetty.quickstart.QuickStartConfiguration;
|
||||
import org.eclipse.jetty.server.Server;
|
||||
import org.eclipse.jetty.util.StringUtil;
|
||||
import org.eclipse.jetty.util.resource.Resource;
|
||||
|
@ -71,9 +72,10 @@ public class WebAppPropertyConverter
|
|||
props.put("web.xml", webApp.getDescriptor());
|
||||
}
|
||||
|
||||
if (webApp.getQuickStartWebDescriptor() != null)
|
||||
Object tmp = webApp.getAttribute(QuickStartConfiguration.QUICKSTART_WEB_XML);
|
||||
if (tmp != null)
|
||||
{
|
||||
props.put("quickstart.web.xml", webApp.getQuickStartWebDescriptor().getFile().getAbsolutePath());
|
||||
props.put("quickstart.web.xml", tmp.toString());
|
||||
}
|
||||
|
||||
//sort out the context path
|
||||
|
@ -183,11 +185,10 @@ public class WebAppPropertyConverter
|
|||
if (!StringUtil.isBlank(str))
|
||||
webApp.setDescriptor(str);
|
||||
|
||||
//TODO the WebAppStarter class doesn't set up the QUICKSTART_CONFIGURATION_CLASSES, but the Starter class does!!!
|
||||
str = props.getProperty("quickstart.web.xml");
|
||||
if (!StringUtil.isBlank(str))
|
||||
{
|
||||
webApp.setQuickStartWebDescriptor(Resource.newResource(new File(str)));
|
||||
webApp.setAttribute(QuickStartConfiguration.QUICKSTART_WEB_XML, Resource.newResource(str));
|
||||
}
|
||||
|
||||
// - the tmp directory
|
||||
|
|
|
@ -78,6 +78,7 @@ import org.eclipse.jetty.util.log.Logger;
|
|||
import org.eclipse.jetty.util.log.StacklessLogging;
|
||||
import org.eclipse.jetty.util.thread.QueuedThreadPool;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.condition.OS;
|
||||
|
||||
|
@ -88,6 +89,7 @@ import static org.junit.jupiter.api.Assertions.assertNotNull;
|
|||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
@Disabled("See issue #3974")
|
||||
public class AsyncMiddleManServletTest
|
||||
{
|
||||
private static final Logger LOG = Log.getLogger(AsyncMiddleManServletTest.class);
|
||||
|
|
|
@ -1,27 +0,0 @@
|
|||
<?xml version="1.0" encoding="ISO-8859-1"?>
|
||||
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "https://www.eclipse.org/jetty/configure_10_0.dtd">
|
||||
|
||||
<!-- An example context XML for a quickstart webapp
|
||||
A quick started webapp has all the jar scanning and fragment resolution done in a
|
||||
Preconfigure phase, with all the discovered configuration encoded into a
|
||||
WEB-INF/quickstart-web.xml file.
|
||||
|
||||
This allows very rapid and precise starting of a webapp, without the risk of accidental
|
||||
deployment of other discovered resources. This is above and beyond what is available
|
||||
with web.xml meta-data-complete, as it also prevents scanning for ServletContainer
|
||||
initialisers and any annotations/classes they require.
|
||||
|
||||
If autoPreconfigure is set to true, then the webapp will be preconfigured the first
|
||||
time it is run.
|
||||
-->
|
||||
<Configure class="org.eclipse.jetty.quickstart.QuickStartWebApp">
|
||||
<Set name="autoPreconfigure">true</Set>
|
||||
<Set name="contextPath">/</Set>
|
||||
<Set name="war"><Property name="jetty.webapps" default="."/>/application.war</Set>
|
||||
<!--
|
||||
<Call name="setInitParameter">
|
||||
<Arg>org.eclipse.jetty.jsp.precompiled</Arg>
|
||||
<Arg>true</Arg>
|
||||
</Call>
|
||||
-->
|
||||
</Configure>
|
|
@ -0,0 +1,31 @@
|
|||
<?xml version="1.0"?>
|
||||
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "https://www.eclipse.org/jetty/configure_10_0.dtd">
|
||||
|
||||
<Configure id="Server" class="org.eclipse.jetty.server.Server">
|
||||
<Call class="org.eclipse.jetty.quickstart.QuickStartConfiguration" name="configureMode">
|
||||
<Arg><Ref refid="Server"/></Arg>
|
||||
<Arg><Property name="jetty.quickstart.mode"/></Arg>
|
||||
</Call>
|
||||
|
||||
<Ref refid="webappprovider">
|
||||
<Get name="configurationManager">
|
||||
<Get name="properties">
|
||||
<Put name="jetty.quickstart.mode"><Property name="jetty.quickstart.mode"/></Put>
|
||||
<Put name="jetty.quickstart.origin"><Property name="jetty.quickstart.origin"/></Put>
|
||||
<Put name="jetty.quickstart.xml"><Property name="jetty.quickstart.xml"/></Put>
|
||||
</Get>
|
||||
</Get>
|
||||
</Ref>
|
||||
|
||||
<Ref refid="DeploymentManager">
|
||||
<Call name="addLifeCycleBinding">
|
||||
<Arg>
|
||||
<New class="org.eclipse.jetty.deploy.bindings.GlobalWebappConfigBinding">
|
||||
<Set name="jettyXml">
|
||||
<Property name="jetty.base"/>/etc/quickstart-webapp.xml
|
||||
</Set>
|
||||
</New>
|
||||
</Arg>
|
||||
</Call>
|
||||
</Ref>
|
||||
</Configure>
|
|
@ -0,0 +1,28 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "https://www.eclipse.org/jetty/configure_10_0.dtd">
|
||||
|
||||
<Configure class="org.eclipse.jetty.webapp.WebAppContext">
|
||||
<Call name="setAttribute">
|
||||
<Arg>org.eclipse.jetty.quickstart.origin</Arg>
|
||||
<Arg><Property name="jetty.quickstart.origin" default="origin"/></Arg>
|
||||
</Call>
|
||||
|
||||
<Call name="setAttribute">
|
||||
<Arg>org.eclipse.jetty.quickstart.xml</Arg>
|
||||
<Arg><Property name="jetty.quickstart.xml"/></Arg>
|
||||
</Call>
|
||||
|
||||
<Call name="setAttribute">
|
||||
<Arg>org.eclipse.jetty.quickstart.mode</Arg>
|
||||
<Arg>
|
||||
<Call class="org.eclipse.jetty.quickstart.QuickStartConfiguration$Mode" name="valueOf">
|
||||
<Arg><Property name="jetty.quickstart.mode" default="AUTO"/></Arg>
|
||||
</Call>
|
||||
</Arg>
|
||||
</Call>
|
||||
|
||||
<Set name="extractWAR">true</Set>
|
||||
<Set name="copyWebDir">false</Set>
|
||||
<Set name="copyWebInf">false</Set>
|
||||
|
||||
</Configure>
|
|
@ -6,8 +6,21 @@ deployment of preconfigured webapplications.
|
|||
|
||||
[depend]
|
||||
server
|
||||
plus
|
||||
annotations
|
||||
deploy
|
||||
|
||||
[lib]
|
||||
lib/jetty-quickstart-${jetty.version}.jar
|
||||
|
||||
[xml]
|
||||
etc/jetty-quickstart.xml
|
||||
|
||||
[files]
|
||||
basehome:modules/jetty-quickstart.d/quickstart-webapp.xml|etc/quickstart-webapp.xml
|
||||
|
||||
|
||||
[ini-template]
|
||||
|
||||
# Modes are AUTO, GENERATE, QUICKSTART
|
||||
# jetty.quickstart.mode=AUTO
|
||||
# jetty.quickstart.origin=origin
|
||||
# jetty.quickstart.xml=
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue