From a6f3a0ee5308564cc37d255464cff0b7c24bb98d Mon Sep 17 00:00:00 2001 From: Vadzim Hushchanskou Date: Mon, 18 Dec 2023 13:55:13 +0300 Subject: [PATCH 1/6] Remove HttpCore dependency, WIP --- CHANGELOG.md | 2 + build.gradle | 2 +- gradle.properties | 2 +- .../formatting/AbstractHttpFormatter.java | 4 +- .../formatting/http/Constants.java | 44 +++++++-------- .../formatting/http/ContentType.java | 55 +++++++++++++++++++ .../formatting/http/HttpFormatUtils.java | 11 ++-- .../formatting/http/HttpRequestFormatter.java | 7 +-- 8 files changed, 92 insertions(+), 35 deletions(-) create mode 100644 src/main/java/com/epam/reportportal/formatting/http/ContentType.java diff --git a/CHANGELOG.md b/CHANGELOG.md index 6fbb5d5..ba67a3c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,8 @@ ## [Unreleased] ### Changed - Client version updated on [5.1.25](https://github.com/reportportal/client-java/releases/tag/5.1.25), by @HardNorth +### Removed +- HttpCore dependency was removed to avoid conflicts, by @HardNorth ## [5.1.6] ### Changed diff --git a/build.gradle b/build.gradle index e0122d7..b0efcf4 100644 --- a/build.gradle +++ b/build.gradle @@ -42,7 +42,6 @@ dependencies { api 'com.epam.reportportal:commons-model:5.0.0' implementation 'org.jsoup:jsoup:1.15.3' - implementation 'org.apache.httpcomponents:httpcore:4.4.15' testImplementation 'com.epam.reportportal:agent-java-test-utils:0.0.2' @@ -54,6 +53,7 @@ dependencies { testImplementation 'org.hamcrest:hamcrest-core:2.2' testImplementation "org.mockito:mockito-core:${mockito_version}" testImplementation "org.mockito:mockito-inline:${mockito_version}" + testImplementation 'org.apache.httpcomponents:httpcore:4.4.15' } test { diff --git a/gradle.properties b/gradle.properties index 14f9cd6..68dda46 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,4 +1,4 @@ -version=5.1.7-SNAPSHOT +version=5.2.0-SNAPSHOT description=Report Portal Java formatting utils for Agents and Loggers junit5_version=5.6.3 junit5_runner_version=1.6.3 diff --git a/src/main/java/com/epam/reportportal/formatting/AbstractHttpFormatter.java b/src/main/java/com/epam/reportportal/formatting/AbstractHttpFormatter.java index 157ee2f..2dad7c7 100644 --- a/src/main/java/com/epam/reportportal/formatting/AbstractHttpFormatter.java +++ b/src/main/java/com/epam/reportportal/formatting/AbstractHttpFormatter.java @@ -16,6 +16,7 @@ package com.epam.reportportal.formatting; +import com.epam.reportportal.formatting.http.ContentType; import com.epam.reportportal.formatting.http.HttpFormatter; import com.epam.reportportal.formatting.http.HttpPartFormatter; import com.epam.reportportal.formatting.http.HttpRequestFormatter; @@ -29,7 +30,6 @@ import com.epam.reportportal.service.ReportPortal; import com.epam.reportportal.service.step.StepReporter; import com.google.common.io.ByteSource; -import org.apache.http.entity.ContentType; import javax.annotation.Nonnull; import javax.annotation.Nullable; @@ -125,7 +125,7 @@ protected void emitLog(HttpFormatter formatter) { attachAsBinary( formatter.formatHead(), formatter.getBinaryBody(), - ofNullable(formatter.getMimeType()).orElse(ContentType.APPLICATION_OCTET_STREAM.getMimeType()) + ofNullable(formatter.getMimeType()).orElse(ContentType.APPLICATION_OCTET_STREAM) ); break; case MULTIPART: diff --git a/src/main/java/com/epam/reportportal/formatting/http/Constants.java b/src/main/java/com/epam/reportportal/formatting/http/Constants.java index f574edf..4589edd 100644 --- a/src/main/java/com/epam/reportportal/formatting/http/Constants.java +++ b/src/main/java/com/epam/reportportal/formatting/http/Constants.java @@ -20,7 +20,6 @@ import com.epam.reportportal.formatting.http.prettiers.HtmlPrettier; import com.epam.reportportal.formatting.http.prettiers.JsonPrettier; import com.epam.reportportal.formatting.http.prettiers.XmlPrettier; -import org.apache.http.entity.ContentType; import java.util.*; import java.util.function.Function; @@ -40,22 +39,22 @@ public class Constants { public static final String BODY_HIGHLIGHT = "```"; public static final Set MULTIPART_TYPES = Collections.unmodifiableSet(new HashSet<>(Arrays.asList( - ContentType.MULTIPART_FORM_DATA.getMimeType(), - "multipart/mixed", - "multipart/alternative", - "multipart/digest", - "multipart/parallel" + ContentType.MULTIPART_FORM_DATA, + ContentType.MULTIPART_MIXED, + ContentType.MULTIPART_ALTERNATIVE, + ContentType.MULTIPART_DIGEST, + ContentType.MULTIPART_PARALLEL ))); - public static final Set TEXT_TYPES = Collections.unmodifiableSet(new HashSet<>(Arrays.asList(ContentType.APPLICATION_JSON.getMimeType(), - ContentType.TEXT_PLAIN.getMimeType(), - ContentType.TEXT_HTML.getMimeType(), - ContentType.TEXT_XML.getMimeType(), - ContentType.APPLICATION_XML.getMimeType(), - ContentType.DEFAULT_TEXT.getMimeType() + public static final Set TEXT_TYPES = + Collections.unmodifiableSet(new HashSet<>(Arrays.asList(ContentType.APPLICATION_JSON, + ContentType.TEXT_PLAIN, + ContentType.TEXT_HTML, + ContentType.TEXT_XML, + ContentType.APPLICATION_XML ))); - public static final Set FORM_TYPES = Collections.singleton(ContentType.APPLICATION_FORM_URLENCODED.getMimeType()); + public static final Set FORM_TYPES = Collections.singleton(ContentType.APPLICATION_FORM_URLENCODED); public static final Map BODY_TYPE_MAP = Collections.unmodifiableMap(Stream.of(TEXT_TYPES.stream() .collect(Collectors.toMap(k -> k, v -> BodyType.TEXT)), @@ -63,15 +62,16 @@ public class Constants { MULTIPART_TYPES.stream().collect(Collectors.toMap(k -> k, v -> BodyType.MULTIPART)) ).flatMap(m -> m.entrySet().stream()).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue))); - public static final Map> DEFAULT_PRETTIERS = Collections.unmodifiableMap(new HashMap>() {{ - put(ContentType.APPLICATION_XML.getMimeType(), XmlPrettier.INSTANCE); - put(ContentType.APPLICATION_SOAP_XML.getMimeType(), XmlPrettier.INSTANCE); - put(ContentType.APPLICATION_ATOM_XML.getMimeType(), XmlPrettier.INSTANCE); - put(ContentType.APPLICATION_SVG_XML.getMimeType(), XmlPrettier.INSTANCE); - put(ContentType.APPLICATION_XHTML_XML.getMimeType(), XmlPrettier.INSTANCE); - put(ContentType.TEXT_XML.getMimeType(), XmlPrettier.INSTANCE); - put(ContentType.APPLICATION_JSON.getMimeType(), JsonPrettier.INSTANCE); + public static final Map> DEFAULT_PRETTIERS = + Collections.unmodifiableMap(new HashMap>() {{ + put(ContentType.APPLICATION_XML, XmlPrettier.INSTANCE); + put(ContentType.APPLICATION_SOAP_XML, XmlPrettier.INSTANCE); + put(ContentType.APPLICATION_ATOM_XML, XmlPrettier.INSTANCE); + put(ContentType.APPLICATION_SVG_XML, XmlPrettier.INSTANCE); + put(ContentType.APPLICATION_XHTML_XML, XmlPrettier.INSTANCE); + put(ContentType.TEXT_XML, XmlPrettier.INSTANCE); + put(ContentType.APPLICATION_JSON, JsonPrettier.INSTANCE); put("text/json", JsonPrettier.INSTANCE); - put(ContentType.TEXT_HTML.getMimeType(), HtmlPrettier.INSTANCE); + put(ContentType.TEXT_HTML, HtmlPrettier.INSTANCE); }}); } diff --git a/src/main/java/com/epam/reportportal/formatting/http/ContentType.java b/src/main/java/com/epam/reportportal/formatting/http/ContentType.java new file mode 100644 index 0000000..b858b7f --- /dev/null +++ b/src/main/java/com/epam/reportportal/formatting/http/ContentType.java @@ -0,0 +1,55 @@ +/* + * Copyright 2023 EPAM Systems + * + * 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.epam.reportportal.formatting.http; + +@SuppressWarnings("unused") +public class ContentType { + + // Binary types + public static final String APPLICATION_OCTET_STREAM = "application/octet-stream"; + public static final String IMAGE_BMP = "image/bmp"; + public static final String IMAGE_GIF = "image/gif"; + public static final String IMAGE_JPEG = "image/jpeg"; + public static final String IMAGE_PNG = "image/png"; + public static final String IMAGE_TIFF = "image/tiff"; + public static final String IMAGE_WEBP = "image/webp"; + + + // Text types + public static final String APPLICATION_ATOM_XML = "application/atom+xml"; + public static final String APPLICATION_JSON = "application/json"; + public static final String APPLICATION_SOAP_XML = "application/soap+xml"; + public static final String APPLICATION_SVG_XML = "application/svg+xml"; + public static final String APPLICATION_XHTML_XML = "application/xhtml+xml"; + public static final String APPLICATION_XML = "application/xml"; + public static final String IMAGE_SVG = "image/svg+xml"; + public static final String TEXT_PLAIN = "text/plain"; + public static final String TEXT_HTML = "text/html"; + public static final String TEXT_XML = "text/xml"; + + // Form types + public static final String APPLICATION_FORM_URLENCODED = "application/x-www-form-urlencoded"; + + // Multipart types + public static final String MULTIPART_FORM_DATA = "multipart/form-data"; + public static final String MULTIPART_MIXED = "multipart/mixed"; + public static final String MULTIPART_ALTERNATIVE = "multipart/alternative"; + public static final String MULTIPART_DIGEST = "multipart/digest"; + public static final String MULTIPART_PARALLEL = "multipart/parallel"; + + +} diff --git a/src/main/java/com/epam/reportportal/formatting/http/HttpFormatUtils.java b/src/main/java/com/epam/reportportal/formatting/http/HttpFormatUtils.java index 9e2acda..4aa7314 100644 --- a/src/main/java/com/epam/reportportal/formatting/http/HttpFormatUtils.java +++ b/src/main/java/com/epam/reportportal/formatting/http/HttpFormatUtils.java @@ -24,7 +24,6 @@ import com.epam.reportportal.formatting.http.entities.Header; import com.epam.reportportal.formatting.http.entities.Param; import org.apache.commons.lang3.tuple.Pair; -import org.apache.http.entity.ContentType; import javax.annotation.Nonnull; import javax.annotation.Nullable; @@ -49,13 +48,15 @@ private HttpFormatUtils() { throw new IllegalStateException("Static only class"); } + @Nonnull public static String getMimeType(@Nullable String contentType) { return ofNullable(contentType).filter(ct -> !ct.isEmpty()) - .map(ct -> ContentType.parse(contentType).getMimeType()) - .orElse(ContentType.APPLICATION_OCTET_STREAM.getMimeType()); + .map(ct -> ContentType.parse(contentType)) + .orElse(ContentType.APPLICATION_OCTET_STREAM); } - public static String joinParts(String delimiter, String... parts) { + @Nonnull + public static String joinParts(@Nonnull String delimiter, @Nullable String... parts) { if (parts == null) { return ""; } @@ -276,7 +277,7 @@ public static BodyType getBodyType(@Nullable String contentType, @Nullable Map m.getOrDefault(mimeType, BodyType.BINARY)).orElse(BodyType.BINARY); } diff --git a/src/main/java/com/epam/reportportal/formatting/http/HttpRequestFormatter.java b/src/main/java/com/epam/reportportal/formatting/http/HttpRequestFormatter.java index f6950ac..45fea31 100644 --- a/src/main/java/com/epam/reportportal/formatting/http/HttpRequestFormatter.java +++ b/src/main/java/com/epam/reportportal/formatting/http/HttpRequestFormatter.java @@ -24,7 +24,6 @@ import com.epam.reportportal.formatting.http.entities.Cookie; import com.epam.reportportal.formatting.http.entities.Header; import com.epam.reportportal.formatting.http.entities.Param; -import org.apache.http.entity.ContentType; import javax.annotation.Nonnull; import javax.annotation.Nullable; @@ -272,21 +271,21 @@ public Builder bodyBytes(String mimeType, byte[] payload) { public Builder bodyParams(List formParameters) { type = BodyType.FORM; - this.mimeType = ContentType.APPLICATION_FORM_URLENCODED.getMimeType(); + this.mimeType = ContentType.APPLICATION_FORM_URLENCODED; body = formParameters; return this; } public Builder bodyParams(Map formParameters) { type = BodyType.FORM; - this.mimeType = ContentType.APPLICATION_FORM_URLENCODED.getMimeType(); + this.mimeType = ContentType.APPLICATION_FORM_URLENCODED; body = HttpFormatUtils.toForm(formParameters); return this; } public Builder bodyParams(String formParameters) { type = BodyType.FORM; - this.mimeType = ContentType.APPLICATION_FORM_URLENCODED.getMimeType(); + this.mimeType = ContentType.APPLICATION_FORM_URLENCODED; body = HttpFormatUtils.toForm(formParameters); return this; } From 2af16a6a3132a5a15a06d164929d0b3e0a651538 Mon Sep 17 00:00:00 2001 From: Vadzim Hushchanskou Date: Wed, 10 Jan 2024 17:09:03 +0300 Subject: [PATCH 2/6] Remove HttpCore dependency, WIP --- .../epam/reportportal/formatting/http/Constants.java | 4 ++++ .../reportportal/formatting/http/ContentType.java | 12 ++++++++++++ 2 files changed, 16 insertions(+) diff --git a/src/main/java/com/epam/reportportal/formatting/http/Constants.java b/src/main/java/com/epam/reportportal/formatting/http/Constants.java index 4589edd..f53be1c 100644 --- a/src/main/java/com/epam/reportportal/formatting/http/Constants.java +++ b/src/main/java/com/epam/reportportal/formatting/http/Constants.java @@ -74,4 +74,8 @@ public class Constants { put("text/json", JsonPrettier.INSTANCE); put(ContentType.TEXT_HTML, HtmlPrettier.INSTANCE); }}); + + private Constants() { + throw new RuntimeException("No instances should exist for the class!"); + } } diff --git a/src/main/java/com/epam/reportportal/formatting/http/ContentType.java b/src/main/java/com/epam/reportportal/formatting/http/ContentType.java index b858b7f..5d9a960 100644 --- a/src/main/java/com/epam/reportportal/formatting/http/ContentType.java +++ b/src/main/java/com/epam/reportportal/formatting/http/ContentType.java @@ -16,6 +16,8 @@ package com.epam.reportportal.formatting.http; +import javax.annotation.Nullable; + @SuppressWarnings("unused") public class ContentType { @@ -51,5 +53,15 @@ public class ContentType { public static final String MULTIPART_DIGEST = "multipart/digest"; public static final String MULTIPART_PARALLEL = "multipart/parallel"; + private ContentType() { + throw new RuntimeException("No instances should exist for the class!"); + } + @Nullable + public static String parse(@Nullable String contentType) { + if (contentType == null || contentType.trim().isEmpty()) { + return null; + } + return null; + } } From 4f120c7fbfb097a6af2ace606f0e0c04bc3799bc Mon Sep 17 00:00:00 2001 From: Vadzim Hushchanskou Date: Wed, 10 Jan 2024 17:27:04 +0300 Subject: [PATCH 3/6] Remove HttpCore dependency, WIP --- .../reportportal/formatting/http/ContentType.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/epam/reportportal/formatting/http/ContentType.java b/src/main/java/com/epam/reportportal/formatting/http/ContentType.java index 5d9a960..62c2879 100644 --- a/src/main/java/com/epam/reportportal/formatting/http/ContentType.java +++ b/src/main/java/com/epam/reportportal/formatting/http/ContentType.java @@ -17,9 +17,12 @@ package com.epam.reportportal.formatting.http; import javax.annotation.Nullable; +import java.util.regex.Matcher; +import java.util.regex.Pattern; @SuppressWarnings("unused") public class ContentType { + private static final Pattern HTTP_HEADER_DELIMITER_PATTERN = Pattern.compile("[=;,]"); // Binary types public static final String APPLICATION_OCTET_STREAM = "application/octet-stream"; @@ -62,6 +65,14 @@ public static String parse(@Nullable String contentType) { if (contentType == null || contentType.trim().isEmpty()) { return null; } - return null; + String trimmed = contentType.trim(); + Matcher m = HTTP_HEADER_DELIMITER_PATTERN.matcher(trimmed); + String mimeType; + if (m.find()) { + mimeType = trimmed.substring(0, m.start()); + } else { + mimeType = trimmed; + } + return mimeType.isEmpty() ? null : mimeType; } } From 429fe4fd7874f7926863084038ce3039b4728d5c Mon Sep 17 00:00:00 2001 From: Vadzim Hushchanskou Date: Wed, 10 Jan 2024 17:31:36 +0300 Subject: [PATCH 4/6] Client version update --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index b0efcf4..2a243e5 100644 --- a/build.gradle +++ b/build.gradle @@ -37,7 +37,7 @@ repositories { } dependencies { - api 'com.epam.reportportal:client-java:5.1.25' + api 'com.epam.reportportal:client-java:5.1.27' api 'com.google.code.findbugs:jsr305:3.0.2' api 'com.epam.reportportal:commons-model:5.0.0' From 8063c88527e7ebaf8ab0c99868e0a31746ee0fda Mon Sep 17 00:00:00 2001 From: Vadzim Hushchanskou Date: Thu, 11 Jan 2024 21:14:30 +0300 Subject: [PATCH 5/6] Client version update --- CHANGELOG.md | 2 +- build.gradle | 2 +- .../formatting/AbstractHttpFormatter.java | 4 +- .../formatting/http/Constants.java | 31 ++++---- .../formatting/http/ContentType.java | 78 ------------------- .../formatting/http/HttpFormatUtils.java | 17 ++-- .../formatting/http/HttpRequestFormatter.java | 3 +- .../http/HttpResponseFormatter.java | 2 +- .../SanitizingHttpHeaderConverter.java | 3 +- .../converters/SanitizingUriConverter.java | 2 +- 10 files changed, 34 insertions(+), 110 deletions(-) delete mode 100644 src/main/java/com/epam/reportportal/formatting/http/ContentType.java diff --git a/CHANGELOG.md b/CHANGELOG.md index ba67a3c..43f9256 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ ## [Unreleased] ### Changed -- Client version updated on [5.1.25](https://github.com/reportportal/client-java/releases/tag/5.1.25), by @HardNorth +- Client version updated on [5.2.0](https://github.com/reportportal/client-java/releases/tag/5.2.0), by @HardNorth ### Removed - HttpCore dependency was removed to avoid conflicts, by @HardNorth diff --git a/build.gradle b/build.gradle index 2a243e5..d917fe3 100644 --- a/build.gradle +++ b/build.gradle @@ -37,7 +37,7 @@ repositories { } dependencies { - api 'com.epam.reportportal:client-java:5.1.27' + api 'com.epam.reportportal:client-java:5.2.0' api 'com.google.code.findbugs:jsr305:3.0.2' api 'com.epam.reportportal:commons-model:5.0.0' diff --git a/src/main/java/com/epam/reportportal/formatting/AbstractHttpFormatter.java b/src/main/java/com/epam/reportportal/formatting/AbstractHttpFormatter.java index 2dad7c7..b5ad331 100644 --- a/src/main/java/com/epam/reportportal/formatting/AbstractHttpFormatter.java +++ b/src/main/java/com/epam/reportportal/formatting/AbstractHttpFormatter.java @@ -16,7 +16,6 @@ package com.epam.reportportal.formatting; -import com.epam.reportportal.formatting.http.ContentType; import com.epam.reportportal.formatting.http.HttpFormatter; import com.epam.reportportal.formatting.http.HttpPartFormatter; import com.epam.reportportal.formatting.http.HttpRequestFormatter; @@ -29,7 +28,8 @@ import com.epam.reportportal.service.Launch; import com.epam.reportportal.service.ReportPortal; import com.epam.reportportal.service.step.StepReporter; -import com.google.common.io.ByteSource; +import com.epam.reportportal.utils.files.ByteSource; +import com.epam.reportportal.utils.http.ContentType; import javax.annotation.Nonnull; import javax.annotation.Nullable; diff --git a/src/main/java/com/epam/reportportal/formatting/http/Constants.java b/src/main/java/com/epam/reportportal/formatting/http/Constants.java index f53be1c..807847b 100644 --- a/src/main/java/com/epam/reportportal/formatting/http/Constants.java +++ b/src/main/java/com/epam/reportportal/formatting/http/Constants.java @@ -20,6 +20,7 @@ import com.epam.reportportal.formatting.http.prettiers.HtmlPrettier; import com.epam.reportportal.formatting.http.prettiers.JsonPrettier; import com.epam.reportportal.formatting.http.prettiers.XmlPrettier; +import com.epam.reportportal.utils.http.ContentType; import java.util.*; import java.util.function.Function; @@ -48,11 +49,11 @@ public class Constants { public static final Set TEXT_TYPES = Collections.unmodifiableSet(new HashSet<>(Arrays.asList(ContentType.APPLICATION_JSON, - ContentType.TEXT_PLAIN, - ContentType.TEXT_HTML, - ContentType.TEXT_XML, - ContentType.APPLICATION_XML - ))); + ContentType.TEXT_PLAIN, + ContentType.TEXT_HTML, + ContentType.TEXT_XML, + ContentType.APPLICATION_XML + ))); public static final Set FORM_TYPES = Collections.singleton(ContentType.APPLICATION_FORM_URLENCODED); @@ -64,16 +65,16 @@ public class Constants { public static final Map> DEFAULT_PRETTIERS = Collections.unmodifiableMap(new HashMap>() {{ - put(ContentType.APPLICATION_XML, XmlPrettier.INSTANCE); - put(ContentType.APPLICATION_SOAP_XML, XmlPrettier.INSTANCE); - put(ContentType.APPLICATION_ATOM_XML, XmlPrettier.INSTANCE); - put(ContentType.APPLICATION_SVG_XML, XmlPrettier.INSTANCE); - put(ContentType.APPLICATION_XHTML_XML, XmlPrettier.INSTANCE); - put(ContentType.TEXT_XML, XmlPrettier.INSTANCE); - put(ContentType.APPLICATION_JSON, JsonPrettier.INSTANCE); - put("text/json", JsonPrettier.INSTANCE); - put(ContentType.TEXT_HTML, HtmlPrettier.INSTANCE); - }}); + put(ContentType.APPLICATION_XML, XmlPrettier.INSTANCE); + put(ContentType.APPLICATION_SOAP_XML, XmlPrettier.INSTANCE); + put(ContentType.APPLICATION_ATOM_XML, XmlPrettier.INSTANCE); + put(ContentType.APPLICATION_SVG_XML, XmlPrettier.INSTANCE); + put(ContentType.APPLICATION_XHTML_XML, XmlPrettier.INSTANCE); + put(ContentType.TEXT_XML, XmlPrettier.INSTANCE); + put(ContentType.APPLICATION_JSON, JsonPrettier.INSTANCE); + put("text/json", JsonPrettier.INSTANCE); + put(ContentType.TEXT_HTML, HtmlPrettier.INSTANCE); + }}); private Constants() { throw new RuntimeException("No instances should exist for the class!"); diff --git a/src/main/java/com/epam/reportportal/formatting/http/ContentType.java b/src/main/java/com/epam/reportportal/formatting/http/ContentType.java deleted file mode 100644 index 62c2879..0000000 --- a/src/main/java/com/epam/reportportal/formatting/http/ContentType.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Copyright 2023 EPAM Systems - * - * 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.epam.reportportal.formatting.http; - -import javax.annotation.Nullable; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -@SuppressWarnings("unused") -public class ContentType { - private static final Pattern HTTP_HEADER_DELIMITER_PATTERN = Pattern.compile("[=;,]"); - - // Binary types - public static final String APPLICATION_OCTET_STREAM = "application/octet-stream"; - public static final String IMAGE_BMP = "image/bmp"; - public static final String IMAGE_GIF = "image/gif"; - public static final String IMAGE_JPEG = "image/jpeg"; - public static final String IMAGE_PNG = "image/png"; - public static final String IMAGE_TIFF = "image/tiff"; - public static final String IMAGE_WEBP = "image/webp"; - - - // Text types - public static final String APPLICATION_ATOM_XML = "application/atom+xml"; - public static final String APPLICATION_JSON = "application/json"; - public static final String APPLICATION_SOAP_XML = "application/soap+xml"; - public static final String APPLICATION_SVG_XML = "application/svg+xml"; - public static final String APPLICATION_XHTML_XML = "application/xhtml+xml"; - public static final String APPLICATION_XML = "application/xml"; - public static final String IMAGE_SVG = "image/svg+xml"; - public static final String TEXT_PLAIN = "text/plain"; - public static final String TEXT_HTML = "text/html"; - public static final String TEXT_XML = "text/xml"; - - // Form types - public static final String APPLICATION_FORM_URLENCODED = "application/x-www-form-urlencoded"; - - // Multipart types - public static final String MULTIPART_FORM_DATA = "multipart/form-data"; - public static final String MULTIPART_MIXED = "multipart/mixed"; - public static final String MULTIPART_ALTERNATIVE = "multipart/alternative"; - public static final String MULTIPART_DIGEST = "multipart/digest"; - public static final String MULTIPART_PARALLEL = "multipart/parallel"; - - private ContentType() { - throw new RuntimeException("No instances should exist for the class!"); - } - - @Nullable - public static String parse(@Nullable String contentType) { - if (contentType == null || contentType.trim().isEmpty()) { - return null; - } - String trimmed = contentType.trim(); - Matcher m = HTTP_HEADER_DELIMITER_PATTERN.matcher(trimmed); - String mimeType; - if (m.find()) { - mimeType = trimmed.substring(0, m.start()); - } else { - mimeType = trimmed; - } - return mimeType.isEmpty() ? null : mimeType; - } -} diff --git a/src/main/java/com/epam/reportportal/formatting/http/HttpFormatUtils.java b/src/main/java/com/epam/reportportal/formatting/http/HttpFormatUtils.java index 4aa7314..f07b1c5 100644 --- a/src/main/java/com/epam/reportportal/formatting/http/HttpFormatUtils.java +++ b/src/main/java/com/epam/reportportal/formatting/http/HttpFormatUtils.java @@ -23,6 +23,7 @@ import com.epam.reportportal.formatting.http.entities.Cookie; import com.epam.reportportal.formatting.http.entities.Header; import com.epam.reportportal.formatting.http.entities.Param; +import com.epam.reportportal.utils.http.ContentType; import org.apache.commons.lang3.tuple.Pair; import javax.annotation.Nonnull; @@ -67,7 +68,7 @@ public static String joinParts(@Nonnull String delimiter, @Nullable String... pa @Nonnull public static String format(@Nullable List entities, @Nonnull Function converter, - @Nullable String tag) { + @Nullable String tag) { String prefix = tag == null ? "" : tag + LINE_DELIMITER; if (entities == null || entities.isEmpty()) { return ""; @@ -80,7 +81,7 @@ public static String format(@Nullable List entities, @Nonnull Function headers, - @Nullable Function headerConverter) { + @Nullable Function headerConverter) { return format(headers, headerConverter == null ? DefaultHttpHeaderConverter.INSTANCE : headerConverter, HEADERS_TAG @@ -89,7 +90,7 @@ public static String formatHeaders(@Nullable List
headers, @Nonnull public static String formatCookies(@Nullable List cookies, - @Nullable Function cookieConverter) { + @Nullable Function cookieConverter) { return format(cookies, cookieConverter == null ? DefaultCookieConverter.INSTANCE : cookieConverter, COOKIES_TAG @@ -98,7 +99,7 @@ public static String formatCookies(@Nullable List cookies, @Nonnull public static String formatText(@Nullable String header, @Nullable List params, @Nullable String tag, - @Nullable Function paramConverter) { + @Nullable Function paramConverter) { if (params == null || params.isEmpty()) { return header == null ? "" : header; } @@ -114,7 +115,7 @@ public static String formatText(@Nullable String header, @Nullable List p @Nonnull public static String formatText(@Nullable String header, @Nullable String body, @Nullable String tag, - @Nullable Map> contentPrettiers, String contentType) { + @Nullable Map> contentPrettiers, String contentType) { Map> prettiers = contentPrettiers; if (contentPrettiers == null) { prettiers = Collections.emptyMap(); @@ -162,9 +163,9 @@ public static Stream> toKeyValue(@Nonnull String headerValu @Nonnull public static Cookie toCookie(@Nonnull String name, @Nullable String value, @Nullable String comment, - @Nullable String path, @Nullable String domain, @Nullable Long maxAge, @Nullable Boolean secured, - @Nullable Boolean httpOnly, @Nullable Date expiryDate, @Nullable Integer version, - @Nullable String sameSite) { + @Nullable String path, @Nullable String domain, @Nullable Long maxAge, @Nullable Boolean secured, + @Nullable Boolean httpOnly, @Nullable Date expiryDate, @Nullable Integer version, + @Nullable String sameSite) { Cookie cookie = new Cookie(name); cookie.setValue(value); cookie.setComment(comment); diff --git a/src/main/java/com/epam/reportportal/formatting/http/HttpRequestFormatter.java b/src/main/java/com/epam/reportportal/formatting/http/HttpRequestFormatter.java index 45fea31..bfa138f 100644 --- a/src/main/java/com/epam/reportportal/formatting/http/HttpRequestFormatter.java +++ b/src/main/java/com/epam/reportportal/formatting/http/HttpRequestFormatter.java @@ -24,6 +24,7 @@ import com.epam.reportportal.formatting.http.entities.Cookie; import com.epam.reportportal.formatting.http.entities.Header; import com.epam.reportportal.formatting.http.entities.Param; +import com.epam.reportportal.utils.http.ContentType; import javax.annotation.Nonnull; import javax.annotation.Nullable; @@ -232,7 +233,7 @@ public Builder addCookie(Cookie cookie) { } public Builder addCookie(String name, String value, String comment, String path, String domain, Long maxAge, - Boolean secured, Boolean httpOnly, Date expiryDate, Integer version, String sameSite) { + Boolean secured, Boolean httpOnly, Date expiryDate, Integer version, String sameSite) { return addCookie(HttpFormatUtils.toCookie(name, value, comment, diff --git a/src/main/java/com/epam/reportportal/formatting/http/HttpResponseFormatter.java b/src/main/java/com/epam/reportportal/formatting/http/HttpResponseFormatter.java index 0313592..a6a7f06 100644 --- a/src/main/java/com/epam/reportportal/formatting/http/HttpResponseFormatter.java +++ b/src/main/java/com/epam/reportportal/formatting/http/HttpResponseFormatter.java @@ -189,7 +189,7 @@ public Builder addCookie(Cookie cookie) { } public Builder addCookie(String name, String value, String comment, String path, String domain, Long maxAge, - Boolean secured, Boolean httpOnly, Date expiryDate, Integer version, String sameSite) { + Boolean secured, Boolean httpOnly, Date expiryDate, Integer version, String sameSite) { return addCookie(HttpFormatUtils.toCookie(name, value, comment, diff --git a/src/main/java/com/epam/reportportal/formatting/http/converters/SanitizingHttpHeaderConverter.java b/src/main/java/com/epam/reportportal/formatting/http/converters/SanitizingHttpHeaderConverter.java index 177a2cf..080ffad 100644 --- a/src/main/java/com/epam/reportportal/formatting/http/converters/SanitizingHttpHeaderConverter.java +++ b/src/main/java/com/epam/reportportal/formatting/http/converters/SanitizingHttpHeaderConverter.java @@ -17,7 +17,6 @@ package com.epam.reportportal.formatting.http.converters; import com.epam.reportportal.formatting.http.entities.Header; -import com.google.common.net.HttpHeaders; import javax.annotation.Nullable; import java.util.Collections; @@ -30,7 +29,7 @@ public class SanitizingHttpHeaderConverter implements Function { public static final Set SENSITIVE_HEADERS = Collections.unmodifiableSet(new HashSet<>(Collections.singletonList( - HttpHeaders.AUTHORIZATION))); + "Authorization"))); public static final Function INSTANCE = new SanitizingHttpHeaderConverter(); diff --git a/src/main/java/com/epam/reportportal/formatting/http/converters/SanitizingUriConverter.java b/src/main/java/com/epam/reportportal/formatting/http/converters/SanitizingUriConverter.java index b8d244d..5cc3926 100644 --- a/src/main/java/com/epam/reportportal/formatting/http/converters/SanitizingUriConverter.java +++ b/src/main/java/com/epam/reportportal/formatting/http/converters/SanitizingUriConverter.java @@ -33,7 +33,7 @@ public String apply(String uriStr) { .map(info -> info.split(":", 2)) .map(info -> { if (info.length > 1) { - return new String[] { info[0], REMOVED_TAG }; + return new String[]{info[0], REMOVED_TAG}; } return info; }) From 15e4ea8fac93db561f0d11df474adfea6d8ddf49 Mon Sep 17 00:00:00 2001 From: Vadzim Hushchanskou Date: Thu, 11 Jan 2024 21:18:25 +0300 Subject: [PATCH 6/6] Fix build --- .../formatting/http/converters/ConvertersTest.java | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/test/java/com/epam/reportportal/formatting/http/converters/ConvertersTest.java b/src/test/java/com/epam/reportportal/formatting/http/converters/ConvertersTest.java index 02c6abb..9ad1f31 100644 --- a/src/test/java/com/epam/reportportal/formatting/http/converters/ConvertersTest.java +++ b/src/test/java/com/epam/reportportal/formatting/http/converters/ConvertersTest.java @@ -23,7 +23,6 @@ import com.epam.reportportal.formatting.http.prettiers.JsonPrettier; import com.epam.reportportal.formatting.http.prettiers.Prettier; import com.epam.reportportal.formatting.http.prettiers.XmlPrettier; -import com.google.common.net.HttpHeaders; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.MethodSource; @@ -62,10 +61,10 @@ public void testSessionIdHeaderRemove(Cookie input, String expected) { public static Iterable headerCases() { return Arrays.asList( - new Object[] { new Header(HttpHeaders.AUTHORIZATION, "Bearer test_token"), - HttpHeaders.AUTHORIZATION + ": " + Constants.REMOVED_TAG }, + new Object[] { new Header("Authorization", "Bearer test_token"), + "Authorization: " + Constants.REMOVED_TAG }, new Object[] { null, null }, - new Object[] { new Header(HttpHeaders.ACCEPT, "*/*"), HttpHeaders.ACCEPT + ": \\*/\\*" } + new Object[] { new Header("Accept", "*/*"), "Accept: \\*/\\*" } ); }