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

public ResponseEntity(HttpStatus status) 

Source Link

Document

Create a new ResponseEntity with the given status code, and no body nor headers.

Usage

From source file:com.sms.server.controller.JobController.java

@RequestMapping(value = "/{id}", method = RequestMethod.GET)
public ResponseEntity<Job> getJobByID(@PathVariable("id") Long id) {
    Job job = jobDao.getJobByID(id);/*www . j  a va  2  s . co  m*/

    if (job == null) {
        return new ResponseEntity<>(HttpStatus.NOT_FOUND);
    }

    return new ResponseEntity<>(job, HttpStatus.OK);
}

From source file:com.github.hateoas.forms.spring.sample.test.DummyEventController.java

@RequestMapping(method = RequestMethod.POST)
public ResponseEntity<Void> addEvent(@RequestBody Event event) {
    return new ResponseEntity(HttpStatus.CREATED);
}

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

@RequestMapping(method = RequestMethod.POST)
public ResponseEntity<?> addOrdenCompra(@RequestBody OrdenCompra o) {
    c.addNewOrdenCompra(o);/*from www.j  a  va  2 s  . co  m*/
    return new ResponseEntity<>(HttpStatus.ACCEPTED);
}

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

@RequestMapping(value = "/federation/", method = RequestMethod.GET, produces = { "application/json" })
public ResponseEntity<String> getId(@RequestParam("type") final String type,
        @RequestParam("q") final String nameToLookUp) throws InvalidStellarAddressException {

    if (!type.equalsIgnoreCase("name")) {
        return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED);
    }/*from w  w w .  j ava  2 s. c  o  m*/

    final StellarAddress stellarAddress = StellarAddress.parse(nameToLookUp);

    final StellarAccountId accountId = federationService.getAccountId(stellarAddress);

    final FederationResponse ret;
    if (accountId.getSubAccount().isPresent()) {
        ret = FederationResponseBuilder.accountInMemoField(stellarAddress.toString(), accountId.getPublicKey(),
                accountId.getSubAccount().get());
    } else {
        ret = FederationResponseBuilder.account(stellarAddress.toString(), accountId.getPublicKey());
    }

    return new ResponseEntity<>(gson.toJson(ret), HttpStatus.OK);
}

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

@RequestMapping(value = "/", method = RequestMethod.POST)
public ResponseEntity<?> registrarCalificacionEstablecimiento(@RequestBody Calificacion calificacion) {
    logica.calificarEstablecimiento(calificacion.getEnsayo().getCliente().getIdCliente(),
            calificacion.getEnsayo().getIdEnsayo(), calificacion.getCalificacionEstablecimiento(),
            calificacion.getDescripcion());
    return new ResponseEntity<>(HttpStatus.CREATED);
}

From source file:com.mycompany.springrest.controllers.UserController.java

@RequestMapping(value = "/user", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<List<User>> listUsers() {
    List<User> users = userService.listUsers();
    if (users.isEmpty()) {
        return new ResponseEntity<List<User>>(HttpStatus.NO_CONTENT);
    }/* w w w.  ja v a 2s .  c om*/
    return new ResponseEntity<List<User>>(users, HttpStatus.OK);
}

From source file:com.sms.server.controller.ImageController.java

@RequestMapping(value = "/{id}/cover/{scale}", method = RequestMethod.GET, produces = "image/jpeg")
@ResponseBody//  w  w  w  . j  a  v  a2s . co  m
public ResponseEntity getCoverArt(@PathVariable("id") Long id, @PathVariable("scale") Integer scale) {
    MediaElement mediaElement;
    BufferedImage image;

    // Get corresponding media element
    mediaElement = mediaDao.getMediaElementByID(id);

    if (mediaElement == null) {
        return new ResponseEntity<>(HttpStatus.NOT_FOUND);
    }

    // Get scaled cover art
    image = imageService.getCoverArt(mediaElement, scale);

    // Check if we were able to retrieve a cover
    if (image == null) {
        return new ResponseEntity<>(HttpStatus.NOT_FOUND);
    }

    // Convert image to bytes to send
    try {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        ImageIO.write(image, "jpg", baos);
        byte[] imageBytes = baos.toByteArray();

        // Return cover art if found
        return new ResponseEntity(imageBytes, HttpStatus.OK);

    } catch (IOException ex) {
        return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
    }
}

From source file:pitayaa.nail.msg.core.account.controller.AccountLicenseController.java

@RequestMapping(value = "/accountsLicense/{ID}", method = RequestMethod.POST)
public @ResponseBody ResponseEntity<?> saveAccountLicenseModel(@RequestBody AccountLicense accLicenseBody,
        @PathVariable("ID") UUID uid) throws Exception {

    Optional<AccountLicense> accountLicense = accLicenseService.findOne(uid);

    if (!accountLicense.isPresent()) {
        return new ResponseEntity<>(HttpStatus.NOT_FOUND);
    }/*from   w ww  .  jav a2 s .  co  m*/

    accLicenseBody = accLicenseService.save(accLicenseBody);

    return ResponseEntity.ok(accLicenseBody);
}

From source file:web.UsersRESTController.java

/**
 * Gets a list of users through a REST API
 * @return/*from w w w.  j  a  va  2s . c om*/
 */
@RequestMapping(value = "/api/users/", method = RequestMethod.GET)
public ResponseEntity<List<Users>> listUsers() {
    List<Users> users = dao.getUsersList();
    //returns NO_CONTENT error if no Users are provided
    if (users.isEmpty()) {
        return new ResponseEntity<List<Users>>(HttpStatus.NO_CONTENT);
    }
    //otherwise returns list of all Users
    return new ResponseEntity<List<Users>>(users, HttpStatus.OK);
}

From source file:de.qucosa.spring.ResourceExceptionHandler.java

@ExceptionHandler(FedoraClientException.class)
public ResponseEntity fedoraClientExceptionHandler(FedoraClientException fe) {
    log.warn(fe);/*from w  w  w.j  a  va2s.  co  m*/
    return new ResponseEntity(HttpStatus.valueOf(fe.getStatus()));
}