More testing of embedded examples
Signed-off-by: Joakim Erdfelt <joakim.erdfelt@gmail.com>
This commit is contained in:
parent
fdaa67e7ec
commit
13413c8027
|
@ -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,12 @@ public class OneServletContextJmxStats
|
|||
|
||||
// Add Connector Statistics tracking to all connectors
|
||||
ServerConnectionStatistics.addToAllConnectors(server);
|
||||
return server;
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception
|
||||
{
|
||||
Server server = createServer(8080);
|
||||
|
||||
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,14 @@ 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
|
||||
{
|
||||
Path dir = Paths.get(System.getProperty("user.dir"));
|
||||
PathResource baseResource = new PathResource(dir);
|
||||
Server server = createServer(8080, baseResource);
|
||||
|
||||
server.start();
|
||||
server.dumpStdErr();
|
||||
|
|
|
@ -19,26 +19,19 @@
|
|||
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.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
|
||||
|
@ -55,6 +48,12 @@ 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
|
||||
{
|
||||
Server server = createServer(8080);
|
||||
|
||||
// Start things up!
|
||||
server.start();
|
||||
|
@ -63,7 +62,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.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.Configuration;
|
||||
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
|
||||
|
@ -93,11 +89,22 @@ 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.
|
||||
URL realmProps = OneWebAppWithJsp.class.getClassLoader().getResource("realm.properties");
|
||||
if (realmProps == null)
|
||||
throw new FileNotFoundException("Unable to find realm.properties");
|
||||
|
||||
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
|
||||
{
|
||||
Server server = createServer(8080);
|
||||
|
||||
// Start things up!
|
||||
server.start();
|
||||
|
||||
|
@ -105,7 +112,6 @@ public class OneWebAppWithJsp
|
|||
|
||||
// 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,14 @@ public class ProxyServer
|
|||
proxyServlet.setInitParameter("blackList", "www.eclipse.org");
|
||||
context.addServlet(proxyServlet, "/*");
|
||||
|
||||
return server;
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception
|
||||
{
|
||||
Server server = createServer(8080);
|
||||
|
||||
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,13 @@ public class RewriteServer
|
|||
|
||||
context.addServlet(DumpServlet.class, "/*");
|
||||
|
||||
return server;
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception
|
||||
{
|
||||
Server server = createServer(8080);
|
||||
|
||||
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,13 @@ 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.
|
||||
ClassLoader classLoader = SecuredHelloHandler.class.getClassLoader();
|
||||
URL realmProps = classLoader.getResource("realm.properties");
|
||||
if (realmProps == null)
|
||||
throw new FileNotFoundException("Unable to find realm.properties");
|
||||
|
||||
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 +75,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 +99,18 @@ public class SecuredHelloHandler
|
|||
// chain the hello handler into the security handler
|
||||
security.setHandler(hh);
|
||||
|
||||
return server;
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception
|
||||
{
|
||||
Server server = createServer(8080);
|
||||
|
||||
// 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.plus.jndi.EnvEntry;
|
||||
import org.eclipse.jetty.plus.jndi.NamingDump;
|
||||
|
@ -34,10 +37,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
|
||||
Server server = new Server(8080);
|
||||
Server server = new Server(port);
|
||||
|
||||
// Enable parsing of jndi-related parts of web.xml and jetty-env.xml
|
||||
Configuration.ClassList classlist = Configuration.ClassList
|
||||
|
@ -63,7 +66,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
|
||||
|
@ -73,10 +76,21 @@ public class ServerWithAnnotations
|
|||
server.addBean(new NamingDump());
|
||||
|
||||
// Configure a LoginService
|
||||
ClassLoader classLoader = ServerWithAnnotations.class.getClassLoader();
|
||||
URL realmProps = classLoader.getResource("realm.properties");
|
||||
if (realmProps == null)
|
||||
throw new FileNotFoundException("Unable to find realm.properties");
|
||||
|
||||
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
|
||||
{
|
||||
Server server = createServer(8080);
|
||||
|
||||
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,13 @@ public class ServerWithJMX
|
|||
"org.eclipse.jetty.jmx:name=rmiconnectorserver");
|
||||
server.addBean(jmx);
|
||||
|
||||
return server;
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception
|
||||
{
|
||||
Server server = createServer(8080);
|
||||
|
||||
server.start();
|
||||
server.dumpStdErr();
|
||||
server.join();
|
||||
|
|
|
@ -18,10 +18,12 @@
|
|||
|
||||
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.server.Server;
|
||||
import org.eclipse.jetty.util.resource.PathResource;
|
||||
import org.eclipse.jetty.webapp.Configuration;
|
||||
import org.eclipse.jetty.webapp.WebAppContext;
|
||||
|
||||
|
@ -30,11 +32,10 @@ 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);
|
||||
|
||||
// Enable parsing of jndi-related parts of web.xml and jetty-env.xml
|
||||
Configuration.ClassList classlist = Configuration.ClassList
|
||||
|
@ -46,9 +47,8 @@ public class ServerWithJNDI
|
|||
// 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);
|
||||
|
||||
// Register new transaction manager in JNDI
|
||||
|
@ -64,7 +64,7 @@ public class ServerWithJNDI
|
|||
// <env-entry-type>java.lang.Integer</env-entry-type>
|
||||
// <env-entry-value>4000</env-entry-value>
|
||||
// </env-entry>
|
||||
new org.eclipse.jetty.plus.jndi.EnvEntry(server, "woggle", new Integer(4000), false);
|
||||
new org.eclipse.jetty.plus.jndi.EnvEntry(server, "woggle", 4000, false);
|
||||
|
||||
// Define an env entry with webapp scope.
|
||||
// At runtime, the webapp accesses this as java:comp/env/wiggle
|
||||
|
@ -77,7 +77,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", new Double(100), 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:
|
||||
|
@ -87,7 +87,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();
|
||||
|
@ -109,6 +110,12 @@ 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
|
||||
{
|
||||
Server server = createServer(8080);
|
||||
|
||||
server.start();
|
||||
server.join();
|
||||
|
|
|
@ -25,11 +25,19 @@ 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);
|
||||
Server server = createServer(8080);
|
||||
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,67 @@ 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
|
||||
{
|
||||
Resource resource0 = new PathResource(Paths.get("src/test/resources/dir0"));
|
||||
Resource resource1 = new PathResource(Paths.get("src/test/resources/dir1"));
|
||||
|
||||
Server server = createServer(8080, 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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,6 +18,8 @@
|
|||
|
||||
package org.eclipse.jetty.embedded;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.websocket.DeploymentException;
|
||||
import javax.websocket.OnMessage;
|
||||
import javax.websocket.Session;
|
||||
import javax.websocket.server.ServerEndpoint;
|
||||
|
@ -47,9 +49,9 @@ public class WebSocketJsrServer
|
|||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception
|
||||
public static Server createServer(int port) throws DeploymentException, ServletException
|
||||
{
|
||||
Server server = new Server(8080);
|
||||
Server server = new Server(port);
|
||||
|
||||
HandlerList handlers = new HandlerList();
|
||||
|
||||
|
@ -68,8 +70,15 @@ public class WebSocketJsrServer
|
|||
handlers.addHandler(new DefaultHandler());
|
||||
|
||||
server.setHandler(handlers);
|
||||
|
||||
return server;
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception
|
||||
{
|
||||
Server server = createServer(8080);
|
||||
|
||||
server.start();
|
||||
context.dumpStdErr();
|
||||
server.join();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,7 +20,6 @@ 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.annotations.OnWebSocketMessage;
|
||||
import org.eclipse.jetty.websocket.api.annotations.WebSocket;
|
||||
|
@ -61,20 +60,24 @@ 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");
|
||||
return server;
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception
|
||||
{
|
||||
Server server = createServer(8080);
|
||||
|
||||
server.start();
|
||||
context.dumpStdErr();
|
||||
server.join();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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.io.IOException;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URI;
|
||||
import java.util.Set;
|
||||
import javax.management.MBeanServer;
|
||||
import javax.management.ObjectInstance;
|
||||
import javax.management.ObjectName;
|
||||
|
||||
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 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
|
||||
{
|
||||
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 IOException
|
||||
{
|
||||
URI uri = server.getURI().resolve("/dump/something");
|
||||
HttpURLConnection http = (HttpURLConnection)uri.toURL().openConnection();
|
||||
assertThat("HTTP Response Status", http.getResponseCode(), is(HttpURLConnection.HTTP_OK));
|
||||
|
||||
// HttpUtil.dumpResponseHeaders(http);
|
||||
|
||||
// test response content
|
||||
String responseBody = HttpUtil.getResponseBody(http);
|
||||
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().get();
|
||||
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,91 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// 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.io.IOException;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URI;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
|
||||
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
|
||||
{
|
||||
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 IOException
|
||||
{
|
||||
URI uri = server.getURI().resolve("/");
|
||||
HttpURLConnection http = (HttpURLConnection)uri.toURL().openConnection();
|
||||
assertThat("HTTP Response Status", http.getResponseCode(), is(HttpURLConnection.HTTP_OK));
|
||||
|
||||
// HttpUtil.dumpResponseHeaders(http);
|
||||
String setCookieValue = http.getHeaderField("Set-Cookie");
|
||||
assertThat("Set-Cookie value", setCookieValue, containsString("JSESSIONID="));
|
||||
|
||||
// test response content
|
||||
String responseBody = HttpUtil.getResponseBody(http);
|
||||
assertThat("Response Content", responseBody,
|
||||
allOf(
|
||||
containsString("session.getId() = "),
|
||||
containsString("session.isNew() = true")
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
|
@ -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 java.io.IOException;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URI;
|
||||
|
||||
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 OneWebAppTest
|
||||
{
|
||||
private Server server;
|
||||
|
||||
@BeforeEach
|
||||
public void startServer() throws Exception
|
||||
{
|
||||
server = OneWebApp.createServer(0);
|
||||
server.start();
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
public void stopServer() throws Exception
|
||||
{
|
||||
server.stop();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetAsyncRest() throws IOException
|
||||
{
|
||||
URI uri = server.getURI().resolve("/testAsync?items=mouse,beer,gnome");
|
||||
HttpURLConnection http = (HttpURLConnection)uri.toURL().openConnection();
|
||||
assertThat("HTTP Response Status", http.getResponseCode(), is(HttpURLConnection.HTTP_OK));
|
||||
|
||||
// HttpUtil.dumpResponseHeaders(http);
|
||||
|
||||
// test response content
|
||||
String responseBody = HttpUtil.getResponseBody(http);
|
||||
assertThat("Response Content", responseBody, containsString("Asynchronous: mouse,beer,gnome"));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,102 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// 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.IOException;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URI;
|
||||
|
||||
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 OneWebAppWithJspTest
|
||||
{
|
||||
private Server server;
|
||||
private URI serverLocalUri;
|
||||
|
||||
@BeforeEach
|
||||
public void startServer() throws Exception
|
||||
{
|
||||
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
|
||||
{
|
||||
server.stop();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetDumpInfo() throws IOException
|
||||
{
|
||||
URI uri = serverLocalUri.resolve("/dump/info");
|
||||
HttpURLConnection http = (HttpURLConnection)uri.toURL().openConnection();
|
||||
assertThat("HTTP Response Status", http.getResponseCode(), is(HttpURLConnection.HTTP_OK));
|
||||
|
||||
HttpUtil.dumpResponseHeaders(http);
|
||||
|
||||
// test response content
|
||||
String responseBody = HttpUtil.getResponseBody(http);
|
||||
assertThat("Response Content", responseBody, containsString("getProtocol: </th><td>HTTP/1.1"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetJspExpr() throws IOException
|
||||
{
|
||||
URI uri = serverLocalUri.resolve("/jsp/expr.jsp?A=1");
|
||||
HttpURLConnection http = (HttpURLConnection)uri.toURL().openConnection();
|
||||
String userAgent = OneWebAppWithJspTest.class.getSimpleName();
|
||||
http.setRequestProperty("User-Agent", userAgent);
|
||||
assertThat("HTTP Response Status", http.getResponseCode(), is(HttpURLConnection.HTTP_OK));
|
||||
|
||||
// HttpUtil.dumpResponseHeaders(http);
|
||||
|
||||
// test response content
|
||||
String responseBody = HttpUtil.getResponseBody(http);
|
||||
assertThat("Response Content", responseBody, containsString("<td>" + userAgent + "</td>"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetJstlExpr() throws IOException
|
||||
{
|
||||
URI uri = serverLocalUri.resolve("/jsp/jstl.jsp");
|
||||
HttpURLConnection http = (HttpURLConnection)uri.toURL().openConnection();
|
||||
assertThat("HTTP Response Status", http.getResponseCode(), is(HttpURLConnection.HTTP_OK));
|
||||
|
||||
// HttpUtil.dumpResponseHeaders(http);
|
||||
|
||||
// test response content
|
||||
String responseBody = HttpUtil.getResponseBody(http);
|
||||
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,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.io.IOException;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.Proxy;
|
||||
import java.net.URI;
|
||||
|
||||
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
|
||||
{
|
||||
private Server server;
|
||||
private Proxy javaHttpProxy;
|
||||
|
||||
@BeforeEach
|
||||
public void startServer() throws Exception
|
||||
{
|
||||
server = ProxyServer.createServer(0);
|
||||
server.start();
|
||||
|
||||
URI uri = server.getURI();
|
||||
javaHttpProxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(uri.getHost(), uri.getPort()));
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
public void stopServer() throws Exception
|
||||
{
|
||||
server.stop();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetProxiedRFC() throws IOException
|
||||
{
|
||||
URI uri = URI.create("https://tools.ietf.org/rfc/rfc7230.txt");
|
||||
HttpURLConnection http = (HttpURLConnection)uri.toURL().openConnection(javaHttpProxy);
|
||||
assertThat("HTTP Response Status", http.getResponseCode(), is(HttpURLConnection.HTTP_OK));
|
||||
|
||||
// HttpUtil.dumpResponseHeaders(http);
|
||||
|
||||
// test response content
|
||||
String responseBody = HttpUtil.getResponseBody(http);
|
||||
assertThat("Response Content", responseBody, containsString("Hypertext Transfer Protocol (HTTP/1.1): Message Syntax and Routing"));
|
||||
}
|
||||
}
|
|
@ -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.io.IOException;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URI;
|
||||
|
||||
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
|
||||
{
|
||||
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 IOException
|
||||
{
|
||||
URI destUri = server.getURI().resolve("/do-be-foo-be-do");
|
||||
HttpURLConnection http = (HttpURLConnection)destUri.toURL().openConnection();
|
||||
assertThat("HTTP Response Status", http.getResponseCode(), is(HttpURLConnection.HTTP_OK));
|
||||
|
||||
// HttpUtil.dumpResponseHeaders(http);
|
||||
|
||||
// test response content
|
||||
String responseBody = HttpUtil.getResponseBody(http);
|
||||
assertThat("Response Content", responseBody, containsString("requestURI=/do-be-FOO-be-do"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetRewriteFooInPath() throws IOException
|
||||
{
|
||||
URI destUri = server.getURI().resolve("/do/be/foo/be/do.it");
|
||||
HttpURLConnection http = (HttpURLConnection)destUri.toURL().openConnection();
|
||||
assertThat("HTTP Response Status", http.getResponseCode(), is(HttpURLConnection.HTTP_OK));
|
||||
|
||||
// HttpUtil.dumpResponseHeaders(http);
|
||||
|
||||
// test response content
|
||||
String responseBody = HttpUtil.getResponseBody(http);
|
||||
assertThat("Response Content", responseBody, containsString("requestURI=/do/be/FOO/be/do.it"));
|
||||
}
|
||||
}
|
|
@ -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.io.IOException;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URI;
|
||||
import java.util.Base64;
|
||||
|
||||
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
|
||||
{
|
||||
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 IOException
|
||||
{
|
||||
URI destUri = server.getURI().resolve("/hello");
|
||||
HttpURLConnection http = (HttpURLConnection)destUri.toURL().openConnection();
|
||||
assertThat("HTTP Response Status", http.getResponseCode(), is(HttpURLConnection.HTTP_UNAUTHORIZED));
|
||||
|
||||
// HttpUtil.dumpResponseHeaders(http);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetWithAuth() throws IOException
|
||||
{
|
||||
URI destUri = server.getURI().resolve("/hello");
|
||||
HttpURLConnection http = (HttpURLConnection)destUri.toURL().openConnection();
|
||||
String authEncoded = Base64.getEncoder().encodeToString("user:password".getBytes(UTF_8));
|
||||
http.setRequestProperty("Authorization", "Basic " + authEncoded);
|
||||
assertThat("HTTP Response Status", http.getResponseCode(), is(HttpURLConnection.HTTP_OK));
|
||||
|
||||
// HttpUtil.dumpResponseHeaders(http);
|
||||
|
||||
// test response content
|
||||
String responseBody = HttpUtil.getResponseBody(http);
|
||||
assertThat("Response Content", responseBody, containsString("<h1>Hello World</h1>"));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,66 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// 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.IOException;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URI;
|
||||
|
||||
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;
|
||||
import static org.hamcrest.Matchers.not;
|
||||
|
||||
public class ServerWithAnnotationsTest
|
||||
{
|
||||
private Server server;
|
||||
|
||||
@BeforeEach
|
||||
public void startServer() throws Exception
|
||||
{
|
||||
server = ServerWithAnnotations.createServer(0);
|
||||
server.start();
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
public void stopServer() throws Exception
|
||||
{
|
||||
server.stop();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetTest() throws IOException
|
||||
{
|
||||
URI destUri = server.getURI().resolve("/test");
|
||||
HttpURLConnection http = (HttpURLConnection)destUri.toURL().openConnection();
|
||||
assertThat("HTTP Response Status", http.getResponseCode(), is(HttpURLConnection.HTTP_OK));
|
||||
|
||||
// HttpUtil.dumpResponseHeaders(http);
|
||||
|
||||
// test response content
|
||||
String responseBody = HttpUtil.getResponseBody(http);
|
||||
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
|
||||
{
|
||||
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,73 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// 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.HttpURLConnection;
|
||||
import java.net.URI;
|
||||
|
||||
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.allOf;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.not;
|
||||
|
||||
public class ServerWithJNDITest
|
||||
{
|
||||
private Server server;
|
||||
|
||||
@BeforeEach
|
||||
public void startServer() throws Exception
|
||||
{
|
||||
server = ServerWithJNDI.createServer(0);
|
||||
server.start();
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
public void stopServer() throws Exception
|
||||
{
|
||||
server.stop();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetTest() throws Exception
|
||||
{
|
||||
URI destUri = server.getURI().resolve("/test");
|
||||
HttpURLConnection http = (HttpURLConnection)destUri.toURL().openConnection();
|
||||
assertThat("HTTP Response Status", http.getResponseCode(), is(HttpURLConnection.HTTP_OK));
|
||||
|
||||
// HttpUtil.dumpResponseHeaders(http);
|
||||
|
||||
// test response content
|
||||
String responseBody = HttpUtil.getResponseBody(http);
|
||||
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,56 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// 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.HttpURLConnection;
|
||||
import java.net.URI;
|
||||
|
||||
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
|
||||
{
|
||||
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 destUri = server.getURI().resolve("/test");
|
||||
HttpURLConnection http = (HttpURLConnection)destUri.toURL().openConnection();
|
||||
assertThat("HTTP Response Status", http.getResponseCode(), is(HttpURLConnection.HTTP_NOT_FOUND));
|
||||
}
|
||||
}
|
|
@ -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.IOException;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URI;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
|
||||
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
|
||||
{
|
||||
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 IOException
|
||||
{
|
||||
URI uri = server.getURI().resolve("/test0.txt");
|
||||
HttpURLConnection http = (HttpURLConnection)uri.toURL().openConnection();
|
||||
assertThat("HTTP Response Status", http.getResponseCode(), is(HttpURLConnection.HTTP_OK));
|
||||
|
||||
// HttpUtil.dumpResponseHeaders(http);
|
||||
|
||||
// test response content
|
||||
String responseBody = HttpUtil.getResponseBody(http);
|
||||
assertThat("Response Content", responseBody, containsString("test0"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetTest1() throws IOException
|
||||
{
|
||||
URI uri = server.getURI().resolve("/test1.txt");
|
||||
HttpURLConnection http = (HttpURLConnection)uri.toURL().openConnection();
|
||||
assertThat("HTTP Response Status", http.getResponseCode(), is(HttpURLConnection.HTTP_OK));
|
||||
|
||||
// HttpUtil.dumpResponseHeaders(http);
|
||||
|
||||
// test response content
|
||||
String responseBody = HttpUtil.getResponseBody(http);
|
||||
assertThat("Response Content", responseBody, containsString("test1"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetTest2() throws IOException
|
||||
{
|
||||
URI uri = server.getURI().resolve("/test2.txt");
|
||||
HttpURLConnection http = (HttpURLConnection)uri.toURL().openConnection();
|
||||
assertThat("HTTP Response Status", http.getResponseCode(), is(HttpURLConnection.HTTP_NOT_FOUND));
|
||||
}
|
||||
}
|
|
@ -295,19 +295,19 @@ public class AnnotationTest extends HttpServlet
|
|||
out.println("private Double minAmount;");
|
||||
out.println("</pre>");
|
||||
if (maxAmount == null)
|
||||
out.println("<p><b>Result: " + envResult + ": <span class=\"fail\">FAIL");
|
||||
out.println("<p><b>Result: " + envResult + ": <span class=\"fail\">FAIL</span>");
|
||||
else
|
||||
out.println("<p><b>Result: " + envResult + ": " + (maxAmount.compareTo(new Double(55)) == 0 ? " <span class=\"pass\">PASS" : " <span class=\"fail\">FAIL") + "</span></b>");
|
||||
out.println("<br/><b>JNDI Lookup Result: " + envLookupResult + "</b>");
|
||||
|
||||
if (minAmount == null)
|
||||
out.println("<p><b>Result: " + envResult2 + ": <span class=\"fail\">FAIL");
|
||||
out.println("<p><b>Result: " + envResult2 + ": <span class=\"fail\">FAIL</span>");
|
||||
else
|
||||
out.println("<br/><b>Result: " + envResult2 + ": " + (minAmount.compareTo(new Double("0.99")) == 0 ? " <span class=\"pass\">PASS" : " <span class=\"fail\">FAIL") + "</span></b>");
|
||||
out.println("<br/><b>JNDI Lookup Result: " + envLookupResult2 + "</b>");
|
||||
|
||||
if (avgAmount == null)
|
||||
out.println("<p><b>Result: " + envResult3 + ": <span class=\"fail\">FAIL");
|
||||
out.println("<p><b>Result: " + envResult3 + ": <span class=\"fail\">FAIL</span>");
|
||||
else
|
||||
out.println("<br/><b>Result: " + envResult3 + ": " + (avgAmount.compareTo(new Double("1.25")) == 0 ? " <span class=\"pass\">PASS" : " <span class=\"fail\">FAIL") + "</span></b>");
|
||||
out.println("<br/><b>JNDI Lookup Result: " + envLookupResult3 + "</b></p>");
|
||||
|
|
Loading…
Reference in New Issue