Exemplo n.º 1
0
  // This throws Exception to remind the caller to deal with arbitrary exceptions including
  // RuntimeException
  // in a way appropriate for the public method that was originally invoked.
  private RestRequest buildRequest(
      URI uri,
      ResourceMethod method,
      DataMap dataMap,
      Map<String, String> headers,
      List<String> cookies,
      ProtocolVersion protocolVersion,
      ContentType contentType,
      List<AcceptType> acceptTypes)
      throws Exception {
    RestRequestBuilder requestBuilder =
        new RestRequestBuilder(uri).setMethod(method.getHttpMethod().toString());

    requestBuilder.setHeaders(headers);
    requestBuilder.setCookies(cookies);
    addAcceptHeaders(requestBuilder, acceptTypes);
    addEntityAndContentTypeHeaders(requestBuilder, dataMap, contentType);
    addProtocolVersionHeader(requestBuilder, protocolVersion);

    if (method.getHttpMethod() == HttpMethod.POST) {
      requestBuilder.setHeader(RestConstants.HEADER_RESTLI_REQUEST_METHOD, method.toString());
    }

    return requestBuilder.build();
  }
Exemplo n.º 2
0
 private RestRequest buildMultiplexedRequest(MultiplexedRequest multiplexedRequest)
     throws IOException {
   URI requestUri = new MultiplexerUriBuilder(_uriPrefix).build();
   RestRequestBuilder requestBuilder =
       new RestRequestBuilder(requestUri).setMethod(HttpMethod.POST.toString());
   addAcceptHeaders(requestBuilder, Collections.singletonList(AcceptType.JSON));
   addEntityAndContentTypeHeaders(
       requestBuilder, multiplexedRequest.getContent().data(), ContentType.JSON);
   return requestBuilder.build();
 }