Package com.linkedin.restli.server

Examples of com.linkedin.restli.server.RestLiServiceException


    long photoId = (Long) key.getPart("photoId");
    long albumId = (Long) key.getPart("albumId");

    // make sure photo and album exist
    if (!_photoDb.getData().containsKey(photoId))
      throw new RestLiServiceException(HttpStatus.S_400_BAD_REQUEST,
                                       "Nonexistent photo ID: " + photoId);
    if (!_albumDb.getData().containsKey(albumId))
      throw new RestLiServiceException(HttpStatus.S_400_BAD_REQUEST,
                                       "Nonexistent album ID: " + albumId);

    // disallow changing entity ID
    if (entity.hasAlbumId() || entity.hasPhotoId())
      throw new RestLiServiceException(HttpStatus.S_400_BAD_REQUEST,
                                       "Photo/album ID are not acceptable in request");

    // make sure the ID in the entity is consistent with the key in the database
    entity.setPhotoId(photoId);
    entity.setAlbumId(albumId);
View Full Code Here


  {
    final Long newId = _db.getCurrentId();

    if (entity.hasId() || entity.hasUrn())
    {
      throw new RestLiServiceException(HttpStatus.S_400_BAD_REQUEST,
                                       "Album ID is not acceptable in request");
    }

    // overwrite ID and URN in entity
    entity.setId(newId);
View Full Code Here

    }

    // disallow changing entity ID and URN
    if (entity.hasId() || entity.hasUrn())
    {
      throw new RestLiServiceException(HttpStatus.S_400_BAD_REQUEST,
                                       "Album ID is not acceptable in request");
    }

    // make sure the ID in the entity is consistent with the key in the database
    entity.setId(key);
View Full Code Here

            if (greeting.hasTone())
            {
              Tone tone = greeting.getTone();
              if (tone == Tone.INSULTING)
              {
                throw new RestLiServiceException(REQ_FILTER_ERROR_STATUS, REQ_FILTER_ERROR_MESSAGE);
              }
              greeting.setTone(mapToneForIncomingRequest(tone));
            }
          }
        }
View Full Code Here

  {
    final Long newId = _db.getCurrentId();

    if (entity.hasId() || entity.hasUrn())
    {
      throw new RestLiServiceException(HttpStatus.S_400_BAD_REQUEST,
                                       "Photo ID is not acceptable in request");
    }

    // overwrite ID and URN in entity
    entity.setId(newId);
View Full Code Here

      {
        result.put(key, get(key));
      }
      else
      {
        errors.put(key, new RestLiServiceException(HttpStatus.S_404_NOT_FOUND,
                                                   "No photo with id=" + key
                                                       + " has been found."));
      }
    }
    return new BatchResult<Long, Photo>(result, errors);
View Full Code Here

    }

    // disallow changing entity ID and URN
    if (entity.hasId() || entity.hasUrn())
    {
      throw new RestLiServiceException(HttpStatus.S_400_BAD_REQUEST,
                                       "Photo ID is not acceptable in request");
    }

    // make sure the ID in the entity is consistent with the key in the database
    entity.setId(key);
View Full Code Here

  void testRestErrors(AcceptTypeData acceptTypeData,
                      ProtocolVersion protocolVersion,
                      String errorResponseHeaderName) throws Exception
  {
    RestResponse response;
    RestLiServiceException ex;
    final RestRequest request = buildRequest(acceptTypeData.acceptHeaders, protocolVersion);

    // #1
    ex = new RestLiServiceException(HttpStatus.S_400_BAD_REQUEST, "missing fields");
    response = _responseHandler.buildResponse(request,
                                              buildRoutingResult(request, acceptTypeData.acceptHeaders),
                                              ex);

    checkResponse(response, 400, 3, acceptTypeData.responseContentType, ErrorResponse.class.getName(), null, true, true, errorResponseHeaderName);
    DataMap dataMap = acceptTypeData.dataCodec.readMap(response.getEntity().asInputStream());

    assertEquals(dataMap.getInteger("status"), Integer.valueOf(400));
    assertEquals(dataMap.getString("message"), "missing fields");

    // #2
    ex = new RestLiServiceException(HttpStatus.S_400_BAD_REQUEST, "missing fields").setServiceErrorCode(11);
    response = _responseHandler.buildResponse(request,
                                              buildRoutingResult(request, acceptTypeData.acceptHeaders),
                                              ex);

    checkResponse(response, 400, 3, acceptTypeData.responseContentType, ErrorResponse.class.getName(), null, true, true, errorResponseHeaderName);
View Full Code Here

        return new AugmentedRestLiResponseData.Builder(routingResult.getResourceMethod().getMethodType())
            .status(HttpStatus.S_200_OK).headers(responseHeaders).build();
      }
      else if (routingResult.getResourceMethod().getType().equals(ResourceMethod.GET))
      {
        throw new RestLiServiceException(HttpStatus.S_404_NOT_FOUND,
            "Requested entity not found: " + routingResult.getResourceMethod());
      }
      else
      {
        //All other cases do not permit null to be returned
        throw new RestLiServiceException(HttpStatus.S_500_INTERNAL_SERVER_ERROR,
            "Unexpected null encountered. Null returned by the resource method: " + routingResult.getResourceMethod());
      }
    }

    RestLiResponseBuilder responseBuilder = chooseResponseBuilder(responseObject, routingResult);
View Full Code Here

    IdResponse<?> idResponse = new IdResponse<Object>(createResponse.getId());

    //Verify that a null status was not passed into the CreateResponse. If so, this is a developer error.
    if (createResponse.getStatus() == null)
    {
      throw new RestLiServiceException(HttpStatus.S_500_INTERNAL_SERVER_ERROR,
          "Unexpected null encountered. HttpStatus is null inside of a CreateResponse from the resource method: "
              + routingResult.getResourceMethod());
    }

    return new AugmentedRestLiResponseData.Builder(routingResult.getResourceMethod().getMethodType()).entity(idResponse)
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.