diff --git a/CHANGELOG.md b/CHANGELOG.md index 6fbb5d5..43f9256 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,9 @@ ## [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 ## [5.1.6] ### Changed diff --git a/build.gradle b/build.gradle index e0122d7..d917fe3 100644 --- a/build.gradle +++ b/build.gradle @@ -37,12 +37,11 @@ repositories { } dependencies { - api 'com.epam.reportportal:client-java:5.1.25' + 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' 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..b5ad331 100644 --- a/src/main/java/com/epam/reportportal/formatting/AbstractHttpFormatter.java +++ b/src/main/java/com/epam/reportportal/formatting/AbstractHttpFormatter.java @@ -28,8 +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 org.apache.http.entity.ContentType; +import com.epam.reportportal.utils.files.ByteSource; +import com.epam.reportportal.utils.http.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..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,7 +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 org.apache.http.entity.ContentType; +import com.epam.reportportal.utils.http.ContentType; import java.util.*; import java.util.function.Function; @@ -40,22 +40,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 +63,20 @@ 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); - put("text/json", JsonPrettier.INSTANCE); - put(ContentType.TEXT_HTML.getMimeType(), HtmlPrettier.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, 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/HttpFormatUtils.java b/src/main/java/com/epam/reportportal/formatting/http/HttpFormatUtils.java index 9e2acda..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,8 +23,8 @@ 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 org.apache.http.entity.ContentType; import javax.annotation.Nonnull; import javax.annotation.Nullable; @@ -49,13 +49,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 ""; } @@ -66,7 +68,7 @@ public static String joinParts(String delimiter, String... parts) { @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 ""; @@ -79,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 @@ -88,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 @@ -97,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; } @@ -113,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(); @@ -161,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); @@ -276,7 +278,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..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,7 +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 org.apache.http.entity.ContentType; +import com.epam.reportportal.utils.http.ContentType; import javax.annotation.Nonnull; import javax.annotation.Nullable; @@ -233,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, @@ -272,21 +272,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; } 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; }) 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: \\*/\\*" } ); }