From f1c56d7f8c1b8c3ff735cbaa2bc02aa476417123 Mon Sep 17 00:00:00 2001 From: Jan Bartel Date: Wed, 15 Jun 2016 13:46:39 +1000 Subject: [PATCH 1/4] Issue #641 Also use mongo createIndex for index on validity and access time fields --- .../jetty/nosql/mongodb/MongoSessionIdManager.java | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/jetty-nosql/src/main/java/org/eclipse/jetty/nosql/mongodb/MongoSessionIdManager.java b/jetty-nosql/src/main/java/org/eclipse/jetty/nosql/mongodb/MongoSessionIdManager.java index 7bff83e444f..18323639d89 100644 --- a/jetty-nosql/src/main/java/org/eclipse/jetty/nosql/mongodb/MongoSessionIdManager.java +++ b/jetty-nosql/src/main/java/org/eclipse/jetty/nosql/mongodb/MongoSessionIdManager.java @@ -204,9 +204,14 @@ public class MongoSessionIdManager extends AbstractSessionIdManager // index our accessed and valid fields so that purges are faster, note that the "valid" field is first // so that we can take advantage of index prefixes // http://docs.mongodb.org/manual/core/index-compound/#compound-index-prefix - _sessions.ensureIndex( - BasicDBObjectBuilder.start().add(MongoSessionManager.__VALID, 1).add(MongoSessionManager.__ACCESSED, 1).get(), - BasicDBObjectBuilder.start().add("sparse", false).add("background", true).get()); + + DBObject validKey = BasicDBObjectBuilder.start().add(MongoSessionManager.__VALID, 1).add(MongoSessionManager.__ACCESSED, 1).get(); + _sessions.createIndex(validKey, + BasicDBObjectBuilder.start() + .add("name", MongoSessionManager.__VALID+"_1_"+MongoSessionManager.__ACCESSED+"_1") + .add("ns", _sessions.getFullName()) + .add("sparse", false) + .add("background", true).get()); } /* ------------------------------------------------------------ */ From 69804f9e768ba4c7a6b092dcf0b977e66cad4e6d Mon Sep 17 00:00:00 2001 From: WalkerWatch Date: Wed, 15 Jun 2016 01:55:11 -0400 Subject: [PATCH 2/4] Chapter 24 touch-ups. (#635) Signed-off-by: WalkerWatch --- .../embedding/embedded-examples.adoc | 4 +- .../embedding/embedding-jetty.adoc | 80 +++++++++---------- .../examples/embedded-file-server.adoc | 4 +- .../examples/embedded-many-connectors.adoc | 6 +- .../examples/embedded-minimal-servlet.adoc | 10 +-- .../examples/embedded-one-webapp.adoc | 6 +- .../embedded-secured-hello-handler.adoc | 6 +- .../examples/embedded-split-file-server.adoc | 2 +- .../embedding/jetty-helloworld.adoc | 6 +- 9 files changed, 62 insertions(+), 62 deletions(-) diff --git a/jetty-documentation/src/main/asciidoc/development/embedding/embedded-examples.adoc b/jetty-documentation/src/main/asciidoc/development/embedding/embedded-examples.adoc index c106a0ed3f3..8b76ad180d3 100644 --- a/jetty-documentation/src/main/asciidoc/development/embedding/embedded-examples.adoc +++ b/jetty-documentation/src/main/asciidoc/development/embedding/embedded-examples.adoc @@ -37,7 +37,7 @@ include::examples/embedded-one-webapp.adoc[] ==== Web Application with JSP This example is very similar to the one in the previous section, although it enables the embedded webapp to use JSPs. -As of jetty-9.2, we use the JSP engine from Apache, which relies on a Servlet Specification 3.1 style ServletContainerInitializer to initialize itself. +As of jetty-9.2, we use the JSP engine from Apache, which relies on a Servlet Specification 3.1 style `ServletContainerInitializer` to initialize itself. To get this to work with Jetty, you need to enable annotations processing, as shown in this example code: [source, java, subs="{sub-order}"] @@ -52,7 +52,7 @@ After you have started things up you should be able to navigate to http://localh ===== Maven Coordinates -To use this example in your project, you will need the following maven dependencies declared, in addition to those from the previous section: +To use this example in your project, you will need the following Maven dependencies declared, in addition to those from the previous section: [source, xml, subs="{sub-order}"] ---- diff --git a/jetty-documentation/src/main/asciidoc/development/embedding/embedding-jetty.adoc b/jetty-documentation/src/main/asciidoc/development/embedding/embedding-jetty.adoc index 61d093b7b06..b72a673016e 100644 --- a/jetty-documentation/src/main/asciidoc/development/embedding/embedding-jetty.adoc +++ b/jetty-documentation/src/main/asciidoc/development/embedding/embedding-jetty.adoc @@ -52,8 +52,8 @@ A handler may: * Examine/modify the HTTP request. * Generate the complete HTTP response. -* Call another Handler (see HandlerWrapper). -* Select one or many Handlers to call (see HandlerCollection). +* Call another Handler (see link:{JDURL}/org/eclipse/jetty/server/handler/HandlerWrapper.html[`HandlerWrapper`]). +* Select one or many Handlers to call (see link:{JDURL}/org/eclipse/jetty/server/handler/HandlerCollection.html[`HandlerCollection`]). ===== HelloWorld Handler @@ -66,10 +66,10 @@ include::{SRCDIR}/examples/embedded/src/main/java/org/eclipse/jetty/embedded/Hel The parameters passed to the handle method are: -* target–the target of the request, which is either a URI or a name from a named dispatcher. -* baseRequest–the Jetty mutable request object, which is always unwrapped. -* request–the immutable request object, which may have been wrapped by a filter or servlet. -* response–the response, which may have been wrapped by a filter or servlet. +* `target` – the target of the request, which is either a URI or a name from a named dispatcher. +* `baseRequest` – the Jetty mutable request object, which is always unwrapped. +* `request` – the immutable request object, which may have been wrapped by a filter or servlet. +* `response` – the response, which may have been wrapped by a filter or servlet. The handler sets the response status, content-type, and marks the request as handled before it generates the body of the response using a writer. @@ -84,7 +84,7 @@ include::{SRCDIR}/examples/embedded/src/main/java/org/eclipse/jetty/embedded/One ---- One or more handlers do all request handling in Jetty. -Some handlers select other specific handlers (for example, a ContextHandlerCollection uses the context path to select a ContextHandler); others use application logic to generate a response (for example, the ServletHandler passes the request to an application Servlet), while others do tasks unrelated to generating the response (for example, RequestLogHandler or StatisticsHandler). +Some handlers select other specific handlers (for example, a `ContextHandlerCollection` uses the context path to select a `ContextHandler`); others use application logic to generate a response (for example, the `ServletHandler` passes the request to an application Servlet), while others do tasks unrelated to generating the response (for example, `RequestLogHandler` or `StatisticsHandler`). Later sections describe how you can combine handlers like aspects. You can see some of the handlers available in Jetty in the link:{JXURL}/org/eclipse/jetty/server/handler/package-summary.html[org.eclipse.jetty.server.handler] package. @@ -92,28 +92,28 @@ You can see some of the handlers available in Jetty in the link:{JXURL}/org/ecli ===== Handler Collections and Wrappers Complex request handling is typically built from multiple Handlers that you can combine in various ways. -Jetty has several implementations of the link:{JDURL}/org/eclipse/jetty/server/HandlerContainer.html[HandlerContainer] interface: +Jetty has several implementations of the link:{JDURL}/org/eclipse/jetty/server/HandlerContainer.html[`HandlerContainer`] interface: -link:{JDURL}/org/eclipse/jetty/server/handler/HandlerCollection.html[HandlerCollection]:: +link:{JDURL}/org/eclipse/jetty/server/handler/HandlerCollection.html[`HandlerCollection`]:: Holds a collection of other handlers and calls each handler in order. This is useful for combining statistics and logging handlers with the handler that generates the response. -link:{JDURL}/org/eclipse/jetty/server/handler/HandlerList.html[HandlerList]:: - A Handler Collection that calls each handler in turn until either an exception is thrown, the response is committed or the request.isHandled() returns true. +link:{JDURL}/org/eclipse/jetty/server/handler/HandlerList.html[`HandlerList`]:: + A Handler Collection that calls each handler in turn until either an exception is thrown, the response is committed or the `request.isHandled()` returns true. You can use it to combine handlers that conditionally handle a request, such as calling multiple contexts until one matches a virtual host. -link:{JDURL}/org/eclipse/jetty/server/handler/HandlerWrapper.html[HandlerWrapper]:: +link:{JDURL}/org/eclipse/jetty/server/handler/HandlerWrapper.html[`HandlerWrapper`]:: A Handler base class that you can use to daisy chain handlers together in the style of aspect-oriented programming. For example, a standard web application is implemented by a chain of a context, session, security and servlet handlers. -link:{JDURL}/org/eclipse/jetty/server/handler/ContextHandlerCollection.html[ContextHandlerCollection]:: - A specialized HandlerCollection that uses the longest prefix of the request URI (the contextPath) to select a contained ContextHandler to handle the request. +link:{JDURL}/org/eclipse/jetty/server/handler/ContextHandlerCollection.html[`ContextHandlerCollection`]:: + A specialized `HandlerCollection` that uses the longest prefix of the request URI (the `contextPath`) to select a contained `ContextHandler` to handle the request. ===== Scoped Handlers -Much of the standard Servlet container in Jetty is implemented with HandlerWrappers that daisy chain handlers together: ContextHandler to SessionHandler to SecurityHandler to ServletHandler. +Much of the standard Servlet container in Jetty is implemented with `HandlerWrappers` that daisy chain handlers together: `ContextHandler` to `SessionHandler` to `SecurityHandler` to `ServletHandler`. However, because of the nature of the servlet specification, this chaining cannot be a pure nesting of handlers as the outer handlers sometimes need information that the inner handlers process. -For example, when a ContextHandler calls some application listeners to inform them of a request entering the context, it must already know which servlet the ServletHandler will dispatch the request to so that the servletPath method returns the correct value. +For example, when a `ContextHandler` calls some application listeners to inform them of a request entering the context, it must already know which servlet the `ServletHandler` will dispatch the request to so that the `servletPath` method returns the correct value. -The HandlerWrapper is specialized to the link:{JXURL}/org/eclipse/jetty/server/handler/ScopedHandler.html[ScopedHandler] abstract class, which supports a daisy chain of scopes. -For example if a ServletHandler is nested within a ContextHandler, the order and nesting of execution of methods is: +The `HandlerWrapper` is specialized to the link:{JXURL}/org/eclipse/jetty/server/handler/ScopedHandler.html[`ScopedHandler`] abstract class, which supports a daisy chain of scopes. +For example if a `ServletHandler` is nested within a `ContextHandler`, the order and nesting of execution of methods is: .... Server.handle(...) @@ -124,23 +124,23 @@ Server.handle(...) SomeServlet.service(...) .... -Thus when the ContextHandler handles the request, it does so within the scope the ServletHandler has established. +Thus when the `ContextHandler` handles the request, it does so within the scope the `ServletHandler` has established. ===== Resource Handler -The link:{JXURL}/org/eclipse/jetty/embedded/FileServer.html[FileServer example] shows how you can use a ResourceHandler to serve static content from the current working directory: +The link:{JXURL}/org/eclipse/jetty/embedded/FileServer.html[FileServer example] shows how you can use a `ResourceHandler` to serve static content from the current working directory: [source, java, subs="{sub-order}"] ---- include::{SRCDIR}/examples/embedded/src/main/java/org/eclipse/jetty/embedded/FileServer.java[] ---- -Notice that a HandlerList is used with the ResourceHandler and a DefaultHandler, so that the DefaultHandler generates a good 404 response for any requests that do not match a static resource. +Notice that a `HandlerList` is used with the `ResourceHandler` and a `DefaultHandler`, so that the `DefaultHandler` generates a good 404 response for any requests that do not match a static resource. ==== Embedding Connectors In the previous examples, the Server instance is passed a port number and it internally creates a default instance of a Connector that listens for requests on that port. -However, often when embedding Jetty it is desirable to explicity instantiate and configure one or more Connectors for a Server instance. +However, often when embedding Jetty it is desirable to explicitly instantiate and configure one or more Connectors for a Server instance. ===== One Connector @@ -152,24 +152,24 @@ instantiates, configures, and adds a single HTTP connector instance to the serve include::{SRCDIR}/examples/embedded/src/main/java/org/eclipse/jetty/embedded/OneConnector.java[] ---- -In this example the connector handles the HTTP protocol, as that is the default for the link:{JXURL}/org/eclipse/jetty/server/ServerConnector.html[ServerConnector] class. +In this example the connector handles the HTTP protocol, as that is the default for the link:{JXURL}/org/eclipse/jetty/server/ServerConnector.html[`ServerConnector`] class. ===== Many Connectors When configuring multiple connectors (for example, HTTP and HTTPS), it may be desirable to share configuration of common parameters for HTTP. -To achieve this you need to explicitly configure the ServerConnector class with ConnectionFactory instances, and provide them with common HTTP configuration. +To achieve this you need to explicitly configure the `ServerConnector` class with `ConnectionFactory` instances, and provide them with common HTTP configuration. -The link:{JXURL}/org/eclipse/jetty/embedded/ManyConnectors.html[ManyConnectors example], configures a server with two ServerConnector instances: the http connector has a link:{JXURL}/org/eclipse/jetty/server/HttpConnectionFactory.html[HTTPConnectionFactory] instance; the https connector has a SslConnectionFactory chained to a HttpConnectionFactory. -Both HttpConnectionFactories are configured based on the same link:{JXURL}/org/eclipse/jetty/server/HttpConfiguration.html[HttpConfiguration] instance, however the HTTPS factory uses a wrapped configuration so that a link:{JXURL}/org/eclipse/jetty/server/SecureRequestCustomizer.html[SecureRequestCustomizer] can be added. +The link:{JXURL}/org/eclipse/jetty/embedded/ManyConnectors.html[ManyConnectors example], configures a server with two `ServerConnector` instances: the http connector has a link:{JXURL}/org/eclipse/jetty/server/HttpConnectionFactory.html[`HTTPConnectionFactory`] instance; the https connector has a `SslConnectionFactory` chained to a `HttpConnectionFactory`. +Both `HttpConnectionFactory` are configured based on the same link:{JXURL}/org/eclipse/jetty/server/HttpConfiguration.html[`HttpConfiguration`] instance, however the HTTPS factory uses a wrapped configuration so that a link:{JXURL}/org/eclipse/jetty/server/SecureRequestCustomizer.html[`SecureRequestCustomizer`] can be added. ==== Embedding Servlets http://en.wikipedia.org/wiki/Java_Servlet[Servlets] are the standard way to provide application logic that handles HTTP requests. Servlets are similar to a Jetty Handler except that the request object is not mutable and thus cannot be modified. -Servlets are handled in Jetty by a link:{JXURL}/org/eclipse/jetty/embedded/MinimalServlets.html[ServletHandler]. -It uses standard path mappings to match a Servlet to a request; sets the requests servletPath and pathInfo; passes the request to the servlet, possibly via Filters to produce a response. +Servlets are handled in Jetty by a link:{JXURL}/org/eclipse/jetty/embedded/MinimalServlets.html[`ServletHandler`]. +It uses standard path mappings to match a Servlet to a request; sets the requests `servletPath` and `pathInfo`; passes the request to the servlet, possibly via Filters to produce a response. -The link:{JXURL}/org/eclipse/jetty/embedded/MinimalServlets.html[MinimalServlets example] creates a ServletHandler instance and configures a single HelloServlet: +The link:{JXURL}/org/eclipse/jetty/embedded/MinimalServlets.html[MinimalServlets example] creates a `ServletHandler` instance and configures a single HelloServlet: [source, java, subs="{sub-order}"] ---- @@ -178,13 +178,13 @@ include::{SRCDIR}/examples/embedded/src/main/java/org/eclipse/jetty/embedded/Min ==== Embedding Contexts -A link:{JXURL}/org/eclipse/jetty/embedded/OneContext.html[ContextHandler] is a ScopedHandler that responds only to requests that have a URI prefix that matches the configured context path. +A link:{JXURL}/org/eclipse/jetty/embedded/OneContext.html[`ContextHandler`] is a `ScopedHandler` that responds only to requests that have a URI prefix that matches the configured context path. Requests that match the context path have their path methods updated accordingly and the contexts scope is available, which optionally may include: -* A Classloader that is set as the Thread context classloader while request handling is in scope. -* A set of attributes that is available via the http://docs.oracle.com/javaee/6/api/javax/servlet/ServletContext.html[ServletContext] API. -* A set of init parameters that is available via the http://docs.oracle.com/javaee/6/api/javax/servlet/ServletContext.html[ServletContext] API. -* A base Resource which is used as the document root for static resource requests via the http://docs.oracle.com/javaee/6/api/javax/servlet/ServletContext.html[ServletContext] API. +* A `Classloader` that is set as the Thread context `classloader` while request handling is in scope. +* A set of attributes that is available via the http://docs.oracle.com/javaee/6/api/javax/servlet/ServletContext.html[`ServletContext`] API. +* A set of init parameters that is available via the http://docs.oracle.com/javaee/6/api/javax/servlet/ServletContext.html[`ServletContext`] API. +* A base Resource which is used as the document root for static resource requests via the http://docs.oracle.com/javaee/6/api/javax/servlet/ServletContext.html[`ServletContext`] API. * A set of virtual host names. The following link:{JXURL}/org/eclipse/jetty/embedded/OneContext.html[OneContext example] shows a context being established that wraps the link:{JXURL}/org/eclipse/jetty/embedded/HelloHandler.html[HelloHandler]: @@ -194,7 +194,7 @@ The following link:{JXURL}/org/eclipse/jetty/embedded/OneContext.html[OneContext include::{SRCDIR}/examples/embedded/src/main/java/org/eclipse/jetty/embedded/OneContext.java[] ---- -When many contexts are present, you can embed a ContextHandlerCollection to efficiently examine a request URI to then select the matching ContextHandler(s) for the request. +When many contexts are present, you can embed a `ContextHandlerCollection` to efficiently examine a request URI to then select the matching `ContextHandler`(s) for the request. The link:{JXURL}/org/eclipse/jetty/embedded/ManyContexts.html[ManyContexts example] shows how many such contexts you can configure: [source, java, subs="{sub-order}"] @@ -204,8 +204,8 @@ include::{SRCDIR}/examples/embedded/src/main/java/org/eclipse/jetty/embedded/Man ==== Embedding ServletContexts -A link:{JXURL}/org/eclipse/jetty/servlet/ServletContextHandler.html[ServletContextHandler] is a specialization of ContextHandler with support for standard sessions and Servlets. -The following link:{JXURL}/org/eclipse/jetty/embedded/OneServletContext.html[OneServletContext example] instantiates a link:{JXURL}/org/eclipse/jetty/servlet/DefaultServlet.html[DefaultServlet] to server static content from /tmp/ and a `DumpServlet` that creates a session and dumps basic details about the request: +A link:{JXURL}/org/eclipse/jetty/servlet/ServletContextHandler.html[`ServletContextHandler`] is a specialization of `ContextHandler` with support for standard sessions and Servlets. +The following link:{JXURL}/org/eclipse/jetty/embedded/OneServletContext.html[OneServletContext example] instantiates a link:{JXURL}/org/eclipse/jetty/servlet/DefaultServlet.html[`DefaultServlet`] to server static content from /tmp/ and a `DumpServlet` that creates a session and dumps basic details about the request: [source, java, subs="{sub-order}"] ---- @@ -214,9 +214,9 @@ include::{SRCDIR}/examples/embedded/src/main/java/org/eclipse/jetty/embedded/One ==== Embedding Web Applications -A link:{JXURL}/org/eclipse/jetty/webapp/WebAppContext.html[WebAppContext] is an extension of a ServletContextHandler that uses the http://en.wikipedia.org/wiki/WAR_%28Sun_file_format%29[standard layout] and web.xml to configure the servlets, filters and other features from a web.xml and/or annotations. +A link:{JXURL}/org/eclipse/jetty/webapp/WebAppContext.html[`WebAppContext`] is an extension of a `ServletContextHandler` that uses the http://en.wikipedia.org/wiki/WAR_%28Sun_file_format%29[standard layout] and web.xml to configure the servlets, filters and other features from a web.xml and/or annotations. The following link:{JXURL}/org/eclipse/jetty/embedded/OneWebApp.html[OneWebApp example] configures the Jetty test webapp. -Web applications can use resources the container provides, and in this case a LoginService is needed and also configured: +Web applications can use resources the container provides, and in this case a `LoginService` is needed and also configured: [source, java, subs="{sub-order}"] ---- @@ -227,7 +227,7 @@ include::{SRCDIR}/examples/embedded/src/main/java/org/eclipse/jetty/embedded/One The typical way to configure an instance of the Jetty server is via `jetty.xml` and associated configuration files. However the Jetty XML configuration format is just a simple rendering of what you can do in code; it is very simple to write embedded code that does precisely what the jetty.xml configuration does. -The link:{JXURL}/org/eclipse/jetty/embedded/LikeJettyXml.html[LikeJettyXml example] following renders in code the behaviour obtained from the configuration files: +The link:{JXURL}/org/eclipse/jetty/embedded/LikeJettyXml.html[LikeJettyXml example] following renders in code the behavior obtained from the configuration files: * link:{GITBROWSEURL}/jetty-server/src/main/config/etc/jetty.xml[jetty.xml] * link:{GITBROWSEURL}/jetty-jmx/src/main/config/etc/jetty-jmx.xml[jetty-jmx.xml] diff --git a/jetty-documentation/src/main/asciidoc/development/embedding/examples/embedded-file-server.adoc b/jetty-documentation/src/main/asciidoc/development/embedding/examples/embedded-file-server.adoc index 8cab6587a46..c1aa4b277e6 100644 --- a/jetty-documentation/src/main/asciidoc/development/embedding/examples/embedded-file-server.adoc +++ b/jetty-documentation/src/main/asciidoc/development/embedding/examples/embedded-file-server.adoc @@ -18,7 +18,7 @@ ==== Simple File Server This example shows how to create a simple file server in Jetty. -It is perfectly suitable for test cases where you need an actual web server to obtain a file from, it could easily be configured to serve files from a directory under src/test/resources. +It is perfectly suitable for test cases where you need an actual web server to obtain a file from, it could easily be configured to serve files from a directory under `src/test/resources`. Note that this does not have any logic for caching of files, either within the server or setting the appropriate headers on the response. It is simply a few lines that illustrate how easy it is to serve out some files. @@ -34,7 +34,7 @@ After you have started things up you should be able to navigate to http://localh ===== Maven Coordinates -To use this example in your project you will need the following maven dependencies declared. +To use this example in your project you will need the following Maven dependencies declared. [source, xml, subs="{sub-order}"] ---- diff --git a/jetty-documentation/src/main/asciidoc/development/embedding/examples/embedded-many-connectors.adoc b/jetty-documentation/src/main/asciidoc/development/embedding/examples/embedded-many-connectors.adoc index 167ad4adb67..8db4f96b199 100644 --- a/jetty-documentation/src/main/asciidoc/development/embedding/examples/embedded-many-connectors.adoc +++ b/jetty-documentation/src/main/asciidoc/development/embedding/examples/embedded-many-connectors.adoc @@ -29,12 +29,12 @@ include::{SRCDIR}/examples/embedded/src/main/java/org/eclipse/jetty/embedded/Man ===== Walkthrough 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()[Thread.join()] for more details. +By using the `server.join()` the server thread will join with the current thread. +See link:http://docs.oracle.com/javase/1.5.0/docs/api/java/lang/Thread.html#join()[`Thread.join()`] for more details. ===== Maven Coordinates -To use this example in your project you will need the following maven dependencies declared. +To use this example in your project you will need the following Maven dependencies declared. [source, xml, subs="{sub-order}"] ---- diff --git a/jetty-documentation/src/main/asciidoc/development/embedding/examples/embedded-minimal-servlet.adoc b/jetty-documentation/src/main/asciidoc/development/embedding/examples/embedded-minimal-servlet.adoc index c709bf7babd..c640f426f4a 100644 --- a/jetty-documentation/src/main/asciidoc/development/embedding/examples/embedded-minimal-servlet.adoc +++ b/jetty-documentation/src/main/asciidoc/development/embedding/examples/embedded-minimal-servlet.adoc @@ -17,7 +17,7 @@ [[embedded-minimal-servlet]] ==== Minimal Servlet -This example shows the bare minimum required for deploying a servlet into jetty. +This example shows the bare minimum required for deploying a servlet into Jetty. Note that this is strictly a servlet, not a servlet in the context of a web application, that example comes later. This is purely just a servlet deployed and mounted on a context and able to process requests. This example is excellent for situations where you have a simple servlet that you need to unit test, just mount it on a context and issue requests using your favorite http client library (like our Jetty client found in xref:http-client[]). @@ -30,16 +30,16 @@ include::{SRCDIR}/examples/embedded/src/main/java/org/eclipse/jetty/embedded/Min ===== Walkthrough -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()[Thread.join()] for more details. +Start things up! By using the `server.join()` the server thread will join with the current thread. +See link:http://docs.oracle.com/javase/1.5.0/docs/api/java/lang/Thread.html#join()[`Thread.join()`] for more details. -It is really simple to create useful servlets for testing behaviors, sometimes you just need a http server to run a unit test against that will return test content and wiring up a servlet like this makes it trivial. +It is really simple to create useful servlets for testing behaviors. Sometimes you need a http server to run a unit test against that will return test content and wiring up a servlet like this makes it trivial. After you have started things up you should be able to navigate to http://localhost:8080/ and you are good to go. ===== Maven Coordinates -To use this example in your project you will need the following maven dependencies declared. +To use this example in your project you will need the following Maven dependencies declared. [source, xml, subs="{sub-order}"] ---- diff --git a/jetty-documentation/src/main/asciidoc/development/embedding/examples/embedded-one-webapp.adoc b/jetty-documentation/src/main/asciidoc/development/embedding/examples/embedded-one-webapp.adoc index 6b17070a34a..a52f1ee3d2a 100644 --- a/jetty-documentation/src/main/asciidoc/development/embedding/examples/embedded-one-webapp.adoc +++ b/jetty-documentation/src/main/asciidoc/development/embedding/examples/embedded-one-webapp.adoc @@ -17,9 +17,9 @@ [[embedded-one-webapp]] ==== Web Application -This example shows how to deploy a simple webapp with an embedded instance of jetty. +This example shows how to deploy a simple webapp with an embedded instance of Jetty. This is useful when you want to manage the lifecycle of a server programmatically, either within a production application or as a simple way to deploying and debugging a full scale application deployment. -In many ways it is easier then traditional deployment since you control the classpath yourself, making this easy to wire up in a test case in maven and issue requests using your favorite http client library (like our Jetty client found in xref:http-client[]). +In many ways it is easier then traditional deployment since you control the classpath yourself, making this easy to wire up in a test case in Maven and issue requests using your favorite http client library (like our Jetty client found in xref:http-client[]). [source, java, subs="{sub-order}"] ---- @@ -33,7 +33,7 @@ After you have started things up you should be able to navigate to http://localh ===== Maven Coordinates -To use this example in your project you will need the following maven dependencies declared. +To use this example in your project you will need the following Maven dependencies declared. [source, xml, subs="{sub-order}"] ---- diff --git a/jetty-documentation/src/main/asciidoc/development/embedding/examples/embedded-secured-hello-handler.adoc b/jetty-documentation/src/main/asciidoc/development/embedding/examples/embedded-secured-hello-handler.adoc index 131d0eea188..e37ddb1cc89 100644 --- a/jetty-documentation/src/main/asciidoc/development/embedding/examples/embedded-secured-hello-handler.adoc +++ b/jetty-documentation/src/main/asciidoc/development/embedding/examples/embedded-secured-hello-handler.adoc @@ -19,8 +19,8 @@ This example shows how to wrap one handler with another one that handles security. We have a simple Hello Handler that just return a greeting but add on the restriction that to get this greeting you must authenticate. -Another thing to remember is that this example uses the ConstraintSecurityHandler which is what supports the security mappings inside of the servlet api, it could be easier to show just the SecurityHandler usage, but the constraint provides more configuration power. -If you don't need that you can drop the Constraint bits and use just the SecurityHandler. +Another thing to remember is that this example uses the `ConstraintSecurityHandler` which is what supports the security mappings inside of the servlet api, it could be easier to show just the `SecurityHandler` usage, but the constraint provides more configuration power. +If you don't need that you can drop the Constraint bits and use just the `SecurityHandler`. [source, java, subs="{sub-order}"] ---- @@ -42,7 +42,7 @@ include::{SRCDIR}/examples/embedded/src/test/resources/realm.properties[] ===== Maven Coordinates -To use this example in your project you will need the following maven dependencies declared. +To use this example in your project you will need the following Maven dependencies declared. [source, xml, subs="{sub-order}"] ---- diff --git a/jetty-documentation/src/main/asciidoc/development/embedding/examples/embedded-split-file-server.adoc b/jetty-documentation/src/main/asciidoc/development/embedding/examples/embedded-split-file-server.adoc index d046bbaae24..1ce987c6eaa 100644 --- a/jetty-documentation/src/main/asciidoc/development/embedding/examples/embedded-split-file-server.adoc +++ b/jetty-documentation/src/main/asciidoc/development/embedding/examples/embedded-split-file-server.adoc @@ -17,7 +17,7 @@ [[embedded-split-file-server]] ==== Split File Server -This example builds on the link:#emebedded-file-server[Simple File Server] to show how chaining multiple ResourceHandlers together can let you aggregate mulitple directories to serve content on a single path and how you can link these together with ContextHandlers. +This example builds on the link:#emebedded-file-server[Simple File Server] to show how chaining multiple `ResourceHandlers` together can let you aggregate multiple directories to serve content on a single path and how you can link these together with `ContextHandlers`. [source, java, subs="{sub-order}"] ---- diff --git a/jetty-documentation/src/main/asciidoc/development/embedding/jetty-helloworld.adoc b/jetty-documentation/src/main/asciidoc/development/embedding/jetty-helloworld.adoc index e9ee5d75cee..90c3c78b2f0 100644 --- a/jetty-documentation/src/main/asciidoc/development/embedding/jetty-helloworld.adoc +++ b/jetty-documentation/src/main/asciidoc/development/embedding/jetty-helloworld.adoc @@ -24,11 +24,11 @@ This section provides a tutorial that shows how you can quickly develop embedded Jetty is decomposed into many jars and dependencies to achieve a minimal footprint by selecting the minimal set of jars. Typically it is best to use something like Maven to manage jars, however this tutorial uses an aggregate Jar that contains all of the Jetty classes in one Jar. -You can manually download the aggregate http://central.maven.org/maven2/org/eclipse/jetty/aggregate/jetty-all/{VERSION}/jetty-all-{VERSION}-uber.jar[`jetty-all.jar`] using `curl`) or a browser. +You can manually download the aggregate link:http://central.maven.org/maven2/org/eclipse/jetty/aggregate/jetty-all/{VERSION}/jetty-all-{VERSION}-uber.jar[`jetty-all.jar`] using `curl`) or a browser. ____ [NOTE] -The central maven repository has started to aggressively reject/deny access to the repository from the `wget` command line tool (due to abusive use of the tool by some groups). +The central Maven repository has started to aggressively reject/deny access to the repository from the `wget` command line tool (due to abusive use of the tool by some groups). The administrators of the central maven repository have stated that the recommended command line download tool is now curl. ____ @@ -82,5 +82,5 @@ You can now point your browser at http://localhost:8080/[http://localhost:8080] To learn more about Jetty, take these next steps: * Follow the examples in link:#embedding-jetty[Embedding Jetty] to better understand the jetty APIs. -* Explore the complete link:{JDURL}/[jetty javadoc] +* Explore the complete link:{JDURL}/[Jetty javadoc] * Consider using link:#maven-and-jetty[Jetty and Maven] to manage your Jars and dependencies. From a8e315a3f5509ae15d1a1478e840668554fd3cab Mon Sep 17 00:00:00 2001 From: Greg Wilkins Date: Wed, 15 Jun 2016 17:27:04 +1000 Subject: [PATCH 3/4] Fix #663 NPE during context stop Avoid adding null beans protect against null beans. --- .../src/main/java/org/eclipse/jetty/server/Server.java | 3 ++- .../org/eclipse/jetty/util/component/ContainerLifeCycle.java | 4 +++- .../java/org/eclipse/jetty/webapp/ClasspathPatternTest.java | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/Server.java b/jetty-server/src/main/java/org/eclipse/jetty/server/Server.java index c5a391a0a6a..af420f1fe59 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/Server.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/Server.java @@ -654,7 +654,8 @@ public class Server extends HandlerWrapper implements Attributes @Override public void setAttribute(String name, Object attribute) { - addBean(attribute); + Object old=_attributes.getAttribute(name); + updateBean(old,attribute); _attributes.setAttribute(name, attribute); } diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/component/ContainerLifeCycle.java b/jetty-util/src/main/java/org/eclipse/jetty/util/component/ContainerLifeCycle.java index 2457a9043ec..f24d22a36b3 100644 --- a/jetty-util/src/main/java/org/eclipse/jetty/util/component/ContainerLifeCycle.java +++ b/jetty-util/src/main/java/org/eclipse/jetty/util/component/ContainerLifeCycle.java @@ -246,7 +246,7 @@ public class ContainerLifeCycle extends AbstractLifeCycle implements Container, public boolean addBean(Object o, Managed managed) { - if (contains(o)) + if (o==null || contains(o)) return false; Bean new_bean = new Bean(o); @@ -751,6 +751,8 @@ public class ContainerLifeCycle extends AbstractLifeCycle implements Container, private Bean(Object b) { + if (b==null) + throw new NullPointerException(); _bean = b; } diff --git a/jetty-webapp/src/test/java/org/eclipse/jetty/webapp/ClasspathPatternTest.java b/jetty-webapp/src/test/java/org/eclipse/jetty/webapp/ClasspathPatternTest.java index eb74b75209f..ee9c7db5ac6 100644 --- a/jetty-webapp/src/test/java/org/eclipse/jetty/webapp/ClasspathPatternTest.java +++ b/jetty-webapp/src/test/java/org/eclipse/jetty/webapp/ClasspathPatternTest.java @@ -66,8 +66,8 @@ public class ClasspathPatternTest public void testExplicitNestedMatch() { assertTrue(pattern.match("org.example.Nested$Something")); - assertFalse(pattern.match("org.example.Nested$Minus")); + assertTrue(pattern.match("org.example.Nested$Other")); } @Test From 0e5de87d49217c2034a47b0a2c2639e7ccb44be1 Mon Sep 17 00:00:00 2001 From: Greg Wilkins Date: Wed, 15 Jun 2016 17:28:06 +1000 Subject: [PATCH 4/4] Issue #663 Cleanup Increased websocket tests timeouts --- .../jsr356/endpoints/TrackingSocket.java | 2 +- .../jsr356/server/TrackingSocket.java | 2 +- .../websocket/client/WebSocketClient.java | 36 +++++++++---------- .../websocket/client/BadNetworkTest.java | 8 ++--- .../websocket/client/ClientCloseTest.java | 12 +++---- .../websocket/client/ClientConnectTest.java | 20 +++++------ .../jetty/websocket/client/CookieTest.java | 2 +- .../websocket/client/JettyTrackingSocket.java | 2 +- .../jetty/websocket/client/SessionTest.java | 9 ++--- .../websocket/client/SlowClientTest.java | 4 +-- .../websocket/client/SlowServerTest.java | 8 ++--- .../websocket/client/WebSocketClientTest.java | 20 +++++------ .../common/message/TrackingSocket.java | 2 +- .../server/AnnotatedMaxMessageSizeTest.java | 4 +-- .../jetty/websocket/server/ChromeTest.java | 2 +- .../jetty/websocket/server/FirefoxTest.java | 2 +- .../websocket/server/IdleTimeoutTest.java | 2 +- .../server/WebSocketOverSSLTest.java | 6 ++-- .../server/WebSocketServletRFCTest.java | 8 ++--- 19 files changed, 75 insertions(+), 76 deletions(-) diff --git a/jetty-websocket/javax-websocket-client-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/endpoints/TrackingSocket.java b/jetty-websocket/javax-websocket-client-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/endpoints/TrackingSocket.java index 63f0ae7c5bb..ea7d057d117 100644 --- a/jetty-websocket/javax-websocket-client-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/endpoints/TrackingSocket.java +++ b/jetty-websocket/javax-websocket-client-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/endpoints/TrackingSocket.java @@ -100,7 +100,7 @@ public abstract class TrackingSocket public void assertWasOpened() throws InterruptedException { - Assert.assertThat("Was Opened",openLatch.await(500,TimeUnit.MILLISECONDS),is(true)); + Assert.assertThat("Was Opened",openLatch.await(30000,TimeUnit.MILLISECONDS),is(true)); } public void clear() diff --git a/jetty-websocket/javax-websocket-server-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/server/TrackingSocket.java b/jetty-websocket/javax-websocket-server-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/server/TrackingSocket.java index 14bfb3830b5..260cdea69e0 100644 --- a/jetty-websocket/javax-websocket-server-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/server/TrackingSocket.java +++ b/jetty-websocket/javax-websocket-server-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/server/TrackingSocket.java @@ -100,7 +100,7 @@ public abstract class TrackingSocket public void assertWasOpened() throws InterruptedException { - Assert.assertThat("Was Opened",openLatch.await(500,TimeUnit.MILLISECONDS),is(true)); + Assert.assertThat("Was Opened",openLatch.await(30000,TimeUnit.MILLISECONDS),is(true)); } public void clear() diff --git a/jetty-websocket/websocket-client/src/main/java/org/eclipse/jetty/websocket/client/WebSocketClient.java b/jetty-websocket/websocket-client/src/main/java/org/eclipse/jetty/websocket/client/WebSocketClient.java index b552d300ed0..fd30726e828 100644 --- a/jetty-websocket/websocket-client/src/main/java/org/eclipse/jetty/websocket/client/WebSocketClient.java +++ b/jetty-websocket/websocket-client/src/main/java/org/eclipse/jetty/websocket/client/WebSocketClient.java @@ -126,18 +126,18 @@ public class WebSocketClient extends ContainerLifeCycle implements WebSocketCont public WebSocketClient(SslContextFactory sslContextFactory, Executor executor, ByteBufferPool bufferPool, DecoratedObjectFactory objectFactory) { - this.executor = executor; + this.sslContextFactory = sslContextFactory; - this.bufferPool = bufferPool; + if(sslContextFactory!=null) + addBean(sslContextFactory); + setExecutor(executor); + setBufferPool(bufferPool); + this.objectFactory = objectFactory; this.extensionRegistry = new WebSocketExtensionFactory(this); this.masker = new RandomMasker(); - this.eventDriverFactory = new EventDriverFactory(policy); - - addBean(this.executor); - addBean(this.sslContextFactory); - addBean(this.bufferPool); + this.eventDriverFactory = new EventDriverFactory(policy); } public Future connect(Object websocket, URI toUri) throws IOException @@ -239,33 +239,27 @@ public class WebSocketClient extends ContainerLifeCycle implements WebSocketCont if (LOG.isDebugEnabled()) LOG.debug("Starting {}",this); - if (sslContextFactory != null) - { - addBean(sslContextFactory); - } - String name = WebSocketClient.class.getSimpleName() + "@" + hashCode(); if (bufferPool == null) { - bufferPool = new MappedByteBufferPool(); + setBufferPool(new MappedByteBufferPool()); } - addBean(bufferPool); if (scheduler == null) { scheduler = new ScheduledExecutorScheduler(name + "-scheduler",daemon); + addBean(scheduler); } - addBean(scheduler); if (cookieStore == null) { - cookieStore = new HttpCookieStore.Empty(); + setCookieStore(new HttpCookieStore.Empty()); } if(this.sessionFactory == null) { - this.sessionFactory = new WebSocketSessionFactory(this); + setSessionFactory(new WebSocketSessionFactory(this)); } if(this.objectFactory == null) @@ -284,19 +278,20 @@ public class WebSocketClient extends ContainerLifeCycle implements WebSocketCont { if (LOG.isDebugEnabled()) LOG.debug("Stopping {}",this); + if (ShutdownThread.isRegistered(this)) { ShutdownThread.deregister(this); } + super.doStop(); + if (cookieStore != null) { cookieStore.removeAll(); cookieStore = null; } - - super.doStop(); if (LOG.isDebugEnabled()) LOG.debug("Stopped {}",this); @@ -523,6 +518,7 @@ public class WebSocketClient extends ContainerLifeCycle implements WebSocketCont public void setBufferPool(ByteBufferPool bufferPool) { + updateBean(this.bufferPool,bufferPool); this.bufferPool = bufferPool; } @@ -543,6 +539,7 @@ public class WebSocketClient extends ContainerLifeCycle implements WebSocketCont public void setCookieStore(CookieStore cookieStore) { + updateBean(this.cookieStore,cookieStore); this.cookieStore = cookieStore; } @@ -597,6 +594,7 @@ public class WebSocketClient extends ContainerLifeCycle implements WebSocketCont public void setSessionFactory(SessionFactory sessionFactory) { + updateBean(this.sessionFactory,sessionFactory); this.sessionFactory = sessionFactory; } diff --git a/jetty-websocket/websocket-client/src/test/java/org/eclipse/jetty/websocket/client/BadNetworkTest.java b/jetty-websocket/websocket-client/src/test/java/org/eclipse/jetty/websocket/client/BadNetworkTest.java index ed88414e2f0..c503c654d3e 100644 --- a/jetty-websocket/websocket-client/src/test/java/org/eclipse/jetty/websocket/client/BadNetworkTest.java +++ b/jetty-websocket/websocket-client/src/test/java/org/eclipse/jetty/websocket/client/BadNetworkTest.java @@ -86,8 +86,8 @@ public class BadNetworkTest ssocket.upgrade(); // Validate that we are connected - future.get(500,TimeUnit.MILLISECONDS); - wsocket.waitForConnected(500,TimeUnit.MILLISECONDS); + future.get(30,TimeUnit.SECONDS); + wsocket.waitForConnected(30,TimeUnit.SECONDS); // Have client disconnect abruptly Session session = wsocket.getSession(); @@ -114,8 +114,8 @@ public class BadNetworkTest ssocket.upgrade(); // Validate that we are connected - future.get(500,TimeUnit.MILLISECONDS); - wsocket.waitForConnected(500,TimeUnit.MILLISECONDS); + future.get(30,TimeUnit.SECONDS); + wsocket.waitForConnected(30,TimeUnit.SECONDS); // Have server disconnect abruptly ssocket.disconnect(); diff --git a/jetty-websocket/websocket-client/src/test/java/org/eclipse/jetty/websocket/client/ClientCloseTest.java b/jetty-websocket/websocket-client/src/test/java/org/eclipse/jetty/websocket/client/ClientCloseTest.java index c9e6f05b238..703d9694e2b 100644 --- a/jetty-websocket/websocket-client/src/test/java/org/eclipse/jetty/websocket/client/ClientCloseTest.java +++ b/jetty-websocket/websocket-client/src/test/java/org/eclipse/jetty/websocket/client/ClientCloseTest.java @@ -113,7 +113,7 @@ public class ClientCloseTest public void assertReceivedError(Class expectedThrownClass, Matcher messageMatcher) throws TimeoutException, InterruptedException { - errorQueue.awaitEventCount(1,500,TimeUnit.MILLISECONDS); + errorQueue.awaitEventCount(1,30,TimeUnit.SECONDS); Throwable actual = errorQueue.poll(); Assert.assertThat("Client Error Event",actual,instanceOf(expectedThrownClass)); if (messageMatcher == null) @@ -191,10 +191,10 @@ public class ClientCloseTest private void confirmConnection(CloseTrackingSocket clientSocket, Future clientFuture, IBlockheadServerConnection serverConns) throws Exception { // Wait for client connect on via future - clientFuture.get(500,TimeUnit.MILLISECONDS); + clientFuture.get(30,TimeUnit.SECONDS); // Wait for client connect via client websocket - Assert.assertThat("Client WebSocket is Open",clientSocket.openLatch.await(500,TimeUnit.MILLISECONDS),is(true)); + Assert.assertThat("Client WebSocket is Open",clientSocket.openLatch.await(30,TimeUnit.SECONDS),is(true)); try { @@ -203,10 +203,10 @@ public class ClientCloseTest Future testFut = clientSocket.getRemote().sendStringByFuture(echoMsg); // Wait for send future - testFut.get(500,TimeUnit.MILLISECONDS); + testFut.get(30,TimeUnit.SECONDS); // Read Frame on server side - IncomingFramesCapture serverCapture = serverConns.readFrames(1,500,TimeUnit.MILLISECONDS); + IncomingFramesCapture serverCapture = serverConns.readFrames(1,30,TimeUnit.SECONDS); serverCapture.assertNoErrors(); serverCapture.assertFrameCount(1); WebSocketFrame frame = serverCapture.getFrames().poll(); @@ -235,7 +235,7 @@ public class ClientCloseTest private void confirmServerReceivedCloseFrame(IBlockheadServerConnection serverConn, int expectedCloseCode, Matcher closeReasonMatcher) throws IOException, TimeoutException { - IncomingFramesCapture serverCapture = serverConn.readFrames(1,500,TimeUnit.MILLISECONDS); + IncomingFramesCapture serverCapture = serverConn.readFrames(1,30,TimeUnit.SECONDS); serverCapture.assertNoErrors(); serverCapture.assertFrameCount(1); serverCapture.assertHasFrame(OpCode.CLOSE,1); diff --git a/jetty-websocket/websocket-client/src/test/java/org/eclipse/jetty/websocket/client/ClientConnectTest.java b/jetty-websocket/websocket-client/src/test/java/org/eclipse/jetty/websocket/client/ClientConnectTest.java index 84b6ba35b62..a13992e4c37 100644 --- a/jetty-websocket/websocket-client/src/test/java/org/eclipse/jetty/websocket/client/ClientConnectTest.java +++ b/jetty-websocket/websocket-client/src/test/java/org/eclipse/jetty/websocket/client/ClientConnectTest.java @@ -122,7 +122,7 @@ public class ClientConnectTest IBlockheadServerConnection connection = server.accept(); connection.upgrade(); - Session sess = future.get(500,TimeUnit.MILLISECONDS); + Session sess = future.get(30,TimeUnit.SECONDS); sess.close(); @@ -146,7 +146,7 @@ public class ClientConnectTest // The attempt to get upgrade response future should throw error try { - future.get(500,TimeUnit.MILLISECONDS); + future.get(30,TimeUnit.SECONDS); Assert.fail("Expected ExecutionException -> UpgradeException"); } catch (ExecutionException e) @@ -175,7 +175,7 @@ public class ClientConnectTest // The attempt to get upgrade response future should throw error try { - future.get(500,TimeUnit.MILLISECONDS); + future.get(30,TimeUnit.SECONDS); Assert.fail("Expected ExecutionException -> UpgradeException"); } catch (ExecutionException e) @@ -211,7 +211,7 @@ public class ClientConnectTest // The attempt to get upgrade response future should throw error try { - future.get(500,TimeUnit.MILLISECONDS); + future.get(30,TimeUnit.SECONDS); Assert.fail("Expected ExecutionException -> UpgradeException"); } catch (ExecutionException e) @@ -247,7 +247,7 @@ public class ClientConnectTest // The attempt to get upgrade response future should throw error try { - future.get(500,TimeUnit.MILLISECONDS); + future.get(30,TimeUnit.SECONDS); Assert.fail("Expected ExecutionException -> UpgradeException"); } catch (ExecutionException e) @@ -283,7 +283,7 @@ public class ClientConnectTest // The attempt to get upgrade response future should throw error try { - future.get(500,TimeUnit.MILLISECONDS); + future.get(30,TimeUnit.SECONDS); Assert.fail("Expected ExecutionException -> UpgradeException"); } catch (ExecutionException e) @@ -312,7 +312,7 @@ public class ClientConnectTest // The attempt to get upgrade response future should throw error try { - future.get(500,TimeUnit.MILLISECONDS); + future.get(30,TimeUnit.SECONDS); Assert.fail("Expected ExecutionException -> UpgradeException"); } catch (ExecutionException e) @@ -338,7 +338,7 @@ public class ClientConnectTest try { - future.get(500,TimeUnit.MILLISECONDS); + future.get(3,TimeUnit.SECONDS); Assert.fail("Should have Timed Out"); } catch (ExecutionException e) @@ -367,7 +367,7 @@ public class ClientConnectTest Future future = client.connect(wsocket,wsUri); // The attempt to get upgrade response future should throw error - future.get(1000,TimeUnit.MILLISECONDS); + future.get(3,TimeUnit.SECONDS); Assert.fail("Expected ExecutionException -> ConnectException"); } catch (ConnectException e) @@ -406,7 +406,7 @@ public class ClientConnectTest // The attempt to get upgrade response future should throw error try { - future.get(500,TimeUnit.MILLISECONDS); + future.get(3,TimeUnit.SECONDS); Assert.fail("Expected ExecutionException -> TimeoutException"); } catch (ExecutionException e) diff --git a/jetty-websocket/websocket-client/src/test/java/org/eclipse/jetty/websocket/client/CookieTest.java b/jetty-websocket/websocket-client/src/test/java/org/eclipse/jetty/websocket/client/CookieTest.java index 0fef309245d..ac6fad4ea0a 100644 --- a/jetty-websocket/websocket-client/src/test/java/org/eclipse/jetty/websocket/client/CookieTest.java +++ b/jetty-websocket/websocket-client/src/test/java/org/eclipse/jetty/websocket/client/CookieTest.java @@ -169,7 +169,7 @@ public class CookieTest serverConn.close(StatusCode.NORMAL); // Confirm client connect on future - clientConnectFuture.get(500,TimeUnit.MILLISECONDS); + clientConnectFuture.get(30000,TimeUnit.MILLISECONDS); // Wait for client receipt of cookie frame via client websocket clientSocket.messageQueue.awaitEventCount(1,2,TimeUnit.SECONDS); diff --git a/jetty-websocket/websocket-client/src/test/java/org/eclipse/jetty/websocket/client/JettyTrackingSocket.java b/jetty-websocket/websocket-client/src/test/java/org/eclipse/jetty/websocket/client/JettyTrackingSocket.java index 0714fc71208..f3c5713de96 100644 --- a/jetty-websocket/websocket-client/src/test/java/org/eclipse/jetty/websocket/client/JettyTrackingSocket.java +++ b/jetty-websocket/websocket-client/src/test/java/org/eclipse/jetty/websocket/client/JettyTrackingSocket.java @@ -94,7 +94,7 @@ public class JettyTrackingSocket extends WebSocketAdapter public void assertWasOpened() throws InterruptedException { - Assert.assertThat("Was Opened",openLatch.await(500,TimeUnit.MILLISECONDS),is(true)); + Assert.assertThat("Was Opened",openLatch.await(30,TimeUnit.SECONDS),is(true)); } public void awaitMessage(int expectedMessageCount, TimeUnit timeoutUnit, int timeoutDuration) throws TimeoutException, InterruptedException diff --git a/jetty-websocket/websocket-client/src/test/java/org/eclipse/jetty/websocket/client/SessionTest.java b/jetty-websocket/websocket-client/src/test/java/org/eclipse/jetty/websocket/client/SessionTest.java index 3d249920223..064eb909e17 100644 --- a/jetty-websocket/websocket-client/src/test/java/org/eclipse/jetty/websocket/client/SessionTest.java +++ b/jetty-websocket/websocket-client/src/test/java/org/eclipse/jetty/websocket/client/SessionTest.java @@ -73,7 +73,7 @@ public class SessionTest final IBlockheadServerConnection srvSock = server.accept(); srvSock.upgrade(); - Session sess = future.get(500,TimeUnit.MILLISECONDS); + Session sess = future.get(30000,TimeUnit.MILLISECONDS); Assert.assertThat("Session",sess,notNullValue()); Assert.assertThat("Session.open",sess.isOpen(),is(true)); Assert.assertThat("Session.upgradeRequest",sess.getUpgradeRequest(),notNullValue()); @@ -91,9 +91,9 @@ public class SessionTest { remote.flush(); } - srvSock.echoMessage(1,500,TimeUnit.MILLISECONDS); + srvSock.echoMessage(1,30000,TimeUnit.MILLISECONDS); // wait for response from server - cliSock.waitForMessage(500,TimeUnit.MILLISECONDS); + cliSock.waitForMessage(30000,TimeUnit.MILLISECONDS); Set open = client.getOpenSessions(); Assert.assertThat("(Before Close) Open Sessions.size", open.size(), is(1)); @@ -102,8 +102,9 @@ public class SessionTest cliSock.close(); srvSock.close(); - cliSock.waitForClose(500,TimeUnit.MILLISECONDS); + cliSock.waitForClose(30000,TimeUnit.MILLISECONDS); open = client.getOpenSessions(); + // TODO this sometimes fails! Assert.assertThat("(After Close) Open Sessions.size", open.size(), is(0)); } finally diff --git a/jetty-websocket/websocket-client/src/test/java/org/eclipse/jetty/websocket/client/SlowClientTest.java b/jetty-websocket/websocket-client/src/test/java/org/eclipse/jetty/websocket/client/SlowClientTest.java index 7ea2d5d94ca..7970d1a8ade 100644 --- a/jetty-websocket/websocket-client/src/test/java/org/eclipse/jetty/websocket/client/SlowClientTest.java +++ b/jetty-websocket/websocket-client/src/test/java/org/eclipse/jetty/websocket/client/SlowClientTest.java @@ -86,8 +86,8 @@ public class SlowClientTest sconnection.upgrade(); // Confirm connected - future.get(500, TimeUnit.MILLISECONDS); - tsocket.waitForConnected(500, TimeUnit.MILLISECONDS); + future.get(30,TimeUnit.SECONDS); + tsocket.waitForConnected(30,TimeUnit.SECONDS); int messageCount = 10; diff --git a/jetty-websocket/websocket-client/src/test/java/org/eclipse/jetty/websocket/client/SlowServerTest.java b/jetty-websocket/websocket-client/src/test/java/org/eclipse/jetty/websocket/client/SlowServerTest.java index 4307df3b654..b5bfb5115cb 100644 --- a/jetty-websocket/websocket-client/src/test/java/org/eclipse/jetty/websocket/client/SlowServerTest.java +++ b/jetty-websocket/websocket-client/src/test/java/org/eclipse/jetty/websocket/client/SlowServerTest.java @@ -88,8 +88,8 @@ public class SlowServerTest sconnection.upgrade(); // Confirm connected - future.get(500,TimeUnit.MILLISECONDS); - tsocket.waitForConnected(500,TimeUnit.MILLISECONDS); + future.get(30,TimeUnit.SECONDS); + tsocket.waitForConnected(30,TimeUnit.SECONDS); int messageCount = 10; @@ -135,8 +135,8 @@ public class SlowServerTest serverConn.upgrade(); // Confirm connected - clientConnectFuture.get(500,TimeUnit.MILLISECONDS); - clientSocket.waitForConnected(500,TimeUnit.MILLISECONDS); + clientConnectFuture.get(30,TimeUnit.SECONDS); + clientSocket.waitForConnected(30,TimeUnit.SECONDS); // Have server write slowly. int messageCount = 1000; diff --git a/jetty-websocket/websocket-client/src/test/java/org/eclipse/jetty/websocket/client/WebSocketClientTest.java b/jetty-websocket/websocket-client/src/test/java/org/eclipse/jetty/websocket/client/WebSocketClientTest.java index 0fce1fe5bca..36e50b916d6 100644 --- a/jetty-websocket/websocket-client/src/test/java/org/eclipse/jetty/websocket/client/WebSocketClientTest.java +++ b/jetty-websocket/websocket-client/src/test/java/org/eclipse/jetty/websocket/client/WebSocketClientTest.java @@ -108,7 +108,7 @@ public class WebSocketClientTest final IBlockheadServerConnection srvSock = server.accept(); srvSock.upgrade(); - Session sess = future.get(500,TimeUnit.MILLISECONDS); + Session sess = future.get(30,TimeUnit.SECONDS); Assert.assertThat("Session",sess,notNullValue()); Assert.assertThat("Session.open",sess.isOpen(),is(true)); Assert.assertThat("Session.upgradeRequest",sess.getUpgradeRequest(),notNullValue()); @@ -124,9 +124,9 @@ public class WebSocketClientTest remote.sendStringByFuture("Hello World!"); if (remote.getBatchMode() == BatchMode.ON) remote.flush(); - srvSock.echoMessage(1,500,TimeUnit.MILLISECONDS); + srvSock.echoMessage(1,30,TimeUnit.SECONDS); // wait for response from server - cliSock.waitForMessage(500,TimeUnit.MILLISECONDS); + cliSock.waitForMessage(30,TimeUnit.SECONDS); cliSock.assertMessage("Hello World!"); } @@ -155,7 +155,7 @@ public class WebSocketClientTest final IBlockheadServerConnection srvSock = server.accept(); srvSock.upgrade(); - Session sess = future.get(500,TimeUnit.MILLISECONDS); + Session sess = future.get(30,TimeUnit.SECONDS); Assert.assertThat("Session",sess,notNullValue()); Assert.assertThat("Session.open",sess.isOpen(),is(true)); Assert.assertThat("Session.upgradeRequest",sess.getUpgradeRequest(),notNullValue()); @@ -193,7 +193,7 @@ public class WebSocketClientTest srvSock.upgrade(); // Validate connect - Session sess = future.get(500,TimeUnit.MILLISECONDS); + Session sess = future.get(30,TimeUnit.SECONDS); Assert.assertThat("Session",sess,notNullValue()); Assert.assertThat("Session.open",sess.isOpen(),is(true)); Assert.assertThat("Session.upgradeRequest",sess.getUpgradeRequest(),notNullValue()); @@ -203,7 +203,7 @@ public class WebSocketClientTest srvSock.write(new TextFrame().setPayload("Hello World")); // Verify connect - future.get(500,TimeUnit.MILLISECONDS); + future.get(30,TimeUnit.SECONDS); wsocket.assertWasOpened(); wsocket.awaitMessage(1,TimeUnit.SECONDS,2); @@ -230,7 +230,7 @@ public class WebSocketClientTest IBlockheadServerConnection ssocket = server.accept(); ssocket.upgrade(); - future.get(500,TimeUnit.MILLISECONDS); + future.get(30,TimeUnit.SECONDS); Assert.assertTrue(wsocket.openLatch.await(1,TimeUnit.SECONDS)); @@ -270,7 +270,7 @@ public class WebSocketClientTest IBlockheadServerConnection ssocket = server.accept(); ssocket.upgrade(); - future.get(500,TimeUnit.MILLISECONDS); + future.get(30,TimeUnit.SECONDS); Assert.assertTrue(wsocket.openLatch.await(1,TimeUnit.SECONDS)); @@ -310,7 +310,7 @@ public class WebSocketClientTest wsocket.awaitConnect(1,TimeUnit.SECONDS); - Session sess = future.get(500,TimeUnit.MILLISECONDS); + Session sess = future.get(30,TimeUnit.SECONDS); Assert.assertThat("Session",sess,notNullValue()); Assert.assertThat("Session.open",sess.isOpen(),is(true)); @@ -350,7 +350,7 @@ public class WebSocketClientTest IBlockheadServerConnection ssocket = server.accept(); ssocket.upgrade(); - future.get(500,TimeUnit.MILLISECONDS); + future.get(30,TimeUnit.SECONDS); Assert.assertTrue(wsocket.openLatch.await(1,TimeUnit.SECONDS)); diff --git a/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/message/TrackingSocket.java b/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/message/TrackingSocket.java index c064bdc7654..36d99f13867 100644 --- a/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/message/TrackingSocket.java +++ b/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/message/TrackingSocket.java @@ -99,7 +99,7 @@ public class TrackingSocket extends WebSocketAdapter public void assertWasOpened() throws InterruptedException { - Assert.assertThat("Was Opened",openLatch.await(500,TimeUnit.MILLISECONDS),is(true)); + Assert.assertThat("Was Opened",openLatch.await(30,TimeUnit.SECONDS),is(true)); } public void awaitMessage(int expectedMessageCount, TimeUnit timeoutUnit, int timeoutDuration) throws TimeoutException, InterruptedException diff --git a/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/AnnotatedMaxMessageSizeTest.java b/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/AnnotatedMaxMessageSizeTest.java index 89f8ba41ded..0255fd403c0 100644 --- a/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/AnnotatedMaxMessageSizeTest.java +++ b/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/AnnotatedMaxMessageSizeTest.java @@ -105,7 +105,7 @@ public class AnnotatedMaxMessageSizeTest client.write(new TextFrame().setPayload(msg)); // Read frame (hopefully text frame) - EventQueue frames = client.readFrames(1,500,TimeUnit.MILLISECONDS); + EventQueue frames = client.readFrames(1,30,TimeUnit.SECONDS); WebSocketFrame tf = frames.poll(); Assert.assertThat("Text Frame.status code",tf.getPayloadAsUTF8(),is(msg)); } @@ -133,7 +133,7 @@ public class AnnotatedMaxMessageSizeTest client.write(new TextFrame().setPayload(ByteBuffer.wrap(buf))); // Read frame (hopefully close frame saying its too large) - EventQueue frames = client.readFrames(1,500,TimeUnit.MILLISECONDS); + EventQueue frames = client.readFrames(1,30,TimeUnit.SECONDS); WebSocketFrame tf = frames.poll(); Assert.assertThat("Frame is close", tf.getOpCode(), is(OpCode.CLOSE)); CloseInfo close = new CloseInfo(tf); diff --git a/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/ChromeTest.java b/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/ChromeTest.java index fda6b1da1f8..e317a4eba60 100644 --- a/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/ChromeTest.java +++ b/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/ChromeTest.java @@ -73,7 +73,7 @@ public class ChromeTest client.write(new TextFrame().setPayload(msg)); // Read frame (hopefully text frame) - EventQueue frames = client.readFrames(1,500,TimeUnit.MILLISECONDS); + EventQueue frames = client.readFrames(1,30,TimeUnit.SECONDS); WebSocketFrame tf = frames.poll(); Assert.assertThat("Text Frame.status code",tf.getPayloadAsUTF8(),is(msg)); } diff --git a/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/FirefoxTest.java b/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/FirefoxTest.java index ee36f5b7efe..86fb5acc8cd 100644 --- a/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/FirefoxTest.java +++ b/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/FirefoxTest.java @@ -66,7 +66,7 @@ public class FirefoxTest client.write(new TextFrame().setPayload(msg)); // Read frame (hopefully text frame) - EventQueue frames = client.readFrames(1, 500, TimeUnit.MILLISECONDS); + EventQueue frames = client.readFrames(1, 30, TimeUnit.SECONDS); WebSocketFrame tf = frames.poll(); Assert.assertThat("Text Frame.status code", tf.getPayloadAsUTF8(), is(msg)); } diff --git a/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/IdleTimeoutTest.java b/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/IdleTimeoutTest.java index 8e401a76639..1af80d73333 100644 --- a/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/IdleTimeoutTest.java +++ b/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/IdleTimeoutTest.java @@ -94,7 +94,7 @@ public class IdleTimeoutTest client.write(new TextFrame().setPayload("Hello")); // Expect server to have closed due to its own timeout - EventQueue frames = client.readFrames(1,500,TimeUnit.MILLISECONDS); + EventQueue frames = client.readFrames(1,30,TimeUnit.SECONDS); WebSocketFrame frame = frames.poll(); Assert.assertThat("frame opcode",frame.getOpCode(),is(OpCode.CLOSE)); CloseInfo close = new CloseInfo(frame); diff --git a/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/WebSocketOverSSLTest.java b/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/WebSocketOverSSLTest.java index 9484de8596d..34a9793a0b2 100644 --- a/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/WebSocketOverSSLTest.java +++ b/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/WebSocketOverSSLTest.java @@ -92,7 +92,7 @@ public class WebSocketOverSSLTest remote.flush(); // Read frame (hopefully text frame) - clientSocket.messages.awaitEventCount(1,500,TimeUnit.MILLISECONDS); + clientSocket.messages.awaitEventCount(1,30,TimeUnit.SECONDS); EventQueue captured = clientSocket.messages; Assert.assertThat("Text Message",captured.poll(),is(msg)); @@ -134,7 +134,7 @@ public class WebSocketOverSSLTest remote.flush(); // Read frame (hopefully text frame) - clientSocket.messages.awaitEventCount(1,500,TimeUnit.MILLISECONDS); + clientSocket.messages.awaitEventCount(1,30,TimeUnit.SECONDS); EventQueue captured = clientSocket.messages; Assert.assertThat("Server.session.isSecure",captured.poll(),is("session.isSecure=true")); @@ -176,7 +176,7 @@ public class WebSocketOverSSLTest remote.flush(); // Read frame (hopefully text frame) - clientSocket.messages.awaitEventCount(1,500,TimeUnit.MILLISECONDS); + clientSocket.messages.awaitEventCount(1,30,TimeUnit.SECONDS); EventQueue captured = clientSocket.messages; String expected = String.format("session.upgradeRequest.requestURI=%s",requestUri.toASCIIString()); Assert.assertThat("session.upgradeRequest.requestURI",captured.poll(),is(expected)); diff --git a/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/WebSocketServletRFCTest.java b/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/WebSocketServletRFCTest.java index c29eeea5345..c185a14c251 100644 --- a/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/WebSocketServletRFCTest.java +++ b/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/WebSocketServletRFCTest.java @@ -191,7 +191,7 @@ public class WebSocketServletRFCTest client.write(new TextFrame().setPayload(msg)); // Read frame (hopefully text frame) - EventQueue frames = client.readFrames(1,500,TimeUnit.MILLISECONDS); + EventQueue frames = client.readFrames(1,30,TimeUnit.SECONDS); WebSocketFrame tf = frames.poll(); Assert.assertThat("Text Frame.status code",tf.getPayloadAsUTF8(),is(msg)); } @@ -222,7 +222,7 @@ public class WebSocketServletRFCTest client.write(new TextFrame().setPayload("CRASH")); // Read frame (hopefully close frame) - EventQueue frames = client.readFrames(1,500,TimeUnit.MILLISECONDS); + EventQueue frames = client.readFrames(1,30,TimeUnit.SECONDS); Frame cf = frames.poll(); CloseInfo close = new CloseInfo(cf); Assert.assertThat("Close Frame.status code",close.getStatusCode(),is(StatusCode.SERVER_ERROR)); @@ -263,7 +263,7 @@ public class WebSocketServletRFCTest client.write(new TextFrame().setPayload(msg)); // Read frame (hopefully text frame) - EventQueue frames = client.readFrames(1,500,TimeUnit.MILLISECONDS); + EventQueue frames = client.readFrames(1,30,TimeUnit.SECONDS); WebSocketFrame tf = frames.poll(); Assert.assertThat("Text Frame.status code",tf.getPayloadAsUTF8(),is(msg)); } @@ -334,7 +334,7 @@ public class WebSocketServletRFCTest client.write(new TextFrame().setPayload(msg)); // Read frame (hopefully text frame) - EventQueue frames = client.readFrames(1,500,TimeUnit.MILLISECONDS); + EventQueue frames = client.readFrames(1,30,TimeUnit.SECONDS); WebSocketFrame tf = frames.poll(); Assert.assertThat("Text Frame.status code",tf.getPayloadAsUTF8(),is(msg)); }