use of com.linkedin.restli.common.ProtocolVersion in project rest.li by linkedin.
the class MultiplexedRequestBuilder method toIndividualRequest.
private static IndividualRequest toIndividualRequest(Request<?> request, IndividualRequestMap dependantRequests) throws RestLiEncodingException {
//TODO: Hardcoding RESTLI_PROTOCOL_2_0_0 for now. We need to refactor this code later to get protocol version using the mechanism similar to
// RestClient.getProtocolVersionForService()
ProtocolVersion protocolVersion = AllProtocolVersions.RESTLI_PROTOCOL_2_0_0.getProtocolVersion();
String relativeUrl = getRelativeUrl(request, protocolVersion);
IndividualRequest individualRequest = new IndividualRequest();
individualRequest.setRelativeUrl(relativeUrl);
individualRequest.setMethod(request.getMethod().getHttpMethod().name());
individualRequest.setHeaders(new StringMap(request.getHeaders()));
List<HttpCookie> cookies = request.getCookies();
if (cookies != null && !cookies.isEmpty()) {
throw new IllegalArgumentException(String.format("Cookies for individual request '%s' MUST be added at the envelope request level", relativeUrl));
}
individualRequest.setBody(getBody(request, protocolVersion), SetMode.IGNORE_NULL);
individualRequest.setDependentRequests(dependantRequests);
return individualRequest;
}
use of com.linkedin.restli.common.ProtocolVersion in project rest.li by linkedin.
the class BatchGetRequestBuilderTest method testUriGeneration.
private static void testUriGeneration(Request<?> request, String protocol1UriString, String protocol2UriString) throws URISyntaxException {
ProtocolVersion protocol1 = AllProtocolVersions.RESTLI_PROTOCOL_1_0_0.getProtocolVersion();
ProtocolVersion protocol2 = AllProtocolVersions.RESTLI_PROTOCOL_2_0_0.getProtocolVersion();
URI protocol1Uri = RestliUriBuilderUtil.createUriBuilder(request, protocol1).build();
URI protocol2Uri = RestliUriBuilderUtil.createUriBuilder(request, protocol2).build();
//V1:
MultivaluedMap actualQueryParamMapV1 = UriComponent.decodeQuery(protocol1Uri, true);
MultivaluedMap expectedQueryParamMapV1 = UriComponent.decodeQuery(new URI(protocol1UriString), true);
assertProtocolURIsMatch(actualQueryParamMapV1, expectedQueryParamMapV1, "Protocol 1");
//V2:
MultivaluedMap actualQueryParamMapV2 = UriComponent.decodeQuery(protocol2Uri, true);
MultivaluedMap expectedQueryParamMapV2 = UriComponent.decodeQuery(new URI(protocol2UriString), true);
assertProtocolURIsMatch(actualQueryParamMapV2, expectedQueryParamMapV2, "Protocol 2");
}
use of com.linkedin.restli.common.ProtocolVersion in project rest.li by linkedin.
the class RestLiServer method ensureRequestUsesValidRestliProtocol.
/**
* Ensures that the Rest.li protocol version used by the client is valid
*
* (assume the protocol version used by the client is "v")
*
* v is valid if {@link com.linkedin.restli.internal.common.AllProtocolVersions#OLDEST_SUPPORTED_PROTOCOL_VERSION}
* <= v <= {@link com.linkedin.restli.internal.common.AllProtocolVersions#NEXT_PROTOCOL_VERSION}
*
* @param request
* the incoming request from the client
* @throws RestLiServiceException
* if the protocol version used by the client is not valid based on the rules described
* above
*/
private void ensureRequestUsesValidRestliProtocol(final RestRequest request) throws RestLiServiceException {
ProtocolVersion clientProtocolVersion = ProtocolVersionUtil.extractProtocolVersion(request.getHeaders());
ProtocolVersion lowerBound = AllProtocolVersions.OLDEST_SUPPORTED_PROTOCOL_VERSION;
ProtocolVersion upperBound = AllProtocolVersions.NEXT_PROTOCOL_VERSION;
if (!isSupportedProtocolVersion(clientProtocolVersion, lowerBound, upperBound)) {
throw new RestLiServiceException(HttpStatus.S_400_BAD_REQUEST, "Rest.li protocol version " + clientProtocolVersion + " used by the client is not supported!");
}
}
use of com.linkedin.restli.common.ProtocolVersion in project rest.li by linkedin.
the class BatchGetResponseBuilder method buildResponse.
@Override
@SuppressWarnings("unchecked")
public PartialRestResponse buildResponse(RoutingResult routingResult, RestLiResponseData responseData) {
final Map<Object, BatchResponseEntry> responses = (Map<Object, BatchResponseEntry>) responseData.getBatchResponseEnvelope().getBatchResponseMap();
// Build the EntityResponse for each key from the merged map with mask from routingResult.
Map<Object, EntityResponse<RecordTemplate>> entityBatchResponse = buildEntityResponse(routingResult, responses);
PartialRestResponse.Builder builder = new PartialRestResponse.Builder();
final ProtocolVersion protocolVersion = ((ServerResourceContext) routingResult.getContext()).getRestliProtocolVersion();
@SuppressWarnings("unchecked") final BatchResponse<AnyRecord> response = toBatchResponse(entityBatchResponse, protocolVersion);
builder.entity(response);
return builder.headers(responseData.getHeaders()).cookies(responseData.getCookies()).build();
}
use of com.linkedin.restli.common.ProtocolVersion in project rest.li by linkedin.
the class BatchUpdateResponseBuilder method buildResponse.
@Override
@SuppressWarnings("unchecked")
public PartialRestResponse buildResponse(RoutingResult routingResult, RestLiResponseData responseData) {
Map<Object, UpdateStatus> mergedResults = new HashMap<Object, UpdateStatus>();
final Map<Object, BatchResponseEntry> responses = (Map<Object, BatchResponseEntry>) responseData.getBatchResponseEnvelope().getBatchResponseMap();
generateResultEntityResponse(routingResult, responses, mergedResults);
PartialRestResponse.Builder builder = new PartialRestResponse.Builder();
final ProtocolVersion protocolVersion = ((ServerResourceContext) routingResult.getContext()).getRestliProtocolVersion();
@SuppressWarnings("unchecked") final BatchResponse<AnyRecord> response = toBatchResponse(mergedResults, protocolVersion);
return builder.entity(response).headers(responseData.getHeaders()).cookies(responseData.getCookies()).build();
}
Aggregations