@Test public void retrieveMultipleObjectsFromStorage_badSignature_errorReturned() { GetHistoryAddressesRequest getHistoryAddressesRequest = AddressTestUtils.generateGetHistoryAddressesRequest( null, null, addressDataInStorage1); when(getHistoryAddressesRequestCrypto.verifySignature(getHistoryAddressesRequest)).thenReturn(false); ResponseEntity<IResponse> actualResponse = addressStorageService.retrieveMultipleObjectsFromStorage(getHistoryAddressesRequest); SerializableResponse expectedResponse = new SerializableResponse(INVALID_SIGNATURE, STATUS_ERROR); Assert.assertEquals(expectedResponse, actualResponse.getBody()); }
public ResponseEntity<IResponse> retrieveMultipleObjectsFromStorage(GetHistoryAddressesRequest getHistoryAddressesRequest) { try { if (!getHistoryAddressesRequestCrypto.verifySignature(getHistoryAddressesRequest)) { return ResponseEntity.status(HttpStatus.UNAUTHORIZED).body(new SerializableResponse(INVALID_SIGNATURE, STATUS_ERROR)); } Map<Hash, AddressData> hashToAddressDataMap = new HashMap<>(); super.retrieveMultipleObjectsFromStorage(getHistoryAddressesRequest.getAddressHashes()).forEach((hash, addressString) -> hashToAddressDataMap.put(hash, addressString != null ? jacksonSerializer.deserialize(addressString) : null)); GetHistoryAddressesResponse getHistoryAddressesResponse = new GetHistoryAddressesResponse(hashToAddressDataMap); getHistoryAddressesResponseCrypto.signMessage(getHistoryAddressesResponse); return ResponseEntity.ok(getHistoryAddressesResponse); } catch (Exception e) { return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(new SerializableResponse(e.getMessage(), STATUS_ERROR)); } }
AddressStorageService extends EntityStorageService { public ResponseEntity<IResponse> retrieveMultipleObjectsFromStorage(GetHistoryAddressesRequest getHistoryAddressesRequest) { try { if (!getHistoryAddressesRequestCrypto.verifySignature(getHistoryAddressesRequest)) { return ResponseEntity.status(HttpStatus.UNAUTHORIZED).body(new SerializableResponse(INVALID_SIGNATURE, STATUS_ERROR)); } Map<Hash, AddressData> hashToAddressDataMap = new HashMap<>(); super.retrieveMultipleObjectsFromStorage(getHistoryAddressesRequest.getAddressHashes()).forEach((hash, addressString) -> hashToAddressDataMap.put(hash, addressString != null ? jacksonSerializer.deserialize(addressString) : null)); GetHistoryAddressesResponse getHistoryAddressesResponse = new GetHistoryAddressesResponse(hashToAddressDataMap); getHistoryAddressesResponseCrypto.signMessage(getHistoryAddressesResponse); return ResponseEntity.ok(getHistoryAddressesResponse); } catch (Exception e) { return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(new SerializableResponse(e.getMessage(), STATUS_ERROR)); } } }
AddressStorageService extends EntityStorageService { public ResponseEntity<IResponse> retrieveMultipleObjectsFromStorage(GetHistoryAddressesRequest getHistoryAddressesRequest) { try { if (!getHistoryAddressesRequestCrypto.verifySignature(getHistoryAddressesRequest)) { return ResponseEntity.status(HttpStatus.UNAUTHORIZED).body(new SerializableResponse(INVALID_SIGNATURE, STATUS_ERROR)); } Map<Hash, AddressData> hashToAddressDataMap = new HashMap<>(); super.retrieveMultipleObjectsFromStorage(getHistoryAddressesRequest.getAddressHashes()).forEach((hash, addressString) -> hashToAddressDataMap.put(hash, addressString != null ? jacksonSerializer.deserialize(addressString) : null)); GetHistoryAddressesResponse getHistoryAddressesResponse = new GetHistoryAddressesResponse(hashToAddressDataMap); getHistoryAddressesResponseCrypto.signMessage(getHistoryAddressesResponse); return ResponseEntity.ok(getHistoryAddressesResponse); } catch (Exception e) { return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(new SerializableResponse(e.getMessage(), STATUS_ERROR)); } }  }
AddressStorageService extends EntityStorageService { public ResponseEntity<IResponse> retrieveMultipleObjectsFromStorage(GetHistoryAddressesRequest getHistoryAddressesRequest) { try { if (!getHistoryAddressesRequestCrypto.verifySignature(getHistoryAddressesRequest)) { return ResponseEntity.status(HttpStatus.UNAUTHORIZED).body(new SerializableResponse(INVALID_SIGNATURE, STATUS_ERROR)); } Map<Hash, AddressData> hashToAddressDataMap = new HashMap<>(); super.retrieveMultipleObjectsFromStorage(getHistoryAddressesRequest.getAddressHashes()).forEach((hash, addressString) -> hashToAddressDataMap.put(hash, addressString != null ? jacksonSerializer.deserialize(addressString) : null)); GetHistoryAddressesResponse getHistoryAddressesResponse = new GetHistoryAddressesResponse(hashToAddressDataMap); getHistoryAddressesResponseCrypto.signMessage(getHistoryAddressesResponse); return ResponseEntity.ok(getHistoryAddressesResponse); } catch (Exception e) { return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(new SerializableResponse(e.getMessage(), STATUS_ERROR)); } }  @PostConstruct void init(); ResponseEntity<IResponse> retrieveMultipleObjectsFromStorage(GetHistoryAddressesRequest getHistoryAddressesRequest); boolean validateObjectDataIntegrity(Hash addressHash, String addressAsJson); Map<Hash, AddressData> getObjectsMapFromJsonMap(Map<Hash, String> responsesMap); }
AddressStorageService extends EntityStorageService { public ResponseEntity<IResponse> retrieveMultipleObjectsFromStorage(GetHistoryAddressesRequest getHistoryAddressesRequest) { try { if (!getHistoryAddressesRequestCrypto.verifySignature(getHistoryAddressesRequest)) { return ResponseEntity.status(HttpStatus.UNAUTHORIZED).body(new SerializableResponse(INVALID_SIGNATURE, STATUS_ERROR)); } Map<Hash, AddressData> hashToAddressDataMap = new HashMap<>(); super.retrieveMultipleObjectsFromStorage(getHistoryAddressesRequest.getAddressHashes()).forEach((hash, addressString) -> hashToAddressDataMap.put(hash, addressString != null ? jacksonSerializer.deserialize(addressString) : null)); GetHistoryAddressesResponse getHistoryAddressesResponse = new GetHistoryAddressesResponse(hashToAddressDataMap); getHistoryAddressesResponseCrypto.signMessage(getHistoryAddressesResponse); return ResponseEntity.ok(getHistoryAddressesResponse); } catch (Exception e) { return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(new SerializableResponse(e.getMessage(), STATUS_ERROR)); } }  @PostConstruct void init(); ResponseEntity<IResponse> retrieveMultipleObjectsFromStorage(GetHistoryAddressesRequest getHistoryAddressesRequest); boolean validateObjectDataIntegrity(Hash addressHash, String addressAsJson); Map<Hash, AddressData> getObjectsMapFromJsonMap(Map<Hash, String> responsesMap);  }