Example #1
0
 /**
  * Sends an untyped REST request using a callback.
  *
  * @param requestContext context for the request
  * @param uri for resource
  * @param method to perform
  * @param dataMap request body entity
  * @param protocolVersion the version of the Rest.li protocol used to build this request
  * @param requestOptions contains compression force on/off overrides, request content type and
  *     accept types
  * @param callback to call on request completion. In the event of an error, the callback will
  *     receive a {@link com.linkedin.r2.RemoteInvocationException}. If a valid error response was
  *     received from the remote server, the callback will receive a {@link
  *     com.linkedin.r2.message.rest.RestException} containing the error details.
  */
 private void sendRequestImpl(
     RequestContext requestContext,
     URI uri,
     ResourceMethod method,
     DataMap dataMap,
     Map<String, String> headers,
     List<String> cookies,
     String methodName,
     ProtocolVersion protocolVersion,
     RestliRequestOptions requestOptions,
     Callback<RestResponse> callback) {
   try {
     RestRequest request =
         buildRequest(
             uri,
             method,
             dataMap,
             headers,
             cookies,
             protocolVersion,
             requestOptions.getContentType(),
             requestOptions.getAcceptTypes());
     String operation = OperationNameGenerator.generate(method, methodName);
     requestContext.putLocalAttr(R2Constants.OPERATION, operation);
     requestContext.putLocalAttr(
         R2Constants.REQUEST_COMPRESSION_OVERRIDE, requestOptions.getRequestCompressionOverride());
     requestContext.putLocalAttr(
         R2Constants.RESPONSE_COMPRESSION_OVERRIDE,
         requestOptions.getResponseCompressionOverride());
     _client.restRequest(request, requestContext, callback);
   } catch (Exception e) {
     // No need to wrap the exception; RestLiCallbackAdapter.onError() will take care of that
     callback.onError(e);
   }
 }
Example #2
0
 @Override
 public void onRestRequest(
     RestRequest req,
     RequestContext requestContext,
     Map<String, String> wireAttrs,
     NextFilter<RestRequest, RestResponse> nextFilter) {
   trace("onRestRequest", req, wireAttrs, requestContext);
   requestContext.putLocalAttr(REQUEST_URI, req.getURI());
   requestContext.putLocalAttr(REQUEST_METHOD, req.getMethod());
   nextFilter.onRequest(req, requestContext, wireAttrs);
 }
Example #3
0
 /**
  * Inserts a hint in RequestContext instructing D2 to bypass normal hashing behavior and instead
  * route to the specified target host. Clients should obtain the URI for target host from D2,
  * e.g., by calling {@link KeyMapper}.mapKeys().
  *
  * @param context RequestContext for the request which will be made
  * @param targetHost target host's URI to be used as a hint in the RequestContext
  */
 public static void setRequestContextTargetHost(RequestContext context, URI targetHost) {
   context.putLocalAttr(TARGET_HOST_KEY_NAME, targetHost);
 }
Example #4
0
 /**
  * Inserts a hint in RequestContext instructing D2 to bypass normal hashing behavior and instead
  * route to the specified target service. This is different than setRequestContextTargetHost
  * because it sets the service context path as well as the host.
  *
  * @param context RequestContext for the request which will be made
  * @param targetService target service's URI to be used as a hint in the RequestContext
  */
 public static void setRequestContextTargetService(RequestContext context, URI targetService) {
   context.putLocalAttr(TARGET_SERVICE_KEY_NAME, targetService);
 }