예제 #1
0
  /**
   * Sends a type-bound REST request using a {@link CallbackAdapter}.
   *
   * @param request to send
   * @param requestContext context for the request
   * @param callback to call on request completion
   */
  public <T> void sendRestRequest(
      final Request<T> request, RequestContext requestContext, Callback<RestResponse> callback) {
    RecordTemplate input = request.getInputRecord();
    ProtocolVersion protocolVersion = getProtocolVersionForService(request);
    URI requestUri =
        RestliUriBuilderUtil.createUriBuilder(request, _uriPrefix, protocolVersion).build();

    sendRequestImpl(
        requestContext,
        requestUri,
        request.getMethod(),
        input != null ? RequestBodyTransformer.transform(request, protocolVersion) : null,
        request.getHeaders(),
        CookieUtil.encodeCookies(request.getCookies()),
        request.getMethodName(),
        protocolVersion,
        request.getRequestOptions(),
        callback);
  }
예제 #2
0
  @SuppressWarnings({"unchecked", "rawtypes"})
  private static void testRequest(
      BatchRequest<?> request,
      Set<String> expectedParams,
      Set<String> expectedFields,
      Map<Long, Greeting> expectedInput,
      Set<Set<String>> requestIdSets,
      Set<Long> requestIds) {
    String[] queryParams =
        RestliUriBuilderUtil.createUriBuilder(request).build().getQuery().split("&");
    Map<String, List<String>> params = new HashMap<String, List<String>>();
    for (String paramString : queryParams) {
      String[] keyValue = paramString.split("=");
      Assert.assertEquals(keyValue.length, 2);
      if (!params.containsKey(keyValue[0])) {
        params.put(keyValue[0], new ArrayList<String>());
      }
      params.get(keyValue[0]).add(keyValue[1]);
    }
    Assert.assertEquals(params.keySet(), expectedParams);

    if (expectedFields != null) {
      Assert.assertTrue(params.get(RestConstants.FIELDS_PARAM).containsAll(expectedFields));
    }

    Set<String> uriIds = new HashSet<String>();
    for (String value : params.get(RestConstants.QUERY_BATCH_IDS_PARAM)) {
      uriIds.addAll(Arrays.asList(value.split(",")));
    }

    if (expectedInput != null) {
      RecordTemplate inputRecordTemplate;
      if (request instanceof BatchUpdateRequest) {
        ResourceSpec resourceSpec = request.getResourceSpec();

        CollectionRequest inputRecord = (CollectionRequest) request.getInputRecord();

        inputRecordTemplate =
            CollectionRequestUtil.convertToBatchRequest(
                inputRecord,
                resourceSpec.getKeyType(),
                resourceSpec.getComplexKeyType(),
                resourceSpec.getKeyParts(),
                resourceSpec.getValueType());
      } else {
        inputRecordTemplate = request.getInputRecord();
      }
      checkInput(
          inputRecordTemplate.data().getDataMap(com.linkedin.restli.common.BatchRequest.ENTITIES),
          expectedInput,
          uriIds);
    }

    @SuppressWarnings("unchecked")
    Set<Object> idObjects = request.getObjectIds();
    Set<String> theseIds = new HashSet<String>(idObjects.size());
    for (Object o : idObjects) {
      theseIds.add(o.toString());
    }

    Assert.assertEquals(uriIds, theseIds);

    Assert.assertFalse(requestIdSets.contains(theseIds)); // no duplicate requests
    for (String id : theseIds) {
      Assert.assertFalse(requestIds.contains(Long.parseLong(id))); // no duplicate ids
      requestIds.add(Long.parseLong(id));
    }
    requestIdSets.add(theseIds);
  }
예제 #3
0
 /**
  * @deprecated Please use {@link
  *     com.linkedin.restli.client.uribuilders.RestliUriBuilder#buildBaseUri()} instead
  * @return
  */
 @Deprecated
 public URI getBaseUri() {
   return RestliUriBuilderUtil.createUriBuilder(this).buildBaseUri();
 }