11/**
2- * (C) Copyright IBM Corp. 2015, 2019 .
2+ * (C) Copyright IBM Corp. 2015, 2020 .
33 *
44 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
55 * the License. You may obtain a copy of the License at
1313
1414package com .ibm .cloud .sdk .core .http ;
1515
16+ import java .io .InputStream ;
17+ import java .util .ArrayList ;
18+ import java .util .List ;
19+
1620import com .google .gson .Gson ;
1721import com .google .gson .JsonObject ;
18- import com .ibm .cloud .sdk .core .service .BaseService ;
1922import com .ibm .cloud .sdk .core .util .GsonSingleton ;
2023import com .ibm .cloud .sdk .core .util .StringHelper ;
2124import com .ibm .cloud .sdk .core .util .Validator ;
25+
2226import okhttp3 .FormBody ;
2327import okhttp3 .HttpUrl ;
2428import okhttp3 .MediaType ;
2529import okhttp3 .Request ;
2630import okhttp3 .RequestBody ;
2731
28- import java .io .InputStream ;
29- import java .util .ArrayList ;
30- import java .util .List ;
31-
3232/**
3333 * Convenience class for constructing HTTP/HTTPS requests.
3434 */
@@ -325,26 +325,33 @@ public RequestBuilder bodyContent(InputStream stream, String contentType) {
325325 return body (InputStreamRequestBody .create (MediaType .parse (contentType ), stream ));
326326 }
327327
328+
328329 /**
329- * Sets the request body content from one of three different sources, based on the content type.
330+ * Sets the request body content from one of three different sources.
331+ * The three input sources are used in this precedence order:
332+ * <ol>
333+ * <li>If 'jsonContent' is not null, then use that.</li>
334+ * <li>If 'jsonPatchContent' is not null, then use that.</li>
335+ * <li>Else use 'nonJsonContent'.
336+ * </ol>
330337 *
331338 * @param contentType
332- * the value of the "Content-Type" header associated with the outgoing request
339+ * the value of the "Content-Type" header associated with the request body
333340 * @param jsonContent
334- * the body content to be used if the content type indicates JSON
341+ * a model instance to be serialized and used for the request body
335342 * @param jsonPatchContent
336- * the body content to be used if the content type indicates JsonPatch
343+ * a collection of JsonPatchOperation instances to be serialized and used for the request body
337344 * @param nonJsonContent
338- * the body content to be used if the content type indicates non-JSON content
345+ * an InputStream whose contents should be used directly as the request body
339346 * @return this
340347 */
341348 public RequestBuilder bodyContent (String contentType , Object jsonContent , Object jsonPatchContent ,
342349 InputStream nonJsonContent ) {
343350 if (contentType != null ) {
344351 Gson requestGson = GsonSingleton .getGsonWithoutPrettyPrinting ().newBuilder ().create ();
345- if (BaseService . isJsonMimeType ( contentType ) ) {
352+ if (jsonContent != null ) {
346353 this .bodyContent (requestGson .toJson (jsonContent ), contentType );
347- } else if (BaseService . isJsonPatchMimeType ( contentType ) ) {
354+ } else if (jsonPatchContent != null ) {
348355 this .bodyContent (requestGson .toJson (jsonPatchContent ), contentType );
349356 } else {
350357 this .bodyContent (nonJsonContent , contentType );
@@ -354,16 +361,22 @@ public RequestBuilder bodyContent(String contentType, Object jsonContent, Object
354361 }
355362
356363 /**
357- * Sets the request body content from one of three different sources, based on the content type.
364+ * Sets the request body content from one of three different sources.
365+ * The three input sources are used in this precedence order:
366+ * <ol>
367+ * <li>If 'jsonContent' is not null, then use that.</li>
368+ * <li>If 'jsonPatchContent' is not null, then use that.</li>
369+ * <li>Else use 'nonJsonContent'.
370+ * </ol>
358371 *
359372 * @param contentType
360- * the value of the "Content-Type" header associated with the outgoing request
373+ * the value of the "Content-Type" header associated with the request body
361374 * @param jsonContent
362- * the body content to be used if the content type indicates JSON
375+ * a model instance to be serialized and used for the request body
363376 * @param jsonPatchContent
364- * the body content to be used if the content type indicates JsonPatch
377+ * a collection of JsonPatchOperation instances to be serialized and used for the request body
365378 * @param nonJsonContent
366- * the body content to be used if the content type indicates non-JSON content
379+ * a string to be used directly as the request body
367380 * @return this
368381 */
369382 public RequestBuilder bodyContent (String contentType , Object jsonContent , Object jsonPatchContent ,
0 commit comments