@Test public void getHeaderTest() throws RestServiceException { Map<String, Object> args = new HashMap<>(); args.put("HeaderA", "ValueA"); args.put("HeaderB", null); assertEquals("Header value does not match", args.get("HeaderA"), RestUtils.getHeader(args, "HeaderA", true)); assertEquals("Header value does not match", args.get("HeaderA"), RestUtils.getHeader(args, "HeaderA", false)); assertNull("There should be no value for HeaderB", RestUtils.getHeader(args, "HeaderB", false)); try { RestUtils.getHeader(args, "HeaderB", true); fail("Getting HeaderB as required should have failed"); } catch (RestServiceException e) { assertEquals("Unexpected RestServiceErrorCode", RestServiceErrorCode.InvalidArgs, e.getErrorCode()); } assertNull("There should be no value for HeaderC", RestUtils.getHeader(args, "HeaderB", false)); try { RestUtils.getHeader(args, "Headerc", true); fail("Getting HeaderB as required should have failed"); } catch (RestServiceException e) { assertEquals("Unexpected RestServiceErrorCode", RestServiceErrorCode.MissingArgs, e.getErrorCode()); } }
public static String getHeader(Map<String, ?> args, String header, boolean required) throws RestServiceException { String value = null; if (args.containsKey(header)) { Object valueObj = args.get(header); value = valueObj != null ? valueObj.toString() : null; if (value == null && required) { throw new RestServiceException("Request has null value for header: " + header, RestServiceErrorCode.InvalidArgs); } } else if (required) { throw new RestServiceException("Request does not have required header: " + header, RestServiceErrorCode.MissingArgs); } return value; }
RestUtils { public static String getHeader(Map<String, ?> args, String header, boolean required) throws RestServiceException { String value = null; if (args.containsKey(header)) { Object valueObj = args.get(header); value = valueObj != null ? valueObj.toString() : null; if (value == null && required) { throw new RestServiceException("Request has null value for header: " + header, RestServiceErrorCode.InvalidArgs); } } else if (required) { throw new RestServiceException("Request does not have required header: " + header, RestServiceErrorCode.MissingArgs); } return value; } }
RestUtils { public static String getHeader(Map<String, ?> args, String header, boolean required) throws RestServiceException { String value = null; if (args.containsKey(header)) { Object valueObj = args.get(header); value = valueObj != null ? valueObj.toString() : null; if (value == null && required) { throw new RestServiceException("Request has null value for header: " + header, RestServiceErrorCode.InvalidArgs); } } else if (required) { throw new RestServiceException("Request does not have required header: " + header, RestServiceErrorCode.MissingArgs); } return value; }  }
RestUtils { public static String getHeader(Map<String, ?> args, String header, boolean required) throws RestServiceException { String value = null; if (args.containsKey(header)) { Object valueObj = args.get(header); value = valueObj != null ? valueObj.toString() : null; if (value == null && required) { throw new RestServiceException("Request has null value for header: " + header, RestServiceErrorCode.InvalidArgs); } } else if (required) { throw new RestServiceException("Request does not have required header: " + header, RestServiceErrorCode.MissingArgs); } return value; }  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 String getHeader(Map<String, ?> args, String header, boolean required) throws RestServiceException { String value = null; if (args.containsKey(header)) { Object valueObj = args.get(header); value = valueObj != null ? valueObj.toString() : null; if (value == null && required) { throw new RestServiceException("Request has null value for header: " + header, RestServiceErrorCode.InvalidArgs); } } else if (required) { throw new RestServiceException("Request does not have required header: " + header, RestServiceErrorCode.MissingArgs); } return value; }  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; }