use of com.linkedin.restli.internal.client.ResponseImpl in project rest.li by linkedin.
the class BatchGetRequestUtil method unbatchKVResponse.
/**
* Extract the get response for this resource out of an auto-batched batch response.
* This is pure rest.li logic, and it complements the auto-batching logic in BatchGetRequestBuilder.
* @throws com.linkedin.r2.RemoteInvocationException if the server returned an error response for this resource,
* or if it returned neither a result nor an error.
*/
public static <K, V extends RecordTemplate> Response<V> unbatchKVResponse(Request<BatchKVResponse<K, V>> request, Response<BatchKVResponse<K, V>> batchResponse, K id) throws RemoteInvocationException {
final BatchKVResponse<K, V> batchEntity = batchResponse.getEntity();
final ErrorResponse errorResponse = batchEntity.getErrors().get(id);
if (errorResponse != null) {
throw new RestLiResponseException(errorResponse);
}
final V entityResult = batchEntity.getResults().get(id);
if (entityResult == null) {
throw new RestLiDecodingException("No result or error for base URI " + request.getBaseUriTemplate() + ", id " + id + ". Verify that the batchGet endpoint returns response keys that match batchGet request IDs.", null);
}
return new ResponseImpl<>(batchResponse, entityResult);
}
use of com.linkedin.restli.internal.client.ResponseImpl in project rest.li by linkedin.
the class TestDefaultScatterGatherStrategy method createBatchKVResponse.
private static Response<BatchKVResponse<Long, UpdateStatus>> createBatchKVResponse(ProtocolVersion version, Set<Long> resultKeys, Set<Long> errorKeys) {
DataMap resultMap = new DataMap();
DataMap errorMap = new DataMap();
for (Long id : resultKeys) {
resultMap.put(id.toString(), new UpdateStatus().setStatus(HttpStatus.S_200_OK.getCode()).data());
}
for (Long id : errorKeys) {
ErrorResponse err = new ErrorResponse().setStatus(HttpStatus.S_404_NOT_FOUND.getCode());
errorMap.put(id.toString(), err.data());
}
DataMap responseMap = new DataMap();
responseMap.put(BatchResponse.RESULTS, resultMap);
responseMap.put(BatchResponse.ERRORS, errorMap);
DataMap mergedMap = ResponseDecoderUtil.mergeUpdateStatusResponseData(responseMap);
BatchKVResponse<Long, UpdateStatus> response = new BatchKVResponse<>(mergedMap, new TypeSpec<>(Long.class), new TypeSpec<>(UpdateStatus.class), Collections.emptyMap(), version);
return new ResponseImpl<>(HttpStatus.S_200_OK.getCode(), Collections.emptyMap(), Collections.emptyList(), response, null);
}
use of com.linkedin.restli.internal.client.ResponseImpl in project rest.li by linkedin.
the class TestDefaultScatterGatherStrategy method createBatchGetKVResponse.
private static Response<BatchKVResponse<Long, TestRecord>> createBatchGetKVResponse(ProtocolVersion version, Set<Long> resultKeys, Set<Long> errorKeys) {
DataMap resultMap = new DataMap();
for (Long id : resultKeys) {
resultMap.put(id.toString(), new TestRecord().setId(id).data());
}
DataMap errorMap = new DataMap();
for (Long id : errorKeys) {
errorMap.put(id.toString(), new ErrorResponse().setStatus(HttpStatus.S_404_NOT_FOUND.getCode()).data());
}
DataMap responseMap = new DataMap();
responseMap.put(BatchResponse.RESULTS, resultMap);
responseMap.put(BatchResponse.ERRORS, errorMap);
BatchKVResponse<Long, TestRecord> response = new BatchKVResponse<>(responseMap, new TypeSpec<>(Long.class), new TypeSpec<>(TestRecord.class), Collections.emptyMap(), null, version);
return new ResponseImpl<>(HttpStatus.S_200_OK.getCode(), Collections.emptyMap(), Collections.emptyList(), response, null);
}
use of com.linkedin.restli.internal.client.ResponseImpl in project rest.li by linkedin.
the class TestDefaultScatterGatherStrategy method createBatchEntityResponse.
private static Response<BatchKVResponse<Long, EntityResponse<TestRecord>>> createBatchEntityResponse(ProtocolVersion version, Set<Long> resultKeys, Set<Long> errorKeys) {
DataMap resultMap = new DataMap();
for (Long id : resultKeys) {
resultMap.put(id.toString(), new EntityResponse<>(TestRecord.class).setEntity(new TestRecord().setId(id)).setStatus(HttpStatus.S_200_OK).data());
}
DataMap errorMap = new DataMap();
for (Long id : errorKeys) {
errorMap.put(id.toString(), new ErrorResponse().setStatus(HttpStatus.S_404_NOT_FOUND.getCode()).data());
}
DataMap responseMap = new DataMap();
responseMap.put(BatchResponse.RESULTS, resultMap);
responseMap.put(BatchResponse.ERRORS, errorMap);
BatchEntityResponse<Long, TestRecord> response = new BatchEntityResponse<>(responseMap, new TypeSpec<>(Long.class), new TypeSpec<>(TestRecord.class), Collections.emptyMap(), null, version);
return new ResponseImpl<>(HttpStatus.S_200_OK.getCode(), Collections.emptyMap(), Collections.emptyList(), response, null);
}
use of com.linkedin.restli.internal.client.ResponseImpl in project rest.li by linkedin.
the class TestDefaultScatterGatherStrategy method createBatchResponse.
private static Response<BatchResponse<TestRecord>> createBatchResponse(Set<Long> resultKeys, Set<Long> errorKeys) {
DataMap resultMap = new DataMap();
for (Long id : resultKeys) {
resultMap.put(id.toString(), new TestRecord().setId(id).data());
}
DataMap errorMap = new DataMap();
for (Long id : errorKeys) {
errorMap.put(id.toString(), new ErrorResponse().setStatus(HttpStatus.S_404_NOT_FOUND.getCode()).data());
}
DataMap responseMap = new DataMap();
responseMap.put(BatchResponse.RESULTS, resultMap);
responseMap.put(BatchResponse.ERRORS, errorMap);
BatchResponse<TestRecord> response = new BatchResponse<>(responseMap, TestRecord.class);
return new ResponseImpl<>(HttpStatus.S_200_OK.getCode(), Collections.emptyMap(), Collections.emptyList(), response, null);
}
Aggregations