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:edu.eci.arsw.kalendan.controllers.ProjectResourceController.java

@RequestMapping(method = RequestMethod.POST)
public ResponseEntity<?> projectPostRecursoActividad(@RequestBody Activity a) {
    try {// w  w w  . j a v a2 s  . c o m
        pj.registrarActividad(a);
        return new ResponseEntity<>(HttpStatus.CREATED);

    } catch (Exception e) {
        Logger.getLogger(ProjectResourceController.class.getName()).log(Level.SEVERE, null, e);
        return new ResponseEntity<>("Actividad no creada!", HttpStatus.FORBIDDEN);
    }

}

From source file:com.salmon.security.xacml.demo.springmvc.rest.controller.MarketPlacePopulatorController.java

@RequestMapping(method = RequestMethod.POST, consumes = "application/json", produces = "application/json", value = "driveradd")
@ResponseStatus(HttpStatus.CREATED)
@ResponseBody//ww w  . java 2  s  .com
public ResponseEntity<Driver> createDriver(@RequestBody Driver driver, UriComponentsBuilder builder) {

    marketPlaceController.registerDriver(driver);

    HttpHeaders headers = new HttpHeaders();

    URI newDriverLocation = builder.path("/aggregators/dvla/drivers/{license}")
            .buildAndExpand(driver.getDriversLicense()).toUri();

    LOG.info("REST CREATE DRIVER - new driver @ " + newDriverLocation.toString());

    headers.setLocation(newDriverLocation);

    Driver newDriver = marketPlaceController.getDriverDetails(driver.getDriversLicense());

    return new ResponseEntity<Driver>(newDriver, headers, HttpStatus.CREATED);
}

From source file:org.openbaton.autoscaling.api.RestElasticityManagementInterface.java

/**
 * Activates autoscaling for the passed NSR
 *
 * @param msg : NSR in payload to add for autoscaling
 *//*ww w .  jav  a2 s. c o m*/
@RequestMapping(value = "INSTANTIATE_FINISH", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseStatus(HttpStatus.CREATED)
public void activate(@RequestBody String msg) throws NotFoundException, VimException {
    log.trace("msg=" + msg);
    JsonParser jsonParser = new JsonParser();
    JsonObject json = jsonParser.parse(msg).getAsJsonObject();
    Gson mapper = new GsonBuilder().create();
    Action action = mapper.fromJson(json.get("action"), Action.class);
    log.trace("ACTION=" + action);
    NetworkServiceRecord nsr = mapper.fromJson(json.get("payload"), NetworkServiceRecord.class);
    log.trace("NSR=" + nsr);
    elasticityManagement.activate(nsr.getProjectId(), nsr.getId());
}

From source file:de.codecentric.boot.admin.services.SpringBootAdminRegistrator.java

/**
 * Registers the client application at spring-boot-admin-server.
 * @return true if successful/*from  ww w.  ja  v  a 2  s . co m*/
 */
public boolean register() {
    Application app = createApplication();
    String adminUrl = adminProps.getUrl() + '/' + adminProps.getContextPath();

    try {
        ResponseEntity<Application> response = template.postForEntity(adminUrl, app, Application.class);

        if (response.getStatusCode().equals(HttpStatus.CREATED)) {
            LOGGER.debug("Application registered itself as {}", response.getBody());
            return true;
        } else if (response.getStatusCode().equals(HttpStatus.CONFLICT)) {
            LOGGER.warn("Application failed to registered itself as {} because of conflict in registry.", app);
        } else {
            LOGGER.warn("Application failed to registered itself as {}. Response: {}", app,
                    response.toString());
        }
    } catch (Exception ex) {
        LOGGER.warn("Failed to register application as {} at spring-boot-admin ({}): {}", app, adminUrl,
                ex.getMessage());
    }

    return false;
}

From source file:com.sambrannen.samples.events.web.RestEventController.java

@RequestMapping(method = POST)
@ResponseStatus(HttpStatus.CREATED)
public void createEvent(@RequestBody Event postedEvent, HttpServletRequest request,
        HttpServletResponse response) {//from  w  w  w .  j a  v a 2s .  c  om
    Event savedEvent = repository.save(postedEvent);
    String newLocation = buildNewLocation(request, savedEvent.getId());
    response.setHeader("Location", newLocation);
}

From source file:com.agroservices.restcontrollers.DespachoRest.java

@RequestMapping(value = "/{id}/seEntrego", method = RequestMethod.POST)
public ResponseEntity<?> modificarEstadoEntrega(@PathVariable int id, @RequestBody Despacho des) {
    boolean ans = df.setEstadoEntrega(id, des.isSeEntrego());
    if (ans) {/*w w w .j  a v  a 2 s  .c  o m*/
        return new ResponseEntity<>(HttpStatus.CREATED);
    }
    return new ResponseEntity<>(HttpStatus.CONFLICT);
}

From source file:edu.eci.arsw.kalendan.controllers.TeamResourceController.java

@RequestMapping(path = "/equipos/{idT}/{permiso}", method = RequestMethod.POST)
public ResponseEntity<?> teamAddMember(@PathVariable("idT") Integer teamid, @PathVariable String permiso,
        @RequestBody User u) {//from  w w  w.ja  v a  2  s . co  m
    try {
        List<Project> con = ps.getProyectos();
        ts.setProyectos(con);
        ts.agregaProject();
        System.out.println("lalalalala");
        ts.agregarMiembro(u, teamid, permiso);
        return new ResponseEntity<>(HttpStatus.CREATED);

    } catch (Exception e) {
        Logger.getLogger(TeamResourceController.class.getName()).log(Level.SEVERE, null, e);
        return new ResponseEntity<>("Equipo no creado!", HttpStatus.FORBIDDEN);
    }
}

From source file:technology.tikal.customers.service.CustomerService.java

@RequestMapping(method = RequestMethod.POST)
@ResponseStatus(HttpStatus.CREATED)
public void createCustomer(@Valid @RequestBody final Customer data, final BindingResult result,
        final HttpServletRequest request, final HttpServletResponse response) {
    if (result.hasErrors()) {
        throw new NotValidException(result);
    }// w  ww  . jav  a  2s . c o  m
    Customer created;
    if (data.getId() != null) {
        //Si viene un id en los datos se intentara crear el customer con ese id
        //esto puede fallar por que el id ya exista o por que no se cuente con los permisos para hacerlo
        created = customersController.createCustomerWithForcedId(data.getId(), data);
    } else {
        created = customersController.createCustomer(data);
    }
    response.setHeader("Location", request.getRequestURI() + "/" + created.getId());
}

From source file:com.sentinel.web.controllers.RegistrationController.java

@RequestMapping(value = "/user", method = RequestMethod.POST)
@ResponseBody// w ww  .jav  a  2  s. co  m
public ResponseEntity<Void> createUser(@RequestBody UserForm accountDto, UriComponentsBuilder ucBuilder) {

    LOG.debug("Registring new user");
    final User registered = createUserAccount(accountDto);
    if (registered == null) {
        return new ResponseEntity<Void>(HttpStatus.CONFLICT);
    }
    /* 
    if (userService.isUserExist(user)) {
    System.out.println("A User with name " + user.getUsername() + " already exist");
    }
    */
    userService.saveRegisteredUser(registered);
    HttpHeaders headers = new HttpHeaders();
    headers.setLocation(ucBuilder.path("/user/{id}").buildAndExpand(registered.getId()).toUri());//TODO
    return new ResponseEntity<Void>(headers, HttpStatus.CREATED);
}

From source file:edu.eci.cosw.restcontrollers.RestControladorCalificarEstablecimiento.java

@RequestMapping(value = "/estCalif", method = RequestMethod.POST)
public ResponseEntity<?> registrarCalificacionCliente(@RequestBody Calificacion calificacion) {
    logica.calificarCliente(calificacion.getEnsayo().getIdEnsayo(), calificacion.getCalificacionBanda(),
            calificacion.getDescripcion());
    return new ResponseEntity<>(HttpStatus.CREATED);
}