Example usage for org.springframework.http HttpStatus CREATED

List of usage examples for org.springframework.http HttpStatus CREATED

Introduction

In this page you can find the example usage for org.springframework.http HttpStatus CREATED.

Prototype

HttpStatus CREATED

To view the source code for org.springframework.http HttpStatus CREATED.

Click Source Link

Document

201 Created .

Usage

From source file:com.tamnd2.basicwebapp.rest.mvc.BlogController.java

@RequestMapping(value = "/{blogId}/blog-entries", method = RequestMethod.POST)
public ResponseEntity<BlogEntryResource> createBlogEntry(@PathVariable Long blogId,
        @RequestBody BlogEntryResource sentBlogEntry) {
    BlogEntry createdBlogEntry = null;//from  ww w.j  a v a 2  s . c  o m
    try {
        createdBlogEntry = blogService.createBlogEntry(blogId, sentBlogEntry.toBlogEntry());
        BlogEntryResource createdResource = new BlogEntryResourceAsm().toResource(createdBlogEntry);
        HttpHeaders headers = new HttpHeaders();
        headers.setLocation(URI.create(createdResource.getLink("self").getHref()));
        return new ResponseEntity<BlogEntryResource>(createdResource, headers, HttpStatus.CREATED);
    } catch (BlogNotFoundException e) {
        throw new NotFoundException(e);
    }
}

From source file:io.curly.gathering.item.ItemControllerTests.java

@Test
public void testAddItem() throws Exception {
    this.mvc.perform(asyncDispatch(this.mvc
            .perform(post("/lists/{listId}/add/artifact", this.list.getId())
                    .principal(User.builder().id("6969").build()).accept(MediaType.APPLICATION_JSON)
                    .contentType(MediaType.APPLICATION_JSON)
                    .content(new ObjectMapper().writeValueAsBytes(body)))
            .andExpect(request().asyncStarted())
            .andExpect(request().asyncResult(new ResponseEntity<>(HttpStatus.CREATED))).andReturn()));
}

From source file:de.zib.gndms.gndmc.dspace.Test.SubspaceClientTest.java

@Test(groups = { "subspaceServiceTest" })
public void testCreateSubspace() {
    final String mode = "CREATE";

    ResponseEntity<Facets> subspace = null;
    try {/*from   w w w.  j  a va2s  . c  om*/
        subspace = subspaceClient.createSubspace(subspaceId, subspaceConfig, admindn);

        Assert.assertNotNull(subspace);
        Assert.assertEquals(subspace.getStatusCode(), HttpStatus.CREATED);
    } catch (HttpClientErrorException e) {
        if (!e.getStatusCode().equals(HttpStatus.UNAUTHORIZED))
            throw e;
    }

    final ResponseEntity<Facets> res = subspaceClient.listAvailableFacets(subspaceId, admindn);
    Assert.assertNotNull(res);
    Assert.assertEquals(res.getStatusCode(), HttpStatus.OK);
}

From source file:io.github.howiefh.jeews.modules.oauth2.controller.ClientController.java

@RequiresPermissions("clients:create")
@RequestMapping(value = "", method = RequestMethod.POST)
public ResponseEntity<ClientResource> create(HttpEntity<Client> entity, HttpServletRequest request)
        throws URISyntaxException {
    Client Client = entity.getBody();/*from   w w w  .  j  a  va2 s  .c o  m*/
    clientService.save(Client);
    HttpHeaders headers = new HttpHeaders();
    ClientResource ClientResource = new ClientResourceAssembler().toResource(Client);
    headers.setLocation(entityLinks.linkForSingleResource(Client.class, Client.getId()).toUri());
    ResponseEntity<ClientResource> responseEntity = new ResponseEntity<ClientResource>(ClientResource, headers,
            HttpStatus.CREATED);
    return responseEntity;
}

From source file:at.ac.tuwien.dsg.cloud.utilities.gateway.registry.UserController.java

@RequestMapping(method = RequestMethod.PUT, value = REST_USER_PATH_VARIABLE)
public ResponseEntity<String> register(@PathVariable String user) {

    RequestEntity<KongUserCreateDto> request = RequestEntity
            .post(URI.create(this.kongUris.getKongConsumersUri())).contentType(MediaType.APPLICATION_JSON)
            .body(KongUserCreateDto.build(user));

    ResponseEntity<KongUser> resp = restUtilities.simpleRestExchange(request, KongUser.class);

    if (resp == null || resp.getStatusCode() != HttpStatus.CREATED) {
        return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
    }/*from   www  .  ja v a  2 s  .  c  om*/

    KongUser kongUser = resp.getBody();
    kongUser.setKey(kongService.createKeyForUser(kongUser.getUserName()));

    if (kongUser.getKey() == null) {
        return new ResponseEntity<>("User was created but key generation failed!",
                HttpStatus.FAILED_DEPENDENCY);
    }

    this.kongUsers.getUsers().add(kongUser);
    return new ResponseEntity(kongUser.getKey().getKey(), HttpStatus.OK);
}

From source file:fr.esiea.windmeal.controller.crud.CrudOrderCtrl.java

@Secured("ROLE_USER")
@RequestMapping(method = RequestMethod.POST, consumes = "application/json;charset=UTF-8")
@ResponseStatus(HttpStatus.CREATED)
public void create(@RequestBody Order order) throws ServiceException, DaoException {

    LOGGER.info("[Controller] Querying to create new order : " + order.toString() + "\"");
    crudValidationService.insert(order);
}

From source file:com.itn.webservices.AdminControllerWebservice.java

@RequestMapping(value = "/food", method = RequestMethod.POST)
public ResponseEntity<Void> createFood(@RequestBody FoodInventory food, UriComponentsBuilder ucBuilder) {
    logger.info("Creating Food " + food.getFoodName());

    if (foodInventoryService.isFoodExist(food)) {
        logger.info("A Food already exist");
        return new ResponseEntity<Void>(HttpStatus.CONFLICT);
    }/*ww  w .  j ava2 s  .  c  o  m*/

    foodInventoryService.save(food);

    HttpHeaders headers = new HttpHeaders();
    headers.setLocation(ucBuilder.path("/food/{id}").buildAndExpand(food.getId()).toUri());
    return new ResponseEntity<Void>(headers, HttpStatus.CREATED);
}

From source file:de.fhg.fokus.nubomedia.paas.VNFRServiceImpl.java

/**
 * Registers a new App to the VNFR with a specific VNFR ID
 *    /*from   w  w  w. j a v a 2  s.  c om*/
 * @param externalAppId - application identifier
 * @param points - capacity
 */
public ApplicationRecord registerApplication(String externalAppId, int points)
        throws NotEnoughResourcesException {
    try {
        if (serviceProfile == null) {
            logger.info("Service Profile not set. make sure the VNFR_ID, VNFM_IP and VNFM_PORT are available ");
            return null;
        }
        String URL = serviceProfile.getServiceApiUrl();
        ApplicationRecordBody bodyObj = new ApplicationRecordBody(externalAppId, points);
        Gson mapper = new GsonBuilder().create();
        String body = mapper.toJson(bodyObj, ApplicationRecordBody.class);

        logger.info("registering new application: \nURL: " + URL + "\n + " + body);
        HttpHeaders creationHeader = new HttpHeaders();
        creationHeader.add("Accept", "application/json");
        creationHeader.add("Content-type", "application/json");

        HttpEntity<String> registerEntity = new HttpEntity<String>(body, creationHeader);
        ResponseEntity response = restTemplate.exchange(URL, HttpMethod.POST, registerEntity, String.class);

        logger.info("response from VNFM " + response);
        HttpStatus status = response.getStatusCode();
        if (status.equals(HttpStatus.CREATED) || status.equals(HttpStatus.OK)) {
            logger.info("Deployment status: " + status + " response: " + response);
            ApplicationRecord responseBody = mapper.fromJson((String) response.getBody(),
                    ApplicationRecord.class);

            logger.info("returned object " + responseBody.toString());
            return responseBody;
        } else if (status.equals(HttpStatus.UNPROCESSABLE_ENTITY)) {

            throw new NotEnoughResourcesException("Not enough resource " + response.getBody());
        }
    } catch (NotEnoughResourcesException e) {
        logger.error(e.getMessage());
    } catch (RestClientException e) {
        logger.error("Error registering application to VNFR - " + e.getMessage());
    }
    return null;
}

From source file:de.thm.arsnova.controller.FeedbackController.java

@DeprecatedApi
@RequestMapping(value = "/session/{sessionkey}/feedback", method = RequestMethod.POST)
@ResponseStatus(HttpStatus.CREATED)
public Feedback postFeedback(@PathVariable final String sessionkey, @RequestBody final int value) {
    User user = userService.getCurrentUser();
    if (feedbackService.saveFeedback(sessionkey, value, user)) {
        Feedback feedback = feedbackService.getFeedback(sessionkey);
        if (feedback != null) {
            return feedback;
        }/*from   ww  w .  j a  v  a  2  s. c  om*/
        throw new RuntimeException();
    }

    throw new NotFoundException();
}

From source file:plbtw.klmpk.barang.hilang.controller.KategoriBarangController.java

@RequestMapping(method = RequestMethod.DELETE, produces = "application/json")
public CustomResponseMessage deleteKategoriBarang(@RequestBody KategoriBarangRequest kategoriBarangRequest) {
    try {//  w  w  w .  j  av  a 2 s .c  o m
        kategoriBarangService.deleteKategoriBarang(kategoriBarangRequest.getId());
        return new CustomResponseMessage(HttpStatus.CREATED, "Delete Kategori Barang Succesfull");
    } catch (Exception ex) {
        return new CustomResponseMessage(HttpStatus.BAD_REQUEST, ex.toString());
    }
}