Package com.linkedin.restli.common

Examples of com.linkedin.restli.common.ProtocolVersion


      {
        final IdResponse<?> idResponse = (IdResponse<?>) _record;
        final Object key = idResponse.getId();
        if (key != null)
        {
          final ProtocolVersion protocolVersion = ProtocolVersionUtil.extractProtocolVersion(_headers);
          _headers.put(HeaderUtil.getIdHeaderName(protocolVersion), URIParamUtils.encodeKeyForHeader(key, protocolVersion));
        }
      }

      return new PartialRestResponse(_status, _record, _headers);
View Full Code Here


  @Override
  public PartialRestResponse buildResponse(RoutingResult routingResult, AugmentedRestLiResponseData responseData)
  {
    PartialRestResponse.Builder builder = new PartialRestResponse.Builder();
    final ProtocolVersion protocolVersion =
        ((ServerResourceContext) routingResult.getContext()).getRestliProtocolVersion();
    @SuppressWarnings("unchecked")
    final BatchResponse<AnyRecord> response =
        toBatchResponse((Map<Object, EntityResponse<RecordTemplate>>) responseData.getBatchResponseMap(),
                        protocolVersion);
View Full Code Here

      throws URISyntaxException
  {
    CompoundKey compoundKey = new CompoundKey().append("a", "a").append("b", 1);
    CreateResponse createResponse = new CreateResponse(compoundKey, null);
    RestRequest restRequest = new RestRequestBuilder(new URI("/foo")).build();
    ProtocolVersion protocolVersion = AllProtocolVersions.RESTLI_PROTOCOL_1_0_0.getProtocolVersion();
    Map<String, String> headers = getHeaders(protocolVersion);

    ResourceMethodDescriptor mockDescriptor = getMockResourceMethodDescriptor();
    ResourceContext mockContext = getMockResourceContext(protocolVersion);
    RoutingResult routingResult = new RoutingResult(mockContext, mockDescriptor);
View Full Code Here

    Set<Key> keys = new HashSet<Key>(2);
    keys.add(new Key("foo", Integer.class));
    keys.add(new Key("bar", String.class));

    // heuristic key syntax detection only occurs in Protocol Version 1.0.0
    ProtocolVersion v1 = AllProtocolVersions.RESTLI_PROTOCOL_1_0_0.getProtocolVersion();

    Set<String> expectedKeys = new HashSet<String>(Arrays.asList("foo", "bar"));
    Assert.assertEquals(expectedKeys, ArgumentUtils.parseCompoundKey("foo:42;bar:abcd", keys, v1).getPartKeys());
    Assert.assertEquals(expectedKeys, ArgumentUtils.parseCompoundKey("foo:42;bar:abcd=1&efg=2", keys, v1).getPartKeys());
    Assert.assertEquals(expectedKeys, ArgumentUtils.parseCompoundKey("foo=42&bar=abcd", keys, v1).getPartKeys());
View Full Code Here

    final MaskTree maskTree = new MaskTree();
    final MutablePathKeys pathKeys = new PathKeysImpl();
    final Map<String, String> requestHeaders = new HashMap<String, String>();
    requestHeaders.put("Key1", "Value1");
    final URI requestUri = new URI("foo.bar.com");
    final ProtocolVersion protoVersion = AllProtocolVersions.BASELINE_PROTOCOL_VERSION;
    final DataMap queryParams = new DataMap();
    queryParams.put("Param1", "Val1");

    final String finderName = UUID.randomUUID().toString();
    final String actionName = UUID.randomUUID().toString();
View Full Code Here

   *           if the protocol version used by the client is not valid based on the rules described
   *           above
   */
  private void ensureRequestUsesValidRestliProtocol(final RestRequest request) throws RestLiServiceException
  {
    ProtocolVersion clientProtocolVersion = ProtocolVersionUtil.extractProtocolVersion(request.getHeaders());
    ProtocolVersion lowerBound = AllProtocolVersions.OLDEST_SUPPORTED_PROTOCOL_VERSION;
    ProtocolVersion upperBound = AllProtocolVersions.NEXT_PROTOCOL_VERSION;
    if (!isSupportedProtocolVersion(clientProtocolVersion, lowerBound, upperBound))
    {
      throw new RestLiServiceException(HttpStatus.S_400_BAD_REQUEST, "Rest.li protocol version "
          + clientProtocolVersion + " used by the client is not supported!");
    }
View Full Code Here

  }

  @SuppressWarnings("unchecked")
  private RestRequest buildRequest(Request<?> request)
  {
    ProtocolVersion protocolVersion;
    switch(_requestOptions.getProtocolVersionOption())
    {
      case FORCE_USE_LATEST:
        protocolVersion = AllProtocolVersions.LATEST_PROTOCOL_VERSION;
        break;
      case USE_LATEST_IF_AVAILABLE:
        protocolVersion = AllProtocolVersions.BASELINE_PROTOCOL_VERSION;
        break;
      case FORCE_USE_NEXT:
        protocolVersion = AllProtocolVersions.NEXT_PROTOCOL_VERSION;
        break;
      default:
        throw new IllegalArgumentException("Unsupported enum value: " + _requestOptions.getProtocolVersionOption());
    }

    URI uri = RestliUriBuilderUtil.createUriBuilder(request, "", protocolVersion).build();
    RestRequestBuilder requestBuilder = new RestRequestBuilder(uri);
    requestBuilder.setMethod(request.getMethod().getHttpMethod().name());

    // unfortunately some headers get set in RestClient, and since we're not using rest client, we
    // replicate that behavior here
    requestBuilder.setHeader(RestConstants.HEADER_ACCEPT, RestConstants.HEADER_VALUE_APPLICATION_JSON);

    requestBuilder.setHeader(RestConstants.HEADER_RESTLI_PROTOCOL_VERSION, protocolVersion.toString());

    if (request.getMethod().getHttpMethod() == HttpMethod.POST)
    {
      requestBuilder.setHeader(RestConstants.HEADER_RESTLI_REQUEST_METHOD, request.getMethod().toString());
    }
View Full Code Here

  private static final ProtocolVersion _NEXT_VERSION = new ProtocolVersion(3, 0, 0);
 
  @DataProvider(name = "data")
  public Object[][] getProtocolVersionClient()
  {
    ProtocolVersion lessThanDefaultVersion = new ProtocolVersion(0, 5, 0);
    ProtocolVersion betweenDefaultAndLatestVersion = new ProtocolVersion(1, 5, 0);
    ProtocolVersion greaterThanLatestVersion = new ProtocolVersion(2, 5, 0);
    ProtocolVersion greaterThanNextVersion = new ProtocolVersion(3, 5, 0);

    /*
    Generate data to test the following function:
      getProtocolVersion(ProtocolVersion defaultVersion,
                         ProtocolVersion latestVersion,
View Full Code Here

    try
    {
      RestClient.getProtocolVersion(_BASELINE_VERSION,
                                    _LATEST_VERSION,
                                    _NEXT_VERSION,
                                    new ProtocolVersion(0, 0, 0),
                                    ProtocolVersionOption.USE_LATEST_IF_AVAILABLE,
                                    false);
      Assert.fail("Expected a RuntimeException as the announced version is less than the default!");
    }
    catch (RuntimeException e)
View Full Code Here

                                                         ProtocolVersion expectedAnnouncedVersion)
  {
      Map<String, Object> properties = new HashMap<String, Object>();
      properties.put(RestConstants.RESTLI_PROTOCOL_VERSION_PROPERTY, versionInput);
      properties.put(RestConstants.RESTLI_PROTOCOL_VERSION_PERCENTAGE_PROPERTY, versionPercentageInput);
      ProtocolVersion announcedVersion = RestClient.getAnnouncedVersion(properties);
      Assert.assertEquals(expectedAnnouncedVersion, announcedVersion);
  }
View Full Code Here

TOP

Related Classes of com.linkedin.restli.common.ProtocolVersion

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.