2727import java .util .HashMap ;
2828import java .util .HashSet ;
2929import java .util .List ;
30+ import java .util .Locale ;
3031import java .util .Objects ;
3132import java .util .concurrent .ThreadLocalRandom ;
3233import java .util .regex .Matcher ;
4647public class BatchRequestContent {
4748 /** Steps part of the batch request */
4849 @ Expose
50+ @ Nullable
4951 @ SerializedName ("requests" )
5052 public List <BatchRequestStep <?>> requests ;
5153
@@ -90,6 +92,7 @@ public <T> String addBatchRequestStep(@Nonnull final IHttpRequest request, @Nonn
9092 * @param dependsOnRequestsIds the ids of steps this request depends on
9193 * @return the id of the step that was just added to the batch
9294 */
95+ @ Nonnull
9396 public <T > String addBatchRequestStep (@ Nonnull final IHttpRequest request , @ Nonnull final HttpMethod httpMethod , @ Nullable final T serializableBody , @ Nullable final String ...dependsOnRequestsIds ) {
9497 Objects .requireNonNull (request , "request parameter cannot be null" );
9598 Objects .requireNonNull (httpMethod , "httpMethod parameter cannot be null" );
@@ -106,15 +109,15 @@ public <T> String addBatchRequestStep(@Nonnull final IHttpRequest request, @Nonn
106109 final BatchRequestStep <T > step = new BatchRequestStep <T >() {{
107110 url = protocolAndHostReplacementMatcher .replaceAll ("" );
108111 body = serializableBody ;
109- method = httpMethod .toString ().toUpperCase ();
112+ method = httpMethod .toString ().toUpperCase (Locale . getDefault () );
110113 dependsOn = dependsOnRequestsIds != null && dependsOnRequestsIds .length > 0 ? new HashSet <String >(Arrays .asList (dependsOnRequestsIds )) : null ;
111114 id = getNextRequestId ();
112115 }};
113116
114117 if (!request .getHeaders ().isEmpty ()) {
115118 step .headers = new HashMap <>();
116119 for (final HeaderOption headerOption : request .getHeaders ())
117- step .headers .putIfAbsent (headerOption .getName ().toLowerCase (), headerOption .getValue ().toString ());
120+ step .headers .putIfAbsent (headerOption .getName ().toLowerCase (Locale . getDefault () ), headerOption .getValue ().toString ());
118121 }
119122 if (step .body != null && step .body instanceof IJsonBackedObject &&
120123 (step .headers == null || !step .headers .containsKey (contentTypeHeaderKey ))) {
@@ -163,8 +166,15 @@ public <T> BatchRequestStep<T> getStepById(@Nonnull final String stepId) {
163166 }
164167 return null ;
165168 }
166- private static final Pattern protocolAndHostReplacementPattern = Pattern .compile ("(?i)^http[s]?:\\ /\\ /graph\\ .microsoft\\ .com\\ /(?>v1\\ .0|beta)\\ /?" ); // (?i) case insensitive
167- private String getNextRequestId () {
169+ /** pattern to replace the protocol and host part of the request if specified */
170+ @ Nonnull
171+ protected static final Pattern protocolAndHostReplacementPattern = Pattern .compile ("(?i)^http[s]?:\\ /\\ /graph\\ .microsoft\\ .com\\ /(?>v1\\ .0|beta)\\ /?" ); // (?i) case insensitive
172+ /**
173+ * Generates a randomly available request id
174+ * @return a random request id
175+ */
176+ @ Nonnull
177+ protected String getNextRequestId () {
168178 String requestId ;
169179 do {
170180 requestId = Integer .toString (ThreadLocalRandom .current ().nextInt (1 , Integer .MAX_VALUE ));
0 commit comments