if (other._requestOptions != null) return false; } else if (!_requestOptions.equals(other._requestOptions)) return false; if (_resourceSpec == null){
@Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + ((_baseUriTemplate == null) ? 0 : _baseUriTemplate.hashCode()); result = prime * result + ((_headers == null) ? 0 : _headers.hashCode()); result = prime * result + ((_queryParams == null) ? 0 : _queryParams.hashCode()); result = prime * result + ((_pathKeys == null) ? 0 : _pathKeys.hashCode()); result = prime * result + ((_requestOptions == null) ? 0 : _requestOptions.hashCode()); return result; }
public RestliRequestOptionsBuilder(RestliRequestOptions restliRequestOptions) { setProtocolVersionOption(restliRequestOptions.getProtocolVersionOption()); setRequestCompressionOverride(restliRequestOptions.getRequestCompressionOverride()); setResponseCompressionOverride(restliRequestOptions.getResponseCompressionOverride()); setContentType(restliRequestOptions.getContentType()); setAcceptTypes(restliRequestOptions.getAcceptTypes()); setAcceptResponseAttachments(restliRequestOptions.getAcceptResponseAttachments()); }
private void getProtocolVersionForService(final Request<?> request, Callback<ProtocolVersion> callback) { try { _client.getMetadata(new URI(_uriPrefix + request.getServiceName()), Callbacks.handle(metadata -> callback.onSuccess(getProtocolVersion(AllProtocolVersions.BASELINE_PROTOCOL_VERSION, AllProtocolVersions.PREVIOUS_PROTOCOL_VERSION, AllProtocolVersions.LATEST_PROTOCOL_VERSION, AllProtocolVersions.NEXT_PROTOCOL_VERSION, getAnnouncedVersion(metadata), request.getRequestOptions().getProtocolVersionOption(), _forceUseNextVersionOverride)), callback)); } catch (URISyntaxException e) { throw new RuntimeException("Failed to create a valid URI to fetch properties for!"); } }
private RestRequest buildMultiplexedRequest(MultiplexedRequest multiplexedRequest) throws IOException { URI requestUri = new MultiplexerUriBuilder(_uriPrefix).build(); RestRequestBuilder requestBuilder = new RestRequestBuilder(requestUri).setMethod(HttpMethod.POST.toString()); addAcceptHeaders(requestBuilder, multiplexedRequest.getRequestOptions().getAcceptTypes(), false); final DataMap multiplexedPayload = multiplexedRequest.getContent().data(); final ContentType type = resolveContentType( requestBuilder, multiplexedPayload, multiplexedRequest.getRequestOptions().getContentType()); assert (type != null); requestBuilder.setHeader(RestConstants.HEADER_CONTENT_TYPE, type.getHeaderKey()); requestBuilder.setEntity(type.getCodec().mapToBytes(multiplexedPayload)); requestBuilder.setHeader(RestConstants.HEADER_RESTLI_PROTOCOL_VERSION, AllProtocolVersions.RESTLI_PROTOCOL_2_0_0.getProtocolVersion().toString()); return requestBuilder.build(); }
if (request.getRequestOptions() != null && request.getRequestOptions().getAcceptResponseAttachments())
public RestliRequestOptions build() { return new RestliRequestOptions(_protocolVersionOption, _requestCompressionOverride, _responseCompressionOverride, _contentType, _acceptTypes != null ? Collections.unmodifiableList(_acceptTypes) : null, _acceptResponseAttachments); }
buildStreamRequest(uri, method, dataMap, headers, cookies, protocolVersion, requestOptions.getContentType(), requestOptions.getAcceptTypes(), requestOptions.getAcceptResponseAttachments(), streamingAttachments); 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.streamRequest(request, requestContext, callback);
private RestRequest buildRequest(Request<?> request) switch(_requestOptions.getProtocolVersionOption()) break; default: throw new IllegalArgumentException("Unsupported enum value: " + _requestOptions.getProtocolVersionOption());
private <T> void sendRequestNoScatterGather(final Request<T> request, final RequestContext requestContext, final Callback<Response<T>> callback) { //Here we need to decide if we want to use StreamRequest/StreamResponse or RestRequest/RestResponse. //Eventually we will move completely to StreamRequest/StreamResponse for all traffic. //However for the time being we will only use StreamRequest/StreamResponse for traffic that contains attachments. // //Therefore the decision is made as follows: //1. If the content-type OR accept-type is multipart/related then we use StreamRequest/StreamResponse, //otherwise we use RestRequest/RestResponse. //2. The content-type will be decided based on the presence of attachments in the request. //3. The accept-type will be based on the RestLiRequestOptions. //Note that it is not possible for the list of streaming attachments to be non-null and have 0 elements. If the //list of streaming attachments is non null then it must have at least one attachment. The request builders enforce //this invariant. if (_restLiClientConfig.isUseStreaming() || request.getStreamingAttachments() != null || request.getRequestOptions().getAcceptResponseAttachments()) { //Set content type and accept type correctly and use StreamRequest/StreamResponse sendStreamRequest(request, requestContext, new RestLiStreamCallbackAdapter<T>(request.getResponseDecoder(), callback)); } else { sendRestRequest(request, requestContext, new RestLiCallbackAdapter<T>(request.getResponseDecoder(), callback)); } }
buildRestRequest(uri, method, dataMap, headers, cookies, protocolVersion, requestOptions.getContentType(), requestOptions.getAcceptTypes(), false); 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);
if (_requestOptions != null ? !_requestOptions.equals(other._requestOptions) : other._requestOptions != null)
/** * Computes the hashCode using the new fields * @return */ @Override public int hashCode() { int hashCode = _method.hashCode(); hashCode = 31 * hashCode + (_inputRecord != null ? _inputRecord.hashCode() : 0); hashCode = 31 * hashCode + (_headers != null ? _headers.hashCode() : 0); hashCode = 31 * hashCode + (_baseUriTemplate != null ? _baseUriTemplate.hashCode() : 0); hashCode = 31 * hashCode + (_pathKeys != null ? _pathKeys.hashCode() : 0); hashCode = 31 * hashCode + (_resourceSpec != null ? _resourceSpec.hashCode() : 0); hashCode = 31 * hashCode + (_queryParams != null ? _queryParams.hashCode() : 0); hashCode = 31 * hashCode + (_methodName != null ? _methodName.hashCode() : 0); hashCode = 31 * hashCode + (_requestOptions != null ? _requestOptions.hashCode() : 0); hashCode = 31 * hashCode + (_streamingAttachments != null ? _streamingAttachments.hashCode() : 0); hashCode = 31 * hashCode + (_cookies != null ? _cookies.hashCode() : 0); return hashCode; }
/** * This method provides granular exception messages for developers to know why a request * intended to be added to a batch, might fail to be batched. * * @param request the request to validate is the same or not * @throws IllegalArgumentException if there are any problems */ public <T> void validate(BatchRequest<T> request) { if( !request.getBaseUriTemplate().equals(_request.getBaseUriTemplate()) || !request.getPathKeys().equals(_request.getPathKeys()) ) { throw new IllegalArgumentException("Requests must have same base URI template and path keys to batch"); } if( !request.getResourceProperties().equals(_request.getResourceProperties()) ) { throw new IllegalArgumentException("Requests must be for the same resource to batch"); } if( !request.getRequestOptions().equals(_request.getRequestOptions()) ) { throw new IllegalArgumentException("Requests must have the same RestliRequestOptions to batch!"); } // Enforce uniformity of query params excluding ids and fields final Map<String, Object> queryParams = BatchGetRequestUtil.getQueryParamsForBatchingKey(request); if ( !queryParams.equals(_queryParams) ) { throw new IllegalArgumentException("Requests must have same parameters to batch"); } if (!_batchFields) { if( !request.getFields().equals(_request.getFields()) ) { throw new IllegalArgumentException("Requests must have same fields to batch"); } } }