Merge remote-tracking branch 'origin/jetty-9.3.x' into jetty-9.4.x
This commit is contained in:
commit
e607acfa4e
|
@ -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}"]
|
||||
----
|
||||
|
|
|
@ -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]
|
||||
|
|
|
@ -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}"]
|
||||
----
|
||||
|
|
|
@ -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}"]
|
||||
----
|
||||
|
|
|
@ -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}"]
|
||||
----
|
||||
|
|
|
@ -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}"]
|
||||
----
|
||||
|
|
|
@ -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}"]
|
||||
----
|
||||
|
|
|
@ -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}"]
|
||||
----
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -680,7 +680,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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
public Future<Session> 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);
|
||||
}
|
||||
|
||||
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)
|
||||
|
@ -285,19 +279,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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -115,7 +115,7 @@ public class ClientCloseTest
|
|||
public void assertReceivedError(Class<? extends Throwable> expectedThrownClass, Matcher<String> 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)
|
||||
|
@ -193,10 +193,10 @@ public class ClientCloseTest
|
|||
private void confirmConnection(CloseTrackingSocket clientSocket, Future<Session> 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
|
||||
{
|
||||
|
@ -205,10 +205,10 @@ public class ClientCloseTest
|
|||
Future<Void> 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();
|
||||
|
@ -237,7 +237,7 @@ public class ClientCloseTest
|
|||
private void confirmServerReceivedCloseFrame(IBlockheadServerConnection serverConn, int expectedCloseCode, Matcher<String> 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);
|
||||
|
|
|
@ -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<Session> 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)
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -75,7 +75,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());
|
||||
|
@ -93,9 +93,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<WebSocketSession> open = client.getOpenSessions();
|
||||
Assert.assertThat("(Before Close) Open Sessions.size", open.size(), is(1));
|
||||
|
@ -104,8 +104,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
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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));
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -105,7 +105,7 @@ public class AnnotatedMaxMessageSizeTest
|
|||
client.write(new TextFrame().setPayload(msg));
|
||||
|
||||
// Read frame (hopefully text frame)
|
||||
EventQueue<WebSocketFrame> frames = client.readFrames(1,500,TimeUnit.MILLISECONDS);
|
||||
EventQueue<WebSocketFrame> 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<WebSocketFrame> frames = client.readFrames(1,500,TimeUnit.MILLISECONDS);
|
||||
EventQueue<WebSocketFrame> 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);
|
||||
|
|
|
@ -73,7 +73,7 @@ public class ChromeTest
|
|||
client.write(new TextFrame().setPayload(msg));
|
||||
|
||||
// Read frame (hopefully text frame)
|
||||
EventQueue<WebSocketFrame> frames = client.readFrames(1,500,TimeUnit.MILLISECONDS);
|
||||
EventQueue<WebSocketFrame> frames = client.readFrames(1,30,TimeUnit.SECONDS);
|
||||
WebSocketFrame tf = frames.poll();
|
||||
Assert.assertThat("Text Frame.status code",tf.getPayloadAsUTF8(),is(msg));
|
||||
}
|
||||
|
|
|
@ -66,7 +66,7 @@ public class FirefoxTest
|
|||
client.write(new TextFrame().setPayload(msg));
|
||||
|
||||
// Read frame (hopefully text frame)
|
||||
EventQueue<WebSocketFrame> frames = client.readFrames(1, 500, TimeUnit.MILLISECONDS);
|
||||
EventQueue<WebSocketFrame> frames = client.readFrames(1, 30, TimeUnit.SECONDS);
|
||||
WebSocketFrame tf = frames.poll();
|
||||
Assert.assertThat("Text Frame.status code", tf.getPayloadAsUTF8(), is(msg));
|
||||
}
|
||||
|
|
|
@ -94,7 +94,7 @@ public class IdleTimeoutTest
|
|||
client.write(new TextFrame().setPayload("Hello"));
|
||||
|
||||
// Expect server to have closed due to its own timeout
|
||||
EventQueue<WebSocketFrame> frames = client.readFrames(1,500,TimeUnit.MILLISECONDS);
|
||||
EventQueue<WebSocketFrame> 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);
|
||||
|
|
|
@ -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<String> 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<String> 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<String> captured = clientSocket.messages;
|
||||
String expected = String.format("session.upgradeRequest.requestURI=%s",requestUri.toASCIIString());
|
||||
Assert.assertThat("session.upgradeRequest.requestURI",captured.poll(),is(expected));
|
||||
|
|
|
@ -191,7 +191,7 @@ public class WebSocketServletRFCTest
|
|||
client.write(new TextFrame().setPayload(msg));
|
||||
|
||||
// Read frame (hopefully text frame)
|
||||
EventQueue<WebSocketFrame> frames = client.readFrames(1,500,TimeUnit.MILLISECONDS);
|
||||
EventQueue<WebSocketFrame> 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<WebSocketFrame> frames = client.readFrames(1,500,TimeUnit.MILLISECONDS);
|
||||
EventQueue<WebSocketFrame> 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<WebSocketFrame> frames = client.readFrames(1,500,TimeUnit.MILLISECONDS);
|
||||
EventQueue<WebSocketFrame> 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<WebSocketFrame> frames = client.readFrames(1,500,TimeUnit.MILLISECONDS);
|
||||
EventQueue<WebSocketFrame> frames = client.readFrames(1,30,TimeUnit.SECONDS);
|
||||
WebSocketFrame tf = frames.poll();
|
||||
Assert.assertThat("Text Frame.status code",tf.getPayloadAsUTF8(),is(msg));
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue