/** * Download the payload from the given path * * @param path the relative path of the payload in the {@link ExternalPayloadStorage} * @return the payload object * @throws ApplicationException in case of JSON parsing errors or download errors */ @SuppressWarnings("unchecked") public Map<String, Object> downloadPayload(String path) { try (InputStream inputStream = externalPayloadStorage.download(path)) { return objectMapper.readValue(IOUtils.toString(inputStream), Map.class); } catch (IOException e) { logger.error("Unable to download payload from external storage path: {}", path, e); throw new ApplicationException(ApplicationException.Code.INTERNAL_ERROR, e); } }
@Test public void testDownloadPayload() throws IOException { String path = "test/payload"; Map<String, Object> payload = new HashMap<>(); payload.put("key1", "value1"); payload.put("key2", 200); byte[] payloadBytes = objectMapper.writeValueAsString(payload).getBytes(); when(externalPayloadStorage.download(path)).thenReturn(new ByteArrayInputStream(payloadBytes)); Map<String, Object> result = externalPayloadStorageUtils.downloadPayload(path); assertNotNull(result); assertEquals(payload, result); }
/** * Download the payload from the given path * * @param path the relative path of the payload in the {@link ExternalPayloadStorage} * @return the payload object * @throws ApplicationException in case of JSON parsing errors or download errors */ @SuppressWarnings("unchecked") public Map<String, Object> downloadPayload(String path) { try (InputStream inputStream = externalPayloadStorage.download(path)) { return objectMapper.readValue(IOUtils.toString(inputStream), Map.class); } catch (IOException e) { logger.error("Unable to download payload from external storage path: {}", path, e); throw new ApplicationException(ApplicationException.Code.INTERNAL_ERROR, e); } }