4040import static com .epam .reportportal .formatting .http .Constants .DEFAULT_PRETTIERS ;
4141import static java .util .Optional .ofNullable ;
4242
43+ /**
44+ * Common class for HTTP formatters.
45+ *
46+ * @param <SELF> the type of the formatter
47+ */
4348public abstract class AbstractHttpFormatter <SELF extends AbstractHttpFormatter <SELF >> {
4449
4550 protected final String logLevel ;
@@ -49,8 +54,18 @@ public abstract class AbstractHttpFormatter<SELF extends AbstractHttpFormatter<S
4954 protected final Function <Cookie , String > cookieConverter ;
5055 protected final Function <String , String > uriConverter ;
5156
52- protected Map <String , Function <String , String >> contentPrettiers = DEFAULT_PRETTIERS ;
57+ private Map <String , Function <String , String >> contentPrettifiers = DEFAULT_PRETTIERS ;
5358
59+ /**
60+ * @deprecated Use {@link #getContentPrettifiers()} instead
61+ */
62+ @ Deprecated
63+ protected Map <String , Function <String , String >> contentPrettiers = contentPrettifiers ;
64+
65+ /**
66+ * @deprecated Use {@link #getBodyTypeMap()} instead
67+ */
68+ @ Deprecated
5469 protected Map <String , BodyType > bodyTypeMap = BODY_TYPE_MAP ;
5570
5671 /**
@@ -66,10 +81,8 @@ public abstract class AbstractHttpFormatter<SELF extends AbstractHttpFormatter<S
6681 * @param uriConverterFunction the same as 'headerConvertFunction' param but for URI, default function returns
6782 * URI "as is"
6883 */
69- protected AbstractHttpFormatter (@ Nonnull LogLevel defaultLogLevel ,
70- @ Nullable Function <Header , String > headerConvertFunction ,
71- @ Nullable Function <Header , String > partHeaderConvertFunction ,
72- @ Nullable Function <Cookie , String > cookieConvertFunction ,
84+ protected AbstractHttpFormatter (@ Nonnull LogLevel defaultLogLevel , @ Nullable Function <Header , String > headerConvertFunction ,
85+ @ Nullable Function <Header , String > partHeaderConvertFunction , @ Nullable Function <Cookie , String > cookieConvertFunction ,
7386 @ Nullable Function <String , String > uriConverterFunction ) {
7487 logLevel = defaultLogLevel .name ();
7588 headerConverter = headerConvertFunction ;
@@ -130,28 +143,88 @@ protected void emitLog(HttpFormatter formatter) {
130143 break ;
131144 case MULTIPART :
132145 Optional <StepReporter > sr = ofNullable (Launch .currentLaunch ()).map (Launch ::getStepReporter );
146+ //noinspection ReactiveStreamsUnusedPublisher
133147 sr .ifPresent (r -> r .sendStep (ItemStatus .INFO , formatter .formatTitle ()));
134148 logMultiPartRequest ((HttpRequestFormatter ) formatter ); // No multipart type for responses
135149 sr .ifPresent (StepReporter ::finishPreviousStep );
136150 break ;
137151 default :
138- ReportPortal .emitLog (
139- "Unknown entity type: " + type .name (),
140- LogLevel .ERROR .name (),
141- Calendar .getInstance ().getTime ()
142- );
152+ ReportPortal .emitLog ("Unknown entity type: " + type .name (), LogLevel .ERROR .name (), Calendar .getInstance ().getTime ());
143153 }
144154 }
145155
156+ /**
157+ * Set the body type map for the formatter.
158+ * <p>
159+ * The map should contain the mapping between the content type and the body type (an instance of {@link BodyType} enum). The body type
160+ * is used to determine how to log the body of the request/response.
161+ *
162+ * @param typeMap a map with the content type as a key and the body type as a value
163+ * @return the formatter instance
164+ */
146165 @ SuppressWarnings ("unchecked" )
166+ @ Nonnull
147167 public SELF setBodyTypeMap (@ Nonnull Map <String , BodyType > typeMap ) {
148168 this .bodyTypeMap = Collections .unmodifiableMap (new HashMap <>(typeMap ));
149169 return (SELF ) this ;
150170 }
151171
172+ /**
173+ * Get the body type map for the formatter.
174+ * <p>
175+ * The map contains the mapping between the content type and the body type (an instance of {@link BodyType} enum). The body type is
176+ * used to determine how to log the body of the request/response.
177+ *
178+ * @return a map with the content type as a key and the body type as a value
179+ */
180+ @ Nonnull
181+ public Map <String , BodyType > getBodyTypeMap () {
182+ return bodyTypeMap ;
183+ }
184+
185+ /***
186+ * Set the content prettifiers for the formatter.
187+ * <p>
188+ * Content prettifiers are used to format the content of the request/response before logging it. The prettifiers are applied to the
189+ * content based on the content type.
190+ *
191+ * @param contentPrettifiers a map with the content type as a key and the prettifier function as a value
192+ * @return the formatter instance
193+ */
152194 @ SuppressWarnings ("unchecked" )
153- public SELF setContentPrettiers (@ Nonnull Map <String , Function <String , String >> contentPrettiers ) {
154- this .contentPrettiers = Collections .unmodifiableMap (new HashMap <>(contentPrettiers ));
195+ @ Nonnull
196+ public SELF setContentPrettifiers (@ Nonnull Map <String , Function <String , String >> contentPrettifiers ) {
197+ this .contentPrettifiers = Collections .unmodifiableMap (new HashMap <>(contentPrettifiers ));
198+ this .contentPrettiers = this .contentPrettifiers ;
155199 return (SELF ) this ;
156200 }
201+
202+ /***
203+ * Set the content prettifiers for the formatter.
204+ * <p>
205+ * Content prettifiers are used to format the content of the request/response before logging it. The prettifiers are applied to the
206+ * content based on the content type.
207+ *
208+ * @param contentPrettifiers a map with the content type as a key and the prettifier function as a value
209+ * @return the formatter instance
210+ * @deprecated Use {@link #setContentPrettifiers(Map)} instead
211+ */
212+ @ Deprecated
213+ @ Nonnull
214+ public SELF setContentPrettiers (@ Nonnull Map <String , Function <String , String >> contentPrettifiers ) {
215+ return setContentPrettifiers (contentPrettifiers );
216+ }
217+
218+ /**
219+ * Get the content prettifiers for the formatter.
220+ * <p>
221+ * Content prettifiers are used to format the content of the request/response before logging it. The prettifiers are applied to the
222+ * content based on the content type.
223+ *
224+ * @return a map with the content type as a key and the prettifier function as a value
225+ */
226+ @ Nonnull
227+ public Map <String , Function <String , String >> getContentPrettifiers () {
228+ return contentPrettifiers ;
229+ }
157230}
0 commit comments