Package com.linkedin.restli.server

Examples of com.linkedin.restli.server.RestLiServiceException


    final Map<Object, UpdateResponse> updates = updateResult.getResults();
    //Verify the map is not null. If so, this is a developer error.
    if (updates == null)
    {
      throw new RestLiServiceException(HttpStatus.S_500_INTERNAL_SERVER_ERROR,
          "Unexpected null encountered. Null Map found inside of the BatchUpdateResult returned by the resource method: "
              + routingResult.getResourceMethod());
    }
    //Verify that there is no null key in the map. If so, this is a developer error.
    if (updates.containsKey(null))
    {
      throw new RestLiServiceException(HttpStatus.S_500_INTERNAL_SERVER_ERROR,
          "Unexpected null encountered. Null key inside of the Map returned inside of the BatchUpdateResult returned by the resource method: "
              + routingResult.getResourceMethod());
    }

    final Map<Object, RestLiServiceException> serviceErrors = updateResult.getErrors();
    //Verify the errors map is not null. If so, this is a developer error.
    //Note that we don't have to check the errors map for nulls, because its taken care
    //of in populateErrors below.
    if (serviceErrors == null)
    {
      throw new RestLiServiceException(HttpStatus.S_500_INTERNAL_SERVER_ERROR,
          "Unexpected null encountered. Null errors Map found inside of the BatchUpdateResult returned by the resource method: "
              + routingResult.getResourceMethod());
    }

    final Map<Object, ErrorResponse> errors =
View Full Code Here


  @Override
  public AugmentedRestLiResponseData buildRestLiResponseData(RestRequest request, RoutingResult routingResult,
                                                             Object object, Map<String, String> headers)
  {
    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)
    {
      type = routingResult.getResourceMethod().getMethodType();
    }
    else
    {
      type = null;
    }
    return new AugmentedRestLiResponseData.Builder(type).headers(headers).status(result.getStatus()).errorResponse(er)
                                                        .build();
  }
View Full Code Here

      final ActionResult<?> actionResult = (ActionResult<?>) result;
      value = actionResult.getValue();
      status = actionResult.getStatus();
      if (status == null)
      {
        throw new RestLiServiceException(HttpStatus.S_500_INTERNAL_SERVER_ERROR,
            "Unexpected null encountered. Null HttpStatus inside of an ActionResult returned by the resource method: "
                + routingResult.getResourceMethod());
      }
    }
    else
View Full Code Here

    Map<Object, RestLiServiceException> serviceErrors = Collections.emptyMap();

    //Verify that there is no null key inside any of the maps. If so, this is a developer error.
    if (entities.containsKey(null))
    {
      throw new RestLiServiceException(HttpStatus.S_500_INTERNAL_SERVER_ERROR,
          "Unexpected null encountered. Null key inside of the Map returned by the resource method: " + routingResult
              .getResourceMethod());
    }

    if (result instanceof BatchResult)
    {
      @SuppressWarnings({ "unchecked" })
      /** constrained by signature of {@link com.linkedin.restli.server.resources.CollectionResource#batchGet(java.util.Set)} */
      final BatchResult<Object, RecordTemplate> batchResult = (BatchResult<Object, RecordTemplate>) result;
      statuses = batchResult.getStatuses();
      //We only need to check the statuses map here inside of BatchResult, otherwise it would be an empty map.
      if (statuses.containsKey(null))
      {
        throw new RestLiServiceException(HttpStatus.S_500_INTERNAL_SERVER_ERROR,
            "Unexpected null encountered. Null key inside of the status map returned by the resource method: " + routingResult
                .getResourceMethod());
      }
      //Note that we don't have to check the service errors map for nulls, because its taken care
      //of in populateErrors below.
View Full Code Here

   * An example action throwing an exception.
   */
  @Action(name = "exceptionTest")
  public void exceptionTest()
  {
    throw new RestLiServiceException(HttpStatus.S_500_INTERNAL_SERVER_ERROR, "Test Exception");
  }
View Full Code Here

    }
    // Handle the case when an accept MIME type that was passed in along with the
    // request is invalid.
    catch (InvalidMimeTypeException e)
    {
      throw new RestLiServiceException(HttpStatus.S_400_BAD_REQUEST,
                                       String.format("Encountered invalid MIME type '%s' in accept header.",
                                                     e.getType()));
    }
  }
View Full Code Here

    // Validate whether the accept headers have at least one type that we support.
    // Fail the validation if we will be unable to support the requested accept type.
    String mimeType = pickBestEncoding(headers.get(RestConstants.HEADER_ACCEPT));
    if (StringUtils.isEmpty(mimeType))
    {
      throw new RestLiServiceException(HttpStatus.S_406_NOT_ACCEPTABLE,
                                       "None of the types in the request's 'Accept' header are supported. Supported MIME types are: "
                                           + RestConstants.SUPPORTED_MIME_TYPES);
    }
    else
    {
View Full Code Here

        //addListener requires Task<Object> in this case
        @SuppressWarnings("unchecked")
        Task<Object> task = (Task<Object>) method.invoke(resource, arguments);
        if (task == null)
        {
          callback.onError(new RestLiServiceException(HttpStatus.S_500_INTERNAL_SERVER_ERROR,
                                                           "Error in application code: null Task"),
                              getRequestExecutionReport(requestExecutionReportBuilder));
        }
        else
        {
          task.addListener(new CallbackPromiseAdapter<Object>(callback, task, requestExecutionReportBuilder));
          _engine.run(task);
        }
        break;

      default:
          throw new AssertionError("Unexpected interface type "
              + descriptor.getInterfaceType());
      }
    }
    catch (InvocationTargetException e)
    {
      if (RestLiServiceException.class.isAssignableFrom(e.getCause().getClass()))
      {
        RestLiServiceException restLiServiceException =
            (RestLiServiceException) e.getCause();
        callback.onError(restLiServiceException, getRequestExecutionReport(requestExecutionReportBuilder));
      }
      else
      {
        callback.onError(new RestLiServiceException(HttpStatus.S_500_INTERNAL_SERVER_ERROR,
                                                       _errorResponseBuilder.getInternalErrorMessage(),
                                                       e.getCause()),
                            getRequestExecutionReport(requestExecutionReportBuilder));
      }
    }
View Full Code Here

              + "Check your RestLiServer construction, spring wiring, "
              + "and container-pegasus-restli-server-cmpt version.";
      final String clazz = desc.getResourceModel().getResourceClass().getName();
      final String method = desc.getMethod().getName();
      final String msg = String.format(fmt, clazz, method);
      callback.onError(new RestLiServiceException(HttpStatus.S_500_INTERNAL_SERVER_ERROR,
                                                  msg),
                       getRequestExecutionReport(executionReportBuilder));
      return false;
    }
    else
View Full Code Here

          _arguments[_contextIndex] = context;
        }
        Object applicationResult = _method.invoke(_resource, _arguments);
        if (applicationResult == null)
        {
          return Promises.error(new RestLiServiceException(HttpStatus.S_500_INTERNAL_SERVER_ERROR,
                                                           "Error in application code: null Promise"));
        }
        // TODO Should we guard against incorrectly returning a task that has no way of
        // starting?
        return (Promise<?>) applicationResult;
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.