use of com.linkedin.restli.common.ProtocolVersion in project rest.li by linkedin.
the class RestClient method sendRestRequest.
/**
* @deprecated as this API will change to private in a future release. Please use other APIs in this class, such as
* {@link RestClient#sendRequest(com.linkedin.restli.client.Request,com.linkedin.r2.message.RequestContext, com.linkedin.common.callback.Callback)}
* to send type-bound REST requests.
*
* Sends a type-bound REST request and answers on the provided callback.
*
* @param request to send
* @param requestContext context for the request
* @param callback to call on request completion
*/
@Deprecated
public <T> void sendRestRequest(final Request<T> request, RequestContext requestContext, Callback<RestResponse> callback) {
//We need this until we remove the deprecation above since clients could attempt these:
if (request.getStreamingAttachments() != null) {
throw new UnsupportedOperationException("Cannot stream attachments using RestRequest/RestResponse!");
}
if (request.getRequestOptions() != null && request.getRequestOptions().getAcceptResponseAttachments()) {
throw new UnsupportedOperationException("Cannot expect streaming attachments using RestRequest/RestResponse!");
}
RecordTemplate input = request.getInputRecord();
ProtocolVersion protocolVersion = getProtocolVersionForService(request);
URI requestUri = RestliUriBuilderUtil.createUriBuilder(request, _uriPrefix, protocolVersion).build();
final ResourceMethod method = request.getMethod();
final String methodName = request.getMethodName();
addDisruptContext(request.getBaseUriTemplate(), method, methodName, requestContext);
sendRestRequestImpl(requestContext, requestUri, method, input != null ? RequestBodyTransformer.transform(request, protocolVersion) : null, request.getHeaders(), CookieUtil.encodeCookies(request.getCookies()), methodName, protocolVersion, request.getRequestOptions(), callback);
}
use of com.linkedin.restli.common.ProtocolVersion in project rest.li by linkedin.
the class MockBatchEntityResponseFactory method createWithComplexKey.
/**
* Create a {@link BatchKVResponse} where the key is a {@link ComplexResourceKey}
*
* @param valueClass the value class
* @param keyKeyClass the class of the key part of the {@link ComplexResourceKey}
* @param keyParamsClass the class of the params part of the {@link ComplexResourceKey}
* @param recordTemplates the data that will be returned for a call to {@link com.linkedin.restli.client.response.BatchKVResponse#getResults()}
* NOTE: the params part of the {@link ComplexResourceKey} is removed in this map. A new
* instance of the params class is created with no data in it.
* @param statuses The HTTP status codes that will be returned as part of {@link EntityResponse}s
* returned in {@link com.linkedin.restli.client.response.BatchKVResponse#getResults()}
* @param errorResponses the data that will be returned for a call to {@link com.linkedin.restli.client.response.BatchKVResponse#getErrors()}
* NOTE: the params part of the {@link ComplexResourceKey} is removed in this map. A new
* instance of the params class is created with no data in it.
* @param <V>
* @return
*/
@SuppressWarnings("rawtypes")
public static <KK extends RecordTemplate, KP extends RecordTemplate, V extends RecordTemplate> BatchKVResponse<ComplexResourceKey<KK, KP>, EntityResponse<V>> createWithComplexKey(Class<V> valueClass, Class<KK> keyKeyClass, Class<KP> keyParamsClass, Map<ComplexResourceKey<KK, KP>, V> recordTemplates, Map<ComplexResourceKey<KK, KP>, HttpStatus> statuses, Map<ComplexResourceKey<KK, KP>, ErrorResponse> errorResponses) {
ProtocolVersion version = AllProtocolVersions.BASELINE_PROTOCOL_VERSION;
DataMap batchResponseDataMap = buildDataMap(recordTemplates, statuses, errorResponses, version);
@SuppressWarnings("unchecked") BatchKVResponse<ComplexResourceKey<KK, KP>, EntityResponse<V>> response = (BatchKVResponse<ComplexResourceKey<KK, KP>, EntityResponse<V>>) (Object) new BatchEntityResponse<ComplexResourceKey, V>(batchResponseDataMap, new TypeSpec<ComplexResourceKey>(ComplexResourceKey.class), TypeSpec.forClassMaybeNull(valueClass), null, ComplexKeySpec.forClassesMaybeNull(keyKeyClass, keyParamsClass), version);
return response;
}
use of com.linkedin.restli.common.ProtocolVersion in project rest.li by linkedin.
the class MockBatchKVResponseFactory method createWithCustomTyperefKey.
/**
* Creates a {@link BatchKVResponse} where the key is a typeref to a custom Java class.
*
* @param keyClass the custom Java class
* @param typerefClass the typeref class (the generated class that extends {@link RecordTemplate})
* @param valueClass class for the value
* @param recordTemplates the data that will be returned for a call to {@link com.linkedin.restli.client.response.BatchKVResponse#getResults()}
* @param errorResponses the data that will be returned for a call to {@link com.linkedin.restli.client.response.BatchKVResponse#getErrors()}
* @param <K>
* @param <TK>
* @param <V>
* @return
*/
@SuppressWarnings({ "unchecked", "rawtypes" })
public static <K, TK, V extends RecordTemplate> BatchKVResponse<K, V> createWithCustomTyperefKey(Class<K> keyClass, Class<TK> typerefClass, Class<V> valueClass, Map<K, V> recordTemplates, Map<K, ErrorResponse> errorResponses) {
ProtocolVersion version = AllProtocolVersions.BASELINE_PROTOCOL_VERSION;
DataMap batchResponseDataMap = buildDataMap(recordTemplates, errorResponses, version);
return new BatchKVResponse(batchResponseDataMap, typerefClass, valueClass, Collections.<String, CompoundKey.TypeInfo>emptyMap(), version);
}
use of com.linkedin.restli.common.ProtocolVersion in project rest.li by linkedin.
the class TestMockBatchCreateIdResponseFactory method testCreate.
@Test(dataProvider = "provideKeys")
public <K> void testCreate(K[] keys) {
ProtocolVersion version = AllProtocolVersions.BASELINE_PROTOCOL_VERSION;
List<CreateIdStatus<K>> elements = new ArrayList<CreateIdStatus<K>>();
elements.add(new CreateIdStatus<K>(HttpStatus.S_201_CREATED.getCode(), keys[0], null, version));
elements.add(new CreateIdStatus<K>(HttpStatus.S_201_CREATED.getCode(), keys[1], null, version));
ErrorResponse error = new ErrorResponse().setMessage("3");
elements.add(new CreateIdStatus<K>(HttpStatus.S_500_INTERNAL_SERVER_ERROR.getCode(), keys[2], error, version));
BatchCreateIdResponse<K> batchResp = MockBatchCreateIdResponseFactory.create(elements);
Assert.assertEquals(batchResp.getElements(), elements);
}
use of com.linkedin.restli.common.ProtocolVersion in project rest.li by linkedin.
the class TestMockRestliResponseExceptionBuilder method testOldProtocolVersion.
@Test
public void testOldProtocolVersion() {
ProtocolVersion expectedProtocolVersion = AllProtocolVersions.RESTLI_PROTOCOL_1_0_0.getProtocolVersion();
RestLiResponseException exception = new MockRestliResponseExceptionBuilder().setProtocolVersion(expectedProtocolVersion).build();
RestResponse errorResponse = exception.getResponse();
assertEquals(errorResponse.getHeader(RestConstants.HEADER_LINKEDIN_ERROR_RESPONSE), "true");
assertEquals(errorResponse.getHeader(RestConstants.HEADER_RESTLI_PROTOCOL_VERSION), expectedProtocolVersion.toString());
}
Aggregations