Improvements to the Jetty documentation.

Moved source code from package `embedded` to `org.eclipse.jetty.docs.programming`.

Signed-off-by: Simone Bordet <simone.bordet@gmail.com>
This commit is contained in:
Simone Bordet 2020-09-08 14:51:18 +02:00
parent 525727416c
commit 7f05bdd06f
31 changed files with 134 additions and 134 deletions

View File

@ -64,7 +64,7 @@ Applications should first compose components in the desired structure, and then
[source,java,indent=0] [source,java,indent=0]
---- ----
include::{doc_code}/embedded/ComponentDocs.java[tags=start] include::{doc_code}/org/eclipse/jetty/docs/programming/ComponentDocs.java[tags=start]
---- ----
The component tree is the following: The component tree is the following:
@ -89,7 +89,7 @@ It is possible to stop and re-start any component in a tree, for example:
[source,java,indent=0] [source,java,indent=0]
---- ----
include::{doc_code}/embedded/ComponentDocs.java[tags=restart] include::{doc_code}/org/eclipse/jetty/docs/programming/ComponentDocs.java[tags=restart]
---- ----
`Service` can be stopped independently of `Root`, and re-started. `Service` can be stopped independently of `Root`, and re-started.
@ -99,7 +99,7 @@ Starting and stopping a non-root component does not alter the structure of the c
[source,java,indent=0] [source,java,indent=0]
---- ----
include::{doc_code}/embedded/ComponentDocs.java[tags=getBeans] include::{doc_code}/org/eclipse/jetty/docs/programming/ComponentDocs.java[tags=getBeans]
---- ----
You can add your own beans to the component tree at application startup time, and later find them from your application code to access their services. You can add your own beans to the component tree at application startup time, and later find them from your application code to access their services.
@ -130,7 +130,7 @@ A `LifeCycle.Listener` emits events for life cycle events such as starting, stop
[source,java,indent=0] [source,java,indent=0]
---- ----
include::{doc_code}/embedded/ComponentDocs.java[tags=lifecycleListener] include::{doc_code}/org/eclipse/jetty/docs/programming/ComponentDocs.java[tags=lifecycleListener]
---- ----
For example, a life cycle listener attached to a `Server` instance could be used to create (for the _started_ event) and delete (for the _stopped_ event) a file containing the process ID of the JVM that runs the `Server`. For example, a life cycle listener attached to a `Server` instance could be used to create (for the _started_ event) and delete (for the _stopped_ event) a file containing the process ID of the JVM that runs the `Server`.
@ -144,14 +144,14 @@ A `Container` emits events when a component (also called _bean_) is added to or
[source,java,indent=0] [source,java,indent=0]
---- ----
include::{doc_code}/embedded/ComponentDocs.java[tags=containerListener] include::{doc_code}/org/eclipse/jetty/docs/programming/ComponentDocs.java[tags=containerListener]
---- ----
A `Container.Listener` added as a bean will also be registered as a listener: A `Container.Listener` added as a bean will also be registered as a listener:
[source,java,indent=0] [source,java,indent=0]
---- ----
include::{doc_code}/embedded/ComponentDocs.java[tags=containerSiblings] include::{doc_code}/org/eclipse/jetty/docs/programming/ComponentDocs.java[tags=containerSiblings]
---- ----
[[pg-arch-bean-listener-inherited]] [[pg-arch-bean-listener-inherited]]

View File

@ -40,14 +40,14 @@ This example shows how a client can connect to a server:
[source,java,indent=0] [source,java,indent=0]
---- ----
include::{doc_code}/embedded/SelectorManagerDocs.java[tags=connect] include::{doc_code}/org/eclipse/jetty/docs/programming/SelectorManagerDocs.java[tags=connect]
---- ----
This example shows how a server accepts a client connection: This example shows how a server accepts a client connection:
[source,java,indent=0] [source,java,indent=0]
---- ----
include::{doc_code}/embedded/SelectorManagerDocs.java[tags=accept] include::{doc_code}/org/eclipse/jetty/docs/programming/SelectorManagerDocs.java[tags=accept]
---- ----
[[pg-arch-io-endpoint-connection]] [[pg-arch-io-endpoint-connection]]
@ -119,7 +119,7 @@ The example below shows a typical implementation that extends `AbstractConnectio
[source,java,indent=0] [source,java,indent=0]
---- ----
include::{doc_code}/embedded/SelectorManagerDocs.java[tags=connection] include::{doc_code}/org/eclipse/jetty/docs/programming/SelectorManagerDocs.java[tags=connection]
---- ----
[[pg-arch-io-connection-listener]] [[pg-arch-io-connection-listener]]
@ -136,7 +136,7 @@ A naive, but wrong, implementation may be the following:
[source,java,indent=0] [source,java,indent=0]
---- ----
include::{doc_code}/embedded/SelectorManagerDocs.java[tags=echo-wrong] include::{doc_code}/org/eclipse/jetty/docs/programming/SelectorManagerDocs.java[tags=echo-wrong]
---- ----
WARNING: The implementation above is wrong and leads to `StackOverflowError`. WARNING: The implementation above is wrong and leads to `StackOverflowError`.
@ -179,7 +179,7 @@ Now that you know how `IteratingCallback` works, a correct implementation for th
[source,java,indent=0] [source,java,indent=0]
---- ----
include::{doc_code}/embedded/SelectorManagerDocs.java[tags=echo-correct] include::{doc_code}/org/eclipse/jetty/docs/programming/SelectorManagerDocs.java[tags=echo-correct]
---- ----
When `onFillable()` is called, for example the first time that bytes are available from the network, the iteration is started. When `onFillable()` is called, for example the first time that bytes are available from the network, the iteration is started.

View File

@ -51,14 +51,14 @@ To enable JMX support on the server:
[source,java,indent=0] [source,java,indent=0]
---- ----
include::{doc_code}/embedded/JMXDocs.java[tags=server] include::{doc_code}/org/eclipse/jetty/docs/programming/JMXDocs.java[tags=server]
---- ----
Similarly on the client: Similarly on the client:
[source,java,indent=0] [source,java,indent=0]
---- ----
include::{doc_code}/embedded/JMXDocs.java[tags=client] include::{doc_code}/org/eclipse/jetty/docs/programming/JMXDocs.java[tags=client]
---- ----
[NOTE] [NOTE]
@ -149,7 +149,7 @@ To allow JMX remote access, create and configure a `ConnectorServer`:
[source,java,indent=0] [source,java,indent=0]
---- ----
include::{doc_code}/embedded/JMXDocs.java[tags=remote] include::{doc_code}/org/eclipse/jetty/docs/programming/JMXDocs.java[tags=remote]
---- ----
[[pg-arch-jmx-remote-authorization]] [[pg-arch-jmx-remote-authorization]]
@ -162,7 +162,7 @@ In the sections below we detail one way to setup JMX authentication and authoriz
[source,java,indent=0] [source,java,indent=0]
---- ----
include::{doc_code}/embedded/JMXDocs.java[tags=remoteAuthorization] include::{doc_code}/org/eclipse/jetty/docs/programming/JMXDocs.java[tags=remoteAuthorization]
---- ----
The `users.access` file format is defined in the `$JAVA_HOME/conf/management/jmxremote.access` file. The `users.access` file format is defined in the `$JAVA_HOME/conf/management/jmxremote.access` file.
@ -195,7 +195,7 @@ It is possible to configure the `ConnectorServer` with a `SslContextFactory` so
[source,java,indent=0] [source,java,indent=0]
---- ----
include::{doc_code}/embedded/JMXDocs.java[tags=tlsRemote] include::{doc_code}/org/eclipse/jetty/docs/programming/JMXDocs.java[tags=tlsRemote]
---- ----
It is possible to use the same `SslContextFactory.Server` used to configure the Jetty `ServerConnector` that supports TLS also for the JMX communication via RMI. It is possible to use the same `SslContextFactory.Server` used to configure the Jetty `ServerConnector` that supports TLS also for the JMX communication via RMI.
@ -214,7 +214,7 @@ For example, trying to connect using the JDK standard `JMXConnector` with both t
[source,java,indent=0] [source,java,indent=0]
---- ----
include::{doc_code}/embedded/JMXDocs.java[tags=tlsJMXConnector] include::{doc_code}/org/eclipse/jetty/docs/programming/JMXDocs.java[tags=tlsJMXConnector]
---- ----
Similarly, to launch JMC: Similarly, to launch JMC:
@ -255,7 +255,7 @@ The bean is scanned for Jetty JMX annotations to obtain JMX metadata: the JMX at
[source,java,indent=0] [source,java,indent=0]
---- ----
include::{doc_code}/embedded/JMXDocs.java[tags=jmxAnnotation] include::{doc_code}/org/eclipse/jetty/docs/programming/JMXDocs.java[tags=jmxAnnotation]
---- ----
The JMX metadata and the bean are wrapped by an instance of `org.eclipse.jetty.jmx.ObjectMBean` that exposes the JMX metadata and, upon request from JMX consoles, invokes methods on the bean to get/set attribute values and perform operations. The JMX metadata and the bean are wrapped by an instance of `org.eclipse.jetty.jmx.ObjectMBean` that exposes the JMX metadata and, upon request from JMX consoles, invokes methods on the bean to get/set attribute values and perform operations.
@ -267,7 +267,7 @@ For example, class `com.acme.Foo` may have a custom `ObjectMBean` subclass named
[source,java,indent=0] [source,java,indent=0]
---- ----
include::{doc_code}/embedded/JMXDocs.java[tags=jmxCustomMBean] include::{doc_code}/org/eclipse/jetty/docs/programming/JMXDocs.java[tags=jmxCustomMBean]
---- ----
The custom `ObjectMBean` subclass is also scanned for Jetty JMX annotations and overrides the JMX metadata obtained by scanning the bean class. The custom `ObjectMBean` subclass is also scanned for Jetty JMX annotations and overrides the JMX metadata obtained by scanning the bean class.
@ -275,7 +275,7 @@ This allows to annotate only the custom `ObjectMBean` subclass and keep the bean
[source,java,indent=0] [source,java,indent=0]
---- ----
include::{doc_code}/embedded/JMXDocs.java[tags=jmxCustomMBeanOverride] include::{doc_code}/org/eclipse/jetty/docs/programming/JMXDocs.java[tags=jmxCustomMBeanOverride]
---- ----
The scan for Jetty JMX annotations is performed on the bean class and all the interfaces implemented by the bean class, then on the super-class and all the interfaces implemented by the super-class and so on until `java.lang.Object` is reached. The scan for Jetty JMX annotations is performed on the bean class and all the interfaces implemented by the bean class, then on the super-class and all the interfaces implemented by the super-class and so on until `java.lang.Object` is reached.

View File

@ -48,21 +48,21 @@ The simplest example that creates and starts a `ClientConnector` is the followin
[source,java,indent=0] [source,java,indent=0]
---- ----
include::../{doc_code}/embedded/client/ClientConnectorDocs.java[tags=simplest] include::../{doc_code}/org/eclipse/jetty/docs/programming/client/ClientConnectorDocs.java[tags=simplest]
---- ----
A more typical example: A more typical example:
[source,java,indent=0] [source,java,indent=0]
---- ----
include::../{doc_code}/embedded/client/ClientConnectorDocs.java[tags=typical] include::../{doc_code}/org/eclipse/jetty/docs/programming/client/ClientConnectorDocs.java[tags=typical]
---- ----
A more advanced example that customizes the `ClientConnector` by overriding some of its methods: A more advanced example that customizes the `ClientConnector` by overriding some of its methods:
[source,java,indent=0] [source,java,indent=0]
---- ----
include::../{doc_code}/embedded/client/ClientConnectorDocs.java[tags=advanced] include::../{doc_code}/org/eclipse/jetty/docs/programming/client/ClientConnectorDocs.java[tags=advanced]
---- ----
Since `ClientConnector` is the component that handles the low-level network, it is also the component where you want to configure the low-level network configuration. Since `ClientConnector` is the component that handles the low-level network, it is also the component where you want to configure the low-level network configuration.
@ -98,7 +98,7 @@ This is done by passing a link:{JDURL}/org/eclipse/jetty/io/ClientConnectionFact
[source,java,indent=0] [source,java,indent=0]
---- ----
include::../{doc_code}/embedded/client/ClientConnectorDocs.java[tags=connect] include::../{doc_code}/org/eclipse/jetty/docs/programming/client/ClientConnectorDocs.java[tags=connect]
---- ----
When a `Connection` is created successfully, its `onOpen()` method is invoked, and then the promise is completed successfully. When a `Connection` is created successfully, its `onOpen()` method is invoked, and then the promise is completed successfully.
@ -107,7 +107,7 @@ It is now possible to write a super-simple `telnet` client that reads and writes
[source,java,indent=0] [source,java,indent=0]
---- ----
include::../{doc_code}/embedded/client/ClientConnectorDocs.java[tags=telnet] include::../{doc_code}/org/eclipse/jetty/docs/programming/client/ClientConnectorDocs.java[tags=telnet]
---- ----
Note how a very basic "telnet" API that applications could use is implemented in the form of the `onLine(Consumer<String>)` for the non-blocking receiving side and `writeLine(String, Callback)` for the non-blocking sending side. Note how a very basic "telnet" API that applications could use is implemented in the form of the `onLine(Consumer<String>)` for the non-blocking receiving side and `writeLine(String, Callback)` for the non-blocking sending side.
@ -127,7 +127,7 @@ The differences between the clear-text version and the TLS encrypted version are
[source,java,indent=0] [source,java,indent=0]
---- ----
include::../{doc_code}/embedded/client/ClientConnectorDocs.java[tags=tlsTelnet] include::../{doc_code}/org/eclipse/jetty/docs/programming/client/ClientConnectorDocs.java[tags=tlsTelnet]
---- ----
The differences with the clear-text version are only: The differences with the clear-text version are only:

View File

@ -28,7 +28,7 @@ The simpler way to perform a HTTP request is the following:
[source,java,indent=0] [source,java,indent=0]
---- ----
include::../../{doc_code}/embedded/client/http/HTTPClientDocs.java[tags=simpleBlockingGet] include::../../{doc_code}/org/eclipse/jetty/docs/programming/client/http/HTTPClientDocs.java[tags=simpleBlockingGet]
---- ----
The method `HttpClient.GET(...)` performs a HTTP `GET` request to the given URI and returns a `ContentResponse` when the request/response conversation completes successfully. The method `HttpClient.GET(...)` performs a HTTP `GET` request to the given URI and returns a `ContentResponse` when the request/response conversation completes successfully.
@ -40,14 +40,14 @@ If you want to customize the request, for example by issuing a `HEAD` request in
[source,java,indent=0] [source,java,indent=0]
---- ----
include::../../{doc_code}/embedded/client/http/HTTPClientDocs.java[tags=headFluent] include::../../{doc_code}/org/eclipse/jetty/docs/programming/client/http/HTTPClientDocs.java[tags=headFluent]
---- ----
This is a shorthand for: This is a shorthand for:
[source,java,indent=0] [source,java,indent=0]
---- ----
include::../../{doc_code}/embedded/client/http/HTTPClientDocs.java[tags=headNonFluent] include::../../{doc_code}/org/eclipse/jetty/docs/programming/client/http/HTTPClientDocs.java[tags=headNonFluent]
---- ----
You first create a request object using `httpClient.newRequest(...)`, and then you customize it using the fluent API style (that is, a chained invocation of methods on the request object). You first create a request object using `httpClient.newRequest(...)`, and then you customize it using the fluent API style (that is, a chained invocation of methods on the request object).
@ -57,7 +57,7 @@ Simple `POST` requests also have a shortcut method:
[source,java,indent=0] [source,java,indent=0]
---- ----
include::../../{doc_code}/embedded/client/http/HTTPClientDocs.java[tags=postFluent] include::../../{doc_code}/org/eclipse/jetty/docs/programming/client/http/HTTPClientDocs.java[tags=postFluent]
---- ----
The `POST` parameter values added via the `param()` method are automatically URL-encoded. The `POST` parameter values added via the `param()` method are automatically URL-encoded.
@ -69,14 +69,14 @@ File uploads also require one line, and make use of `java.nio.file` classes:
[source,java,indent=0] [source,java,indent=0]
---- ----
include::../../{doc_code}/embedded/client/http/HTTPClientDocs.java[tags=fileFluent] include::../../{doc_code}/org/eclipse/jetty/docs/programming/client/http/HTTPClientDocs.java[tags=fileFluent]
---- ----
It is possible to impose a total timeout for the request/response conversation using the `Request.timeout(...)` method as follows: It is possible to impose a total timeout for the request/response conversation using the `Request.timeout(...)` method as follows:
[source,java,indent=0] [source,java,indent=0]
---- ----
include::../../{doc_code}/embedded/client/http/HTTPClientDocs.java[tags=totalTimeout] include::../../{doc_code}/org/eclipse/jetty/docs/programming/client/http/HTTPClientDocs.java[tags=totalTimeout]
---- ----
In the example above, when the 5 seconds expire, the request/response cycle is aborted and a `java.util.concurrent.TimeoutException` is thrown. In the example above, when the 5 seconds expire, the request/response cycle is aborted and a `java.util.concurrent.TimeoutException` is thrown.
@ -115,7 +115,7 @@ A simple non-blocking `GET` request that discards the response content can be wr
[source,java,indent=0] [source,java,indent=0]
---- ----
include::../../{doc_code}/embedded/client/http/HTTPClientDocs.java[tags=simpleNonBlocking] include::../../{doc_code}/org/eclipse/jetty/docs/programming/client/http/HTTPClientDocs.java[tags=simpleNonBlocking]
---- ----
Method `Request.send(Response.CompleteListener)` returns `void` and does not block; the `Response.CompleteListener` lambda provided as a parameter is notified when the request/response conversation is complete, and the `Result` parameter allows you to access the request and response objects as well as failures, if any. Method `Request.send(Response.CompleteListener)` returns `void` and does not block; the `Response.CompleteListener` lambda provided as a parameter is notified when the request/response conversation is complete, and the `Result` parameter allows you to access the request and response objects as well as failures, if any.
@ -124,7 +124,7 @@ You can impose a total timeout for the request/response conversation in the same
[source,java,indent=0] [source,java,indent=0]
---- ----
include::../../{doc_code}/embedded/client/http/HTTPClientDocs.java[tags=nonBlockingTotalTimeout] include::../../{doc_code}/org/eclipse/jetty/docs/programming/client/http/HTTPClientDocs.java[tags=nonBlockingTotalTimeout]
---- ----
The example above will impose a total timeout of 3 seconds on the request/response conversation. The example above will impose a total timeout of 3 seconds on the request/response conversation.
@ -133,7 +133,7 @@ The HTTP client APIs use listeners extensively to provide hooks for all possible
[source,java,indent=0] [source,java,indent=0]
---- ----
include::../../{doc_code}/embedded/client/http/HTTPClientDocs.java[tags=listeners] include::../../{doc_code}/org/eclipse/jetty/docs/programming/client/http/HTTPClientDocs.java[tags=listeners]
---- ----
This makes Jetty HTTP client suitable for HTTP load testing because, for example, you can accurately time every step of the request/response conversation (thus knowing where the request/response time is really spent). This makes Jetty HTTP client suitable for HTTP load testing because, for example, you can accurately time every step of the request/response conversation (thus knowing where the request/response time is really spent).
@ -153,14 +153,14 @@ Heres an example that provides the request content using `java.nio.file.Paths
[source,java,indent=0] [source,java,indent=0]
---- ----
include::../../{doc_code}/embedded/client/http/HTTPClientDocs.java[tags=pathRequestContent] include::../../{doc_code}/org/eclipse/jetty/docs/programming/client/http/HTTPClientDocs.java[tags=pathRequestContent]
---- ----
Alternatively, you can use `FileInputStream` via the `InputStreamRequestContent` utility class: Alternatively, you can use `FileInputStream` via the `InputStreamRequestContent` utility class:
[source,java,indent=0] [source,java,indent=0]
---- ----
include::../../{doc_code}/embedded/client/http/HTTPClientDocs.java[tags=inputStreamRequestContent] include::../../{doc_code}/org/eclipse/jetty/docs/programming/client/http/HTTPClientDocs.java[tags=inputStreamRequestContent]
---- ----
Since `InputStream` is blocking, then also the send of the request will block if the input stream blocks, even in case of usage of the non-blocking `HttpClient` APIs. Since `InputStream` is blocking, then also the send of the request will block if the input stream blocks, even in case of usage of the non-blocking `HttpClient` APIs.
@ -169,14 +169,14 @@ If you have already read the content in memory, you can pass it as a `byte[]` (o
[source,java,indent=0] [source,java,indent=0]
---- ----
include::../../{doc_code}/embedded/client/http/HTTPClientDocs.java[tags=bytesStringRequestContent] include::../../{doc_code}/org/eclipse/jetty/docs/programming/client/http/HTTPClientDocs.java[tags=bytesStringRequestContent]
---- ----
If the request content is not immediately available, but your application will be notified of the content to send, you can use `AsyncRequestContent` in this way: If the request content is not immediately available, but your application will be notified of the content to send, you can use `AsyncRequestContent` in this way:
[source,java,indent=0] [source,java,indent=0]
---- ----
include::../../{doc_code}/embedded/client/http/HTTPClientDocs.java[tags=asyncRequestContent] include::../../{doc_code}/org/eclipse/jetty/docs/programming/client/http/HTTPClientDocs.java[tags=asyncRequestContent]
---- ----
While the request content is awaited and consequently uploaded by the client application, the server may be able to respond (at least with the response headers) completely asynchronously. While the request content is awaited and consequently uploaded by the client application, the server may be able to respond (at least with the response headers) completely asynchronously.
@ -187,7 +187,7 @@ Another way to provide request content is by using an `OutputStreamRequestConten
[source,java,indent=0] [source,java,indent=0]
---- ----
include::../../{doc_code}/embedded/client/http/HTTPClientDocs.java[tags=outputStreamRequestContent] include::../../{doc_code}/org/eclipse/jetty/docs/programming/client/http/HTTPClientDocs.java[tags=outputStreamRequestContent]
---- ----
[[pg-client-http-content-response]] [[pg-client-http-content-response]]
@ -201,7 +201,7 @@ If you want to control the length of the response content (for example limiting
[source,java,indent=0] [source,java,indent=0]
---- ----
include::../../{doc_code}/embedded/client/http/HTTPClientDocs.java[tags=futureResponseListener] include::../../{doc_code}/org/eclipse/jetty/docs/programming/client/http/HTTPClientDocs.java[tags=futureResponseListener]
---- ----
If the response content length is exceeded, the response will be aborted, and an exception will be thrown by method `get(...)`. If the response content length is exceeded, the response will be aborted, and an exception will be thrown by method `get(...)`.
@ -210,14 +210,14 @@ You can buffer the response content in memory also using the xref:pg-client-http
[source,java,indent=0] [source,java,indent=0]
---- ----
include::../../{doc_code}/embedded/client/http/HTTPClientDocs.java[tags=bufferingResponseListener] include::../../{doc_code}/org/eclipse/jetty/docs/programming/client/http/HTTPClientDocs.java[tags=bufferingResponseListener]
---- ----
If you want to avoid buffering, you can wait for the response and then stream the content using the `InputStreamResponseListener` utility class: If you want to avoid buffering, you can wait for the response and then stream the content using the `InputStreamResponseListener` utility class:
[source,java,indent=0] [source,java,indent=0]
---- ----
include::../../{doc_code}/embedded/client/http/HTTPClientDocs.java[tags=inputStreamResponseListener] include::../../{doc_code}/org/eclipse/jetty/docs/programming/client/http/HTTPClientDocs.java[tags=inputStreamResponseListener]
---- ----
Finally, let's look at the advanced usage of the response content handling. Finally, let's look at the advanced usage of the response content handling.
@ -261,5 +261,5 @@ An application that implements a forwarder between two servers can be implemente
[source,java,indent=0] [source,java,indent=0]
---- ----
include::../../{doc_code}/embedded/client/http/HTTPClientDocs.java[tags=demandedContentListener] include::../../{doc_code}/org/eclipse/jetty/docs/programming/client/http/HTTPClientDocs.java[tags=demandedContentListener]
---- ----

View File

@ -45,7 +45,7 @@ You can configure authentication credentials in the `HttpClient` instance as fol
[source,java,indent=0] [source,java,indent=0]
---- ----
include::../../{doc_code}/embedded/client/http/HTTPClientDocs.java[tag=addAuthentication] include::../../{doc_code}/org/eclipse/jetty/docs/programming/client/http/HTTPClientDocs.java[tag=addAuthentication]
---- ----
``Authentication``s are matched against the server challenge first by mechanism (e.g. `BASIC` or `DIGEST`), then by realm and then by URI. ``Authentication``s are matched against the server challenge first by mechanism (e.g. `BASIC` or `DIGEST`), then by realm and then by URI.
@ -59,14 +59,14 @@ It is possible to clear ``Authentication.Result``s in order to force authenticat
[source,java,indent=0] [source,java,indent=0]
---- ----
include::../../{doc_code}/embedded/client/http/HTTPClientDocs.java[tag=clearResults] include::../../{doc_code}/org/eclipse/jetty/docs/programming/client/http/HTTPClientDocs.java[tag=clearResults]
---- ----
Authentication results may be preempted to avoid the additional roundtrip due to the server challenge in this way: Authentication results may be preempted to avoid the additional roundtrip due to the server challenge in this way:
[source,java,indent=0] [source,java,indent=0]
---- ----
include::../../{doc_code}/embedded/client/http/HTTPClientDocs.java[tag=preemptedResult] include::../../{doc_code}/org/eclipse/jetty/docs/programming/client/http/HTTPClientDocs.java[tag=preemptedResult]
---- ----
In this way, requests for the given URI are enriched immediately with the `Authorization` header, and the server should respond with HTTP 200 (and the resource content) rather than with the 401 and the challenge. In this way, requests for the given URI are enriched immediately with the `Authorization` header, and the server should respond with HTTP 200 (and the resource content) rather than with the 401 and the challenge.
@ -75,7 +75,7 @@ It is also possible to preempt the authentication for a single request only, in
[source,java,indent=0] [source,java,indent=0]
---- ----
include::../../{doc_code}/embedded/client/http/HTTPClientDocs.java[tag=requestPreemptedResult] include::../../{doc_code}/org/eclipse/jetty/docs/programming/client/http/HTTPClientDocs.java[tag=requestPreemptedResult]
---- ----
See also the xref:pg-client-http-proxy-authentication[proxy authentication section] for further information about how authentication works with HTTP proxies. See also the xref:pg-client-http-proxy-authentication[proxy authentication section] for further information about how authentication works with HTTP proxies.

View File

@ -40,7 +40,7 @@ If not explicitly configured, the `ClientConnector` will allocate a default one
[source,java,indent=0] [source,java,indent=0]
---- ----
include::../../{doc_code}/embedded/client/http/HTTPClientDocs.java[tags=tlsExplicit] include::../../{doc_code}/org/eclipse/jetty/docs/programming/client/http/HTTPClientDocs.java[tags=tlsExplicit]
---- ----
The default `SslContextFactory.Client` verifies the certificate sent by the server by verifying the certificate chain. The default `SslContextFactory.Client` verifies the certificate sent by the server by verifying the certificate chain.
@ -56,14 +56,14 @@ You can configure the `SslContextFactory.Client` to skip certificate validation
[source,java,indent=0] [source,java,indent=0]
---- ----
include::../../{doc_code}/embedded/client/http/HTTPClientDocs.java[tags=tlsNoValidation] include::../../{doc_code}/org/eclipse/jetty/docs/programming/client/http/HTTPClientDocs.java[tags=tlsNoValidation]
---- ----
You can enable certificate validation at the application level: You can enable certificate validation at the application level:
[source,java,indent=0] [source,java,indent=0]
---- ----
include::../../{doc_code}/embedded/client/http/HTTPClientDocs.java[tags=tlsAppValidation] include::../../{doc_code}/org/eclipse/jetty/docs/programming/client/http/HTTPClientDocs.java[tags=tlsAppValidation]
---- ----
Please refer to the `SslContextFactory.Client` link:{JDURL}/org/eclipse/jetty/util/ssl/SslContextFactory.Client.html[javadocs] for the complete list of configurable parameters. Please refer to the `SslContextFactory.Client` link:{JDURL}/org/eclipse/jetty/util/ssl/SslContextFactory.Client.html[javadocs] for the complete list of configurable parameters.

View File

@ -28,28 +28,28 @@ Applications can programmatically access the cookie store to find the cookies th
[source,java,indent=0] [source,java,indent=0]
---- ----
include::../../{doc_code}/embedded/client/http/HTTPClientDocs.java[tag=getCookies] include::../../{doc_code}/org/eclipse/jetty/docs/programming/client/http/HTTPClientDocs.java[tag=getCookies]
---- ----
Applications can also programmatically set cookies as if they were returned from a HTTP response: Applications can also programmatically set cookies as if they were returned from a HTTP response:
[source,java,indent=0] [source,java,indent=0]
---- ----
include::../../{doc_code}/embedded/client/http/HTTPClientDocs.java[tag=setCookie] include::../../{doc_code}/org/eclipse/jetty/docs/programming/client/http/HTTPClientDocs.java[tag=setCookie]
---- ----
Cookies may be added explicitly only for a particular request: Cookies may be added explicitly only for a particular request:
[source,java,indent=0] [source,java,indent=0]
---- ----
include::../../{doc_code}/embedded/client/http/HTTPClientDocs.java[tag=requestCookie] include::../../{doc_code}/org/eclipse/jetty/docs/programming/client/http/HTTPClientDocs.java[tag=requestCookie]
---- ----
You can remove cookies that you do not want to be sent in future HTTP requests: You can remove cookies that you do not want to be sent in future HTTP requests:
[source,java,indent=0] [source,java,indent=0]
---- ----
include::../../{doc_code}/embedded/client/http/HTTPClientDocs.java[tag=removeCookie] include::../../{doc_code}/org/eclipse/jetty/docs/programming/client/http/HTTPClientDocs.java[tag=removeCookie]
---- ----
If you want to totally disable cookie handling, you can install a `HttpCookieStore.Empty`. If you want to totally disable cookie handling, you can install a `HttpCookieStore.Empty`.
@ -57,14 +57,14 @@ This must be done when `HttpClient` is used in a proxy application, in this way:
[source,java,indent=0] [source,java,indent=0]
---- ----
include::../../{doc_code}/embedded/client/http/HTTPClientDocs.java[tag=emptyCookieStore] include::../../{doc_code}/org/eclipse/jetty/docs/programming/client/http/HTTPClientDocs.java[tag=emptyCookieStore]
---- ----
You can enable cookie filtering by installing a cookie store that performs the filtering logic in this way: You can enable cookie filtering by installing a cookie store that performs the filtering logic in this way:
[source,java,indent=0] [source,java,indent=0]
---- ----
include::../../{doc_code}/embedded/client/http/HTTPClientDocs.java[tag=filteringCookieStore] include::../../{doc_code}/org/eclipse/jetty/docs/programming/client/http/HTTPClientDocs.java[tag=filteringCookieStore]
---- ----
The example above will retain only cookies that come from the `google.com` domain or sub-domains. The example above will retain only cookies that come from the `google.com` domain or sub-domains.

View File

@ -64,7 +64,7 @@ In order to use `HttpClient`, you must instantiate it, configure it, and then st
[source,java,indent=0] [source,java,indent=0]
---- ----
include::../../{doc_code}/embedded/client/http/HTTPClientDocs.java[tags=start] include::../../{doc_code}/org/eclipse/jetty/docs/programming/client/http/HTTPClientDocs.java[tags=start]
---- ----
You may create multiple instances of `HttpClient`, but typically one instance is enough for an application. You may create multiple instances of `HttpClient`, but typically one instance is enough for an application.
@ -84,7 +84,7 @@ It is recommended that when your application stops, you also stop the `HttpClien
[source,java,indent=0] [source,java,indent=0]
---- ----
include::../../{doc_code}/embedded/client/http/HTTPClientDocs.java[tags=stop] include::../../{doc_code}/org/eclipse/jetty/docs/programming/client/http/HTTPClientDocs.java[tags=stop]
---- ----
Stopping `HttpClient` makes sure that the memory it holds (for example, authentication credentials, cookies, etc.) is released, and that the thread pool and scheduler are properly stopped allowing all threads used by `HttpClient` to exit. Stopping `HttpClient` makes sure that the memory it holds (for example, authentication credentials, cookies, etc.) is released, and that the thread pool and scheduler are properly stopped allowing all threads used by `HttpClient` to exit.
@ -130,7 +130,7 @@ You can access the `ConnectionPool` in this way:
[source,java,indent=0] [source,java,indent=0]
---- ----
include::../../{doc_code}/embedded/client/http/HTTPClientDocs.java[tags=getConnectionPool] include::../../{doc_code}/org/eclipse/jetty/docs/programming/client/http/HTTPClientDocs.java[tags=getConnectionPool]
---- ----
Jetty's client library provides the following `ConnectionPool` implementations: Jetty's client library provides the following `ConnectionPool` implementations:
@ -143,7 +143,7 @@ The `ConnectionPool` implementation can be customized for each destination in by
[source,java,indent=0] [source,java,indent=0]
---- ----
include::../../{doc_code}/embedded/client/http/HTTPClientDocs.java[tags=setConnectionPool] include::../../{doc_code}/org/eclipse/jetty/docs/programming/client/http/HTTPClientDocs.java[tags=setConnectionPool]
---- ----
[[pg-client-http-request-processing]] [[pg-client-http-request-processing]]

View File

@ -28,7 +28,7 @@ The following is a typical configuration:
[source,java,indent=0] [source,java,indent=0]
---- ----
include::../../{doc_code}/embedded/client/http/HTTPClientDocs.java[tag=proxy] include::../../{doc_code}/org/eclipse/jetty/docs/programming/client/http/HTTPClientDocs.java[tag=proxy]
---- ----
You specify the proxy host and proxy port, and optionally also the addresses that you do not want to be proxied, and then add the proxy configuration on the `ProxyConfiguration` instance. You specify the proxy host and proxy port, and optionally also the addresses that you do not want to be proxied, and then add the proxy configuration on the `ProxyConfiguration` instance.
@ -46,7 +46,7 @@ In the example below, the proxy requires `BASIC` authentication, but the server
[source,java,indent=0] [source,java,indent=0]
---- ----
include::../../{doc_code}/embedded/client/http/HTTPClientDocs.java[tag=proxyAuthentication] include::../../{doc_code}/org/eclipse/jetty/docs/programming/client/http/HTTPClientDocs.java[tag=proxyAuthentication]
---- ----
The HTTP conversation for successful authentications on both the proxy and the server is the following: The HTTP conversation for successful authentications on both the proxy and the server is the following:

View File

@ -68,14 +68,14 @@ HTTP/1.1 is the default transport.
[source,java,indent=0] [source,java,indent=0]
---- ----
include::../../{doc_code}/embedded/client/http/HTTPClientDocs.java[tag=defaultTransport] include::../../{doc_code}/org/eclipse/jetty/docs/programming/client/http/HTTPClientDocs.java[tag=defaultTransport]
---- ----
If you want to customize the HTTP/1.1 transport, you can explicitly configure it in this way: If you want to customize the HTTP/1.1 transport, you can explicitly configure it in this way:
[source,java,indent=0] [source,java,indent=0]
---- ----
include::../../{doc_code}/embedded/client/http/HTTPClientDocs.java[tag=http11Transport] include::../../{doc_code}/org/eclipse/jetty/docs/programming/client/http/HTTPClientDocs.java[tag=http11Transport]
---- ----
[[pg-client-http-transport-http2]] [[pg-client-http-transport-http2]]
@ -85,7 +85,7 @@ The HTTP/2 transport can be configured in this way:
[source,java,indent=0] [source,java,indent=0]
---- ----
include::../../{doc_code}/embedded/client/http/HTTPClientDocs.java[tag=http2Transport] include::../../{doc_code}/org/eclipse/jetty/docs/programming/client/http/HTTPClientDocs.java[tag=http2Transport]
---- ----
`HTTP2Client` is the lower-level client that provides an API based on HTTP/2 concepts such as _sessions_, _streams_ and _frames_ that are specific to HTTP/2. See xref:pg-client-http2[the HTTP/2 client section] for more information. `HTTP2Client` is the lower-level client that provides an API based on HTTP/2 concepts such as _sessions_, _streams_ and _frames_ that are specific to HTTP/2. See xref:pg-client-http2[the HTTP/2 client section] for more information.
@ -99,7 +99,7 @@ The FastCGI transport can be configured in this way:
[source,java,indent=0] [source,java,indent=0]
---- ----
include::../../{doc_code}/embedded/client/http/HTTPClientDocs.java[tag=fcgiTransport] include::../../{doc_code}/org/eclipse/jetty/docs/programming/client/http/HTTPClientDocs.java[tag=fcgiTransport]
---- ----
In order to make requests using the FastCGI transport, you need to have a FastCGI server such as https://en.wikipedia.org/wiki/PHP#PHPFPM[PHP-FPM] (see also http://php.net/manual/en/install.fpm.php). In order to make requests using the FastCGI transport, you need to have a FastCGI server such as https://en.wikipedia.org/wiki/PHP#PHPFPM[PHP-FPM] (see also http://php.net/manual/en/install.fpm.php).
@ -122,21 +122,21 @@ By default, the dynamic transport only speaks HTTP/1.1:
[source,java,indent=0] [source,java,indent=0]
---- ----
include::../../{doc_code}/embedded/client/http/HTTPClientDocs.java[tag=dynamicDefault] include::../../{doc_code}/org/eclipse/jetty/docs/programming/client/http/HTTPClientDocs.java[tag=dynamicDefault]
---- ----
The dynamic transport can be configured with just one protocol, making it equivalent to the corresponding static transport: The dynamic transport can be configured with just one protocol, making it equivalent to the corresponding static transport:
[source,java,indent=0] [source,java,indent=0]
---- ----
include::../../{doc_code}/embedded/client/http/HTTPClientDocs.java[tag=dynamicOneProtocol] include::../../{doc_code}/org/eclipse/jetty/docs/programming/client/http/HTTPClientDocs.java[tag=dynamicOneProtocol]
---- ----
The dynamic transport, however, has been implemented to support multiple transports, in particular both HTTP/1.1 and HTTP/2: The dynamic transport, however, has been implemented to support multiple transports, in particular both HTTP/1.1 and HTTP/2:
[source,java,indent=0] [source,java,indent=0]
---- ----
include::../../{doc_code}/embedded/client/http/HTTPClientDocs.java[tag=dynamicH1H2] include::../../{doc_code}/org/eclipse/jetty/docs/programming/client/http/HTTPClientDocs.java[tag=dynamicH1H2]
---- ----
IMPORTANT: The order in which the protocols are specified to `HttpClientTransportDynamic` indicates what is the client preference. IMPORTANT: The order in which the protocols are specified to `HttpClientTransportDynamic` indicates what is the client preference.
@ -147,7 +147,7 @@ Provided that the server supports both HTTP/1.1 and HTTP/2 clear-text, client ap
[source,java,indent=0] [source,java,indent=0]
---- ----
include::../../{doc_code}/embedded/client/http/HTTPClientDocs.java[tag=dynamicClearText] include::../../{doc_code}/org/eclipse/jetty/docs/programming/client/http/HTTPClientDocs.java[tag=dynamicClearText]
---- ----
In case of TLS encrypted communication using the HTTPS scheme, things are a little more complicated. In case of TLS encrypted communication using the HTTPS scheme, things are a little more complicated.

View File

@ -45,14 +45,14 @@ The main class is named `org.eclipse.jetty.http2.client.HTTP2Client`, and must b
[source,java,indent=0] [source,java,indent=0]
---- ----
include::../../{doc_code}/embedded/client/http2/HTTP2ClientDocs.java[tags=start] include::../../{doc_code}/org/eclipse/jetty/docs/programming/client/http2/HTTP2ClientDocs.java[tags=start]
---- ----
When your application stops, or otherwise does not need `HTTP2Client` anymore, it should stop the `HTTP2Client` instance (or instances) that were started: When your application stops, or otherwise does not need `HTTP2Client` anymore, it should stop the `HTTP2Client` instance (or instances) that were started:
[source,java,indent=0] [source,java,indent=0]
---- ----
include::../../{doc_code}/embedded/client/http2/HTTP2ClientDocs.java[tags=stop] include::../../{doc_code}/org/eclipse/jetty/docs/programming/client/http2/HTTP2ClientDocs.java[tags=stop]
---- ----
`HTTP2Client` allows client applications to connect to an HTTP/2 server. `HTTP2Client` allows client applications to connect to an HTTP/2 server.
@ -76,14 +76,14 @@ The following example connects to the server on a clear-text port:
[source,java,indent=0] [source,java,indent=0]
---- ----
include::../../{doc_code}/embedded/client/http2/HTTP2ClientDocs.java[tags=clearTextConnect] include::../../{doc_code}/org/eclipse/jetty/docs/programming/client/http2/HTTP2ClientDocs.java[tags=clearTextConnect]
---- ----
The following example connects to the server on an encrypted port: The following example connects to the server on an encrypted port:
[source,java,indent=0] [source,java,indent=0]
---- ----
include::../../{doc_code}/embedded/client/http2/HTTP2ClientDocs.java[tags=encryptedConnect] include::../../{doc_code}/org/eclipse/jetty/docs/programming/client/http2/HTTP2ClientDocs.java[tags=encryptedConnect]
---- ----
IMPORTANT: Applications must know in advance whether they want to connect to a clear-text or encrypted port, and pass the `SslContextFactory` parameter accordingly to the `connect(...)` method. IMPORTANT: Applications must know in advance whether they want to connect to a clear-text or encrypted port, and pass the `SslContextFactory` parameter accordingly to the `connect(...)` method.
@ -97,7 +97,7 @@ Client applications can override this method to change the default configuration
[source,java,indent=0] [source,java,indent=0]
---- ----
include::../../{doc_code}/embedded/client/http2/HTTP2ClientDocs.java[tags=configure] include::../../{doc_code}/org/eclipse/jetty/docs/programming/client/http2/HTTP2ClientDocs.java[tags=configure]
---- ----
The `Session.Listener` is notified of session events originated by the server such as receiving a `SETTINGS` frame from the server, or the server closing the connection, or the client timing out the connection due to idleness. The `Session.Listener` is notified of session events originated by the server such as receiving a `SETTINGS` frame from the server, or the server closing the connection, or the client timing out the connection due to idleness.
@ -116,7 +116,7 @@ Sending the `HEADERS` frame opens the `Stream`:
[source,java,indent=0,subs=normal] [source,java,indent=0,subs=normal]
---- ----
include::../../{doc_code}/embedded/client/http2/HTTP2ClientDocs.java[tags=newStream] include::../../{doc_code}/org/eclipse/jetty/docs/programming/client/http2/HTTP2ClientDocs.java[tags=newStream]
---- ----
Note how `Session.newStream(...)` takes a `Stream.Listener` parameter. Note how `Session.newStream(...)` takes a `Stream.Listener` parameter.
@ -127,7 +127,7 @@ HTTP requests may have content, which is sent using the `Stream` APIs:
[source,java,indent=0] [source,java,indent=0]
---- ----
include::../../{doc_code}/embedded/client/http2/HTTP2ClientDocs.java[tags=newStreamWithData] include::../../{doc_code}/org/eclipse/jetty/docs/programming/client/http2/HTTP2ClientDocs.java[tags=newStreamWithData]
---- ----
IMPORTANT: When sending two `DATA` frames consecutively, the second call to `Stream.data(...)` must be done only when the first is completed, or a `WritePendingException` will be thrown. IMPORTANT: When sending two `DATA` frames consecutively, the second call to `Stream.data(...)` must be done only when the first is completed, or a `WritePendingException` will be thrown.
@ -146,7 +146,7 @@ A client application can therefore receive the HTTP/2 frames sent by the server
[source,java,indent=0] [source,java,indent=0]
---- ----
include::../../{doc_code}/embedded/client/http2/HTTP2ClientDocs.java[tags=responseListener] include::../../{doc_code}/org/eclipse/jetty/docs/programming/client/http2/HTTP2ClientDocs.java[tags=responseListener]
---- ----
include::../../http2.adoc[tag=apiFlowControl] include::../../http2.adoc[tag=apiFlowControl]
@ -160,7 +160,7 @@ The `HTTP2Client` APIs allow client applications to send and receive this "reset
[source,java,indent=0] [source,java,indent=0]
---- ----
include::../../{doc_code}/embedded/client/http2/HTTP2ClientDocs.java[tags=reset] include::../../{doc_code}/org/eclipse/jetty/docs/programming/client/http2/HTTP2ClientDocs.java[tags=reset]
---- ----
[[pg-client-http2-push]] [[pg-client-http2-push]]
@ -175,12 +175,12 @@ Client applications can listen to the push events, and act accordingly:
[source,java,indent=0] [source,java,indent=0]
---- ----
include::../../{doc_code}/embedded/client/http2/HTTP2ClientDocs.java[tags=push] include::../../{doc_code}/org/eclipse/jetty/docs/programming/client/http2/HTTP2ClientDocs.java[tags=push]
---- ----
If a client application does not want to handle a particular HTTP/2 push, it can just reset the pushed stream to tell the server to stop sending bytes for the pushed stream: If a client application does not want to handle a particular HTTP/2 push, it can just reset the pushed stream to tell the server to stop sending bytes for the pushed stream:
[source,java,indent=0] [source,java,indent=0]
---- ----
include::../../{doc_code}/embedded/client/http2/HTTP2ClientDocs.java[tags=pushReset] include::../../{doc_code}/org/eclipse/jetty/docs/programming/client/http2/HTTP2ClientDocs.java[tags=pushReset]
---- ----

View File

@ -66,7 +66,7 @@ Applications can also precisely control _when_ to demand more `DATA` frames, by
[source,java,indent=0] [source,java,indent=0]
---- ----
include::{doc_code}/embedded/HTTP2Docs.java[tags=dataDemanded] include::{doc_code}/org/eclipse/jetty/docs/programming/HTTP2Docs.java[tags=dataDemanded]
---- ----
IMPORTANT: Applications that implement `onDataDemanded(...)` must remember to call `Stream.demand(...)`. IMPORTANT: Applications that implement `onDataDemanded(...)` must remember to call `Stream.demand(...)`.

View File

@ -40,7 +40,7 @@ Thus a filter/servlet may inspect the headers of a request before getting the in
[source,java,indent=0] [source,java,indent=0]
---- ----
include::../../{doc_code}/embedded/server/http/HTTPServerDocs.java[tags=continue100] include::../../{doc_code}/org/eclipse/jetty/docs/programming/server/http/HTTPServerDocs.java[tags=continue100]
---- ----
[[jetty-102-processing]] [[jetty-102-processing]]

View File

@ -28,7 +28,7 @@ Since `ServerConnector` wraps a `ServerSocketChannel`, it can be configured in a
[source,java,indent=0] [source,java,indent=0]
---- ----
include::../../{doc_code}/embedded/server/http/HTTPServerDocs.java[tags=configureConnector] include::../../{doc_code}/org/eclipse/jetty/docs/programming/server/http/HTTPServerDocs.java[tags=configureConnector]
---- ----
The _acceptors_ are threads (typically only one) that compete to accept TCP connections on the listening port. The _acceptors_ are threads (typically only one) that compete to accept TCP connections on the listening port.
@ -51,7 +51,7 @@ It is possible to configure more than one `ServerConnector`, each listening on a
[source,java,indent=0] [source,java,indent=0]
---- ----
include::../../{doc_code}/embedded/server/http/HTTPServerDocs.java[tags=configureConnectors] include::../../{doc_code}/org/eclipse/jetty/docs/programming/server/http/HTTPServerDocs.java[tags=configureConnectors]
---- ----
[[pg-server-http-connector-protocol]] [[pg-server-http-connector-protocol]]
@ -71,7 +71,7 @@ This is how you configure Jetty to support clear-text HTTP/1.1:
[source,java,indent=0] [source,java,indent=0]
---- ----
include::../../{doc_code}/embedded/server/http/HTTPServerDocs.java[tags=http11] include::../../{doc_code}/org/eclipse/jetty/docs/programming/server/http/HTTPServerDocs.java[tags=http11]
---- ----
[[pg-server-http-connector-protocol-http11-tls]] [[pg-server-http-connector-protocol-http11-tls]]
@ -81,7 +81,7 @@ Supporting encrypted HTTP/1.1 (that is, requests with the `https` scheme) is sup
[source,java,indent=0] [source,java,indent=0]
---- ----
include::../../{doc_code}/embedded/server/http/HTTPServerDocs.java[tags=tlsHttp11] include::../../{doc_code}/org/eclipse/jetty/docs/programming/server/http/HTTPServerDocs.java[tags=tlsHttp11]
---- ----
[[pg-server-http-connector-protocol-proxy-http11]] [[pg-server-http-connector-protocol-proxy-http11]]
@ -97,7 +97,7 @@ To support this case, Jetty can be configured in this way:
[source,java,indent=0] [source,java,indent=0]
---- ----
include::../../{doc_code}/embedded/server/http/HTTPServerDocs.java[tags=proxyHTTP] include::../../{doc_code}/org/eclipse/jetty/docs/programming/server/http/HTTPServerDocs.java[tags=proxyHTTP]
---- ----
Note how the ``ConnectionFactory``s passed to `ServerConnector` are in order: first PROXY, then HTTP/1.1. Note how the ``ConnectionFactory``s passed to `ServerConnector` are in order: first PROXY, then HTTP/1.1.
@ -120,7 +120,7 @@ Jetty can support both HTTP/1.1 and HTTP/2 on the same clear-text port by config
[source,java,indent=0] [source,java,indent=0]
---- ----
include::../../{doc_code}/embedded/server/http/HTTPServerDocs.java[tags=http11H2C] include::../../{doc_code}/org/eclipse/jetty/docs/programming/server/http/HTTPServerDocs.java[tags=http11H2C]
---- ----
Note how the ``ConnectionFactory``s passed to `ServerConnector` are in order: first HTTP/1.1, then HTTP/2. Note how the ``ConnectionFactory``s passed to `ServerConnector` are in order: first HTTP/1.1, then HTTP/2.
@ -138,7 +138,7 @@ Jetty supports ALPN and encrypted HTTP/2 with this configuration:
[source,java,indent=0] [source,java,indent=0]
---- ----
include::../../{doc_code}/embedded/server/http/HTTPServerDocs.java[tags=tlsALPNHTTP] include::../../{doc_code}/org/eclipse/jetty/docs/programming/server/http/HTTPServerDocs.java[tags=tlsALPNHTTP]
---- ----
Note how the ``ConnectionFactory``s passed to `ServerConnector` are in order: TLS, ALPN, HTTP/1.1, HTTP/2. Note how the ``ConnectionFactory``s passed to `ServerConnector` are in order: TLS, ALPN, HTTP/1.1, HTTP/2.

View File

@ -23,7 +23,7 @@ The `Handler` API consist fundamentally of just one method:
[source,java,indent=0] [source,java,indent=0]
---- ----
include::../../{doc_code}/embedded/server/http/HTTPServerDocs.java[tags=handlerAPI] include::../../{doc_code}/org/eclipse/jetty/docs/programming/server/http/HTTPServerDocs.java[tags=handlerAPI]
---- ----
The `target` parameter is an identifier for the resource. The `target` parameter is an identifier for the resource.
@ -40,7 +40,7 @@ A simple "Hello World" `Handler` is the following:
[source,java,indent=0] [source,java,indent=0]
---- ----
include::../../{doc_code}/embedded/server/http/HTTPServerDocs.java[tags=handlerHello] include::../../{doc_code}/org/eclipse/jetty/docs/programming/server/http/HTTPServerDocs.java[tags=handlerHello]
---- ----
Such a simple `Handler` extends from `AbstractHandler` and can access the request and response main features, such as reading request headers and content, or writing response headers and content. Such a simple `Handler` extends from `AbstractHandler` and can access the request and response main features, such as reading request headers and content, or writing response headers and content.
@ -52,7 +52,7 @@ A filtering `Handler` is a handler that perform some modification to the request
[source,java,indent=0] [source,java,indent=0]
---- ----
include::../../{doc_code}/embedded/server/http/HTTPServerDocs.java[tags=handlerFilter] include::../../{doc_code}/org/eclipse/jetty/docs/programming/server/http/HTTPServerDocs.java[tags=handlerFilter]
---- ----
Note how a filtering `Handler` extends from `HandlerWrapper` and as such needs another handler to forward the request processing to, and how the two ``Handler``s needs to be linked together to work properly. Note how a filtering `Handler` extends from `HandlerWrapper` and as such needs another handler to forward the request processing to, and how the two ``Handler``s needs to be linked together to work properly.

View File

@ -61,7 +61,7 @@ The simplest use of `ContextHandler` is the following:
[source,java,indent=0] [source,java,indent=0]
---- ----
include::../../{doc_code}/embedded/server/http/HTTPServerDocs.java[tags=contextHandler] include::../../{doc_code}/org/eclipse/jetty/docs/programming/server/http/HTTPServerDocs.java[tags=contextHandler]
---- ----
The `Handler` tree structure looks like the following: The `Handler` tree structure looks like the following:
@ -89,7 +89,7 @@ Eventually, if `Request.setHandled(true)` is not called, Jetty returns an HTTP `
[source,java,indent=0] [source,java,indent=0]
---- ----
include::../../{doc_code}/embedded/server/http/HTTPServerDocs.java[tags=contextHandlerCollection] include::../../{doc_code}/org/eclipse/jetty/docs/programming/server/http/HTTPServerDocs.java[tags=contextHandlerCollection]
---- ----
The `Handler` tree structure looks like the following: The `Handler` tree structure looks like the following:
@ -130,14 +130,14 @@ This is how you configure a `ResourceHandler` to create a simple file server:
[source,java,indent=0] [source,java,indent=0]
---- ----
include::../../{doc_code}/embedded/server/http/HTTPServerDocs.java[tags=resourceHandler] include::../../{doc_code}/org/eclipse/jetty/docs/programming/server/http/HTTPServerDocs.java[tags=resourceHandler]
---- ----
If you need to serve static resources from multiple directories: If you need to serve static resources from multiple directories:
[source,java,indent=0] [source,java,indent=0]
---- ----
include::../../{doc_code}/embedded/server/http/HTTPServerDocs.java[tags=multipleResourcesHandler] include::../../{doc_code}/org/eclipse/jetty/docs/programming/server/http/HTTPServerDocs.java[tags=multipleResourcesHandler]
---- ----
If the resource is not found, `ResourceHandler` will not call `Request.setHandled(true)` so what happens next depends on the `Handler` tree structure. If the resource is not found, `ResourceHandler` will not call `Request.setHandled(true)` so what happens next depends on the `Handler` tree structure.
@ -155,7 +155,7 @@ The decompression/compression is not performed until the web application reads r
[source,java,indent=0] [source,java,indent=0]
---- ----
include::../../{doc_code}/embedded/server/http/HTTPServerDocs.java[tags=serverGzipHandler] include::../../{doc_code}/org/eclipse/jetty/docs/programming/server/http/HTTPServerDocs.java[tags=serverGzipHandler]
---- ----
The `Handler` tree structure looks like the following: The `Handler` tree structure looks like the following:
@ -174,7 +174,7 @@ However, in less common cases, you can configure `GzipHandler` on a per-context
[source,java,indent=0] [source,java,indent=0]
---- ----
include::../../{doc_code}/embedded/server/http/HTTPServerDocs.java[tags=contextGzipHandler] include::../../{doc_code}/org/eclipse/jetty/docs/programming/server/http/HTTPServerDocs.java[tags=contextGzipHandler]
---- ----
The `Handler` tree structure looks like the following: The `Handler` tree structure looks like the following:
@ -219,7 +219,7 @@ You typically want to configure `RewriteHandler` at the server level, although i
[source,java,indent=0] [source,java,indent=0]
---- ----
include::../../{doc_code}/embedded/server/http/HTTPServerDocs.java[tags=rewriteHandler] include::../../{doc_code}/org/eclipse/jetty/docs/programming/server/http/HTTPServerDocs.java[tags=rewriteHandler]
---- ----
The `Handler` tree structure looks like the following: The `Handler` tree structure looks like the following:
@ -251,7 +251,7 @@ Server applications can read these values and use them internally, or expose the
[source,java,indent=0] [source,java,indent=0]
---- ----
include::../../{doc_code}/embedded/server/http/HTTPServerDocs.java[tags=statsHandler] include::../../{doc_code}/org/eclipse/jetty/docs/programming/server/http/HTTPServerDocs.java[tags=statsHandler]
---- ----
The `Handler` tree structure looks like the following: The `Handler` tree structure looks like the following:
@ -279,7 +279,7 @@ Server applications must configure a `HttpConfiguration` object with the secure
[source,java,indent=0] [source,java,indent=0]
---- ----
include::../../{doc_code}/embedded/server/http/HTTPServerDocs.java[tags=securedHandler] include::../../{doc_code}/org/eclipse/jetty/docs/programming/server/http/HTTPServerDocs.java[tags=securedHandler]
---- ----
[[pg-server-http-handler-use-util-default-handler]] [[pg-server-http-handler-use-util-default-handler]]
@ -295,7 +295,7 @@ include::../../{doc_code}/embedded/server/http/HTTPServerDocs.java[tags=securedH
[source,java,indent=0] [source,java,indent=0]
---- ----
include::../../{doc_code}/embedded/server/http/HTTPServerDocs.java[tags=defaultHandler] include::../../{doc_code}/org/eclipse/jetty/docs/programming/server/http/HTTPServerDocs.java[tags=defaultHandler]
---- ----
The `Handler` tree structure looks like the following: The `Handler` tree structure looks like the following:
@ -339,7 +339,7 @@ The Maven artifact coordinates are:
[source,java,indent=0] [source,java,indent=0]
---- ----
include::../../{doc_code}/embedded/server/http/HTTPServerDocs.java[tags=servletContextHandler] include::../../{doc_code}/org/eclipse/jetty/docs/programming/server/http/HTTPServerDocs.java[tags=servletContextHandler]
---- ----
The `Handler` and Servlet components tree structure looks like the following: The `Handler` and Servlet components tree structure looks like the following:
@ -375,7 +375,7 @@ Where server applications using `ServletContextHandler` must manually invoke met
[source,java,indent=0] [source,java,indent=0]
---- ----
include::../../{doc_code}/embedded/server/http/HTTPServerDocs.java[tags=webAppContextHandler] include::../../{doc_code}/org/eclipse/jetty/docs/programming/server/http/HTTPServerDocs.java[tags=webAppContextHandler]
---- ----
[[pg-server-http-handler-use-webapp-context-class-loading]] [[pg-server-http-handler-use-webapp-context-class-loading]]
@ -416,5 +416,5 @@ The features are similar, but `DefaultServlet` is more commonly used to serve st
[source,java,indent=0] [source,java,indent=0]
---- ----
include::../../{doc_code}/embedded/server/http/HTTPServerDocs.java[tags=defaultServlet] include::../../{doc_code}/org/eclipse/jetty/docs/programming/server/http/HTTPServerDocs.java[tags=defaultServlet]
---- ----

View File

@ -39,7 +39,7 @@ The nested behavior is useful to enrich the request with additional services suc
[source,java,indent=0] [source,java,indent=0]
---- ----
include::../../{doc_code}/embedded/server/http/HTTPServerDocs.java[tags=handlerTree] include::../../{doc_code}/org/eclipse/jetty/docs/programming/server/http/HTTPServerDocs.java[tags=handlerTree]
---- ----
The corresponding `Handler` tree structure looks like the following: The corresponding `Handler` tree structure looks like the following:

View File

@ -63,7 +63,7 @@ A `Server` must be created, configured and started:
[source,java,indent=0] [source,java,indent=0]
---- ----
include::../../{doc_code}/embedded/server/http/HTTPServerDocs.java[tags=simple] include::../../{doc_code}/org/eclipse/jetty/docs/programming/server/http/HTTPServerDocs.java[tags=simple]
---- ----
The example above shows the simplest HTTP/1.1 server; it has no support for HTTP sessions, for HTTP authentication, or for any of the features required by the Servlet specification. The example above shows the simplest HTTP/1.1 server; it has no support for HTTP sessions, for HTTP authentication, or for any of the features required by the Servlet specification.
@ -155,7 +155,7 @@ Server applications can register `HttpChannel.Listener` by adding them as xref:p
[source,java,indent=0] [source,java,indent=0]
---- ----
include::../../{doc_code}/embedded/server/http/HTTPServerDocs.java[tags=httpChannelListener] include::../../{doc_code}/org/eclipse/jetty/docs/programming/server/http/HTTPServerDocs.java[tags=httpChannelListener]
---- ----
include::server-http-connector.adoc[] include::server-http-connector.adoc[]

View File

@ -55,7 +55,7 @@ The low-level HTTP/2 support is provided by `org.eclipse.jetty.http2.server.RawH
[source,java,indent=0] [source,java,indent=0]
---- ----
include::../../{doc_code}/embedded/server/http2/HTTP2ServerDocs.java[tags=setup] include::../../{doc_code}/org/eclipse/jetty/docs/programming/server/http2/HTTP2ServerDocs.java[tags=setup]
---- ----
Where server applications using the xref:pg-server-http[high-level server library] deal with HTTP requests and responses in ``Handler``s, server applications using the low-level HTTP/2 server library deal directly with HTTP/2 __session__s, __stream__s and __frame__s in a `ServerSessionListener` implementation. Where server applications using the xref:pg-server-http[high-level server library] deal with HTTP requests and responses in ``Handler``s, server applications using the low-level HTTP/2 server library deal directly with HTTP/2 __session__s, __stream__s and __frame__s in a `ServerSessionListener` implementation.
@ -69,7 +69,7 @@ This is the first occasion where server applications have access to the HTTP/2 `
[source,java,indent=0] [source,java,indent=0]
---- ----
include::../../{doc_code}/embedded/server/http2/HTTP2ServerDocs.java[tags=accept] include::../../{doc_code}/org/eclipse/jetty/docs/programming/server/http2/HTTP2ServerDocs.java[tags=accept]
---- ----
After connecting to the server, a compliant HTTP/2 client must send the link:https://tools.ietf.org/html/rfc7540#section-3.5[HTTP/2 client preface], and when the server receives it, it generates the _preface_ event on the server. After connecting to the server, a compliant HTTP/2 client must send the link:https://tools.ietf.org/html/rfc7540#section-3.5[HTTP/2 client preface], and when the server receives it, it generates the _preface_ event on the server.
@ -77,7 +77,7 @@ This is where server applications can customize the connection settings by retur
[source,java,indent=0] [source,java,indent=0]
---- ----
include::../../{doc_code}/embedded/server/http2/HTTP2ServerDocs.java[tags=preface] include::../../{doc_code}/org/eclipse/jetty/docs/programming/server/http2/HTTP2ServerDocs.java[tags=preface]
---- ----
[[pg-server-http2-request]] [[pg-server-http2-request]]
@ -91,7 +91,7 @@ Receiving the `HEADERS` frame opens the `Stream`:
[source,java,indent=0] [source,java,indent=0]
---- ----
include::../../{doc_code}/embedded/server/http2/HTTP2ServerDocs.java[tags=request] include::../../{doc_code}/org/eclipse/jetty/docs/programming/server/http2/HTTP2ServerDocs.java[tags=request]
---- ----
Server applications should return a `Stream.Listener` implementation from `onNewStream(...)` to be notified of events generated by the client, such as `DATA` frames carrying request content, or a `RST_STREAM` frame indicating that the client wants to _reset_ the request, or an idle timeout event indicating that the client was supposed to send more frames but it did not. Server applications should return a `Stream.Listener` implementation from `onNewStream(...)` to be notified of events generated by the client, such as `DATA` frames carrying request content, or a `RST_STREAM` frame indicating that the client wants to _reset_ the request, or an idle timeout event indicating that the client was supposed to send more frames but it did not.
@ -100,7 +100,7 @@ The example below shows how to receive request content:
[source,java,indent=0] [source,java,indent=0]
---- ----
include::../../{doc_code}/embedded/server/http2/HTTP2ServerDocs.java[tags=requestContent] include::../../{doc_code}/org/eclipse/jetty/docs/programming/server/http2/HTTP2ServerDocs.java[tags=requestContent]
---- ----
include::../../http2.adoc[tag=apiFlowControl] include::../../http2.adoc[tag=apiFlowControl]
@ -118,7 +118,7 @@ A server application can send a response in this way:
[source,java,indent=0] [source,java,indent=0]
---- ----
include::../../{doc_code}/embedded/server/http2/HTTP2ServerDocs.java[tags=response;!exclude] include::../../{doc_code}/org/eclipse/jetty/docs/programming/server/http2/HTTP2ServerDocs.java[tags=response;!exclude]
---- ----
[[pg-server-http2-reset]] [[pg-server-http2-reset]]
@ -131,7 +131,7 @@ A request can be reset in this way:
[source,java,indent=0] [source,java,indent=0]
---- ----
include::../../{doc_code}/embedded/server/http2/HTTP2ServerDocs.java[tags=reset;!exclude] include::../../{doc_code}/org/eclipse/jetty/docs/programming/server/http2/HTTP2ServerDocs.java[tags=reset;!exclude]
---- ----
[[pg-server-http2-push]] [[pg-server-http2-push]]
@ -144,5 +144,5 @@ Server applications must track `SETTINGS` frames and verify whether the client s
[source,java,indent=0] [source,java,indent=0]
---- ----
include::../../{doc_code}/embedded/server/http2/HTTP2ServerDocs.java[tags=push] include::../../{doc_code}/org/eclipse/jetty/docs/programming/server/http2/HTTP2ServerDocs.java[tags=push]
---- ----

View File

@ -37,7 +37,7 @@ For example, this is how clear-text HTTP/1.1 is configured:
[source,java,indent=0] [source,java,indent=0]
---- ----
include::../{doc_code}/embedded/server/ServerDocs.java[tags=http] include::../{doc_code}/org/eclipse/jetty/docs/programming/server/ServerDocs.java[tags=http]
---- ----
With this configuration, the `ServerConnector` will listen on port `8080`. With this configuration, the `ServerConnector` will listen on port `8080`.
@ -73,7 +73,7 @@ Therefore, to support encrypted HTTP/1.1 (also known as `https`), you need to co
[source,java,indent=0] [source,java,indent=0]
---- ----
include::../{doc_code}/embedded/server/ServerDocs.java[tags=tlsHttp] include::../{doc_code}/org/eclipse/jetty/docs/programming/server/ServerDocs.java[tags=tlsHttp]
---- ----
With this configuration, the `ServerConnector` will listen on port `8443`. With this configuration, the `ServerConnector` will listen on port `8443`.
@ -121,7 +121,7 @@ In the example below you can see how to support both clear-text and encrypted HT
[source,java,indent=0] [source,java,indent=0]
---- ----
include::../{doc_code}/embedded/server/ServerDocs.java[tags=detector] include::../{doc_code}/org/eclipse/jetty/docs/programming/server/ServerDocs.java[tags=detector]
---- ----
With this configuration, the `ServerConnector` will listen on port 8181. With this configuration, the `ServerConnector` will listen on port 8181.
@ -161,7 +161,7 @@ First, the `JSONHTTPConnectionFactory`:
[source,java,indent=0] [source,java,indent=0]
---- ----
include::../{doc_code}/embedded/server/ServerDocs.java[tags=jsonHttpConnectionFactory] include::../{doc_code}/org/eclipse/jetty/docs/programming/server/ServerDocs.java[tags=jsonHttpConnectionFactory]
---- ----
Note how `JSONHTTPConnectionFactory` extends `AbstractConnectionFactory` to inherit facilities common to all `ConnectionFactory` implementations. Note how `JSONHTTPConnectionFactory` extends `AbstractConnectionFactory` to inherit facilities common to all `ConnectionFactory` implementations.
@ -172,7 +172,7 @@ Furthermore, because the Jetty libraries are non-blocking and asynchronous, you
[source,java,indent=0] [source,java,indent=0]
---- ----
include::../{doc_code}/embedded/server/ServerDocs.java[tags=jsonHttpConnection] include::../{doc_code}/org/eclipse/jetty/docs/programming/server/ServerDocs.java[tags=jsonHttpConnection]
---- ----
Again, note how `JSONHTTPConnection` extends `AbstractConnection` to inherit facilities that you would otherwise need to re-implement from scratch. Again, note how `JSONHTTPConnection` extends `AbstractConnection` to inherit facilities that you would otherwise need to re-implement from scratch.
@ -191,7 +191,7 @@ This results in the following API:
[source,java,indent=0] [source,java,indent=0]
---- ----
include::../{doc_code}/embedded/server/ServerDocs.java[tags=jsonHttpAPI] include::../{doc_code}/org/eclipse/jetty/docs/programming/server/ServerDocs.java[tags=jsonHttpAPI]
---- ----
The important part of this simple API example is the `Callback` parameter that makes the API non-blocking and asynchronous. The important part of this simple API example is the `Callback` parameter that makes the API non-blocking and asynchronous.

View File

@ -16,7 +16,7 @@
// ======================================================================== // ========================================================================
// //
package embedded; package org.eclipse.jetty.docs.programming;
import java.util.Collection; import java.util.Collection;
import java.util.HashSet; import java.util.HashSet;

View File

@ -16,7 +16,7 @@
// ======================================================================== // ========================================================================
// //
package embedded; package org.eclipse.jetty.docs.programming;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import java.net.SocketAddress; import java.net.SocketAddress;

View File

@ -16,7 +16,7 @@
// ======================================================================== // ========================================================================
// //
package embedded; package org.eclipse.jetty.docs.programming;
import java.lang.management.ManagementFactory; import java.lang.management.ManagementFactory;
import java.util.HashMap; import java.util.HashMap;

View File

@ -16,7 +16,7 @@
// ======================================================================== // ========================================================================
// //
package embedded; package org.eclipse.jetty.docs.programming;
import java.io.IOException; import java.io.IOException;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;

View File

@ -16,7 +16,7 @@
// ======================================================================== // ========================================================================
// //
package embedded.client; package org.eclipse.jetty.docs.programming.client;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;

View File

@ -16,7 +16,7 @@
// ======================================================================== // ========================================================================
// //
package embedded.client.http; package org.eclipse.jetty.docs.programming.client.http;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.IOException; import java.io.IOException;

View File

@ -16,7 +16,7 @@
// ======================================================================== // ========================================================================
// //
package embedded.client.http2; package org.eclipse.jetty.docs.programming.client.http2;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import java.net.SocketAddress; import java.net.SocketAddress;

View File

@ -16,7 +16,7 @@
// ======================================================================== // ========================================================================
// //
package embedded.server; package org.eclipse.jetty.docs.programming.server;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.util.Map; import java.util.Map;

View File

@ -16,7 +16,7 @@
// ======================================================================== // ========================================================================
// //
package embedded.server.http; package org.eclipse.jetty.docs.programming.server.http;
import java.io.IOException; import java.io.IOException;
import java.util.EnumSet; import java.util.EnumSet;

View File

@ -16,7 +16,7 @@
// ======================================================================== // ========================================================================
// //
package embedded.server.http2; package org.eclipse.jetty.docs.programming.server.http2;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;