Skip to content

Commit

Permalink
Fix use of deprecated Vert.x methods and unchecked casts (#866)
Browse files Browse the repository at this point in the history
Signed-off-by: Jakub Scholz <[email protected]>
  • Loading branch information
scholzj authored Feb 1, 2024
1 parent 6479490 commit 05513af
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 12 deletions.
26 changes: 21 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@
<maven-jar-plugin.version>3.3.0</maven-jar-plugin.version>
<maven-surefire-plugin.version>3.0.0-M7</maven-surefire-plugin.version>
<maven-failsafe-plugin.version>3.0.0-M7</maven-failsafe-plugin.version>
<maven.compiler.version>3.10.1</maven.compiler.version>
<maven.assembly.version>3.4.2</maven.assembly.version>
<maven.javadoc.version>3.4.1</maven.javadoc.version>
<maven.source.version>3.2.1</maven.source.version>
Expand Down Expand Up @@ -186,11 +187,6 @@
<artifactId>netty-common</artifactId>
<version>${netty.version}</version>
</dependency>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-buffer</artifactId>
<version>${netty.version}</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
Expand Down Expand Up @@ -422,6 +418,26 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven.compiler.version}</version>
<executions>
<execution>
<id>default-compile</id>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
<configuration>
<compilerArgs>
<arg>-Xlint:unchecked,deprecation</arg>
<arg>-Werror</arg>
</compilerArgs>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
Expand Down
9 changes: 6 additions & 3 deletions src/main/java/io/strimzi/kafka/bridge/http/HttpBridge.java
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,8 @@ private CorsHandler getCorsHandler() {
String allowedOrigins = this.bridgeConfig.getHttpConfig().getCorsAllowedOrigins();

LOGGER.info("Allowed origins for Cors: {}", allowedOrigins);
return CorsHandler.create(allowedOrigins)
return CorsHandler.create()
.addRelativeOrigin(allowedOrigins)
.allowedHeaders(allowedHeaders)
.allowedMethods(allowedMethods);
}
Expand Down Expand Up @@ -292,7 +293,7 @@ private void createConsumer(RoutingContext routingContext) {
this.httpBridgeContext.setOpenApiOperation(HttpOpenApiOperations.CREATE_CONSUMER);

// check for an empty body
JsonNode body = !routingContext.body().isEmpty() ? JsonUtils.bytesToJson(routingContext.body().buffer().getByteBuf().array()) : JsonUtils.createObjectNode();
JsonNode body = !routingContext.body().isEmpty() ? JsonUtils.bytesToJson(routingContext.body().buffer().getBytes()) : JsonUtils.createObjectNode();
HttpSinkBridgeEndpoint<byte[], byte[]> sink = null;

try {
Expand All @@ -302,12 +303,14 @@ private void createConsumer(RoutingContext routingContext) {
new ByteArrayDeserializer(), new ByteArrayDeserializer());

sink.closeHandler(endpoint -> {
@SuppressWarnings("unchecked")
HttpSinkBridgeEndpoint<byte[], byte[]> httpEndpoint = (HttpSinkBridgeEndpoint<byte[], byte[]>) endpoint;
httpBridgeContext.getHttpSinkEndpoints().remove(httpEndpoint.consumerInstanceId());
});
sink.open();

sink.handle(routingContext, endpoint -> {
@SuppressWarnings("unchecked")
HttpSinkBridgeEndpoint<byte[], byte[]> httpEndpoint = (HttpSinkBridgeEndpoint<byte[], byte[]>) endpoint;
httpBridgeContext.getHttpSinkEndpoints().put(httpEndpoint.consumerInstanceId(), httpEndpoint);
timestampMap.put(httpEndpoint.consumerInstanceId(), System.currentTimeMillis());
Expand Down Expand Up @@ -532,7 +535,7 @@ private void openapi(RoutingContext routingContext) {
if (xForwardedPath != null) {
path = xForwardedPath;
}
ObjectNode json = (ObjectNode) JsonUtils.bytesToJson(readFile.result().getByteBuf().array());
ObjectNode json = (ObjectNode) JsonUtils.bytesToJson(readFile.result().getBytes());
json.put("basePath", path);
HttpUtils.sendResponse(routingContext, HttpResponseStatus.OK.code(), BridgeContentType.JSON, JsonUtils.jsonToBytes(json));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@ public void handle(RoutingContext routingContext, Handler<HttpBridgeEndpoint> ha
try {
// check for an empty body
if (!routingContext.body().isEmpty()) {
bodyAsJson = JsonUtils.bytesToJson(routingContext.body().buffer().getByteBuf().array());
bodyAsJson = JsonUtils.bytesToJson(routingContext.body().buffer().getBytes());
}
LOGGER.debug("[{}] Request: body = {}", routingContext.get("request-id"), bodyAsJson);
} catch (JsonDecodeException ex) {
Expand Down Expand Up @@ -605,6 +605,7 @@ public void handle(RoutingContext routingContext, Handler<HttpBridgeEndpoint> ha
}
}

@SuppressWarnings("unchecked")
private MessageConverter<K, V, byte[], byte[]> buildMessageConverter() {
switch (this.format) {
case JSON:
Expand Down Expand Up @@ -634,7 +635,7 @@ private boolean checkAcceptedBody(String accept) {
private String buildRequestUri(RoutingContext routingContext) {
// by default schema/proto and host comes from the base request information (i.e. "Host" header)
String scheme = routingContext.request().scheme();
String host = routingContext.request().host();
String host = routingContext.request().authority().toString();
// eventually get the request path from "X-Forwarded-Path" if set by a gateway/proxy
String xForwardedPath = routingContext.request().getHeader("x-forwarded-path");
String path = (xForwardedPath != null && !xForwardedPath.isEmpty()) ? xForwardedPath : routingContext.request().path();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public void handle(RoutingContext routingContext, Handler<HttpBridgeEndpoint> ha

return;
}
records = messageConverter.toKafkaRecords(topic, partition, routingContext.body().buffer().getByteBuf().array());
records = messageConverter.toKafkaRecords(topic, partition, routingContext.body().buffer().getBytes());

for (ProducerRecord<K, V> record :records) {
span.inject(record);
Expand Down Expand Up @@ -213,6 +213,7 @@ private int handleError(Throwable ex) {
}
}

@SuppressWarnings("unchecked")
private MessageConverter<K, V, byte[], byte[]> buildMessageConverter() {
switch (this.format) {
case JSON:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public ContextStorage get() {
enum BridgeContextStorage implements ContextStorage {
INSTANCE;

private final ConcurrentMap<Object, Object> data = new ConcurrentHashMap();
private final ConcurrentMap<Object, Object> data = new ConcurrentHashMap<>();

@Override
public Scope attach(Context toAttach) {
Expand Down

0 comments on commit 05513af

Please sign in to comment.