Search in sources :

Example 21 with ProtocolVersion

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);
}
Also used : RecordTemplate(com.linkedin.data.template.RecordTemplate) ByteString(com.linkedin.data.ByteString) ProtocolVersion(com.linkedin.restli.common.ProtocolVersion) URI(java.net.URI) ResourceMethod(com.linkedin.restli.common.ResourceMethod)

Example 22 with ProtocolVersion

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;
}
Also used : BatchEntityResponse(com.linkedin.restli.internal.client.response.BatchEntityResponse) BatchEntityResponse(com.linkedin.restli.internal.client.response.BatchEntityResponse) EntityResponse(com.linkedin.restli.common.EntityResponse) ComplexResourceKey(com.linkedin.restli.common.ComplexResourceKey) ProtocolVersion(com.linkedin.restli.common.ProtocolVersion) BatchKVResponse(com.linkedin.restli.client.response.BatchKVResponse) DataMap(com.linkedin.data.DataMap)

Example 23 with ProtocolVersion

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);
}
Also used : CompoundKey(com.linkedin.restli.common.CompoundKey) ProtocolVersion(com.linkedin.restli.common.ProtocolVersion) BatchKVResponse(com.linkedin.restli.client.response.BatchKVResponse) DataMap(com.linkedin.data.DataMap)

Example 24 with ProtocolVersion

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);
}
Also used : ArrayList(java.util.ArrayList) CreateIdStatus(com.linkedin.restli.common.CreateIdStatus) ProtocolVersion(com.linkedin.restli.common.ProtocolVersion) ErrorResponse(com.linkedin.restli.common.ErrorResponse) Test(org.testng.annotations.Test)

Example 25 with ProtocolVersion

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());
}
Also used : RestResponse(com.linkedin.r2.message.rest.RestResponse) RestLiResponseException(com.linkedin.restli.client.RestLiResponseException) ProtocolVersion(com.linkedin.restli.common.ProtocolVersion) MockRestliResponseExceptionBuilder(com.linkedin.restli.client.testutils.MockRestliResponseExceptionBuilder) Test(org.testng.annotations.Test)

Aggregations

ProtocolVersion (com.linkedin.restli.common.ProtocolVersion)35 DataMap (com.linkedin.data.DataMap)12 Test (org.testng.annotations.Test)8 CompoundKey (com.linkedin.restli.common.CompoundKey)7 RestLiServiceException (com.linkedin.restli.server.RestLiServiceException)7 URI (java.net.URI)7 ServerResourceContext (com.linkedin.restli.internal.server.ServerResourceContext)5 HashMap (java.util.HashMap)5 ComplexResourceKey (com.linkedin.restli.common.ComplexResourceKey)4 ResourceMethod (com.linkedin.restli.common.ResourceMethod)4 ByteString (com.linkedin.data.ByteString)3 BatchKVResponse (com.linkedin.restli.client.response.BatchKVResponse)3 ErrorResponse (com.linkedin.restli.common.ErrorResponse)3 IdResponse (com.linkedin.restli.common.IdResponse)3 AnyRecord (com.linkedin.restli.internal.server.methods.AnyRecord)3 HttpCookie (java.net.HttpCookie)3 HashSet (java.util.HashSet)3 RecordTemplate (com.linkedin.data.template.RecordTemplate)2 MaskTree (com.linkedin.data.transform.filter.request.MaskTree)2 Foo (com.linkedin.pegasus.generator.examples.Foo)2