-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
103 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>org.eclipse.jetty.examples.embedded</groupId> | ||
<artifactId>jetty-embedded-examples</artifactId> | ||
<version>10.0.x</version> | ||
</parent> | ||
<artifactId>client</artifactId> | ||
<version>10.0.x</version> | ||
<packaging>jar</packaging> | ||
<name>Jetty Examples :: Jetty 9.4.x :: Embedded :: Client</name> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.eclipse.jetty</groupId> | ||
<artifactId>jetty-client</artifactId> | ||
<version>${jetty.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.eclipse.jetty.http2</groupId> | ||
<artifactId>http2-client</artifactId> | ||
<version>${jetty.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.eclipse.jetty.http2</groupId> | ||
<artifactId>http2-http-client-transport</artifactId> | ||
<version>${jetty.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.eclipse.jetty</groupId> | ||
<artifactId>jetty-slf4j-impl</artifactId> | ||
<version>${jetty.version}</version> | ||
</dependency> | ||
</dependencies> | ||
|
||
</project> |
63 changes: 63 additions & 0 deletions
63
embedded/client/src/main/java/examples/ClientWithDynamicConnection.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// | ||
// ======================================================================== | ||
// Copyright (c) 1995 Mort Bay Consulting Pty Ltd and others. | ||
// | ||
// This program and the accompanying materials are made available under the | ||
// terms of the Eclipse Public License v. 2.0 which is available at | ||
// https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 | ||
// which is available at https://www.apache.org/licenses/LICENSE-2.0. | ||
// | ||
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 | ||
// ======================================================================== | ||
// | ||
|
||
package examples; | ||
|
||
import org.eclipse.jetty.client.HttpClient; | ||
import org.eclipse.jetty.client.api.ContentResponse; | ||
import org.eclipse.jetty.client.dynamic.HttpClientTransportDynamic; | ||
import org.eclipse.jetty.client.http.HttpClientConnectionFactory; | ||
import org.eclipse.jetty.http2.client.HTTP2Client; | ||
import org.eclipse.jetty.http2.client.http.ClientConnectionFactoryOverHTTP2; | ||
import org.eclipse.jetty.io.ClientConnectionFactory; | ||
import org.eclipse.jetty.io.ClientConnector; | ||
import org.eclipse.jetty.util.ssl.SslContextFactory; | ||
|
||
/** | ||
* Example of using a high level HttpClient to connect to a server that | ||
* supports both HTTP/2 and HTTP/1.1, using TLSv1.3 only. | ||
*/ | ||
public class ClientWithDynamicConnection | ||
{ | ||
public static void main(String[] args) throws Exception | ||
{ | ||
SslContextFactory.Client sslContextFactory = new SslContextFactory.Client(); | ||
sslContextFactory.setIncludeProtocols("TLSv1.3"); | ||
ClientConnector clientConnector = new ClientConnector(); | ||
clientConnector.setSslContextFactory(sslContextFactory); | ||
|
||
ClientConnectionFactory.Info h1 = HttpClientConnectionFactory.HTTP11; | ||
HTTP2Client http2Client = new HTTP2Client(clientConnector); | ||
ClientConnectionFactory.Info h2 = new ClientConnectionFactoryOverHTTP2.HTTP2(http2Client); | ||
HttpClientTransportDynamic dynamicTransport = new HttpClientTransportDynamic(clientConnector, h1, h2); | ||
|
||
HttpClient httpClient = new HttpClient(dynamicTransport); | ||
try | ||
{ | ||
httpClient.start(); | ||
// To see the SslContextFactory configuration, dump the client | ||
System.out.printf("Dump of client: %s%n", httpClient.dump()); | ||
ContentResponse res = httpClient.GET("https://api.github.com/zen"); | ||
System.out.printf("response status: %d%n", res.getStatus()); | ||
res.getHeaders().forEach((field) -> | ||
{ | ||
System.out.printf("response header [%s]: %s%n", field.getName(), field.getValue()); | ||
}); | ||
System.out.printf("response body: %s%n", res.getContentAsString()); | ||
} | ||
finally | ||
{ | ||
httpClient.stop(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
examples.LEVEL=DEBUG | ||
org.eclipse.jetty.LEVEL=INFO |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters