Examples of CreateResponse


Examples of com.linkedin.restli.server.CreateResponse

    // overwrite ID and URN in entity
    entity.setId(newId);
    entity.setUrn(String.valueOf(newId));
    _db.getData().put(newId, entity);
    return new CreateResponse(newId);
  }
View Full Code Here

Examples of com.linkedin.restli.server.CreateResponse

    // overwrite ID and URN in entity
    entity.setId(newId);
    entity.setUrn(String.valueOf(newId));
    _db.getData().put(newId, entity);
    return new CreateResponse(newId);
  }
View Full Code Here

Examples of com.linkedin.restli.server.CreateResponse

      Assert.assertEquals(e.getStatus().getCode(), 406);
    }
    // check response without body (expect 406 error)
    try
    {
      invokeResponseHandler("/test", new CreateResponse(HttpStatus.S_201_CREATED), ResourceMethod.CREATE,
                                                    badAcceptHeaders, AllProtocolVersions.LATEST_PROTOCOL_VERSION);
      Assert.fail();
    }
    catch (RestLiServiceException e)
    {
View Full Code Here

Examples of com.linkedin.restli.server.CreateResponse

    checkResponse(response, 200, 2, acceptTypeData.responseContentType, Status.class.getName(), null, true, errorResponseHeaderName);
    assertEquals(response.getEntity().asAvroString(), expectedStatus);

    // #2 create (with id)
    response = invokeResponseHandler("/test", new CreateResponse(1), ResourceMethod.CREATE, acceptTypeData.acceptHeaders, protocolVersion);
    checkResponse(response, 201, 3, null, null, null, false, errorResponseHeaderName);
    assertEquals(response.getHeader(RestConstants.HEADER_LOCATION), "/test/1");
    assertEquals(response.getHeader(idHeaderName), "1");

    // #2.1 create (without id)
    response = invokeResponseHandler("/test", new CreateResponse(HttpStatus.S_201_CREATED),
                                     ResourceMethod.CREATE, acceptTypeData.acceptHeaders,
                                     protocolVersion);
    checkResponse(response, 201, 1, null, null, null, false, errorResponseHeaderName);

    // #2.2 create (with id and slash at the end of uri)
    response = invokeResponseHandler("/test/", new CreateResponse(1), ResourceMethod.CREATE, acceptTypeData.acceptHeaders, protocolVersion);
    checkResponse(response, 201, 3, null, null, null, false, errorResponseHeaderName);
    assertEquals(response.getHeader(RestConstants.HEADER_LOCATION), "/test/1");
    assertEquals(response.getHeader(idHeaderName), "1");

    // #2.3 create (without id and slash at the end of uri)
    response = invokeResponseHandler("/test/", new CreateResponse(HttpStatus.S_201_CREATED),
                                     ResourceMethod.CREATE, acceptTypeData.acceptHeaders,
                                     protocolVersion);
    checkResponse(response, 201, 1, null, null, null, false, errorResponseHeaderName);

    // #3 update
View Full Code Here

Examples of com.linkedin.restli.server.CreateResponse

    response = invokeResponseHandler("/test", batchUpdateResult, ResourceMethod.BATCH_DELETE, acceptTypeData.acceptHeaders, protocolVersion);
    checkResponse(response, 200, 2, acceptTypeData.responseContentType, BatchResponse.class.getName(), UpdateStatus.class.getName(), true, errorResponseHeaderName);

    List<CreateResponse> createResponses = new ArrayList<CreateResponse>();
    createResponses.add(new CreateResponse("42", HttpStatus.S_204_NO_CONTENT));
    createResponses.add(new CreateResponse(HttpStatus.S_400_BAD_REQUEST));
    createResponses.add(new CreateResponse(HttpStatus.S_500_INTERNAL_SERVER_ERROR));
    BatchCreateResult<Long, Status> batchCreateResult = new BatchCreateResult<Long, Status>(createResponses);

    response = invokeResponseHandler("/test", batchCreateResult, ResourceMethod.BATCH_CREATE, acceptTypeData.acceptHeaders, protocolVersion); // here
    checkResponse(response, 200, 2, acceptTypeData.responseContentType, CollectionResponse.class.getName(), CreateStatus.class.getName(), true, errorResponseHeaderName);
  }
View Full Code Here

Examples of com.linkedin.restli.server.CreateResponse

  @Override
  public AugmentedRestLiResponseData buildRestLiResponseData(RestRequest request, RoutingResult routingResult,
                                                             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());
    }
    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)
                                                                                                     .headers(headers)
                                                                                                     .status(createResponse.getStatus())
                                                                                                     .build();
  }
View Full Code Here

Examples of com.linkedin.restli.server.CreateResponse

{
  @Test
  @SuppressWarnings("unchecked")
  public void testBuilder()
  {
    List<CreateResponse> createResponses = Arrays.asList(new CreateResponse(1L), new CreateResponse(2L));
    BatchCreateResult<Long, Foo> results =
        new BatchCreateResult<Long, Foo>(createResponses);
    Map<String, String> headers = getHeaders();

    ResourceMethodDescriptor mockDescriptor = getMockResourceMethodDescriptor();
View Full Code Here

Examples of com.linkedin.restli.server.CreateResponse

  @DataProvider(name = "testData")
  public Object[][] dataProvider()
  {
    return new Object[][]
        {
            {new BatchCreateResult<Long, Foo>(Arrays.asList(new CreateResponse(1L), null)),
                "Unexpected null encountered. Null element inside of List inside of a BatchCreateResult returned by the resource method: "},
            {new BatchCreateResult<Long, Foo>(null),
                "Unexpected null encountered. Null List inside of a BatchCreateResult returned by the resource method: "}
        };
  }
View Full Code Here

Examples of com.linkedin.restli.server.CreateResponse

  {
    entity.setId(_idSeq.incrementAndGet());
    _db.put(entity.getId(), entity);
    if (isNullId)
    {
      return new CreateResponse(null, HttpStatus.S_201_CREATED);
    }
    return new CreateResponse(entity.getId());
  }
View Full Code Here

Examples of com.linkedin.restli.server.CreateResponse

  @Override
  public CreateResponse create(Group group)
  {
    Group createdGroup = getGroupMgr().create(group);

    return new CreateResponse(createdGroup.getId());
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.