use of com.linkedin.restli.examples.greetings.api.Greeting in project rest.li by linkedin.
the class TestMultiplexerIntegration method twoParallelCalls.
@Test
public void twoParallelCalls() throws Exception {
GetRequest<Greeting> request1 = new GreetingsCallbackBuilders().get().id(1L).build();
FutureCallback<Response<Greeting>> muxCallback1 = new FutureCallback<Response<Greeting>>();
FutureCallback<Response<Greeting>> directCallback1 = new FutureCallback<Response<Greeting>>();
GetRequest<Greeting> request2 = new GreetingsCallbackBuilders().get().id(2L).build();
FutureCallback<Response<Greeting>> muxCallback2 = new FutureCallback<Response<Greeting>>();
FutureCallback<Response<Greeting>> directCallback2 = new FutureCallback<Response<Greeting>>();
MultiplexedRequest multiplexedRequest = MultiplexedRequestBuilder.createParallelRequest().addRequest(request1, muxCallback1).addRequest(request2, muxCallback2).build();
getClient().sendRequest(multiplexedRequest);
getClient().sendRequest(request1, directCallback1);
getClient().sendRequest(request2, directCallback2);
assertEqualResponses(muxCallback1, directCallback1);
assertEqualResponses(muxCallback2, directCallback2);
}
use of com.linkedin.restli.examples.greetings.api.Greeting in project rest.li by linkedin.
the class TestScatterGather method checkInput.
// TODO modify this method to accept a CollectionRequest as it's first parameter once our server code has been
// updated to work with the new representation of BatchUpdateRequests and BatchPartialUpdateRequests. As of now
// we are still converting to the old representation using CollectionRequestUtil.convertToBatchRequest
private static void checkInput(DataMap dataMap, Map<Long, Greeting> inputMap, Set<String> uriIds) {
Assert.assertEquals(dataMap.size(), uriIds.size());
for (String key : dataMap.keySet()) {
DataMap inputDM = dataMap.getDataMap(key);
Greeting expectedGreeting = inputMap.get(Long.parseLong(key));
Assert.assertTrue(uriIds.contains(key));
Assert.assertTrue(inputDM.equals(expectedGreeting.data()));
}
}
use of com.linkedin.restli.examples.greetings.api.Greeting in project rest.li by linkedin.
the class NullGreetingsResourceImpl method batchUpdate.
@RestMethod.BatchPartialUpdate
public BatchUpdateResult<Long, Greeting> batchUpdate(BatchPatchRequest<Long, Greeting> entityUpdates) {
final Map<Long, UpdateResponse> responseMap = new HashMap<Long, UpdateResponse>();
responseMap.put(3l, new UpdateResponse(HttpStatus.S_201_CREATED));
if (entityUpdates.getData().containsKey(1l)) {
//Return a null BatchUpdateResult
return null;
} else if (entityUpdates.getData().containsKey(2l)) {
//Return a BatchUpdateResult with a null results Map
return new BatchUpdateResult<Long, Greeting>(null);
} else if (entityUpdates.getData().containsKey(3l)) {
//Return a BatchUpdateResult with a null errors Map
return new BatchUpdateResult<Long, Greeting>(responseMap, null);
} else {
//Return a BatchUpdateResult with a map that has a null key in it
responseMap.put(null, new UpdateResponse(HttpStatus.S_201_CREATED));
return new BatchUpdateResult<Long, Greeting>(responseMap);
}
}
use of com.linkedin.restli.examples.greetings.api.Greeting in project rest.li by linkedin.
the class SimpleResourceUnderCollectionResource method update.
/**
* Updates the greeting.
*/
@Override
public UpdateResponse update(PatchRequest<Greeting> patchRequest) {
Long key = this.getContext().getPathKeys().get("subgreetingsId");
if (TONES.containsKey(key)) {
try {
Greeting patched = new Greeting();
PatchApplier.applyPatch(patched, patchRequest);
TONES.put(key, patched.getTone());
return new UpdateResponse(HttpStatus.S_204_NO_CONTENT);
} catch (DataProcessingException e) {
return new UpdateResponse((HttpStatus.S_400_BAD_REQUEST));
}
} else {
return new UpdateResponse(HttpStatus.S_404_NOT_FOUND);
}
}
use of com.linkedin.restli.examples.greetings.api.Greeting in project rest.li by linkedin.
the class StreamingGreetings method get.
@Override
public void get(Long key, @CallbackParam Callback<Greeting> callback) {
if (getContext().responseAttachmentsSupported()) {
final GreetingWriter greetingWriter = new GreetingWriter(ByteString.copy(greetingBytes));
final RestLiResponseAttachments streamingAttachments = new RestLiResponseAttachments.Builder().appendSingleAttachment(greetingWriter).build();
getContext().setResponseAttachments(streamingAttachments);
final String headerValue = getContext().getRequestHeaders().get("getHeader");
getContext().setResponseHeader("getHeader", headerValue);
callback.onSuccess(new Greeting().setMessage("Your greeting has an attachment since you were kind and " + "decided you wanted to read it!").setId(key));
}
callback.onError(new RestLiServiceException(HttpStatus.S_400_BAD_REQUEST, "You must be able to receive attachments!"));
}
Aggregations