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.tsg.cms.StaticPageController.java

@RequestMapping(value = "/staticPageOrder/{id}", method = RequestMethod.PUT)
@ResponseStatus(HttpStatus.CREATED)
@ResponseBody//from   ww  w. j  a v  a 2s.  c  o m
public List<StaticPage> updatePageOrder(@PathVariable("id") int id, @RequestBody StaticPage staticPage) {
    staticPage.setSideBarPosition(id);
    staticPageDao.updateStaticPage(staticPage);

    return staticPageDao.getAllStaticPages();
}

From source file:io.github.microcks.web.DynamicMockRestController.java

@RequestMapping(value = "/{service}/{version}/{resource}", method = RequestMethod.POST)
public ResponseEntity<String> createResource(@PathVariable("service") String serviceName,
        @PathVariable("version") String version, @PathVariable("resource") String resource,
        @RequestParam(value = "delay", required = false) Long delay, @RequestBody(required = true) String body,
        HttpServletRequest request) {//from w w  w. j a  va2  s .  c o  m
    log.debug("Creating a new resource '{}' for service '{}-{}'", resource, serviceName, version);
    long startTime = System.currentTimeMillis();

    MockContext mockContext = getMockContext(serviceName, version, "POST /" + resource);
    if (mockContext != null) {
        Document document = null;
        GenericResource genericResource = null;

        try {
            // Try parsing body payload that should be json.
            document = Document.parse(body);
            // Now create a generic resource.
            genericResource = new GenericResource();
            genericResource.setServiceId(mockContext.service.getId());
            genericResource.setPayload(document);

            genericResource = genericResourceRepository.save(genericResource);
        } catch (JsonParseException jpe) {
            // Return a 422 code : unprocessable entity.
            return new ResponseEntity<>(HttpStatus.UNPROCESSABLE_ENTITY);
        }

        // Append id and wait if specified before returning.
        document.append(ID_FIELD, genericResource.getId());
        waitForDelay(startTime, delay, mockContext);
        return new ResponseEntity<>(document.toJson(), HttpStatus.CREATED);
    }
    // Return a 400 code : bad request.
    return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
}

From source file:org.fineract.module.stellar.controller.BridgeController.java

@RequestMapping(value = "", method = RequestMethod.POST, consumes = { "application/json" }, produces = {
        "application/json" })
@Transactional/*from   w  w w  .  j  a  v  a2 s .c o m*/
public ResponseEntity<String> createStellarBridgeConfiguration(
        @RequestBody final AccountBridgeConfiguration stellarBridgeConfig) {
    if (stellarBridgeConfig.getMifosTenantId() == null || stellarBridgeConfig.getMifosToken() == null
            || stellarBridgeConfig.getEndpoint() == null) {
        return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
    }

    try {
        StellarAddress.parse(stellarBridgeConfig.getMifosTenantId() + "*some-syntactically-valid-domain.com");
    } catch (final InvalidStellarAddressException e) {
        return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
    }

    final String newApiKey = this.securityService.generateApiKey(stellarBridgeConfig.getMifosTenantId());

    bridgeService.createStellarBridgeConfig(stellarBridgeConfig.getMifosTenantId(),
            stellarBridgeConfig.getMifosToken(), stellarBridgeConfig.getEndpoint());

    return new ResponseEntity<>(newApiKey, HttpStatus.CREATED);
}

From source file:su90.mybatisdemo.web.endpoints.EmployeesEndpoints.java

@RequestMapping(value = "/set/", method = RequestMethod.POST, consumes = {
        MediaType.APPLICATION_JSON_UTF8_VALUE }, produces = { MediaType.TEXT_PLAIN_VALUE })
@ApiOperation(value = "create one employee if possible")
public ResponseEntity<Void> createEmployee(@RequestBody EmployeeIn employeeIn) {
    if (employeeIn.email == null) {
        return new ResponseEntity<>(HttpStatus.NOT_ACCEPTABLE);
    }/*from w  w w  .  j  av  a  2 s .  c o m*/
    if (employeesService.hasEntityWithEmail(employeeIn.email)) {
        return new ResponseEntity<>(HttpStatus.CONFLICT);
    }

    if (employeeIn.job_id != null && jobsService.getEntryById(employeeIn.job_id) == null) {
        return new ResponseEntity<>(HttpStatus.NOT_ACCEPTABLE);
    }

    if (employeeIn.manager_id != null && employeesService.getEntryById(employeeIn.manager_id) == null) {
        return new ResponseEntity<>(HttpStatus.NOT_ACCEPTABLE);
    }

    if (employeeIn.department_id != null && departmentsService.getEntryById(employeeIn.department_id) == null) {
        return new ResponseEntity<>(HttpStatus.NOT_ACCEPTABLE);
    }

    Long thekey = employeesService.saveEntry(employeeIn.getDomain());

    if (thekey != null) {
        HttpHeaders headers = new HttpHeaders();
        headers.setLocation(
                UriUtils.generateUri(MvcUriComponentsBuilder.on(EmployeesEndpoints.class).getOne(thekey)));
        return new ResponseEntity<>(headers, HttpStatus.CREATED);
    } else {
        return new ResponseEntity<>(HttpStatus.NOT_ACCEPTABLE);
    }

}

From source file:web.ClientsRESTController.java

/**
 * Adds a client to the database through a REST API
 * @param client/*  w w w . jav a2s .  c  om*/
 * @param ucBuilder
 * @return
 */
@RequestMapping(value = "/api/clients/", method = RequestMethod.POST)
public ResponseEntity<Void> addClient(@RequestBody Clients client, UriComponentsBuilder ucBuilder) {
    dao.addClient(client);
    //returns newly added Client info
    HttpHeaders headers = new HttpHeaders();
    headers.setLocation(
            ucBuilder.path("/api/clients/clientinfo/{id}").buildAndExpand(client.getClientid()).toUri());
    return new ResponseEntity<Void>(headers, HttpStatus.CREATED);
}

From source file:com.epam.ta.reportportal.ws.controller.impl.ExternalSystemController.java

@Override
@RequestMapping(method = RequestMethod.POST, consumes = { APPLICATION_JSON_VALUE })
@ResponseBody/* www.  java 2s .c o  m*/
@PreAuthorize(PROJECT_LEAD)
@ResponseStatus(HttpStatus.CREATED)
@ApiOperation("Register external system instance")
public EntryCreatedRS createExternalSystemInstance(@Validated @RequestBody CreateExternalSystemRQ createRQ,
        @PathVariable String projectName, Principal principal) {
    return createExternalSystemHandler.createExternalSystem(createRQ,
            EntityUtils.normalizeProjectName(projectName), principal.getName());
}

From source file:com.tsguild.upsproject.controller.HomeController.java

@ResponseBody
@ResponseStatus(HttpStatus.CREATED)
@RequestMapping(value = "/package", method = RequestMethod.POST)
public Box addPackage(@RequestBody Box incomingPackage) {
    dao.addBox(incomingPackage);//  ww w  . j  ava2  s .  c om
    return incomingPackage;
}

From source file:be.boyenvaesen.Humidity.HumidityControllerTest.java

@Test
public void testScenarioPostOneGetList() {
    //Set up date that will be posted
    Date date = new Date();
    Calendar cal = Calendar.getInstance();
    cal.setTime(date);/*from   w  w  w  .  j av  a  2 s .  c om*/
    cal.add(Calendar.MINUTE, 15); // add 10 minutes
    Date postedDate = cal.getTime();

    //Check if list is the list from setup
    ResponseEntity<Humidity[]> responseEntity = restTemplate.getForEntity("/humidity", Humidity[].class);
    assertEquals(HttpStatus.OK, responseEntity.getStatusCode());
    Humidity[] humidities = responseEntity.getBody();

    assertEquals(75.1f, humidities[0].getPercentage(), MAX_ASSERT_FLOAT_OFFSET);
    assertEquals(80f, humidities[1].getPercentage(), MAX_ASSERT_FLOAT_OFFSET);
    assertEquals(2, humidities.length);

    //Post a new Humidity
    ResponseEntity<Humidity> postedEntity = restTemplate.postForEntity("/humidity",
            new postObject<>(95f, postedDate), Humidity.class);
    Humidity postedHumidity = postedEntity.getBody();
    assertEquals(HttpStatus.CREATED, postedEntity.getStatusCode());
    assertEquals(95f, postedHumidity.getPercentage(), MAX_ASSERT_FLOAT_OFFSET);

    //Check if list is now changed with the new value
    responseEntity = restTemplate.getForEntity("/humidity", Humidity[].class);
    assertEquals(HttpStatus.OK, responseEntity.getStatusCode());
    humidities = responseEntity.getBody();
    //Check humidity percentages
    assertEquals(75.1f, humidities[0].getPercentage(), MAX_ASSERT_FLOAT_OFFSET);
    assertEquals(postedHumidity.getPercentage(), humidities[humidities.length - 1].getPercentage(),
            MAX_ASSERT_FLOAT_OFFSET);
    assertEquals(95f, humidities[humidities.length - 1].getPercentage(), MAX_ASSERT_FLOAT_OFFSET);
    //Check humidity dates
    assertEquals(postedHumidity.getMeasured().getTime(),
            humidities[humidities.length - 1].getMeasured().getTime(), MAX_ASSERT_DATE_MILLISECONDS_OFFSET);
    assertEquals(postedDate.getTime(), humidities[humidities.length - 1].getMeasured().getTime(),
            MAX_ASSERT_DATE_MILLISECONDS_OFFSET);
    //Check list length
    assertEquals(3, humidities.length);

}

From source file:org.avidj.zuul.rs.ZuulTest.java

@Test
public void itShallCreateShallowWriteLock() {
    final Zuul zuul = createZuul();
    given().standaloneSetup(zuul).param("t", "w").param("s", "s").when().put("/s/1/a/b").then()
            .statusCode(HttpStatus.CREATED.value());
    given().standaloneSetup(zuul).when().get("/s/1/").then().statusCode(HttpStatus.OK.value()).and()
            .body("key", hasItem(Arrays.asList("a", "b"))).and().body("session", hasItem("1")).and()
            .body("type", hasItem("WRITE")).and().body("scope", hasItem("SHALLOW")).and()
            .body("count", hasItem(1));
}

From source file:de.sainth.recipe.backend.rest.controller.RecipeController.java

@Secured({ "ROLE_USER", "ROLE_ADMIN" })
@RequestMapping(method = RequestMethod.POST)
HttpEntity<Recipe> add(@Valid @RequestBody Recipe recipe) {
    Recipe r = repository.save(recipe);/*www.jav a 2s . com*/
    return new ResponseEntity<>(r, HttpStatus.CREATED);
}