use of com.linkedin.restli.server.CreateResponse in project rest.li by linkedin.
the class ComplexKeysResource method batchCreate.
@Override
public BatchCreateResult<ComplexResourceKey<TwoPartKey, TwoPartKey>, Message> batchCreate(final BatchCreateRequest<ComplexResourceKey<TwoPartKey, TwoPartKey>, Message> entities) {
List<CreateResponse> createResponses = new ArrayList<CreateResponse>(entities.getInput().size());
for (Message message : entities.getInput()) {
ComplexResourceKey<TwoPartKey, TwoPartKey> key = _dataProvider.create(message);
CreateResponse createResponse = new CreateResponse(key);
createResponses.add(createResponse);
}
return new BatchCreateResult<ComplexResourceKey<TwoPartKey, TwoPartKey>, Message>(createResponses);
}
use of com.linkedin.restli.server.CreateResponse in project rest.li by linkedin.
the class ValidationDemoResource method batchCreate.
@RestMethod.BatchCreate
public BatchCreateResult<Integer, ValidationDemo> batchCreate(final BatchCreateRequest<Integer, ValidationDemo> entities, @ValidatorParam RestLiDataValidator validator) {
List<CreateResponse> results = new ArrayList<CreateResponse>();
int id = 0;
for (ValidationDemo entity : entities.getInput()) {
ValidationResult result = validator.validateInput(entity);
if (result.isValid()) {
results.add(new CreateResponse(id));
id++;
} else {
results.add(new CreateResponse(new RestLiServiceException(HttpStatus.S_422_UNPROCESSABLE_ENTITY, result.getMessages().toString())));
}
}
return new BatchCreateResult<Integer, ValidationDemo>(results);
}
use of com.linkedin.restli.server.CreateResponse in project rest.li by linkedin.
the class TestRestLiResponseHandler method testBasicResponses.
@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "statusData")
public void testBasicResponses(AcceptTypeData acceptTypeData, String expectedStatus, ProtocolVersion protocolVersion, String errorResponseHeaderName, String idHeaderName) throws Exception {
RestResponse response;
// #1 simple record template
response = invokeResponseHandler("/test", buildStatusRecord(), ResourceMethod.GET, acceptTypeData.acceptHeaders, protocolVersion);
checkResponse(response, 200, 2, acceptTypeData.responseContentType, Status.class.getName(), null, true, errorResponseHeaderName);
assertEquals(response.getEntity().asAvroString(), expectedStatus);
// #2 create (with id)
response = invokeResponseHandler("/test", new CreateResponse(1), ResourceMethod.CREATE, acceptTypeData.acceptHeaders, protocolVersion);
checkResponse(response, 201, 3, null, null, null, false, errorResponseHeaderName);
assertEquals(response.getHeader(RestConstants.HEADER_LOCATION), "/test/1");
assertEquals(response.getHeader(idHeaderName), "1");
// #2.1 create (without id)
response = invokeResponseHandler("/test", new CreateResponse(HttpStatus.S_201_CREATED), ResourceMethod.CREATE, acceptTypeData.acceptHeaders, protocolVersion);
checkResponse(response, 201, 1, null, null, null, false, errorResponseHeaderName);
// #2.2 create (with id and slash at the end of uri)
response = invokeResponseHandler("/test/", new CreateResponse(1), ResourceMethod.CREATE, acceptTypeData.acceptHeaders, protocolVersion);
checkResponse(response, 201, 3, null, null, null, false, errorResponseHeaderName);
assertEquals(response.getHeader(RestConstants.HEADER_LOCATION), "/test/1");
assertEquals(response.getHeader(idHeaderName), "1");
// #2.3 create (without id and slash at the end of uri)
response = invokeResponseHandler("/test/", new CreateResponse(HttpStatus.S_201_CREATED), ResourceMethod.CREATE, acceptTypeData.acceptHeaders, protocolVersion);
checkResponse(response, 201, 1, null, null, null, false, errorResponseHeaderName);
// #3 update
response = invokeResponseHandler("/test", new UpdateResponse(HttpStatus.S_204_NO_CONTENT), ResourceMethod.UPDATE, acceptTypeData.acceptHeaders, protocolVersion);
checkResponse(response, 204, 1, null, null, null, false, errorResponseHeaderName);
}
use of com.linkedin.restli.server.CreateResponse in project rest.li by linkedin.
the class TestRestLiResponseHandler method testInvalidAcceptHeaders.
@Test
private void testInvalidAcceptHeaders() throws Exception {
Map<String, String> badAcceptHeaders = Collections.singletonMap("Accept", "foo/bar");
// check response with body (expect 406 error)
try {
invokeResponseHandler("/test", buildStatusRecord(), ResourceMethod.GET, badAcceptHeaders, AllProtocolVersions.LATEST_PROTOCOL_VERSION);
Assert.fail();
} catch (RestLiServiceException e) {
Assert.assertEquals(e.getStatus().getCode(), 406);
}
// check response without body (expect 406 error)
try {
invokeResponseHandler("/test", new CreateResponse(HttpStatus.S_201_CREATED), ResourceMethod.CREATE, badAcceptHeaders, AllProtocolVersions.LATEST_PROTOCOL_VERSION);
Assert.fail();
} catch (RestLiServiceException e) {
Assert.assertEquals(e.getStatus().getCode(), 406);
}
}
Aggregations