Package com.linkedin.restli.common

Examples of com.linkedin.restli.common.ProtocolVersion


       Class<KK> keyKeyClass,
       Class<KP> keyParamsClass,
       Map<ComplexResourceKey<KK, KP>, V> recordTemplates,
       Map<ComplexResourceKey<KK, KP>, ErrorResponse> errorResponses)
  {
    ProtocolVersion version = AllProtocolVersions.BASELINE_PROTOCOL_VERSION;

    DataMap batchResponseDataMap = buildDataMap(recordTemplates, errorResponses, version);

    @SuppressWarnings("unchecked")
    BatchKVResponse<ComplexResourceKey<KK, KP>, V> response =
View Full Code Here


                                                                                                   Class<TK> typerefClass,
                                                                                                   Class<V> valueClass,
                                                                                                   Map<K, V> recordTemplates,
                                                                                                   Map<K, ErrorResponse> errorResponses)
  {
    ProtocolVersion version = AllProtocolVersions.BASELINE_PROTOCOL_VERSION;

    DataMap batchResponseDataMap = buildDataMap(recordTemplates, errorResponses, version);

    return new BatchKVResponse(batchResponseDataMap,
                               typerefClass,
View Full Code Here

    if (_headers != null)
    {
      headers.putAll(_headers);
    }

    ProtocolVersion protocolVersion = (_protocolVersion == null) ?
        AllProtocolVersions.BASELINE_PROTOCOL_VERSION : _protocolVersion;
    headers.put(RestConstants.HEADER_RESTLI_PROTOCOL_VERSION, protocolVersion.toString());

    int status = (_status == 0) ? DEFAULT_HTTP_STATUS : _status;

    if (_entity instanceof CreateResponse || _entity instanceof IdResponse)
    {
View Full Code Here

    }

    _errorHandlingBehavior = (_errorHandlingBehavior == null) ?
        ErrorHandlingBehavior.FAIL_ON_ERROR : _errorHandlingBehavior;

    ProtocolVersion protocolVersion = (getProtocolVersion() == null) ? AllProtocolVersions.BASELINE_PROTOCOL_VERSION :
        getProtocolVersion();

    if (_errorResponse != null)
    {
      return buildWithErrorResponse(protocolVersion);
View Full Code Here

  public AugmentedRestLiResponseData buildRestLiResponseData(final RestRequest request,
                                                            final RoutingResult routingResult,
                                                            final Object responseObject) throws IOException
  {
    ServerResourceContext context = (ServerResourceContext) routingResult.getContext();
    final ProtocolVersion protocolVersion = context.getRestliProtocolVersion();
    Map<String, String> responseHeaders = new HashMap<String, String>();
    responseHeaders.putAll(context.getResponseHeaders());
    responseHeaders.put(ProtocolVersionUtil.getProtocolVersionHeaderName(request.getHeaders()), protocolVersion.toString());

    if (responseObject == null)
    {
      //If we have a null result, we have to assign the correct response status
      if (routingResult.getResourceMethod().getType().equals(ResourceMethod.ACTION))
View Full Code Here

                                                             Object result, Map<String, String> headers)
  {
    CreateResponse createResponse = (CreateResponse) result;
    if (createResponse.hasId())
    {
      final ProtocolVersion protocolVersion = ((ServerResourceContext) routingResult.getContext()).getRestliProtocolVersion();
      String stringKey = URIParamUtils.encodeKeyForUri(createResponse.getId(), UriComponent.Type.PATH_SEGMENT, protocolVersion);
      UriBuilder uribuilder = UriBuilder.fromUri(request.getURI());
      uribuilder.path(stringKey);
      headers.put(RestConstants.HEADER_LOCATION, uribuilder.build((Object) null).toString());
    }
View Full Code Here

  private void parseBatchKeysParameter(final ResourceModel resource,
                                       final ServerResourceContext context)
  {
    Class<?> keyClass = resource.getKeyClass();
    ProtocolVersion version = context.getRestliProtocolVersion();
    final Set<Object> batchKeys;

    if (ComplexResourceKey.class.equals(keyClass))
    {
      // Parse all query parameters into a data map.
      DataMap allParametersDataMap = context.getParameters();

      // Get the batch request keys from the IDS list at the root of the map.
      DataList batchIds = allParametersDataMap.getDataList(RestConstants.QUERY_BATCH_IDS_PARAM);
      if (batchIds == null)
      {
        batchKeys = null;
      }
      else if (batchIds.isEmpty())
      {
        batchKeys = Collections.emptySet();
      }
      else
      {
        batchKeys = new HashSet<Object>();

        // Validate the complex keys and put them into the context batch keys
        for (Object complexKey : batchIds)
        {
          if (!(complexKey instanceof DataMap))
          {
            log.warn("Invalid structure of key '" + complexKey.toString() + "', skipping key.");
            context.getBatchKeyErrors().put(complexKey, new RestLiServiceException(HttpStatus.S_400_BAD_REQUEST));
            continue;
          }
          batchKeys.add(ComplexResourceKey.buildFromDataMap((DataMap) complexKey, ComplexKeySpec.forClassesMaybeNull(resource.getKeyKeyClass(), resource.getKeyParamsClass())));
        }
      }
    }
    else if (CompoundKey.class.equals(keyClass)
      && version.compareTo(AllProtocolVersions.RESTLI_PROTOCOL_2_0_0.getProtocolVersion()) >= 0)
    {
      DataMap allParametersDataMap = context.getParameters();

      // Get the batch request keys from the IDS list at the root of the map.
      DataList batchIds = allParametersDataMap.getDataList(RestConstants.QUERY_BATCH_IDS_PARAM);
      if (batchIds == null)
      {
        batchKeys = null;
      }
      else if (batchIds.isEmpty())
      {
        batchKeys = Collections.emptySet();
      }
      else
      {
        batchKeys = new HashSet<Object>();

        // Validate the compound keys and put them into the contex batch keys
        for (Object compoundKey : batchIds)
        {
          if (!(compoundKey instanceof DataMap))
          {
            log.warn("Invalid structure of key '" + compoundKey.toString() + "', skipping key.");
            context.getBatchKeyErrors().put(compoundKey.toString(), new RestLiServiceException(HttpStatus.S_400_BAD_REQUEST));
            continue;
          }
          CompoundKey finalKey;
          try
          {
            finalKey = ArgumentUtils.dataMapToCompoundKey((DataMap) compoundKey, resource.getKeys());
          }
          catch (IllegalArgumentException e)
          {
            log.warn("Invalid structure of key '" + compoundKey.toString() + "', skipping key.");
            context.getBatchKeyErrors().put(compoundKey.toString(), new RestLiServiceException(HttpStatus.S_400_BAD_REQUEST));
            continue;
          }
          batchKeys.add(finalKey);
        }
      }
    }
    // collection batch get in v2, collection or association batch get in v1
    else if (context.hasParameter(RestConstants.QUERY_BATCH_IDS_PARAM))
    {
      batchKeys = new HashSet<Object>();

      List<String> ids = context.getParameterValues(RestConstants.QUERY_BATCH_IDS_PARAM);
      if (version.compareTo(AllProtocolVersions.RESTLI_PROTOCOL_2_0_0.getProtocolVersion()) >= 0)
      {
        for (String id: ids)
        {
          Key key = resource.getPrimaryKey();
          Object value;
View Full Code Here

  }

  private static Object parseKeyFromBatchV1(String value, ResourceModel resource)
    throws PathSegmentSyntaxException, IllegalArgumentException
  {
    ProtocolVersion version = AllProtocolVersions.RESTLI_PROTOCOL_1_0_0.getProtocolVersion();
    if (CompoundKey.class.isAssignableFrom(resource.getKeyClass()))
    {
      return ArgumentUtils.parseCompoundKey(value, resource.getKeys(), version);
    }
    else
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, UpdateStatus>) responseData.getBatchResponseMap(), protocolVersion);
    builder.entity(response);
View Full Code Here

  {
    RestLiServiceException result = (RestLiServiceException) object;
    ErrorResponse er = buildErrorResponse(result);
    if (_errorResponseFormat.showHeaders())
    {
      final ProtocolVersion protocolVersion = ProtocolVersionUtil.extractProtocolVersion(headers);
      headers.put(HeaderUtil.getErrorResponseHeaderName(protocolVersion), RestConstants.HEADER_VALUE_ERROR);
    }
    final ResourceMethod type;
    if (routingResult != null && routingResult.getResourceMethod() != null)
    {
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.