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:org.echocat.marquardt.authority.spring.SpringAuthorityController.java

@RequestMapping(value = "/initializeSignUp", method = RequestMethod.POST)
@ResponseStatus(value = HttpStatus.CREATED)
@ResponseBody//from  w ww.jav  a 2  s  . com
public JsonWrappedCertificate initializeSignUp(@RequestBody final CLIENT_INFORMATION clientInformation) {
    return createCertificateResponse(_authority.initializeSignUp(clientInformation));
}

From source file:net.eusashead.hateoas.conditional.interceptor.AsyncTestController.java

@RequestMapping(method = RequestMethod.POST)
public Callable<ResponseEntity<Void>> post() {
    return new Callable<ResponseEntity<Void>>() {

        @Override//w w w.  j  a  v  a2 s . c  o  m
        public ResponseEntity<Void> call() throws Exception {
            return new ResponseEntity<Void>(HttpStatus.CREATED);
        }
    };
}

From source file:com.msyla.usergreeter.user.web.UserPreferenceResource.java

@RequestMapping(method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<UserPreferenceDto> create(
        @NotNull(message = "{userPreference.null}") @Valid @RequestBody UserPreferenceDto dto,
        UriComponentsBuilder builder) {// w w  w  .j av  a 2  s .c  om
    UserPreferenceDto savedDto = service.create(dto);

    Link link = ControllerLinkBuilder.linkTo(UserPreferenceResource.class).slash(savedDto.getKey())
            .withSelfRel();
    savedDto.add(link);

    HttpHeaders headers = new HttpHeaders();
    headers.setLocation(builder.path("/api/user/preferences/{id}").buildAndExpand(savedDto.getKey()).toUri());
    return new ResponseEntity<>(savedDto, headers, HttpStatus.CREATED);
}

From source file:rest.DependenciaRestController.java

@RequestMapping(value = "/dependencia/", method = RequestMethod.POST)
public ResponseEntity<Void> createDependencia(@RequestBody DependenciaBean dependencia,
        UriComponentsBuilder ucBuilder) {
    System.out.println("Registrar una Dependencia");
    if (dependenciaService.isDependenciaExist(dependencia)) {
        System.out.println("La dependencia con Nombre " + dependencia.getDesDep() + " ya existe.");
        return new ResponseEntity<Void>(HttpStatus.CONFLICT);
    }//from  www.  ja  va 2  s  .c om
    dependenciaService.save(dependencia);

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

From source file:eu.agilejava.javaonedemo.api.RecipeResource.java

@RequestMapping(method = RequestMethod.POST, consumes = APPLICATION_JSON_VALUE)
public ResponseEntity<Recipe> create(@RequestBody Recipe recipe) {
    recipeService.create(recipe);/*ww  w . ja  v  a2s  .  c o m*/

    HttpHeaders responseHeaders = new HttpHeaders();
    responseHeaders.add("Location", ServletUriComponentsBuilder.fromCurrentRequestUri()
            .pathSegment(String.valueOf(recipe.getId())).build().toUriString());
    return new ResponseEntity<>(responseHeaders, HttpStatus.CREATED);
}

From source file:com.graphaware.module.timetree.api.TimedEventsApi.java

@RequestMapping(value = "/single/event", method = RequestMethod.POST)
public void attachEvent(@RequestBody TimedEventVO event, HttpServletResponse response) {
    event.validate();//  w ww  .  ja  v a2 s.co  m

    try (Transaction tx = database.beginTx()) {
        Node eventNode = database.getNodeById(event.getEvent().getNodeId());

        boolean attached = timedEvents.attachEvent(eventNode,
                DynamicRelationshipType.withName(event.getEvent().getRelationshipType()),
                TimeInstant.fromValueObject(event.getTimeInstant()));

        if (attached) {
            response.setStatus(HttpStatus.CREATED.value());
        } else {
            response.setStatus(HttpStatus.OK.value());
        }

        tx.success();
    }
}

From source file:com._8x8.presentation.restController.UserRestController.java

@RequestMapping(value = "/user/", method = RequestMethod.POST)
public ResponseEntity<Void> createUser(@RequestBody User user, UriComponentsBuilder ucBuilder) {

    System.out.println("Creating Username: " + user.getUsername());

    if (_userService.isUserExist(user)) {
        System.out.println("A User with name " + user.getUsername() + " already exist");
        return new ResponseEntity<Void>(HttpStatus.CONFLICT);
    }/*from w ww .  j  av a2  s.  co m*/

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

From source file:web.EventLogRESTController.java

/**
 * Adds an event to the Event Log through REST API
 * @param el//from  w w w .  j  a  v  a 2  s .c  o m
 * @param ucBuilder
 * @return
 */
@RequestMapping(value = "/api/eventlog/", method = RequestMethod.POST)
public ResponseEntity<Void> addEvent(@RequestBody EventLog el, UriComponentsBuilder ucBuilder) {
    dao.addEvent(el);
    //returns newly added Event info
    HttpHeaders headers = new HttpHeaders();
    headers.setLocation(ucBuilder.path("/api/eventlog/{id}").buildAndExpand(el.getEventid()).toUri());
    return new ResponseEntity<Void>(headers, HttpStatus.CREATED);
}

From source file:com.baidu.terminator.manager.action.LinkAction.java

/**
 * Add a link./* w ww .ja  v  a  2  s.  co m*/
 * 
 * @param linkForm
 *            the link form , for example:
 *            {"name":"http_proxy","localPort":8080
 *            ,"remoteAddress":"61.135.169.125"
 *            ,"remotePort":80,"workMode":"RECORD"
 *            ,"protocolType":"HTTP","storageType":"CACHE","signClass":
 *            "com.baidu.terminator.plugin.signer.DefaultHttpSigner"
 *            ,"extractClass"
 *            :"com.baidu.terminator.plugin.extractor.DefaultHttpExtractor"}
 * @return the new created resource location in HTTP header
 */
@SuppressWarnings({ "unchecked", "rawtypes" })
@RequestMapping(method = RequestMethod.POST)
@ResponseBody
public ResponseEntity<?> addLink(@Valid @RequestBody LinkForm linkForm) {
    Link link = new Link();
    link.setName(linkForm.getName());
    link.setLocalPort(linkForm.getLocalPort());
    link.setRemoteAddress(linkForm.getRemoteAddress());
    link.setRemotePort(linkForm.getRemotePort());
    link.setWorkMode(linkForm.getWorkMode());
    link.setProtocolType(linkForm.getProtocolType());
    link.setStorageType(linkForm.getStorageType());
    link.setSignClass(linkForm.getSignClass());
    link.setExtractClass(linkForm.getExtractClass());
    linkService.addLink(link);

    return new ResponseEntity(link, HttpStatus.CREATED);
}

From source file:$.TaskRestController.java

@RequestMapping(method = RequestMethod.POST, consumes = MediaTypes.JSON)
    public ResponseEntity<?> create(@RequestBody Task task, UriComponentsBuilder uriBuilder) {
        // JSR303 Bean Validator, RestExceptionHandler?.
        BeanValidators.validateWithException(validator, task);

        // ?/* ww w  . j a v  a  2s  .c om*/
        taskService.saveTask(task);

        // Restful?url, ?id.
        Long id = task.getId();
        URI uri = uriBuilder.path("/api/v1/task/" + id).build().toUri();
        HttpHeaders headers = new HttpHeaders();
        headers.setLocation(uri);

        return new ResponseEntity(headers, HttpStatus.CREATED);
    }