From 7eb6f16b82f51683334596d64f7dbfb96340ca8f Mon Sep 17 00:00:00 2001 From: Julien Viet Date: Thu, 30 Jan 2020 10:36:50 +0100 Subject: [PATCH] CaseInsensitiveHeaders deprecation - fixes #3268 --- src/main/java/io/vertx/core/MultiMap.java | 4 +++- src/main/java/io/vertx/core/eventbus/DeliveryOptions.java | 5 ++--- src/main/java/io/vertx/core/eventbus/impl/MessageImpl.java | 5 ++--- .../core/eventbus/impl/clustered/ClusteredMessage.java | 5 ++--- .../java/io/vertx/core/http/CaseInsensitiveHeaders.java | 6 ++++++ src/main/java/io/vertx/core/http/RequestOptions.java | 2 +- .../java/io/vertx/core/http/impl/Http2ClientConnection.java | 2 +- .../io/vertx/core/http/impl/Http2ServerRequestImpl.java | 3 +-- .../java/io/vertx/core/http/impl/HttpServerRequestImpl.java | 2 +- src/main/java/io/vertx/core/http/impl/HttpUtils.java | 3 +-- .../io/vertx/core/http/impl/headers/VertxHttpHeaders.java | 2 -- src/test/java/io/vertx/core/eventbus/LocalEventBusTest.java | 3 +-- .../java/io/vertx/core/http/CaseInsensitiveHeadersTest.java | 2 +- 13 files changed, 22 insertions(+), 22 deletions(-) diff --git a/src/main/java/io/vertx/core/MultiMap.java b/src/main/java/io/vertx/core/MultiMap.java index 08ff8685c..6f29fa3c7 100644 --- a/src/main/java/io/vertx/core/MultiMap.java +++ b/src/main/java/io/vertx/core/MultiMap.java @@ -41,7 +41,9 @@ public interface MultiMap extends Iterable> { * @return the multi-map */ static MultiMap caseInsensitiveMultiMap() { - return new CaseInsensitiveHeaders(); + @SuppressWarnings("deprecation") + CaseInsensitiveHeaders map = new CaseInsensitiveHeaders(); + return map; } @GenIgnore(GenIgnore.PERMITTED_TYPE) diff --git a/src/main/java/io/vertx/core/eventbus/DeliveryOptions.java b/src/main/java/io/vertx/core/eventbus/DeliveryOptions.java index bc41a9af8..ecbf69e2d 100644 --- a/src/main/java/io/vertx/core/eventbus/DeliveryOptions.java +++ b/src/main/java/io/vertx/core/eventbus/DeliveryOptions.java @@ -14,7 +14,6 @@ package io.vertx.core.eventbus; import io.vertx.codegen.annotations.DataObject; import io.vertx.codegen.annotations.GenIgnore; import io.vertx.core.MultiMap; -import io.vertx.core.http.CaseInsensitiveHeaders; import io.vertx.core.impl.Arguments; import io.vertx.core.json.JsonObject; @@ -75,7 +74,7 @@ public class DeliveryOptions { this.codecName = json.getString("codecName", null); JsonObject hdrs = json.getJsonObject("headers", null); if (hdrs != null) { - headers = new CaseInsensitiveHeaders(); + headers = MultiMap.caseInsensitiveMultiMap(); for (Map.Entry entry: hdrs) { if (!(entry.getValue() instanceof String)) { throw new IllegalStateException("Invalid type for message header value " + entry.getValue().getClass()); @@ -194,7 +193,7 @@ public class DeliveryOptions { private void checkHeaders() { if (headers == null) { - headers = new CaseInsensitiveHeaders(); + headers = MultiMap.caseInsensitiveMultiMap(); } } diff --git a/src/main/java/io/vertx/core/eventbus/impl/MessageImpl.java b/src/main/java/io/vertx/core/eventbus/impl/MessageImpl.java index 9ef032919..ecac79a34 100644 --- a/src/main/java/io/vertx/core/eventbus/impl/MessageImpl.java +++ b/src/main/java/io/vertx/core/eventbus/impl/MessageImpl.java @@ -15,7 +15,6 @@ import io.vertx.core.AsyncResult; import io.vertx.core.Handler; import io.vertx.core.MultiMap; import io.vertx.core.eventbus.*; -import io.vertx.core.http.CaseInsensitiveHeaders; import io.vertx.core.logging.Logger; import io.vertx.core.logging.LoggerFactory; @@ -63,7 +62,7 @@ public class MessageImpl implements Message { this.messageCodec = other.messageCodec; if (other.headers != null) { List> entries = other.headers.entries(); - this.headers = new CaseInsensitiveHeaders(); + this.headers = MultiMap.caseInsensitiveMultiMap(); for (Map.Entry entry: entries) { this.headers.add(entry.getKey(), entry.getValue()); } @@ -89,7 +88,7 @@ public class MessageImpl implements Message { public MultiMap headers() { // Lazily decode headers if (headers == null) { - headers = new CaseInsensitiveHeaders(); + headers = MultiMap.caseInsensitiveMultiMap(); } return headers; } diff --git a/src/main/java/io/vertx/core/eventbus/impl/clustered/ClusteredMessage.java b/src/main/java/io/vertx/core/eventbus/impl/clustered/ClusteredMessage.java index 44a3dd1a9..0f8e02bdb 100644 --- a/src/main/java/io/vertx/core/eventbus/impl/clustered/ClusteredMessage.java +++ b/src/main/java/io/vertx/core/eventbus/impl/clustered/ClusteredMessage.java @@ -20,7 +20,6 @@ import io.vertx.core.eventbus.MessageCodec; import io.vertx.core.eventbus.impl.CodecManager; import io.vertx.core.eventbus.impl.EventBusImpl; import io.vertx.core.eventbus.impl.MessageImpl; -import io.vertx.core.http.CaseInsensitiveHeaders; import io.vertx.core.logging.Logger; import io.vertx.core.logging.LoggerFactory; import io.vertx.core.net.impl.ServerID; @@ -76,7 +75,7 @@ public class ClusteredMessage extends MessageImpl { decodeHeaders(); } if (headers == null) { - headers = new CaseInsensitiveHeaders(); + headers = MultiMap.caseInsensitiveMultiMap(); } } return headers; @@ -207,7 +206,7 @@ public class ClusteredMessage extends MessageImpl { headersPos += 4; int numHeaders = wireBuffer.getInt(headersPos); headersPos += 4; - headers = new CaseInsensitiveHeaders(); + headers = MultiMap.caseInsensitiveMultiMap(); for (int i = 0; i < numHeaders; i++) { int keyLength = wireBuffer.getInt(headersPos); headersPos += 4; diff --git a/src/main/java/io/vertx/core/http/CaseInsensitiveHeaders.java b/src/main/java/io/vertx/core/http/CaseInsensitiveHeaders.java index 9380f463c..0ceaf6401 100644 --- a/src/main/java/io/vertx/core/http/CaseInsensitiveHeaders.java +++ b/src/main/java/io/vertx/core/http/CaseInsensitiveHeaders.java @@ -27,7 +27,9 @@ import java.util.function.Consumer; * prior to making an HTTP request. * * @author Norman Maurer + * @deprecated instead use {@link MultiMap} */ +@Deprecated public final class CaseInsensitiveHeaders implements MultiMap { private static final int BUCKET_SIZE = 17; @@ -104,6 +106,10 @@ public final class CaseInsensitiveHeaders implements MultiMap { private final MapEntry[] entries = new MapEntry[BUCKET_SIZE]; private final MapEntry head = new MapEntry(-1, null, null); + /** + * @deprecated use {@link MultiMap#caseInsensitiveMultiMap()} instead + */ + @Deprecated public CaseInsensitiveHeaders() { head.before = head.after = head; } diff --git a/src/main/java/io/vertx/core/http/RequestOptions.java b/src/main/java/io/vertx/core/http/RequestOptions.java index d88e6d0cb..2d4f0a285 100644 --- a/src/main/java/io/vertx/core/http/RequestOptions.java +++ b/src/main/java/io/vertx/core/http/RequestOptions.java @@ -197,7 +197,7 @@ public class RequestOptions { private void checkHeaders() { if (headers == null) { - headers = new CaseInsensitiveHeaders(); + headers = MultiMap.caseInsensitiveMultiMap(); } } diff --git a/src/main/java/io/vertx/core/http/impl/Http2ClientConnection.java b/src/main/java/io/vertx/core/http/impl/Http2ClientConnection.java index dbd777cf3..598142391 100644 --- a/src/main/java/io/vertx/core/http/impl/Http2ClientConnection.java +++ b/src/main/java/io/vertx/core/http/impl/Http2ClientConnection.java @@ -249,7 +249,7 @@ class Http2ClientConnection extends Http2ConnectionBase implements HttpClientCon responseEnded = true; // Should use a shared immutable object for CaseInsensitiveHeaders ? if (trailers == null) { - trailers = new CaseInsensitiveHeaders(); + trailers = MultiMap.caseInsensitiveMultiMap(); } response.handleEnd(trailers); } diff --git a/src/main/java/io/vertx/core/http/impl/Http2ServerRequestImpl.java b/src/main/java/io/vertx/core/http/impl/Http2ServerRequestImpl.java index ae4b984cb..439ca8c63 100644 --- a/src/main/java/io/vertx/core/http/impl/Http2ServerRequestImpl.java +++ b/src/main/java/io/vertx/core/http/impl/Http2ServerRequestImpl.java @@ -26,7 +26,6 @@ import io.vertx.codegen.annotations.Nullable; import io.vertx.core.Handler; import io.vertx.core.MultiMap; import io.vertx.core.buffer.Buffer; -import io.vertx.core.http.CaseInsensitiveHeaders; import io.vertx.core.http.Cookie; import io.vertx.core.http.HttpConnection; import io.vertx.core.http.HttpMethod; @@ -449,7 +448,7 @@ public class Http2ServerRequestImpl extends Http2ServerStream implements HttpSer synchronized (conn) { // Create it lazily if (attributes == null) { - attributes = new CaseInsensitiveHeaders(); + attributes = MultiMap.caseInsensitiveMultiMap(); } return attributes; } diff --git a/src/main/java/io/vertx/core/http/impl/HttpServerRequestImpl.java b/src/main/java/io/vertx/core/http/impl/HttpServerRequestImpl.java index 1a95b632f..332c250d5 100644 --- a/src/main/java/io/vertx/core/http/impl/HttpServerRequestImpl.java +++ b/src/main/java/io/vertx/core/http/impl/HttpServerRequestImpl.java @@ -605,7 +605,7 @@ public class HttpServerRequestImpl implements HttpServerRequest { private MultiMap attributes() { // Create it lazily if (attributes == null) { - attributes = new CaseInsensitiveHeaders(); + attributes = MultiMap.caseInsensitiveMultiMap(); } return attributes; } diff --git a/src/main/java/io/vertx/core/http/impl/HttpUtils.java b/src/main/java/io/vertx/core/http/impl/HttpUtils.java index 48d7e7b93..3f1cfbb46 100644 --- a/src/main/java/io/vertx/core/http/impl/HttpUtils.java +++ b/src/main/java/io/vertx/core/http/impl/HttpUtils.java @@ -23,7 +23,6 @@ import io.netty.util.AsciiString; import io.netty.util.CharsetUtil; import io.vertx.core.MultiMap; import io.vertx.core.buffer.Buffer; -import io.vertx.core.http.CaseInsensitiveHeaders; import io.vertx.core.http.HttpServerRequest; import io.vertx.core.http.StreamPriority; @@ -381,7 +380,7 @@ public final class HttpUtils { static MultiMap params(String uri) { QueryStringDecoder queryStringDecoder = new QueryStringDecoder(uri); Map> prms = queryStringDecoder.parameters(); - MultiMap params = new CaseInsensitiveHeaders(); + MultiMap params = MultiMap.caseInsensitiveMultiMap(); if (!prms.isEmpty()) { for (Map.Entry> entry: prms.entrySet()) { params.add(entry.getKey(), entry.getValue()); diff --git a/src/main/java/io/vertx/core/http/impl/headers/VertxHttpHeaders.java b/src/main/java/io/vertx/core/http/impl/headers/VertxHttpHeaders.java index 82f4e9153..abcedfeb3 100644 --- a/src/main/java/io/vertx/core/http/impl/headers/VertxHttpHeaders.java +++ b/src/main/java/io/vertx/core/http/impl/headers/VertxHttpHeaders.java @@ -18,11 +18,9 @@ import io.netty.util.AsciiString; import io.netty.util.CharsetUtil; import io.netty.util.HashingStrategy; import io.vertx.core.MultiMap; -import io.vertx.core.http.CaseInsensitiveHeaders; import io.vertx.core.http.impl.HttpUtils; import java.util.AbstractMap; -import java.util.ArrayList; import java.util.Iterator; import java.util.LinkedList; import java.util.List; diff --git a/src/test/java/io/vertx/core/eventbus/LocalEventBusTest.java b/src/test/java/io/vertx/core/eventbus/LocalEventBusTest.java index b114d6f13..41ede792d 100644 --- a/src/test/java/io/vertx/core/eventbus/LocalEventBusTest.java +++ b/src/test/java/io/vertx/core/eventbus/LocalEventBusTest.java @@ -13,7 +13,6 @@ package io.vertx.core.eventbus; import io.vertx.core.*; import io.vertx.core.eventbus.impl.HandlerRegistration; -import io.vertx.core.http.CaseInsensitiveHeaders; import io.vertx.core.impl.ConcurrentHashSet; import io.vertx.core.impl.ContextInternal; import io.vertx.core.impl.EventLoopContext; @@ -758,7 +757,7 @@ public class LocalEventBusTest extends EventBusTestBase { @Test public void testHeadersCopiedAfterSend() throws Exception { - MultiMap headers = new CaseInsensitiveHeaders(); + MultiMap headers = MultiMap.caseInsensitiveMultiMap(); headers.add("foo", "bar"); vertx.eventBus().consumer(ADDRESS1).handler(msg -> { assertNotSame(headers, msg.headers()); diff --git a/src/test/java/io/vertx/core/http/CaseInsensitiveHeadersTest.java b/src/test/java/io/vertx/core/http/CaseInsensitiveHeadersTest.java index 205bdea5b..8879e38e2 100644 --- a/src/test/java/io/vertx/core/http/CaseInsensitiveHeadersTest.java +++ b/src/test/java/io/vertx/core/http/CaseInsensitiveHeadersTest.java @@ -27,7 +27,7 @@ public class CaseInsensitiveHeadersTest extends VertxHttpHeadersTest { } protected MultiMap newMultiMap() { - return new CaseInsensitiveHeaders(); + return MultiMap.caseInsensitiveMultiMap(); } @Test