}
@SuppressWarnings("unchecked")
private RestRequest buildRequest(Request<?> request)
{
ProtocolVersion protocolVersion;
switch(_requestOptions.getProtocolVersionOption())
{
case FORCE_USE_LATEST:
protocolVersion = AllProtocolVersions.LATEST_PROTOCOL_VERSION;
break;
case USE_LATEST_IF_AVAILABLE:
protocolVersion = AllProtocolVersions.BASELINE_PROTOCOL_VERSION;
break;
case FORCE_USE_NEXT:
protocolVersion = AllProtocolVersions.NEXT_PROTOCOL_VERSION;
break;
default:
throw new IllegalArgumentException("Unsupported enum value: " + _requestOptions.getProtocolVersionOption());
}
URI uri = RestliUriBuilderUtil.createUriBuilder(request, "", protocolVersion).build();
RestRequestBuilder requestBuilder = new RestRequestBuilder(uri);
requestBuilder.setMethod(request.getMethod().getHttpMethod().name());
// unfortunately some headers get set in RestClient, and since we're not using rest client, we
// replicate that behavior here
requestBuilder.setHeader(RestConstants.HEADER_ACCEPT, RestConstants.HEADER_VALUE_APPLICATION_JSON);
requestBuilder.setHeader(RestConstants.HEADER_RESTLI_PROTOCOL_VERSION, protocolVersion.toString());
if (request.getMethod().getHttpMethod() == HttpMethod.POST)
{
requestBuilder.setHeader(RestConstants.HEADER_RESTLI_REQUEST_METHOD, request.getMethod().toString());
}