@Test public void setUserMetadataHeadersTest() throws Exception { MockRestResponseChannel responseChannel = new MockRestResponseChannel(); assertTrue("Should report that headers are set", RestUtils.setUserMetadataHeaders(new byte[0], responseChannel)); assertEquals("No headers should have been set", 0, responseChannel.getResponseHeaders().size()); JSONObject headers = new JSONObject(); setUserMetadataHeaders(headers, Collections.emptyMap()); RestRequest restRequest = createRestRequest(RestMethod.POST, "/", headers); byte[] userMetadata = RestUtils.buildUserMetadata(restRequest.getArgs()); responseChannel = new MockRestResponseChannel(); assertTrue("Should report that headers are set", RestUtils.setUserMetadataHeaders(userMetadata, responseChannel)); assertEquals("No headers should have been set", 0, responseChannel.getResponseHeaders().size()); Map<String, String> usermetadataMap = new HashMap<>(); for (int i = 0; i < 10; i++) { usermetadataMap.put(RestUtils.Headers.USER_META_DATA_HEADER_PREFIX + "key" + i, "value" + i); } setUserMetadataHeaders(headers, usermetadataMap); restRequest = createRestRequest(RestMethod.POST, "/", headers); userMetadata = RestUtils.buildUserMetadata(restRequest.getArgs()); responseChannel = new MockRestResponseChannel(); assertTrue("Should report that headers are set", RestUtils.setUserMetadataHeaders(userMetadata, responseChannel)); Map<String, Object> responseHeaders = responseChannel.getResponseHeaders(); assertEquals("There is a mismatch in the numebr of headers", usermetadataMap.size(), responseHeaders.size()); usermetadataMap.forEach((k, v) -> assertEquals("Value of " + k + " not as expected", v, responseHeaders.get(k))); responseChannel = new MockRestResponseChannel(); userMetadata = TestUtils.getRandomBytes(100); assertFalse("Should report that headers are not set", RestUtils.setUserMetadataHeaders(userMetadata, responseChannel)); assertEquals("No headers should have been set", 0, responseChannel.getResponseHeaders().size()); }
public static boolean setUserMetadataHeaders(byte[] userMetadata, RestResponseChannel restResponseChannel) throws RestServiceException { Map<String, String> userMetadataMap = buildUserMetadata(userMetadata); boolean setHeaders = userMetadataMap != null; if (setHeaders) { for (Map.Entry<String, String> entry : userMetadataMap.entrySet()) { restResponseChannel.setHeader(entry.getKey(), entry.getValue()); } } return setHeaders; }
RestUtils { public static boolean setUserMetadataHeaders(byte[] userMetadata, RestResponseChannel restResponseChannel) throws RestServiceException { Map<String, String> userMetadataMap = buildUserMetadata(userMetadata); boolean setHeaders = userMetadataMap != null; if (setHeaders) { for (Map.Entry<String, String> entry : userMetadataMap.entrySet()) { restResponseChannel.setHeader(entry.getKey(), entry.getValue()); } } return setHeaders; } }
RestUtils { public static boolean setUserMetadataHeaders(byte[] userMetadata, RestResponseChannel restResponseChannel) throws RestServiceException { Map<String, String> userMetadataMap = buildUserMetadata(userMetadata); boolean setHeaders = userMetadataMap != null; if (setHeaders) { for (Map.Entry<String, String> entry : userMetadataMap.entrySet()) { restResponseChannel.setHeader(entry.getKey(), entry.getValue()); } } return setHeaders; }  }
RestUtils { public static boolean setUserMetadataHeaders(byte[] userMetadata, RestResponseChannel restResponseChannel) throws RestServiceException { Map<String, String> userMetadataMap = buildUserMetadata(userMetadata); boolean setHeaders = userMetadataMap != null; if (setHeaders) { for (Map.Entry<String, String> entry : userMetadataMap.entrySet()) { restResponseChannel.setHeader(entry.getKey(), entry.getValue()); } } return setHeaders; }  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 boolean setUserMetadataHeaders(byte[] userMetadata, RestResponseChannel restResponseChannel) throws RestServiceException { Map<String, String> userMetadataMap = buildUserMetadata(userMetadata); boolean setHeaders = userMetadataMap != null; if (setHeaders) { for (Map.Entry<String, String> entry : userMetadataMap.entrySet()) { restResponseChannel.setHeader(entry.getKey(), entry.getValue()); } } return setHeaders; }  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; }