use of com.linkedin.restli.server.CreateResponse in project rest.li by linkedin.
the class MixedResource method create.
@Create
public void create(Greeting entity, @CallbackParam final Callback<CreateResponse> callback) {
final Runnable requestHandler = new Runnable() {
public void run() {
callback.onSuccess(new CreateResponse(HttpStatus.S_200_OK));
}
};
scheduler.schedule(requestHandler, DELAY, TimeUnit.MILLISECONDS);
}
use of com.linkedin.restli.server.CreateResponse in project rest.li by linkedin.
the class AssociationAltKeyResource method create.
public CreateResponse create(Greeting entity) {
CompoundKey key = new CompoundKey();
key.append("message", "h");
key.append("greetingId", 3L);
return new CreateResponse(key, HttpStatus.S_201_CREATED);
}
use of com.linkedin.restli.server.CreateResponse in project rest.li by linkedin.
the class ComplexKeyAltKeyResource method create.
@Override
public CreateResponse create(Message entity) {
TwoPartKey key = new TwoPartKey();
key.setMajor("testKey");
key.setMinor("testKey");
ComplexResourceKey<TwoPartKey, TwoPartKey> complexKey = new ComplexResourceKey<>(key, new TwoPartKey());
return new CreateResponse(complexKey, HttpStatus.S_201_CREATED);
}
use of com.linkedin.restli.server.CreateResponse in project rest.li by linkedin.
the class ExceptionsResource method create.
/**
* Responds with an error for requests to create insulting greetings, responds
* with 201 created for all other requests.
*/
@RestMethod.Create
public CreateResponse create(Greeting g) {
if (g.hasTone() && g.getTone() == Tone.INSULTING) {
RestLiServiceException notAcceptableException = new RestLiServiceException(HttpStatus.S_406_NOT_ACCEPTABLE, "I will not tolerate your insolence!");
DataMap details = new DataMap();
details.put("reason", "insultingGreeting");
notAcceptableException.setErrorDetails(new EmptyRecord(details));
notAcceptableException.setServiceErrorCode(999);
throw notAcceptableException;
} else {
return new CreateResponse(g.getId(), HttpStatus.S_201_CREATED);
}
}
use of com.linkedin.restli.server.CreateResponse in project rest.li by linkedin.
the class BatchCreateResponseBuilder method buildRestLiResponseData.
/**
* {@inheritDoc}
*
* @param result The result for a Rest.li BATCH_CREATE method. It's an instance of {@link BatchCreateResult}, if the
* BATCH_CREATE method doesn't return the entity; or an instance of {@link BatchCreateKVResult}, if it
* does.
*/
@Override
public RestLiResponseData<BatchCreateResponseEnvelope> buildRestLiResponseData(Request request, RoutingResult routingResult, Object result, Map<String, String> headers, List<HttpCookie> cookies) {
Object altKey = null;
if (routingResult.getContext().hasParameter(RestConstants.ALT_KEY_PARAM)) {
altKey = routingResult.getContext().getParameter(RestConstants.ALT_KEY_PARAM);
}
final ProtocolVersion protocolVersion = ProtocolVersionUtil.extractProtocolVersion(headers);
final ResourceContext resourceContext = routingResult.getContext();
if (result instanceof BatchCreateKVResult && resourceContext.isReturnEntityRequested()) {
BatchCreateKVResult<?, ?> list = (BatchCreateKVResult<?, ?>) result;
if (list.getResults() == null) {
throw new RestLiServiceException(HttpStatus.S_500_INTERNAL_SERVER_ERROR, "Unexpected null encountered. Null List inside of a BatchCreateKVResult returned by the resource method: " + routingResult.getResourceMethod());
}
List<BatchCreateResponseEnvelope.CollectionCreateResponseItem> collectionCreateList = new ArrayList<>(list.getResults().size());
TimingContextUtil.beginTiming(routingResult.getContext().getRawRequestContext(), FrameworkTimingKeys.SERVER_RESPONSE_RESTLI_PROJECTION_APPLY.key());
for (CreateKVResponse<?, ?> createKVResponse : list.getResults()) {
if (createKVResponse == null) {
throw new RestLiServiceException(HttpStatus.S_500_INTERNAL_SERVER_ERROR, "Unexpected null encountered. Null element inside of List inside of a BatchCreateKVResult returned by the resource method: " + routingResult.getResourceMethod());
} else {
Object id = ResponseUtils.translateCanonicalKeyToAlternativeKeyIfNeeded(createKVResponse.getId(), routingResult);
if (createKVResponse.getError() == null) {
DataMap entityData = createKVResponse.getEntity() != null ? createKVResponse.getEntity().data() : null;
final DataMap data = RestUtils.projectFields(entityData, resourceContext);
CreateIdEntityStatus<Object, RecordTemplate> entry = new CreateIdEntityStatus<>(createKVResponse.getStatus().getCode(), id, new AnyRecord(data), // location uri
getLocationUri(request, id, altKey, protocolVersion), null, protocolVersion);
collectionCreateList.add(new BatchCreateResponseEnvelope.CollectionCreateResponseItem(entry));
} else {
collectionCreateList.add(new BatchCreateResponseEnvelope.CollectionCreateResponseItem(createKVResponse.getError()));
}
}
}
TimingContextUtil.endTiming(routingResult.getContext().getRawRequestContext(), FrameworkTimingKeys.SERVER_RESPONSE_RESTLI_PROJECTION_APPLY.key());
return new RestLiResponseDataImpl<>(new BatchCreateResponseEnvelope(HttpStatus.S_200_OK, collectionCreateList, true), headers, cookies);
} else {
List<? extends CreateResponse> createResponses = extractCreateResponseList(result);
// Verify that a null list was not passed into the BatchCreateResult. If so, this is a developer error.
if (createResponses == null) {
throw new RestLiServiceException(HttpStatus.S_500_INTERNAL_SERVER_ERROR, "Unexpected null encountered. Null List inside of a BatchCreateResult returned by the resource method: " + routingResult.getResourceMethod());
}
List<BatchCreateResponseEnvelope.CollectionCreateResponseItem> collectionCreateList = new ArrayList<>(createResponses.size());
for (CreateResponse createResponse : createResponses) {
// Verify that a null element was not passed into the BatchCreateResult list. If so, this is a developer error.
if (createResponse == null) {
throw new RestLiServiceException(HttpStatus.S_500_INTERNAL_SERVER_ERROR, "Unexpected null encountered. Null element inside of List inside of a BatchCreateResult returned by the resource method: " + routingResult.getResourceMethod());
} else {
Object id = ResponseUtils.translateCanonicalKeyToAlternativeKeyIfNeeded(createResponse.getId(), routingResult);
if (createResponse.getError() == null) {
CreateIdStatus<Object> entry = new CreateIdStatus<>(createResponse.getStatus().getCode(), id, // location uri
getLocationUri(request, id, altKey, protocolVersion), null, protocolVersion);
collectionCreateList.add(new BatchCreateResponseEnvelope.CollectionCreateResponseItem(entry));
} else {
collectionCreateList.add(new BatchCreateResponseEnvelope.CollectionCreateResponseItem(createResponse.getError()));
}
}
}
return new RestLiResponseDataImpl<>(new BatchCreateResponseEnvelope(HttpStatus.S_200_OK, collectionCreateList, false), headers, cookies);
}
}
Aggregations