Skip to content

Commit

Permalink
Merge pull request #266 from wultra/develop
Browse files Browse the repository at this point in the history
Merge develop to master
  • Loading branch information
banterCZ authored Feb 23, 2024
2 parents 7f19099 + 86f4b71 commit f260f1b
Show file tree
Hide file tree
Showing 12 changed files with 117 additions and 36 deletions.
2 changes: 1 addition & 1 deletion annotations/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>io.getlime.core</groupId>
<artifactId>lime-java-core-parent</artifactId>
<version>1.8.0</version>
<version>1.9.0</version>
</parent>

<artifactId>annotations</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion audit-base/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>io.getlime.core</groupId>
<artifactId>lime-java-core-parent</artifactId>
<version>1.8.0</version>
<version>1.9.0</version>
</parent>

<artifactId>audit-base</artifactId>
Expand Down
11 changes: 1 addition & 10 deletions audit-base/src/test/resources/application.properties
Original file line number Diff line number Diff line change
@@ -1,11 +1,2 @@
# H2
spring.h2.console.enabled=true
spring.h2.console.path=/h2
# Datasource
spring.datasource.url=jdbc:h2:file:~/audit
spring.datasource.username=sa
spring.datasource.password=
spring.datasource.driver-class-name=org.h2.Driver

# Audit configuration
spring.application.name=test-application
spring.application.name=test-application
2 changes: 1 addition & 1 deletion bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>io.getlime.core</groupId>
<artifactId>lime-java-core-parent</artifactId>
<version>1.8.0</version>
<version>1.9.0</version>
</parent>

<artifactId>core-bom</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion http-common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>io.getlime.core</groupId>
<artifactId>lime-java-core-parent</artifactId>
<version>1.8.0</version>
<version>1.9.0</version>
</parent>

<artifactId>http-common</artifactId>
Expand Down
32 changes: 13 additions & 19 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<description>Wultra - Core Java Libraries</description>
<groupId>io.getlime.core</groupId>
<artifactId>lime-java-core-parent</artifactId>
<version>1.8.0</version>
<version>1.9.0</version>
<packaging>pom</packaging>

<inceptionYear>2017</inceptionYear>
Expand Down Expand Up @@ -53,14 +53,14 @@

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<maven-surefire-plugin.version>3.2.2</maven-surefire-plugin.version>
<java.version>17</java.version>
<maven.compiler.release>${java.version}</maven.compiler.release>

<maven-compiler-plugin.version>3.12.1</maven-compiler-plugin.version>
<maven-surefire-plugin.version>3.2.5</maven-surefire-plugin.version>

<!-- Dependencies -->
<spring-boot.version>3.1.6</spring-boot.version>
<!-- TODO (racansky, 2023-12-08) temporarily override the version 1.4.11 from spring boot version because of CVE -->
<logback.version>1.4.14</logback.version>
<spring-boot.version>3.2.3</spring-boot.version>
<findbugs-annotations.version>3.0.1</findbugs-annotations.version>
</properties>

Expand All @@ -73,18 +73,6 @@
<type>pom</type>
<scope>import</scope>
</dependency>

<!-- TODO (racansky, 2023-12-08) temporarily override the version 1.4.11 from spring boot version because of CVE -->
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>${logback.version}</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-core</artifactId>
<version>${logback.version}</version>
</dependency>
</dependencies>
</dependencyManagement>

Expand All @@ -99,6 +87,12 @@
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven-compiler-plugin.version}</version>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
Expand Down
8 changes: 7 additions & 1 deletion rest-client-base/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>io.getlime.core</groupId>
<artifactId>lime-java-core-parent</artifactId>
<version>1.8.0</version>
<version>1.9.0</version>
</parent>

<artifactId>rest-client-base</artifactId>
Expand Down Expand Up @@ -61,6 +61,12 @@
<artifactId>netty-http-authenticator</artifactId>
<version>1.5</version>
</dependency>

<dependency>
<groupId>io.opentelemetry</groupId>
<artifactId>opentelemetry-api</artifactId>
</dependency>

</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ private void initializeWebClient() throws RestClientException {
});
});
}
builder.filter(TraceparentFilterFunction.handleTraceparentContext());

final ReactorClientHttpConnector connector = new ReactorClientHttpConnector(httpClient);
webClient = builder.baseUrl(config.getBaseUrl()).clientConnector(connector).build();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/*
* Copyright 2024 Wultra s.r.o.
*
* 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 com.wultra.core.rest.client.base;

import io.opentelemetry.api.trace.Span;
import io.opentelemetry.api.trace.SpanContext;
import io.opentelemetry.api.trace.TraceFlags;
import org.springframework.web.reactive.function.client.ClientRequest;
import org.springframework.web.reactive.function.client.ClientResponse;
import org.springframework.web.reactive.function.client.ExchangeFilterFunction;
import org.springframework.web.reactive.function.client.ExchangeFunction;
import reactor.core.publisher.Mono;

/**
* An ExchangeFilterFunction for adding traceparent header to WebClient requests.
* It also propagates trace ID through Reactor context and MDC for logging purposes.
*
* @author Jan Dusil, [email protected]
*/
public class TraceparentFilterFunction implements ExchangeFilterFunction {

private static final String TRACEPARENT_HEADER_KEY = "traceparent";

/**
* Applies the filter to the given ClientRequest and ExchangeFunction.
*
* @param request The client request.
* @param next The next exchange function in the chain.
* @return a Mono<ClientResponse> after applying the filter.
*/
@Override
public Mono<ClientResponse> filter(final ClientRequest request, final ExchangeFunction next) {
return next.exchange(addTraceparentHeader(request));
}

/**
* Adds a traceparent header to the ClientRequest if a current span context is available.
*
* @param request The client request.
* @return a modified ClientRequest with the traceparent header added.
*/
private ClientRequest addTraceparentHeader(final ClientRequest request) {
final Span currentSpan = Span.current();
if (currentSpan != null) {
final SpanContext spanContext = currentSpan.getSpanContext();
if (spanContext != null) {
final String traceId = spanContext.getTraceId();
/* The parentId of the next server Span will be the current spanId */
final String parentId = spanContext.getSpanId();
final TraceFlags traceFlags = spanContext.getTraceFlags();
if (traceId != null && parentId != null && traceFlags != null) {
final String headerValue = String.format("00-%s-%s-%s",
traceId,
parentId,
traceFlags.asHex());
return ClientRequest.from(request)
.headers(headers -> headers.set(TRACEPARENT_HEADER_KEY, headerValue))
.build();
}
}
}
return request;
}

/**
* Factory method to create an instance of TraceparentFilterFunction.
*
* @return a new instance of TraceparentFilterFunction.
*/
public static ExchangeFilterFunction handleTraceparentContext() {
return new TraceparentFilterFunction();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public ObjectResponse<TestResponse> testPostWithObjectRequestAndResponse(@Reques
}

@PostMapping(value = "/multipart-request-response", consumes = { MediaType.MULTIPART_FORM_DATA_VALUE })
public ObjectResponse<TestResponse> testPostWithMultipartRequestAndResponse(@RequestPart TestRequest request) {
public ObjectResponse<TestResponse> testPostWithMultipartRequestAndResponse(@RequestPart("request") TestRequest request) {
TestResponse testResponse = new TestResponse(request.getRequest());
return new ObjectResponse<>(testResponse);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,14 @@
*/
package com.wultra.core.rest.client.base.model;

import lombok.ToString;

/**
* Test request.
*
* @author Roman Strobl, [email protected]
*/
@ToString
public class TestRequest {

private String request;
Expand Down
2 changes: 1 addition & 1 deletion rest-model-base/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>io.getlime.core</groupId>
<artifactId>lime-java-core-parent</artifactId>
<version>1.8.0</version>
<version>1.9.0</version>
</parent>

<artifactId>rest-model-base</artifactId>
Expand Down

0 comments on commit f260f1b

Please sign in to comment.