-
Notifications
You must be signed in to change notification settings - Fork 569
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Context propagation across HTTP. (#4612)
* Context propagation across HTTP. Signed-off-by: Tomas Langer <tomas.langer@oracle.com>
- Loading branch information
1 parent
beed5a1
commit 9e11f0d
Showing
32 changed files
with
1,806 additions
and
8 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
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
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
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
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,64 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
Copyright (c) 2022 Oracle and/or its affiliates. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
--> | ||
|
||
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<parent> | ||
<artifactId>helidon-tests-integration-webserver</artifactId> | ||
<groupId>io.helidon.tests.integration</groupId> | ||
<version>2.5.2-SNAPSHOT</version> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<artifactId>helidon-tests-integration-webserver-context-propagation</artifactId> | ||
<name>Helidon Integration Test WebServer Context Propagation</name> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>io.helidon.webserver</groupId> | ||
<artifactId>helidon-webserver</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.helidon.webserver</groupId> | ||
<artifactId>helidon-webserver-context-propagation</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.helidon.webclient</groupId> | ||
<artifactId>helidon-webclient-context-propagation</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.helidon.config</groupId> | ||
<artifactId>helidon-config-yaml</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.helidon.media</groupId> | ||
<artifactId>helidon-media-jsonb</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.junit.jupiter</groupId> | ||
<artifactId>junit-jupiter-api</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.hamcrest</groupId> | ||
<artifactId>hamcrest-all</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
</project> |
95 changes: 95 additions & 0 deletions
95
...va/io/helidon/tests/integration/webserver/context/propagation/ContextPropagationMain.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,95 @@ | ||
/* | ||
* Copyright (c) 2022 Oracle and/or its affiliates. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.helidon.tests.integration.webserver.context.propagation; | ||
|
||
import java.time.Duration; | ||
|
||
import io.helidon.common.context.Context; | ||
import io.helidon.config.Config; | ||
import io.helidon.media.jsonb.JsonbSupport; | ||
import io.helidon.webclient.WebClient; | ||
import io.helidon.webserver.Routing; | ||
import io.helidon.webserver.ServerRequest; | ||
import io.helidon.webserver.ServerResponse; | ||
import io.helidon.webserver.WebServer; | ||
import io.helidon.webserver.context.propagation.ContextPropagationFilter; | ||
|
||
/** | ||
* Main test class. | ||
* Starts the server and configures context propagation on it. | ||
*/ | ||
public class ContextPropagationMain { | ||
static final String CLASSIFIER_VALUE = "io.helidon.tests.integration.value"; | ||
static final String CLASSIFIER_VALUES = "io.helidon.tests.integration.values"; | ||
static final String CLASSIFIER_DEFAULT = "io.helidon.tests.integration.default"; | ||
static final String CLASSIFIER_DEFAULTS = "io.helidon.tests.integration.defaults"; | ||
static final String NOT_PROPAGATED = "some.random.classifier"; | ||
static final Duration TIMEOUT = Duration.ofSeconds(10); | ||
private static WebServer server; | ||
private static WebClient client; | ||
|
||
private ContextPropagationMain() { | ||
} | ||
|
||
/** | ||
* Main method. | ||
* | ||
* @param args command line arguments are ignored | ||
*/ | ||
public static void main(String[] args) { | ||
Config config = Config.create(); | ||
|
||
server = WebServer.builder() | ||
.config(config.get("server")) | ||
.addMediaSupport(JsonbSupport.create()) | ||
.routing(Routing.builder() | ||
.any(ContextPropagationFilter.create(config.get("server.context"))) | ||
.get("/", ContextPropagationMain::route) | ||
.build()) | ||
.build() | ||
.start() | ||
.await(TIMEOUT); | ||
|
||
client = WebClient.builder() | ||
.config(config.get("client")) | ||
.baseUri("http://localhost:" + server.port()) | ||
.build(); | ||
} | ||
|
||
static WebServer server() { | ||
return server; | ||
} | ||
|
||
static WebClient client() { | ||
return client; | ||
} | ||
|
||
private static void route(ServerRequest req, ServerResponse res) { | ||
Context ctx = req.context(); | ||
DataDto dto = new DataDto(); | ||
|
||
ctx.get(CLASSIFIER_VALUE, String.class).ifPresent(dto::setValue); | ||
ctx.get(CLASSIFIER_VALUES, String[].class).ifPresent(dto::setValues); | ||
|
||
ctx.get(CLASSIFIER_DEFAULT, String.class).ifPresent(dto::setDefaultValue); | ||
ctx.get(CLASSIFIER_DEFAULTS, String[].class).ifPresent(dto::setDefaultValues); | ||
|
||
ctx.get(NOT_PROPAGATED, String.class).ifPresent(dto::setNotPropagated); | ||
|
||
res.send(dto); | ||
} | ||
} |
Oops, something went wrong.