Skip to content

Commit de82451

Browse files
salaboysiri-varmasvegiraju-microsoftartur-ciocanucicoyle
authored
Support App HTTP middleware Pipelines (#1271)
* supporting appHttpPipelines for middleware Signed-off-by: salaboy <[email protected]> * adding test with inline string Signed-off-by: salaboy <[email protected]> * fixing checkstyle Signed-off-by: salaboy <[email protected]> * adding license hearders and TODO references Signed-off-by: salaboy <[email protected]> * Move dependency management and plugin management to parent pom (#1260) * Clean up pom Signed-off-by: sirivarma <[email protected]> * downgrade dependency Signed-off-by: sirivarma <[email protected]> * Fix Signed-off-by: sirivarma <[email protected]> * Fix thigns Signed-off-by: sirivarma <[email protected]> * Fix class not found Signed-off-by: sirivarma <[email protected]> * Remove import Signed-off-by: sirivarma <[email protected]> * Address comments Signed-off-by: Siri Varma Vegiraju <[email protected]> * cleanup Signed-off-by: Siri Varma Vegiraju <[email protected]> * Fix deps Signed-off-by: siri-varma <[email protected]> * cleanup Signed-off-by: Siri Varma Vegiraju <[email protected]> Signed-off-by: siri-varma <[email protected]> * Fix deps Signed-off-by: siri-varma <[email protected]> * Fix things Signed-off-by: siri-varma <[email protected]> * Fix finals Signed-off-by: siri-varma <[email protected]> * Fix finals Signed-off-by: siri-varma <[email protected]> * upgrade test containers to .5 Signed-off-by: sirivarma <[email protected]> * This is it Signed-off-by: sirivarma <[email protected]> * Fix feedback Signed-off-by: sirivarma <[email protected]> * Add comment Signed-off-by: sirivarma <[email protected]> * Add comment Signed-off-by: sirivarma <[email protected]> * Change to properties Signed-off-by: sirivarma <[email protected]> --------- Signed-off-by: sirivarma <[email protected]> Signed-off-by: Siri Varma Vegiraju <[email protected]> Signed-off-by: siri-varma <[email protected]> Co-authored-by: Siri Varma Vegiraju <[email protected]> Co-authored-by: salaboy <[email protected]> Co-authored-by: artur-ciocanu <[email protected]> Co-authored-by: Cassie Coyle <[email protected]> Signed-off-by: salaboy <[email protected]> * Update docker version for CI to fix flaky tests (#1276) * update docker version for ci Signed-off-by: salaboy <[email protected]> * adding DOCKER_HOST to all tests Signed-off-by: salaboy <[email protected]> * Move dependency management and plugin management to parent pom (#1260) * Clean up pom Signed-off-by: sirivarma <[email protected]> * downgrade dependency Signed-off-by: sirivarma <[email protected]> * Fix Signed-off-by: sirivarma <[email protected]> * Fix thigns Signed-off-by: sirivarma <[email protected]> * Fix class not found Signed-off-by: sirivarma <[email protected]> * Remove import Signed-off-by: sirivarma <[email protected]> * Address comments Signed-off-by: Siri Varma Vegiraju <[email protected]> * cleanup Signed-off-by: Siri Varma Vegiraju <[email protected]> * Fix deps Signed-off-by: siri-varma <[email protected]> * cleanup Signed-off-by: Siri Varma Vegiraju <[email protected]> Signed-off-by: siri-varma <[email protected]> * Fix deps Signed-off-by: siri-varma <[email protected]> * Fix things Signed-off-by: siri-varma <[email protected]> * Fix finals Signed-off-by: siri-varma <[email protected]> * Fix finals Signed-off-by: siri-varma <[email protected]> * upgrade test containers to .5 Signed-off-by: sirivarma <[email protected]> * This is it Signed-off-by: sirivarma <[email protected]> * Fix feedback Signed-off-by: sirivarma <[email protected]> * Add comment Signed-off-by: sirivarma <[email protected]> * Add comment Signed-off-by: sirivarma <[email protected]> * Change to properties Signed-off-by: sirivarma <[email protected]> --------- Signed-off-by: sirivarma <[email protected]> Signed-off-by: Siri Varma Vegiraju <[email protected]> Signed-off-by: siri-varma <[email protected]> Co-authored-by: Siri Varma Vegiraju <[email protected]> Co-authored-by: salaboy <[email protected]> Co-authored-by: artur-ciocanu <[email protected]> Co-authored-by: Cassie Coyle <[email protected]> Signed-off-by: salaboy <[email protected]> * fixing flaky docker network Signed-off-by: salaboy <[email protected]> --------- Signed-off-by: salaboy <[email protected]> Signed-off-by: sirivarma <[email protected]> Signed-off-by: Siri Varma Vegiraju <[email protected]> Signed-off-by: siri-varma <[email protected]> Co-authored-by: Siri Varma Vegiraju <[email protected]> Co-authored-by: Siri Varma Vegiraju <[email protected]> Co-authored-by: artur-ciocanu <[email protected]> Co-authored-by: Cassie Coyle <[email protected]> Signed-off-by: salaboy <[email protected]> * Change CountWordsAcitivy output format due to clashing (#1279) Signed-off-by: Matheus Cruz <[email protected]> Co-authored-by: Cassie Coyle <[email protected]> Signed-off-by: salaboy <[email protected]> * Bump codecov/codecov-action from 4.4.1 to 5.4.0 (#1278) Bumps [codecov/codecov-action](https://github.com/codecov/codecov-action) from 4.4.1 to 5.4.0. - [Release notes](https://github.com/codecov/codecov-action/releases) - [Changelog](https://github.com/codecov/codecov-action/blob/main/CHANGELOG.md) - [Commits](codecov/codecov-action@v4.4.1...v5.4.0) --- updated-dependencies: - dependency-name: codecov/codecov-action dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Cassie Coyle <[email protected]> Signed-off-by: salaboy <[email protected]> * Bump fossas/fossa-action from 1.3.3 to 1.6.0 (#1277) Bumps [fossas/fossa-action](https://github.com/fossas/fossa-action) from 1.3.3 to 1.6.0. - [Release notes](https://github.com/fossas/fossa-action/releases) - [Commits](fossas/fossa-action@v1.3.3...v1.6.0) --- updated-dependencies: - dependency-name: fossas/fossa-action dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Cassie Coyle <[email protected]> Signed-off-by: salaboy <[email protected]> * update instructions to cover podman (#1274) Signed-off-by: salaboy <[email protected]> Co-authored-by: artur-ciocanu <[email protected]> Co-authored-by: Cassie Coyle <[email protected]> Signed-off-by: salaboy <[email protected]> * following checkstyle Signed-off-by: salaboy <[email protected]> --------- Signed-off-by: salaboy <[email protected]> Signed-off-by: sirivarma <[email protected]> Signed-off-by: Siri Varma Vegiraju <[email protected]> Signed-off-by: siri-varma <[email protected]> Signed-off-by: Matheus Cruz <[email protected]> Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: Siri Varma Vegiraju <[email protected]> Co-authored-by: Siri Varma Vegiraju <[email protected]> Co-authored-by: artur-ciocanu <[email protected]> Co-authored-by: Cassie Coyle <[email protected]> Co-authored-by: Matheus Cruz <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
1 parent f0c3596 commit de82451

File tree

7 files changed

+185
-11
lines changed

7 files changed

+185
-11
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Copyright 2025 The Dapr Authors
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
* http://www.apache.org/licenses/LICENSE-2.0
7+
* Unless required by applicable law or agreed to in writing, software
8+
* distributed under the License is distributed on an "AS IS" BASIS,
9+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
* See the License for the specific language governing permissions and
11+
limitations under the License.
12+
*/
13+
14+
package io.dapr.testcontainers;
15+
16+
import java.util.Collections;
17+
import java.util.List;
18+
19+
public class AppHttpPipeline implements ConfigurationSettings {
20+
private List<ListEntry> handlers;
21+
22+
/**
23+
* Creates an AppHttpPipeline.
24+
*
25+
* @param handlers List of handlers for the AppHttpPipeline
26+
*/
27+
public AppHttpPipeline(List<ListEntry> handlers) {
28+
if (handlers != null) {
29+
this.handlers = Collections.unmodifiableList(handlers);
30+
}
31+
}
32+
33+
public List<ListEntry> getHandlers() {
34+
return handlers;
35+
}
36+
37+
}

testcontainers-dapr/src/main/java/io/dapr/testcontainers/Configuration.java

+19-7
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,28 @@
1919
public class Configuration {
2020
private final String name;
2121
private final TracingConfigurationSettings tracing;
22+
private final AppHttpPipeline appHttpPipeline;
2223

23-
//@TODO: add httpPipeline
24-
//@TODO: add secrets
25-
//@TODO: add components
26-
//@TODO: add accessControl
24+
// @TODO: add secrets https://github.com/dapr/java-sdk/issues/1280
25+
// @TODO: add metrics https://github.com/dapr/java-sdk/issues/1281
26+
// @TODO: add logging https://github.com/dapr/java-sdk/issues/1282
27+
// @TODO: add middleware httpPipeline https://github.com/dapr/java-sdk/issues/1283
28+
// @TODO: add nameResolution https://github.com/dapr/java-sdk/issues/1284
29+
// @TODO: add disallow components https://github.com/dapr/java-sdk/issues/1285
30+
// @TODO: add mtls https://github.com/dapr/java-sdk/issues/1286
2731

2832
/**
2933
* Creates a new configuration.
30-
* @param name Configuration name.
31-
* @param tracing TracingConfigParameters tracing configuration parameters.
34+
*
35+
* @param name Configuration name.
36+
* @param tracing TracingConfigParameters tracing configuration
37+
* parameters.
38+
* @param appHttpPipeline AppHttpPipeline middleware configuration.
3239
*/
33-
public Configuration(String name, TracingConfigurationSettings tracing) {
40+
public Configuration(String name, TracingConfigurationSettings tracing, AppHttpPipeline appHttpPipeline) {
3441
this.name = name;
3542
this.tracing = tracing;
43+
this.appHttpPipeline = appHttpPipeline;
3644
}
3745

3846
public String getName() {
@@ -42,4 +50,8 @@ public String getName() {
4250
public TracingConfigurationSettings getTracing() {
4351
return tracing;
4452
}
53+
54+
public AppHttpPipeline getAppHttpPipeline() {
55+
return appHttpPipeline;
56+
}
4557
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* Copyright 2024 The Dapr Authors
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
* http://www.apache.org/licenses/LICENSE-2.0
7+
* Unless required by applicable law or agreed to in writing, software
8+
* distributed under the License is distributed on an "AS IS" BASIS,
9+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
* See the License for the specific language governing permissions and
11+
limitations under the License.
12+
*/
13+
14+
package io.dapr.testcontainers;
15+
16+
public class ListEntry {
17+
private String name;
18+
private String type;
19+
20+
public ListEntry(String name, String type) {
21+
this.name = name;
22+
this.type = type;
23+
}
24+
25+
public String getName() {
26+
return name;
27+
}
28+
29+
public String getType() {
30+
return type;
31+
}
32+
33+
public void setName(String name) {
34+
this.name = name;
35+
}
36+
37+
public void setType(String type) {
38+
this.type = type;
39+
}
40+
}

testcontainers-dapr/src/main/java/io/dapr/testcontainers/converter/ConfigurationYamlConverter.java

+14
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
package io.dapr.testcontainers.converter;
22

3+
import io.dapr.testcontainers.AppHttpPipeline;
34
import io.dapr.testcontainers.Configuration;
5+
import io.dapr.testcontainers.ListEntry;
46
import io.dapr.testcontainers.OtelTracingConfigurationSettings;
57
import io.dapr.testcontainers.TracingConfigurationSettings;
68
import io.dapr.testcontainers.ZipkinTracingConfigurationSettings;
79
import org.yaml.snakeyaml.Yaml;
810

911
import java.util.LinkedHashMap;
12+
import java.util.List;
1013
import java.util.Map;
1114

1215
public class ConfigurationYamlConverter implements YamlConverter<Configuration> {
@@ -58,6 +61,17 @@ public String convert(Configuration configuration) {
5861
}
5962

6063
configurationSpec.put("tracing", tracingMap);
64+
65+
}
66+
67+
AppHttpPipeline appHttpPipeline = configuration.getAppHttpPipeline();
68+
if (appHttpPipeline != null) {
69+
70+
Map<String, Object> appHttpPipelineMap = new LinkedHashMap<>();
71+
List<ListEntry> handlers = appHttpPipeline.getHandlers();
72+
appHttpPipelineMap.put("handlers", handlers);
73+
configurationSpec.put("appHttpPipeline", appHttpPipelineMap);
74+
6175
}
6276

6377
configurationProps.put("spec", configurationSpec);

testcontainers-dapr/src/main/java/io/dapr/testcontainers/converter/YamlMapperFactory.java

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package io.dapr.testcontainers.converter;
22

3+
import io.dapr.testcontainers.ListEntry;
34
import io.dapr.testcontainers.MetadataEntry;
45
import org.yaml.snakeyaml.DumperOptions;
56
import org.yaml.snakeyaml.Yaml;
@@ -21,6 +22,7 @@ public static Yaml create() {
2122
options.setPrettyFlow(true);
2223
Representer representer = new Representer(options);
2324
representer.addClassTag(MetadataEntry.class, Tag.MAP);
25+
representer.addClassTag(ListEntry.class, Tag.MAP);
2426
return new Yaml(representer);
2527
}
2628
}

testcontainers-dapr/src/test/java/io/dapr/testcontainers/converter/ComponentYamlConverterTest.java

+43-2
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@ public void testComponentToYaml() {
3434
assertFalse(kvstore.getMetadata().isEmpty());
3535

3636
String componentYaml = converter.convert(kvstore);
37-
String expectedComponentYaml =
38-
"apiVersion: dapr.io/v1alpha1\n"
37+
String expectedComponentYaml = "apiVersion: dapr.io/v1alpha1\n"
3938
+ "kind: Component\n"
4039
+ "metadata:\n"
4140
+ " name: statestore\n"
@@ -48,4 +47,46 @@ public void testComponentToYaml() {
4847

4948
assertEquals(expectedComponentYaml, componentYaml);
5049
}
50+
51+
@Test
52+
public void testComponentWithInLineStringToYaml() {
53+
DaprContainer dapr = new DaprContainer("daprio/daprd")
54+
.withAppName("dapr-app")
55+
.withAppPort(8081)
56+
.withComponent(new Component(
57+
"alias",
58+
"middleware.http.routeralias",
59+
"v1",
60+
Map.of("routes", "{\n" +
61+
" \"/mall/activity/info\": \"/v1.0/invoke/srv.default/method/mall/activity/info\",\n" +
62+
" \"/hello/activity/{id}/info\": \"/v1.0/invoke/srv.default/method/hello/activity/info\",\n" + //
63+
" \"/hello/activity/{id}/user\": \"/v1.0/invoke/srv.default/method/hello/activity/user\"\n" + //
64+
"}")))
65+
.withAppChannelAddress("host.testcontainers.internal");
66+
67+
Set<Component> components = dapr.getComponents();
68+
assertEquals(1, components.size());
69+
70+
Component kvstore = components.iterator().next();
71+
assertFalse(kvstore.getMetadata().isEmpty());
72+
73+
String componentYaml = converter.convert(kvstore);
74+
String expectedComponentYaml = "apiVersion: dapr.io/v1alpha1\n"
75+
+ "kind: Component\n"
76+
+ "metadata:\n"
77+
+ " name: alias\n"
78+
+ "spec:\n"
79+
+ " type: middleware.http.routeralias\n"
80+
+ " version: v1\n"
81+
+ " metadata:\n"
82+
+ " - name: routes\n"
83+
+ " value: |-\n"
84+
+ " {\n"
85+
+ " \"/mall/activity/info\": \"/v1.0/invoke/srv.default/method/mall/activity/info\",\n"
86+
+ " \"/hello/activity/{id}/info\": \"/v1.0/invoke/srv.default/method/hello/activity/info\",\n"
87+
+ " \"/hello/activity/{id}/user\": \"/v1.0/invoke/srv.default/method/hello/activity/user\"\n"
88+
+ " }\n";
89+
90+
assertEquals(expectedComponentYaml, componentYaml);
91+
}
5192
}

testcontainers-dapr/src/test/java/io/dapr/testcontainers/converter/ConfigurationYamlConverterTest.java

+30-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,22 @@
1+
/*
2+
* Copyright 2025 The Dapr Authors
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
* http://www.apache.org/licenses/LICENSE-2.0
7+
* Unless required by applicable law or agreed to in writing, software
8+
* distributed under the License is distributed on an "AS IS" BASIS,
9+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
* See the License for the specific language governing permissions and
11+
limitations under the License.
12+
*/
13+
114
package io.dapr.testcontainers.converter;
215

16+
import io.dapr.testcontainers.AppHttpPipeline;
317
import io.dapr.testcontainers.Configuration;
418
import io.dapr.testcontainers.DaprContainer;
19+
import io.dapr.testcontainers.ListEntry;
520
import io.dapr.testcontainers.OtelTracingConfigurationSettings;
621
import io.dapr.testcontainers.TracingConfigurationSettings;
722
import org.junit.jupiter.api.Test;
@@ -10,6 +25,9 @@
1025
import static org.junit.jupiter.api.Assertions.assertEquals;
1126
import static org.junit.jupiter.api.Assertions.assertNotNull;
1227

28+
import java.util.ArrayList;
29+
import java.util.List;
30+
1331
class ConfigurationYamlConverterTest {
1432
private final Yaml MAPPER = YamlMapperFactory.create();
1533
private final ConfigurationYamlConverter converter = new ConfigurationYamlConverter(MAPPER);
@@ -28,10 +46,16 @@ public void testConfigurationToYaml() {
2846
null
2947
);
3048

49+
50+
List<ListEntry> handlers = new ArrayList<>();
51+
handlers.add(new ListEntry("alias", "middleware.http.routeralias"));
52+
53+
AppHttpPipeline appHttpPipeline = new AppHttpPipeline(handlers);
54+
3155
DaprContainer dapr = new DaprContainer("daprio/daprd")
3256
.withAppName("dapr-app")
3357
.withAppPort(8081)
34-
.withConfiguration(new Configuration("my-config", tracing))
58+
.withConfiguration(new Configuration("my-config", tracing, appHttpPipeline))
3559
.withAppChannelAddress("host.testcontainers.internal");
3660

3761
Configuration configuration = dapr.getConfiguration();
@@ -50,7 +74,11 @@ public void testConfigurationToYaml() {
5074
+ " otel:\n"
5175
+ " endpointAddress: localhost:4317\n"
5276
+ " isSecure: false\n"
53-
+ " protocol: grpc\n";
77+
+ " protocol: grpc\n"
78+
+ " appHttpPipeline:\n"
79+
+ " handlers:\n"
80+
+ " - name: alias\n"
81+
+ " type: middleware.http.routeralias\n";
5482

5583
assertEquals(expectedConfigurationYaml, configurationYaml);
5684
}

0 commit comments

Comments
 (0)