use of com.linkedin.jersey.api.uri.UriBuilder in project rest.li by linkedin.
the class CreateResponseBuilder method buildRestLiResponseData.
@Override
public RestLiResponseData buildRestLiResponseData(RestRequest request, RoutingResult routingResult, Object result, Map<String, String> headers, List<HttpCookie> cookies) {
CreateResponse createResponse = (CreateResponse) result;
if (createResponse.hasError()) {
RestLiResponseDataImpl responseData = new RestLiResponseDataImpl(createResponse.getError(), headers, cookies);
responseData.setResponseEnvelope(new CreateResponseEnvelope(null, responseData));
return responseData;
}
Object id = null;
if (createResponse.hasId()) {
id = ResponseUtils.translateCanonicalKeyToAlternativeKeyIfNeeded(createResponse.getId(), routingResult);
final ProtocolVersion protocolVersion = ((ServerResourceContext) routingResult.getContext()).getRestliProtocolVersion();
String stringKey = URIParamUtils.encodeKeyForUri(id, UriComponent.Type.PATH_SEGMENT, protocolVersion);
UriBuilder uribuilder = UriBuilder.fromUri(request.getURI());
uribuilder.path(stringKey);
if (routingResult.getContext().hasParameter(RestConstants.ALT_KEY_PARAM)) {
// add altkey param to location URI
uribuilder.queryParam(RestConstants.ALT_KEY_PARAM, routingResult.getContext().getParameter(RestConstants.ALT_KEY_PARAM));
}
headers.put(RestConstants.HEADER_LOCATION, uribuilder.build((Object) null).toString());
headers.put(HeaderUtil.getIdHeaderName(protocolVersion), URIParamUtils.encodeKeyForHeader(id, protocolVersion));
}
//Verify that a null status was not passed into the CreateResponse. If so, this is a developer error.
if (createResponse.getStatus() == null) {
throw new RestLiServiceException(HttpStatus.S_500_INTERNAL_SERVER_ERROR, "Unexpected null encountered. HttpStatus is null inside of a CreateResponse from the resource method: " + routingResult.getResourceMethod());
}
RestLiResponseDataImpl responseData = new RestLiResponseDataImpl(createResponse.getStatus(), headers, cookies);
CreateResponseEnvelope responseEnvelope;
if (createResponse instanceof CreateKVResponse) {
final ResourceContext resourceContext = routingResult.getContext();
DataMap entityData = ((CreateKVResponse) createResponse).getEntity().data();
final DataMap data = RestUtils.projectFields(entityData, resourceContext.getProjectionMode(), resourceContext.getProjectionMask());
responseEnvelope = new CreateResponseEnvelope(new AnyRecord(data), true, responseData);
} else //Instance of idResponse
{
IdResponse<?> idResponse = new IdResponse<Object>(id);
responseEnvelope = new CreateResponseEnvelope(idResponse, responseData);
}
responseData.setResponseEnvelope(responseEnvelope);
return responseData;
}
use of com.linkedin.jersey.api.uri.UriBuilder in project rest.li by linkedin.
the class BatchGetKVRequestUriBuilder method build.
@Override
public URI build() {
UriBuilder b = UriBuilder.fromUri(buildBaseUriWithPrefix());
appendQueryParams(b);
return b.build();
}
use of com.linkedin.jersey.api.uri.UriBuilder in project rest.li by linkedin.
the class BatchPartialUpdateRequestUriBuilder method build.
@Override
public URI build() {
UriBuilder b = UriBuilder.fromUri(buildBaseUriWithPrefix());
appendQueryParams(b);
return b.build();
}
use of com.linkedin.jersey.api.uri.UriBuilder in project rest.li by linkedin.
the class BatchUpdateRequestUriBuilder method build.
@Override
public URI build() {
UriBuilder b = UriBuilder.fromUri(buildBaseUriWithPrefix());
appendQueryParams(b);
return b.build();
}
use of com.linkedin.jersey.api.uri.UriBuilder in project rest.li by linkedin.
the class CreateIdRequestUriBuilder method build.
@Override
public URI build() {
UriBuilder b = UriBuilder.fromUri(buildBaseUriWithPrefix());
appendQueryParams(b);
return b.build();
}
Aggregations