From fe0b32c7507cbdb67337713eae9733cab935a9fd Mon Sep 17 00:00:00 2001 From: Urban Malc Date: Mon, 5 Dec 2022 10:29:42 +0100 Subject: [PATCH] Added null check to Accept header parsing, upped KEE version, added Java 18 to CI --- .github/workflows/kumuluzee-ci.yml | 2 +- .../com/kumuluz/ee/metrics/utils/MediaTypeUtil.java | 13 +++++++++---- pom.xml | 2 +- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/.github/workflows/kumuluzee-ci.yml b/.github/workflows/kumuluzee-ci.yml index 33271e4..597020b 100644 --- a/.github/workflows/kumuluzee-ci.yml +++ b/.github/workflows/kumuluzee-ci.yml @@ -9,7 +9,7 @@ jobs: strategy: matrix: - java-version: ['11', '17'] + java-version: ['11', '17', '18'] steps: - name: Checkout code diff --git a/core/src/main/java/com/kumuluz/ee/metrics/utils/MediaTypeUtil.java b/core/src/main/java/com/kumuluz/ee/metrics/utils/MediaTypeUtil.java index c2b1e96..6d22626 100644 --- a/core/src/main/java/com/kumuluz/ee/metrics/utils/MediaTypeUtil.java +++ b/core/src/main/java/com/kumuluz/ee/metrics/utils/MediaTypeUtil.java @@ -25,7 +25,7 @@ import java.util.List; /** - * Utility class for media type (Accept header) parsing. + * Utility class for media type ('Accept' header) parsing. * * @author Urban Malc * @since 2.0.0 @@ -48,10 +48,15 @@ public enum ReturnType { UNKNOWN } - public static ReturnType parseMediaType(String headers) { + public static ReturnType parseMediaType(String acceptHeader) { + + if (acceptHeader == null) { + return ReturnType.PROMETHEUS; + } + List parsedHeaders = new ArrayList<>(); - for (String header : headers.split(",")) { + for (String header : acceptHeader.split(",")) { String[] headerElements = header.split(";"); if (!KNOWN_HEADERS.contains(headerElements[0])) { @@ -69,7 +74,7 @@ public static ReturnType parseMediaType(String headers) { } if (parsedHeaders.size() == 0) { - if (headers.length() > 0) { + if (acceptHeader.length() > 0) { // no known headers return ReturnType.UNKNOWN; } else { diff --git a/pom.xml b/pom.xml index eda74af..67a0118 100644 --- a/pom.xml +++ b/pom.xml @@ -30,7 +30,7 @@ 2.3.1 - 3.13.0-SNAPSHOT + 4.1.0 1.4.1 3.0