Package com.linkedin.restli.server

Examples of com.linkedin.restli.server.RestLiServiceException


    BatchCreateResult<?, ?> list = (BatchCreateResult<?, ?>) result;

    //Verify that a null list was not passed into the BatchCreateResult. If so, this is a developer error.
    if (list.getResults() == null)
    {
      throw new RestLiServiceException(HttpStatus.S_500_INTERNAL_SERVER_ERROR,
          "Unexpected null encountered. Null List inside of a BatchCreateResult returned by the resource method: " + routingResult
              .getResourceMethod());
    }

    List<CreateIdStatus<Object>> statuses = new ArrayList<CreateIdStatus<Object>>(list.getResults().size());
    for (CreateResponse e : list.getResults())
    {
      //Verify that a null element was not passed into the BatchCreateResult list. If so, this is a developer error.
      if (e == null)
      {
        throw new RestLiServiceException(HttpStatus.S_500_INTERNAL_SERVER_ERROR,
            "Unexpected null encountered. Null element inside of List inside of a BatchCreateResult returned by the resource method: "
                + routingResult.getResourceMethod());
      }
      statuses.add(new CreateIdStatus<Object>(e.getStatus().getCode(), e.getId(), e.getError() == null ? null
          : _errorResponseBuilder.buildErrorResponse(e.getError()), ProtocolVersionUtil.extractProtocolVersion(headers)));
View Full Code Here


  {
    UpdateResponse updateResponse = (UpdateResponse) result;
    //Verify that the status in the UpdateResponse is not null. If so, this is a developer error.
    if (updateResponse.getStatus() == null)
    {
      throw new RestLiServiceException(HttpStatus.S_500_INTERNAL_SERVER_ERROR,
          "Unexpected null encountered. HttpStatus is null inside of a UpdateResponse returned by the resource method: "
              + routingResult.getResourceMethod());
    }
    return new AugmentedRestLiResponseData.Builder(routingResult.getResourceMethod().getMethodType()).headers(headers)
                                                                                                     .status(updateResponse.getStatus())
View Full Code Here

    Map<CompoundKey, HttpStatus> statuses = new HashMap<CompoundKey, HttpStatus>();
    statuses.put(c1, HttpStatus.S_200_OK);
    statuses.put(c2, HttpStatus.S_200_OK);
    Map<CompoundKey, RestLiServiceException> exceptions = new HashMap<CompoundKey, RestLiServiceException>();
    exceptions.put(c3, new RestLiServiceException(HttpStatus.S_404_NOT_FOUND));
    BatchResult<CompoundKey, Foo> batchResult = new BatchResult<CompoundKey, Foo>(results, statuses, exceptions);
    Map<Object, RestLiServiceException> exceptionsWithUntypedKey = new HashMap<Object, RestLiServiceException>(exceptions);

    return new Object[][]
        {
View Full Code Here

      {
        batch.put(id, g);
      }
      else
      {
        errors.put(id, new RestLiServiceException(HttpStatus.S_404_NOT_FOUND));
      }
    }

    return new BatchResult<Long, Greeting>(batch, errors);
  }
View Full Code Here

  }

  @Action(name = "exceptionTest")
  public void exceptionTest()
  {
    throw new RestLiServiceException(HttpStatus.S_500_INTERNAL_SERVER_ERROR, "Test Exception");
  }
View Full Code Here

    ResourceMethodDescriptor mockDescriptor = getMockResourceMethodDescriptor();
    RoutingResult routingResult = new RoutingResult(null, mockDescriptor);

    RuntimeException runtimeException = new RuntimeException("Internal server error!");
    RestLiServiceException serviceException = new RestLiServiceException(HttpStatus.S_500_INTERNAL_SERVER_ERROR,
                                                                         runtimeException);

    ErrorResponseBuilder errorResponseBuilder = new ErrorResponseBuilder();
    AugmentedRestLiResponseData responseData = errorResponseBuilder.buildRestLiResponseData(null,
                                                                                            routingResult,
View Full Code Here

    for (Map.Entry<K, RestLiServiceException> serviceErrorEntry : serviceErrors.entrySet())
    {
      if (serviceErrorEntry.getKey() == null)
      {
        throw new RestLiServiceException(HttpStatus.S_500_INTERNAL_SERVER_ERROR,
            "Unexpected null encountered. Null key inside of the errors map returned by resource method: "
                + routingResult.getResourceMethod());
      }

      if (serviceErrorEntry.getValue() == null)
      {
        throw new RestLiServiceException(HttpStatus.S_500_INTERNAL_SERVER_ERROR,
            "Unexpected null encountered. Null value inside of the errors map returned by resource method: "
                + routingResult.getResourceMethod());
      }
      mergedErrors.put(serviceErrorEntry.getKey(), builder.buildErrorResponse(serviceErrorEntry.getValue()));
    }
View Full Code Here

        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;
          // in v2, compound keys have already been converted and dealt with, so all we need to do here is convert simple values.
          value = ArgumentUtils.convertSimpleValue(id, key.getDataSchema(), key.getType());
          batchKeys.add(value);
        }
      }
      else
      {
        for (String id: ids)
        {
          try
          {
            // in v1, compound keys have not been fully parsed or dealt with yet, so we need to take them into account.
            Object value = parseKeyFromBatchV1(id, resource);
            batchKeys.add(value);
          }
          catch (NumberFormatException e)
          {
            log.warn("Caught NumberFormatException parsing batch key '" + id + "', skipping key.");
            context.getBatchKeyErrors().put(id, new RestLiServiceException(HttpStatus.S_400_BAD_REQUEST, null, e));
          }
          catch (IllegalArgumentException e)
          {
            log.warn("Caught IllegalArgumentException parsing batch key '" + id + "', skipping key.");
            context.getBatchKeyErrors().put(id, new RestLiServiceException(HttpStatus.S_400_BAD_REQUEST, null, e));
          }
          catch (PathSegmentSyntaxException e)
          {
            log.warn("Caught IllegalArgumentException parsing batch key '" + id + "', skipping key.");
            context.getBatchKeyErrors().put(id,
                                            new RestLiServiceException(HttpStatus.S_400_BAD_REQUEST,
                                                                       null, e));
          }
        }
      }
    }
View Full Code Here

          (CollectionResult<? extends RecordTemplate, ? extends RecordTemplate>) object;

      //Verify that a null wasn't passed into the collection result. If so, this is a developer error.
      if (collectionResult.getElements() == null)
      {
        throw new RestLiServiceException(HttpStatus.S_500_INTERNAL_SERVER_ERROR,
            "Unexpected null encountered. Null elements List inside of CollectionResult returned by the resource method: "
                + routingResult.getResourceMethod());
      }

      return buildRestLiResponseData(request, routingResult, collectionResult.getElements(),
View Full Code Here

    for (RecordTemplate entry : elements)
    {
      //We don't permit null elements in our lists. If so, this is a developer error.
      if (entry == null)
      {
        throw new RestLiServiceException(HttpStatus.S_500_INTERNAL_SERVER_ERROR,
            "Unexpected null encountered. Null element inside of a List returned by the resource method: " + routingResult
                .getResourceMethod());
      }
      processedElements.add(new AnyRecord(RestUtils
          .projectFields(entry.data(), resourceContext.getProjectionMode(), resourceContext.getProjectionMask())));
View Full Code Here

TOP

Related Classes of com.linkedin.restli.server.RestLiServiceException

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.