Example usage for org.springframework.http ResponseEntity ResponseEntity

List of usage examples for org.springframework.http ResponseEntity ResponseEntity

Introduction

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

Prototype

private ResponseEntity(@Nullable T body, @Nullable MultiValueMap<String, String> headers, Object status) 

Source Link

Document

Create a new HttpEntity with the given body, headers, and status code.

Usage

From source file:com.github.ljtfreitas.restify.http.spring.client.call.exec.ResponseEntityConverter.java

@Override
public ResponseEntity<T> convert(EndpointResponse<T> source) {
    return new ResponseEntity<T>(source.body(), headersOf(source.headers()),
            HttpStatus.valueOf(source.code().value()));
}

From source file:hello.TodoController.java

@RequestMapping(method = RequestMethod.GET, produces = "application/json")
public ResponseEntity<Iterable<Todo>> list() {
    HttpHeaders headers = new HttpHeaders();
    headers.add("Accept-Patch", "application/json-patch+json");
    return new ResponseEntity<Iterable<Todo>>(repository.findAll(), headers, HttpStatus.OK);
}

From source file:fi.hsl.parkandride.front.ContactController.java

@RequestMapping(method = POST, value = CONTACTS, produces = APPLICATION_JSON_VALUE)
public ResponseEntity<Contact> createContact(@RequestBody Contact contact, User currentUser,
        UriComponentsBuilder builder) {/*from ww  w  .  j a  va2 s.co  m*/
    log.info("createContact");
    Contact newContact = contactService.createContact(contact, currentUser);
    log.info("createContact({})", newContact.id);

    HttpHeaders headers = new HttpHeaders();
    headers.setLocation(builder.path(CONTACT).buildAndExpand(newContact.id).toUri());
    return new ResponseEntity<>(newContact, headers, CREATED);
}

From source file:edu.infsci2560.services.BlogsService.java

@RequestMapping(method = RequestMethod.POST, consumes = "application/json", produces = "application/json")
public ResponseEntity<Blog> create(@RequestBody Blog blog) {
    HttpHeaders headers = new HttpHeaders();
    return new ResponseEntity<>(repository.save(blog), headers, HttpStatus.OK);
}

From source file:fi.hsl.parkandride.front.OperatorController.java

@RequestMapping(method = POST, value = OPERATORS, produces = APPLICATION_JSON_VALUE)
public ResponseEntity<Operator> createOperator(@RequestBody Operator operator, User currentUser,
        UriComponentsBuilder builder) {/*from w w w  .j  ava 2 s .com*/
    log.info("createOperator");
    Operator newOperator = operatorService.createOperator(operator, currentUser);
    log.info("createOperator({})", newOperator.id);

    HttpHeaders headers = new HttpHeaders();
    headers.setLocation(builder.path(OPERATOR).buildAndExpand(newOperator.id).toUri());
    return new ResponseEntity<>(newOperator, headers, CREATED);
}

From source file:ru.portal.controllers.RestController.java

@RequestMapping(value = { "/main" })
@ResponseBody//from w  w  w.  j  a  va  2s .c  o m
public ResponseEntity<String> main() {
    HttpHeaders headers = new HttpHeaders();
    headers.add("Content-type", "application/json;charset=UTF-8");
    ResponseEntity responseEntity = new ResponseEntity<>("main", headers, HttpStatus.OK);

    return responseEntity;

}

From source file:edu.infsci2560.services.FriendService.java

@RequestMapping(method = RequestMethod.POST, consumes = "application/json", produces = "application/json")
public ResponseEntity<Friend> create(@RequestBody Friend friends) {
    HttpHeaders headers = new HttpHeaders();
    return new ResponseEntity<>(repository.save(friends), headers, HttpStatus.OK);
}

From source file:com.w3ma.m3u8web.controller.DownloadPlaylistController.java

@RequestMapping(value = "/playlist", method = RequestMethod.GET, produces = MediaType.APPLICATION_OCTET_STREAM_VALUE)
public ResponseEntity<ByteArrayResource> getPlaylist(final HttpServletResponse response) throws IOException {
    logger.debug("getPlaylist called");
    final HttpHeaders headers = new HttpHeaders();
    response.setHeader("Content-Disposition", "attachment; filename=playlist.m3u");
    return new ResponseEntity<>(
            new ByteArrayResource(playlistGeneratorService.getPlaylistByteArrayOutputStream().toByteArray()),
            headers, HttpStatus.OK);//from   w w  w. ja v  a2 s.  c  o m
}

From source file:business.CustomResponseEntityExceptionHandler.java

@Override
protected ResponseEntity<Object> handleMethodArgumentNotValid(MethodArgumentNotValidException ex,
        HttpHeaders headers, HttpStatus status, WebRequest request) {
    List<FieldError> fieldErrors = ex.getBindingResult().getFieldErrors();
    List<ObjectError> globalErrors = ex.getBindingResult().getGlobalErrors();
    List<String> errors = new ArrayList<>(fieldErrors.size() + globalErrors.size());
    for (FieldError fieldError : fieldErrors) {
        errors.add(fieldError.getField() + ", " + fieldError.getDefaultMessage());
    }/*w  w  w.  j  av  a2  s. c  o m*/
    for (ObjectError objectError : globalErrors) {
        errors.add(objectError.getObjectName() + ", " + objectError.getDefaultMessage());
    }
    ErrorMessage errorMessage = new ErrorMessage(errors);
    return new ResponseEntity<Object>(errorMessage, headers, status);
}

From source file:edu.infsci2560.services.DvdsService.java

@RequestMapping(method = RequestMethod.POST, consumes = "application/json", produces = "application/json")
public ResponseEntity<Dvd> create(@RequestBody Dvd dvd) {
    HttpHeaders headers = new HttpHeaders();
    return new ResponseEntity<>(repository.save(dvd), headers, HttpStatus.OK);
}