RequestConfigCacheKey(Optional<InboundRequestContext> inbound, Request<?> outbound) { StringJoiner sj = new StringJoiner(":"); for (String pathComponent: URIParamUtils.extractPathComponentsFromUriTemplate(outbound.getBaseUriTemplate())) { sj.add(pathComponent); } _outboundName = sj.toString(); _inboundName = inbound.map(r -> r.getName()); _outboundOp = outbound.getMethod(); _outboundOpName = getOpOutName(outbound); _inboundOp = inbound.map(r -> r.getMethod()); _inboundOpName = _inboundOp.flatMap(method -> getOpInName(inbound, method)); }
/** * Generates a task name for the request. * @param request * @return a task name */ static String generateTaskName(final Request<?> request) { return request.getBaseUriTemplate() + " " + OperationNameGenerator.generate(request.getMethod(), request.getMethodName()); }
@SuppressWarnings("deprecation") public GetRequestGroup(Request<?> request, int maxBatchSize) { _baseUriTemplate = request.getBaseUriTemplate(); _headers = request.getHeaders(); _queryParams = getQueryParamsForBatchingKey(request); _resourceSpec = request.getResourceSpec(); _requestOptions = request.getRequestOptions(); _pathKeys = request.getPathKeys(); _maxBatchSize = maxBatchSize; }
/** * Validates that all path keys in the URI template are present. If not, an {@link IllegalStateException} is thrown. */ private void validatePathKeys() { UriTemplate template = new UriTemplate(getBaseUriTemplate()); for (String key: template.getTemplateVariables()) { Object value = getPathKeys().get(key); if (value == null) { throw new IllegalStateException("Missing path key: " + key); } } }
private String bindPathKeys() { UriTemplate template = new UriTemplate(_request.getBaseUriTemplate()); return template.createURI(URIParamUtils.encodePathKeysForUri(_request.getPathKeys(), _version)); }
_baseUriTemplate = request.getBaseUriTemplate();
/** * Extract the get response for this resource out of an auto-batched batch response. * This is pure rest.li logic, and it complements the auto-batching logic in BatchGetRequestBuilder. * @throws com.linkedin.r2.RemoteInvocationException if the server returned an error response for this resource, * or if it returned neither a result nor an error. */ public static <K, V extends RecordTemplate> Response<V> unbatchKVResponse(Request<BatchKVResponse<K, V>> request, Response<BatchKVResponse<K, V>> batchResponse, K id) throws RemoteInvocationException { final BatchKVResponse<K, V> batchEntity = batchResponse.getEntity(); final ErrorResponse errorResponse = batchEntity.getErrors().get(id); if (errorResponse != null) { throw new RestLiResponseException(errorResponse); } final V entityResult = batchEntity.getResults().get(id); if (entityResult == null) { throw new RestLiDecodingException("No result or error for base URI " + request.getBaseUriTemplate() + ", id " + id + ". Verify that the batchGet endpoint returns response keys that match batchGet request IDs.", null); } return new ResponseImpl<V>(batchResponse, entityResult); }
/** * Extract the get response for this resource out of an auto-batched batch response. * This is pure rest.li logic, and it complements the auto-batching logic in BatchGetRequestBuilder. * @throws com.linkedin.r2.RemoteInvocationException if the server returned an error response for this resource, * or if it returned neither a result nor an error. */ public static <T extends RecordTemplate> Response<T> unbatchResponse(Request<BatchResponse<T>> request, Response<BatchResponse<T>> batchResponse, Object id) throws RemoteInvocationException { final BatchResponse<T> batchEntity = batchResponse.getEntity(); final ErrorResponse errorResponse = batchEntity.getErrors().get(id); if (errorResponse != null) { throw new RestLiResponseException(errorResponse); } final T entityResult = batchEntity.getResults().get(id); if (entityResult == null) { throw new RestLiDecodingException("No result or error for base URI " + request.getBaseUriTemplate() + ", id " + id + ". Verify that the batchGet endpoint returns response keys that match batchGet request IDs.", null); } return new ResponseImpl<T>(batchResponse, entityResult); } }
final String resource = request.getBaseUriTemplate(); final String name = request.getMethodName(); final DisruptContext disruptContext;
@Override public void onSuccess(ProtocolVersion protocolVersion) { 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); } });
@Override public void onSuccess(ProtocolVersion protocolVersion) { URI requestUri = RestliUriBuilderUtil.createUriBuilder(request, _uriPrefix, protocolVersion).build(); final ResourceMethod method = request.getMethod(); final String methodName = request.getMethodName(); addDisruptContext(request.getBaseUriTemplate(), method, methodName, requestContext); sendStreamRequestImpl(requestContext, requestUri, method, input != null ? RequestBodyTransformer.transform(request, protocolVersion) : null, request.getHeaders(), CookieUtil.encodeCookies(request.getCookies()), methodName, protocolVersion, request.getRequestOptions(), request.getStreamingAttachments(), callback); } });