Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions console-framework-client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,27 @@
<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-cbor</artifactId>
<scope>provided</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.module</groupId>
<artifactId>jackson-module-kotlin</artifactId>
</dependency>
<dependency>
<groupId>tools.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>3.1.0</version>
</dependency>
<dependency>
<groupId>tools.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-cbor</artifactId>
<version>3.1.0</version>
</dependency>
<dependency>
<groupId>tools.jackson.module</groupId>
<artifactId>jackson-module-kotlin</artifactId>
<version>3.1.0</version>
</dependency>

<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
import io.axoniq.console.framework.client.RSocketHandlerRegistrar;
import io.axoniq.console.framework.client.ServerProcessorReporter;
import io.axoniq.console.framework.client.SetupPayloadCreator;
import io.axoniq.console.framework.client.strategy.CborEncodingStrategy;
import io.axoniq.console.framework.client.strategy.CborJackson2EncodingStrategy;
import io.axoniq.console.framework.client.strategy.CborJackson3EncodingStrategy;
import io.axoniq.console.framework.client.strategy.RSocketPayloadEncodingStrategy;
import io.axoniq.console.framework.eventprocessor.DeadLetterManager;
import io.axoniq.console.framework.eventprocessor.EventProcessorManager;
Expand Down Expand Up @@ -176,7 +177,7 @@
)
)
.registerComponent(RSocketPayloadEncodingStrategy.class,
c -> new CborEncodingStrategy()
c -> createJackson2Or3EncodingStrategy()
)
.registerComponent(RSocketHandlerRegistrar.class,
c -> new RSocketHandlerRegistrar(c.getComponent(RSocketPayloadEncodingStrategy.class))
Expand Down Expand Up @@ -313,6 +314,54 @@
new AxoniqConsoleEnhancingConfigurerModule(spanMatcherPredicateMap).configureModule(configurer);
}

/**
* Checks the classpath for Jackson 2 or Jackson 3 and its requirements for this application.
* Will fail to create the component if neither is there, or if one is present and doesn't have the right modules.
*/
private static RSocketPayloadEncodingStrategy createJackson2Or3EncodingStrategy() {
try {
Class.forName("com.fasterxml.jackson.databind.ObjectMapper");
try {

Check warning on line 324 in console-framework-client/src/main/java/io/axoniq/console/framework/AxoniqConsoleConfigurerModule.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Extract this nested try block into a separate method.

See more on https://sonarcloud.io/project/issues?id=AxonIQ_console-framework-client&issues=AZ1I8k7i0Hy_-YdDj5U5&open=AZ1I8k7i0Hy_-YdDj5U5&pullRequest=134
Class.forName(
"com.fasterxml.jackson.dataformat.cbor.databind.CBORMapper");
try {

Check warning on line 327 in console-framework-client/src/main/java/io/axoniq/console/framework/AxoniqConsoleConfigurerModule.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Extract this nested try block into a separate method.

See more on https://sonarcloud.io/project/issues?id=AxonIQ_console-framework-client&issues=AZ1I8k7i0Hy_-YdDj5U8&open=AZ1I8k7i0Hy_-YdDj5U8&pullRequest=134
Class.forName(
"com.fasterxml.jackson.module.kotlin.KotlinModule");
return new CborJackson2EncodingStrategy();
} catch (ClassNotFoundException e) {
throw new IllegalArgumentException(
"Found Jackson 2 on the classpath, but can not find the KotlinModule. Please add the com.fasterxml.jackson.module:jackson-module-kotlin dependency to your project");
}
} catch (ClassNotFoundException e) {
throw new IllegalArgumentException(
"Found Jackson 2 on the classpath, but cannot find the CBOR dataformat. Please add the com.fasterxml.jackson.dataformat:jackson-dataformat-cbor dependency to your project.");
}
} catch (ClassNotFoundException e) {

Check warning on line 339 in console-framework-client/src/main/java/io/axoniq/console/framework/AxoniqConsoleConfigurerModule.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove this block of code, fill it in, or add a comment explaining why it is empty.

See more on https://sonarcloud.io/project/issues?id=AxonIQ_console-framework-client&issues=AZ1JhkgpXykSk5tqA81N&open=AZ1JhkgpXykSk5tqA81N&pullRequest=134
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The 'do nothing' comment is on like 359 instead of here


}

try {
Class.forName("tools.jackson.databind.ObjectMapper");
try {

Check warning on line 345 in console-framework-client/src/main/java/io/axoniq/console/framework/AxoniqConsoleConfigurerModule.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Extract this nested try block into a separate method.

See more on https://sonarcloud.io/project/issues?id=AxonIQ_console-framework-client&issues=AZ1I8k7i0Hy_-YdDj5U7&open=AZ1I8k7i0Hy_-YdDj5U7&pullRequest=134
Class.forName("tools.jackson.dataformat.cbor.CBORMapper");
try {

Check warning on line 347 in console-framework-client/src/main/java/io/axoniq/console/framework/AxoniqConsoleConfigurerModule.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Extract this nested try block into a separate method.

See more on https://sonarcloud.io/project/issues?id=AxonIQ_console-framework-client&issues=AZ1I8k7i0Hy_-YdDj5U6&open=AZ1I8k7i0Hy_-YdDj5U6&pullRequest=134
Class.forName("tools.jackson.module.kotlin.KotlinModule");
return new CborJackson3EncodingStrategy();
} catch (ClassNotFoundException e) {
throw new IllegalArgumentException(
"Found Jackson 3 on the classpath, but can not find the KotlinModule. Please add the tools.jackson.module:jackson-module-kotlin dependency to your project");
}
} catch (ClassNotFoundException e) {
throw new IllegalArgumentException(
"Found Jackson 3 on the classpath, but cannot find the CBOR dataformat. Please add the tools.jackson.dataformat:jackson-dataformat-cbor dependency to your project.");
}
} catch (ClassNotFoundException e) {
// Do nothing, Jackson 3 is not on the classpath. Continue to check for 2
throw new IllegalArgumentException(
"Neither Jackson 2 nor 3 was found on the classpath. Please add either Jackson 2 or 3 to your project.");
}
}

/**
* Builder class to instantiate a {@link AxoniqConsoleConfigurerModule}.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import io.rsocket.metadata.WellKnownMimeType
import io.rsocket.util.DefaultPayload

class CborEncodingStrategy : RSocketPayloadEncodingStrategy {
class CborJackson2EncodingStrategy : RSocketPayloadEncodingStrategy {
private val mapper = CBORMapper.builder().build().findAndRegisterModules()
.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)

Expand All @@ -41,7 +41,7 @@

override fun <T> decode(payload: Payload, expectedType: Class<T>): T {
if (expectedType == String::class.java) {
return payload.dataUtf8 as T

Check warning on line 44 in console-framework-client/src/main/java/io/axoniq/console/framework/client/strategy/CborJackson2EncodingStrategy.kt

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove this unchecked cast.

See more on https://sonarcloud.io/project/issues?id=AxonIQ_console-framework-client&issues=AZ1I8k6S0Hy_-YdDj5Uo&open=AZ1I8k6S0Hy_-YdDj5Uo&pullRequest=134
}

return mapper.readValue(payload.data.array(), expectedType)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* Copyright (c) 2022-2024. AxonIQ B.V.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* Copyright (c) 2022-2024. AxonIQ B.V.
* Copyright (c) 2022-2026. AxonIQ B.V.

Any file that has been touched should have the copyright notice updated.

*
* 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.axoniq.console.framework.client.strategy

import io.netty.buffer.ByteBuf
import io.netty.buffer.ByteBufAllocator
import io.netty.buffer.CompositeByteBuf
import io.rsocket.Payload
import io.rsocket.metadata.WellKnownMimeType
import io.rsocket.util.DefaultPayload
import tools.jackson.databind.DeserializationFeature
import tools.jackson.dataformat.cbor.CBORMapper

class CborJackson3EncodingStrategy : RSocketPayloadEncodingStrategy {
private val mapper = CBORMapper.builder()
.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES)
.build()

override fun getMimeType(): WellKnownMimeType {
return WellKnownMimeType.APPLICATION_CBOR
}

override fun encode(payload: Any, metadata: ByteBuf?): Payload {
val payloadBuffer: CompositeByteBuf = ByteBufAllocator.DEFAULT.compositeBuffer()
payloadBuffer.writeBytes(mapper.writeValueAsBytes(payload))
return DefaultPayload.create(payloadBuffer, metadata)
}

override fun <T> decode(payload: Payload, expectedType: Class<T>): T {
if (expectedType == String::class.java) {
return payload.dataUtf8 as T

Check warning on line 45 in console-framework-client/src/main/java/io/axoniq/console/framework/client/strategy/CborJackson3EncodingStrategy.kt

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove this unchecked cast.

See more on https://sonarcloud.io/project/issues?id=AxonIQ_console-framework-client&issues=AZ1I8k6a0Hy_-YdDj5Up&open=AZ1I8k6a0Hy_-YdDj5Up&pullRequest=134
}

return mapper.readValue(payload.data.array(), expectedType)
}
}
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@
<sonar.organization>axoniq</sonar.organization>
<sonar.host.url>https://sonarcloud.io</sonar.host.url>

<kotlin.version>1.9.25</kotlin.version>
<dokka.version>1.9.20</dokka.version>
<kotlin.version>2.2.20</kotlin.version>
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't upgrade kotlin. This upgrades the stdlib, and causes any older kotlin version to be incompatible with the client.
This is why we keep the version as low as possible in this project.

<dokka.version>2.0.0</dokka.version>

<axon.version>4.6.7</axon.version>

Expand Down
Loading