Skip to content

Release #35

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Changelog

## [Unreleased]
### Changed
- `utils-java-formatting` dependency version updated on [5.2.7](https://github.com/reportportal/utils-java-formatting/releases/tag/5.2.7), by @HardNorth

## [5.3.8]
### Changed
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ repositories {
}

dependencies {
api 'com.epam.reportportal:utils-java-formatting:5.2.6'
api 'com.epam.reportportal:utils-java-formatting:5.2.7'
compileOnly "com.epam.reportportal:client-java:${client_version}"
implementation 'com.google.code.findbugs:jsr305:3.0.2'
implementation 'commons-codec:commons-codec:1.15'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@

import com.epam.reportportal.formatting.AbstractHttpFormatter;
import com.epam.reportportal.formatting.http.converters.DefaultCookieConverter;
import com.epam.reportportal.formatting.http.converters.DefaultFormParamConverter;
import com.epam.reportportal.formatting.http.converters.DefaultHttpHeaderConverter;
import com.epam.reportportal.formatting.http.converters.DefaultUriConverter;
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.listeners.LogLevel;
import com.epam.reportportal.restassured.support.HttpEntityFactory;
import com.epam.reportportal.service.ReportPortal;
Expand Down Expand Up @@ -67,6 +69,8 @@ public class ReportPortalRestAssuredLoggingFilter extends AbstractHttpFormatter<

private final int order;

protected final Function<Param, String> paramConverter;

/**
* Create an ordered REST Assured filter with the log level and different converters.
*
Expand All @@ -82,14 +86,48 @@ public class ReportPortalRestAssuredLoggingFilter extends AbstractHttpFormatter<
* formats Cookies with <code>toString</code> method
* @param uriConverterFunction the same as 'headerConvertFunction' param but for URI, default function returns
* URI "as is"
* @param paramConverter the same as 'headerConvertFunction' param but for Web Form Params, default function returns
* <code>param.getName() + ": " + param.getValue()</code>
*/
public ReportPortalRestAssuredLoggingFilter(int filterOrder, @Nonnull LogLevel defaultLogLevel,
@Nullable Function<Header, String> headerConvertFunction, @Nullable Function<Header, String> partHeaderConvertFunction,
@Nullable Function<Cookie, String> cookieConvertFunction, @Nullable Function<String, String> uriConverterFunction) {
@Nullable Function<Cookie, String> cookieConvertFunction, @Nullable Function<String, String> uriConverterFunction,
@Nullable Function<Param, String> paramConverter) {
super(defaultLogLevel, headerConvertFunction, partHeaderConvertFunction, cookieConvertFunction, uriConverterFunction);
this.paramConverter = paramConverter != null ? paramConverter : DefaultFormParamConverter.INSTANCE;
order = filterOrder;
}

/**
* Create an ordered REST Assured filter with the log level and different converters.z
*
* @param filterOrder if you have different filters which modify requests on fly this parameter allows
* you to control the order when Report Portal logger will be called, and therefore
* log or don't log some data.
* @param defaultLogLevel log level on which REST Assured requests/responses will appear on Report Portal
* @param headerConvertFunction if you want to preprocess your HTTP Headers before they appear on Report Portal
* provide this custom function for the class, default function formats it like
* that: <code>header.getName() + ": " + header.getValue()</code>
* @param partHeaderConvertFunction the same as fot HTTP Headers, but for parts in Multipart request
* @param cookieConvertFunction the same as 'headerConvertFunction' param but for Cookies, default function
* formats Cookies with <code>toString</code> method
* @param uriConverterFunction the same as 'headerConvertFunction' param but for URI, default function returns
* URI "as is"
*/
public ReportPortalRestAssuredLoggingFilter(int filterOrder, @Nonnull LogLevel defaultLogLevel,
@Nullable Function<Header, String> headerConvertFunction, @Nullable Function<Header, String> partHeaderConvertFunction,
@Nullable Function<Cookie, String> cookieConvertFunction, @Nullable Function<String, String> uriConverterFunction) {
this(
filterOrder,
defaultLogLevel,
headerConvertFunction,
partHeaderConvertFunction,
cookieConvertFunction,
uriConverterFunction,
DefaultFormParamConverter.INSTANCE
);
}

/**
* Create an ordered REST Assured filter with the log level and different converters.
*
Expand Down Expand Up @@ -178,6 +216,7 @@ public Response filter(FilterableRequestSpecification requestSpec, FilterableRes
uriConverter,
myHeaderConverter,
cookieConverter,
paramConverter,
getContentPrettifiers(),
partHeaderConverter,
getBodyTypeMap()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.epam.reportportal.formatting.http.entities.BodyType;
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.message.TypeAwareByteSource;
import com.epam.reportportal.service.ReportPortal;
import com.epam.reportportal.utils.files.Utils;
Expand Down Expand Up @@ -99,8 +100,9 @@ private static List<HttpPartFormatter> toParts(@Nonnull FilterableRequestSpecifi
@Nonnull
public static HttpRequestFormatter createHttpRequestFormatter(@Nonnull FilterableRequestSpecification requestSpecification,
@Nullable Function<String, String> uriConverter, @Nullable Function<Header, String> headerConverter,
@Nullable Function<Cookie, String> cookieConverter, @Nullable Map<String, Function<String, String>> prettiers,
@Nullable Function<Header, String> partHeaderConverter, @Nonnull Map<String, BodyType> bodyTypeMap) {
@Nullable Function<Cookie, String> cookieConverter, @Nullable Function<Param, String> paramConverter,
@Nullable Map<String, Function<String, String>> prettifiers, @Nullable Function<Header, String> partHeaderConverter,
@Nonnull Map<String, BodyType> bodyTypeMap) {
HttpRequestFormatter.Builder builder = new HttpRequestFormatter.Builder(
requestSpecification.getMethod(),
requestSpecification.getURI()
Expand All @@ -122,7 +124,11 @@ public static HttpRequestFormatter createHttpRequestFormatter(@Nonnull Filterabl
c.getVersion(),
c.getSameSite()
)));
builder.uriConverter(uriConverter).headerConverter(headerConverter).cookieConverter(cookieConverter).prettiers(prettiers);
builder.uriConverter(uriConverter)
.headerConverter(headerConverter)
.cookieConverter(cookieConverter)
.paramConverter(paramConverter)
.prettifiers(prettifiers);
String mimeType = getMimeType(requestSpecification.getContentType());
BodyType bodyType = getBodyType(requestSpecification.getContentType(), bodyTypeMap);
switch (bodyType) {
Expand All @@ -144,7 +150,7 @@ public static HttpRequestFormatter createHttpRequestFormatter(@Nonnull Filterabl
@Nonnull
public static HttpResponseFormatter createHttpResponseFormatter(@Nonnull Response response,
@Nullable Function<Header, String> headerConverter, @Nullable Function<Cookie, String> cookieConverter,
@Nullable Map<String, Function<String, String>> prettiers, @Nonnull Map<String, BodyType> bodyTypeMap) {
@Nullable Map<String, Function<String, String>> prettifiers, @Nonnull Map<String, BodyType> bodyTypeMap) {
HttpResponseFormatter.Builder builder = new HttpResponseFormatter.Builder(response.statusCode(), response.getStatusLine());
ofNullable(response.getHeaders()).ifPresent(headers -> headers.forEach(h -> builder.addHeader(h.getName(), h.getValue())));
ofNullable(response.getDetailedCookies()).ifPresent(cookies -> cookies.forEach(c -> builder.addCookie(
Expand All @@ -160,7 +166,7 @@ public static HttpResponseFormatter createHttpResponseFormatter(@Nonnull Respons
c.getVersion(),
c.getSameSite()
)));
builder.headerConverter(headerConverter).cookieConverter(cookieConverter).prettiers(prettiers);
builder.headerConverter(headerConverter).cookieConverter(cookieConverter).prettifiers(prettifiers);

String type = getMimeType(response.getContentType());
BodyType bodyType = getBodyType(response.getContentType(), bodyTypeMap);
Expand Down
Loading