use of com.linkedin.restli.server.RestLiServiceException in project rest.li by linkedin.
the class TestBatchUpdateResponseBuilder method unsupportedNullKeyMapData.
@DataProvider(name = "unsupportedNullKeyMapData")
public Object[][] unsupportedNullKeyMapData() {
final CompoundKey c1 = new CompoundKey().append("a", "a1").append("b", 1);
final Map<CompoundKey, UpdateResponse> results = new ConcurrentHashMap<CompoundKey, UpdateResponse>();
results.put(c1, new UpdateResponse(HttpStatus.S_202_ACCEPTED));
final BatchUpdateResult<CompoundKey, Foo> batchUpdateResult = new BatchUpdateResult<CompoundKey, Foo>(results, new ConcurrentHashMap<CompoundKey, RestLiServiceException>());
final UpdateStatus updateStatus = new UpdateStatus().setStatus(202);
final Map<String, UpdateStatus> expectedProtocol1Results = new HashMap<String, UpdateStatus>();
expectedProtocol1Results.put("a=a1&b=1", updateStatus);
final Map<String, UpdateStatus> expectedProtocol2Results = new HashMap<String, UpdateStatus>();
expectedProtocol2Results.put("(a:a1,b:1)", updateStatus);
return new Object[][] { { batchUpdateResult, AllProtocolVersions.RESTLI_PROTOCOL_1_0_0.getProtocolVersion(), expectedProtocol1Results }, { batchUpdateResult, AllProtocolVersions.RESTLI_PROTOCOL_2_0_0.getProtocolVersion(), expectedProtocol2Results } };
}
use of com.linkedin.restli.server.RestLiServiceException in project rest.li by linkedin.
the class TestRestLiMethodInvocation method testInvokeWithUnsupportedAcceptMimeType.
@Test
public void testInvokeWithUnsupportedAcceptMimeType() throws Exception {
RestRequestBuilder builder = new RestRequestBuilder(new URI("")).addHeaderValue("Accept", "text/plain").setHeader(RestConstants.HEADER_RESTLI_PROTOCOL_VERSION, version.toString());
RestRequest request = builder.build();
final RestLiAttachmentReader attachmentReader = new RestLiAttachmentReader(null);
final CountDownLatch latch = new CountDownLatch(1);
RestLiResponseHandler restLiResponseHandler = new RestLiResponseHandler.Builder().build();
RequestExecutionCallback<RestResponse> executionCallback = new RequestExecutionCallback<RestResponse>() {
@Override
public void onError(Throwable e, RequestExecutionReport executionReport, RestLiAttachmentReader requestAttachmentReader, RestLiResponseAttachments responseAttachments) {
latch.countDown();
Assert.assertTrue(e instanceof RestException);
RestException ex = (RestException) e;
Assert.assertEquals(ex.getResponse().getStatus(), HttpStatus.S_406_NOT_ACCEPTABLE.getCode());
Assert.assertEquals(requestAttachmentReader, attachmentReader);
Assert.assertNull(responseAttachments);
}
@Override
public void onSuccess(RestResponse result, RequestExecutionReport executionReport, RestLiResponseAttachments responseAttachments) {
Assert.fail();
}
};
ServerResourceContext resourceContext = new ResourceContextImpl(new PathKeysImpl(), new RestRequestBuilder(URI.create("")).setHeader(RestConstants.HEADER_RESTLI_PROTOCOL_VERSION, AllProtocolVersions.LATEST_PROTOCOL_VERSION.toString()).build(), new RequestContext(), false, attachmentReader);
try {
RoutingResult routingResult = new RoutingResult(resourceContext, null);
RestUtils.validateRequestHeadersAndUpdateResourceContext(request.getHeaders(), (ServerResourceContext) routingResult.getContext());
FilterChainCallback filterChainCallback = new FilterChainCallbackImpl(null, _invoker, null, null, null, restLiResponseHandler, executionCallback);
final RestLiCallback<Object> callback = new RestLiCallback<Object>(null, new RestLiFilterResponseContextFactory<Object>(request, null, restLiResponseHandler), new RestLiFilterChain(null, filterChainCallback));
_invoker.invoke(null, routingResult, null, callback, null);
latch.await();
} catch (Exception e) {
// exception is expected
Assert.assertTrue(e instanceof RestLiServiceException);
}
Assert.assertNull(resourceContext.getResponseMimeType());
}
use of com.linkedin.restli.server.RestLiServiceException in project rest.li by linkedin.
the class GroupMembershipsResource2 method batchGet.
/**
* @see GroupMembershipsResource2#batchGet(Set)
*/
@Override
public BatchResult<CompoundKey, GroupMembership> batchGet(Set<CompoundKey> ids) {
Map<CompoundKey, GroupMembership> result = new HashMap<CompoundKey, GroupMembership>(ids.size());
Map<CompoundKey, RestLiServiceException> errors = new HashMap<CompoundKey, RestLiServiceException>();
Iterator<CompoundKey> iterator = ids.iterator();
while (iterator.hasNext()) {
CompoundKey key = iterator.next();
GroupMembership membership = _app.getMembershipMgr().get(key);
if (membership != null) {
result.put(key, membership);
} else {
errors.put(key, new RestLiServiceException(HttpStatus.S_404_NOT_FOUND));
}
}
return new BatchResult<CompoundKey, GroupMembership>(result, errors);
}
use of com.linkedin.restli.server.RestLiServiceException in project rest.li by linkedin.
the class GroupMembershipsResource3 method create.
/** @see com.linkedin.restli.server.resources.ComplexKeyResourceTemplate#create(com.linkedin.data.template.RecordTemplate) */
@Override
public CreateResponse create(ComplexKeyGroupMembership groupMembership) {
// object
if (!groupMembership.getId().hasMemberID() || !groupMembership.getId().hasGroupID()) {
throw new RestLiServiceException(S_400_BAD_REQUEST, "groupID and memberID fields must be set while creating a ComplexKeyGroupMembership.");
}
GroupMembershipKey groupMembershipKey = new GroupMembershipKey();
groupMembershipKey.setMemberID(groupMembership.getId().getMemberID());
groupMembershipKey.setGroupID(groupMembership.getId().getGroupID());
ComplexResourceKey<GroupMembershipKey, GroupMembershipParam> complexResourceKey = new ComplexResourceKey<GroupMembershipKey, GroupMembershipParam>(groupMembershipKey, new GroupMembershipParam());
groupMembership.setId(complexResourceKey.getKey());
_app.getMembershipMgr().save(toGroupMembership(groupMembership));
return new CreateResponse(complexResourceKey, HttpStatus.S_201_CREATED);
}
use of com.linkedin.restli.server.RestLiServiceException in project rest.li by linkedin.
the class GroupMembershipsResource3 method batchGet.
/**
* @see GroupMembershipsResource2#batchGet(Set)
*/
@Override
public BatchResult<ComplexResourceKey<GroupMembershipKey, GroupMembershipParam>, ComplexKeyGroupMembership> batchGet(Set<ComplexResourceKey<GroupMembershipKey, GroupMembershipParam>> ids) {
Map<ComplexResourceKey<GroupMembershipKey, GroupMembershipParam>, ComplexKeyGroupMembership> result = new HashMap<ComplexResourceKey<GroupMembershipKey, GroupMembershipParam>, ComplexKeyGroupMembership>(ids.size());
Map<ComplexResourceKey<GroupMembershipKey, GroupMembershipParam>, RestLiServiceException> errors = new HashMap<ComplexResourceKey<GroupMembershipKey, GroupMembershipParam>, RestLiServiceException>();
Iterator<ComplexResourceKey<GroupMembershipKey, GroupMembershipParam>> iterator = ids.iterator();
while (iterator.hasNext()) {
ComplexResourceKey<GroupMembershipKey, GroupMembershipParam> key = iterator.next();
ComplexKeyGroupMembership membership = fromGroupMembership(_app.getMembershipMgr().get(complexKeyToCompoundKey(key)));
if (membership != null) {
result.put(key, membership);
} else {
errors.put(key, new RestLiServiceException(HttpStatus.S_404_NOT_FOUND));
}
}
return new BatchResult<ComplexResourceKey<GroupMembershipKey, GroupMembershipParam>, ComplexKeyGroupMembership>(result, errors);
}
Aggregations