@Test public void ensureRequiredHeadersOrThrowTest() throws Exception { JSONObject headers = new JSONObject(); Set<String> requiredHeaders = new HashSet<>(Arrays.asList("required_a", "required_b", "required_c")); for (String requiredHeader : requiredHeaders) { headers.put(requiredHeader, TestUtils.getRandomString(10)); } headers.put(TestUtils.getRandomString(10), TestUtils.getRandomString(10)); RestRequest restRequest = createRestRequest(RestMethod.POST, "/", headers); RestUtils.ensureRequiredHeadersOrThrow(restRequest, requiredHeaders); headers.put(requiredHeaders.iterator().next(), JSONObject.NULL); restRequest = createRestRequest(RestMethod.POST, "/", headers); try { RestUtils.ensureRequiredHeadersOrThrow(restRequest, requiredHeaders); fail("Should have failed because one of the required headers has a bad value"); } catch (RestServiceException e) { assertEquals("Unexpected RestServiceErrorCode", RestServiceErrorCode.InvalidArgs, e.getErrorCode()); } headers.remove(requiredHeaders.iterator().next()); restRequest = createRestRequest(RestMethod.POST, "/", headers); try { RestUtils.ensureRequiredHeadersOrThrow(restRequest, requiredHeaders); fail("Should have failed because one of the required headers is not present"); } catch (RestServiceException e) { assertEquals("Unexpected RestServiceErrorCode", RestServiceErrorCode.MissingArgs, e.getErrorCode()); } }
public static void ensureRequiredHeadersOrThrow(RestRequest restRequest, Set<String> requiredHeaders) throws RestServiceException { Map<String, Object> args = restRequest.getArgs(); for (String header : requiredHeaders) { getHeader(args, header, true); } }
RestUtils { public static void ensureRequiredHeadersOrThrow(RestRequest restRequest, Set<String> requiredHeaders) throws RestServiceException { Map<String, Object> args = restRequest.getArgs(); for (String header : requiredHeaders) { getHeader(args, header, true); } } }
RestUtils { public static void ensureRequiredHeadersOrThrow(RestRequest restRequest, Set<String> requiredHeaders) throws RestServiceException { Map<String, Object> args = restRequest.getArgs(); for (String header : requiredHeaders) { getHeader(args, header, true); } }  }
RestUtils { public static void ensureRequiredHeadersOrThrow(RestRequest restRequest, Set<String> requiredHeaders) throws RestServiceException { Map<String, Object> args = restRequest.getArgs(); for (String header : requiredHeaders) { getHeader(args, header, true); } }  static BlobProperties buildBlobProperties(Map<String, Object> args); static byte[] buildUserMetadata(Map<String, Object> args); static Map<String, String> buildUserMetadata(byte[] userMetadata); static GetBlobOptions buildGetBlobOptions(Map<String, Object> args, SubResource subResource,
      GetOption getOption, int blobSegmentIdx); static Pair<String, Long> buildContentRangeAndLength(ByteRange range, long blobSize,
      boolean resolveRangeOnEmptyBlob); static RequestPath getRequestPath(RestRequest restRequest); static Long getTimeFromDateString(String dateString); static long toSecondsPrecisionInMs(long ms); static GetOption getGetOption(RestRequest restRequest, GetOption defaultGetOption); static boolean isPrivate(Map<String, Object> args); static boolean isChunkUpload(Map<String, Object> args); static void ensureRequiredHeadersOrThrow(RestRequest restRequest, Set<String> requiredHeaders); static String getHeader(Map<String, ?> args, String header, boolean required); static Long getLongHeader(Map<String, ?> args, String header, boolean required); static T getNumericalHeader(Map<String, ?> args, String header, boolean required,
      Function<String, T> converter); static boolean getBooleanHeader(Map<String, Object> args, String header, boolean required); static Account getAccountFromArgs(Map<String, Object> args); static Container getContainerFromArgs(Map<String, Object> args); static void accountAndContainerNamePreconditionCheck(RestRequest restRequest); static boolean setUserMetadataHeaders(byte[] userMetadata, RestResponseChannel restResponseChannel); }
RestUtils { public static void ensureRequiredHeadersOrThrow(RestRequest restRequest, Set<String> requiredHeaders) throws RestServiceException { Map<String, Object> args = restRequest.getArgs(); for (String header : requiredHeaders) { getHeader(args, header, true); } }  static BlobProperties buildBlobProperties(Map<String, Object> args); static byte[] buildUserMetadata(Map<String, Object> args); static Map<String, String> buildUserMetadata(byte[] userMetadata); static GetBlobOptions buildGetBlobOptions(Map<String, Object> args, SubResource subResource,
      GetOption getOption, int blobSegmentIdx); static Pair<String, Long> buildContentRangeAndLength(ByteRange range, long blobSize,
      boolean resolveRangeOnEmptyBlob); static RequestPath getRequestPath(RestRequest restRequest); static Long getTimeFromDateString(String dateString); static long toSecondsPrecisionInMs(long ms); static GetOption getGetOption(RestRequest restRequest, GetOption defaultGetOption); static boolean isPrivate(Map<String, Object> args); static boolean isChunkUpload(Map<String, Object> args); static void ensureRequiredHeadersOrThrow(RestRequest restRequest, Set<String> requiredHeaders); static String getHeader(Map<String, ?> args, String header, boolean required); static Long getLongHeader(Map<String, ?> args, String header, boolean required); static T getNumericalHeader(Map<String, ?> args, String header, boolean required,
      Function<String, T> converter); static boolean getBooleanHeader(Map<String, Object> args, String header, boolean required); static Account getAccountFromArgs(Map<String, Object> args); static Container getContainerFromArgs(Map<String, Object> args); static void accountAndContainerNamePreconditionCheck(RestRequest restRequest); static boolean setUserMetadataHeaders(byte[] userMetadata, RestResponseChannel restResponseChannel); static final String HTTP_DATE_FORMAT; static final String BYTE_RANGE_UNITS; static final String SIGNED_ID_PREFIX; static final String JSON_CONTENT_TYPE; }