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(MultiValueMap<String, String> headers, HttpStatus status) 

Source Link

Document

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

Usage

From source file:com.ar.dev.tierra.api.controller.DetalleNotaCreditoController.java

@RequestMapping(value = "/nota", method = RequestMethod.GET)
public ResponseEntity<?> getByNotaCredito(@RequestParam("idNota") int idNota) {
    List<DetalleNotaCredito> list = facadeService.getDetalleNotaCreditoDAO().getByNotaCredito(idNota);
    if (!list.isEmpty()) {
        return new ResponseEntity<>(list, HttpStatus.OK);
    } else {/*from  w w  w  .j  a  v  a 2s.  c  o m*/
        return new ResponseEntity<>(HttpStatus.NOT_FOUND);
    }
}

From source file:uk.gov.nationalarchives.discovery.taxonomy.ws.controller.TaxonomyExceptionHandler.java

@ExceptionHandler(ParseException.class)
public ResponseEntity<TaxonomyErrorResponse> handleLuceneParseException(ParseException ex,
        WebRequest webRequest) {// www .j a  v  a  2s  .  c o  m
    TaxonomyErrorResponse errorResponse = new TaxonomyErrorResponse(TaxonomyErrorType.INVALID_CATEGORY_QUERY,
            ex.getMessage());
    logger.error("{} < {}", extractPathFromWebRequest(webRequest), errorResponse.toString());
    return new ResponseEntity<TaxonomyErrorResponse>(errorResponse, HttpStatus.BAD_REQUEST);
}

From source file:com.ar.dev.tierra.api.controller.PlanPagoController.java

@RequestMapping(value = "/list", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<?> getAll() {
    List<PlanPago> list = facadeService.getPlanPagoDAO().getAll();
    if (!list.isEmpty()) {
        return new ResponseEntity<>(list, HttpStatus.OK);
    } else {//from w w w .j  a  v  a 2s .c  om
        return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
    }
}

From source file:com.baidu.stqa.signet.web.action.ProjectAction.java

/**
 * //from ww w .j  a v  a  2 s . c om
 * 
 * @return
 */
@RequestMapping(value = "/project", method = RequestMethod.GET)
@ResponseBody
public ResponseEntity<List<Project>> queryUserProjects() {

    doLog(null);

    String user = getUser();

    List<Project> projectList = new ArrayList<Project>();

    if (user != null) {
        projectList = projectService.listProject(user);
    }

    return new ResponseEntity<List<Project>>(projectList, HttpStatus.OK);
}

From source file:com.ge.predix.acs.commons.web.ResponseEntityBuilder.java

/**
 * Creates a typed ResponseEntity with HTTP status code 201/204 with a given location.
 *
 * @param location/*from w  w w  .  jav  a  2  s  .c  o m*/
 *            The location of the created resource
 * @param noContent
 *            false means updated resource which returns 204, true means created resource which returns 201
 * @return The corresponding ResponseEntity
 */
public static <T> ResponseEntity<T> created(final String location, final boolean noContent) {
    HttpStatus status = noContent ? HttpStatus.NO_CONTENT : HttpStatus.CREATED;

    if (location != null) {

        HttpHeaders headers = new HttpHeaders();
        headers.setLocation(URI.create(location));
        return new ResponseEntity<T>(headers, status);
    }
    return new ResponseEntity<T>(status);
}

From source file:com.tribuo.backend.controllers.FabricantesController.java

/**
 *
 * @return// ww  w .j a  va2s  .  c o m
 */
@RequestMapping(value = "/all", method = RequestMethod.GET)
@ResponseBody
public ResponseEntity<List<Fabricantes>> getFabricantes() {
    List<Fabricantes> u = se.getFabricantes();
    return new ResponseEntity<>(u, HttpStatus.OK);
}

From source file:gt.dakaik.rest.impl.CountryImpl.java

@Override
public ResponseEntity<Country> findById(int idUsuario, String token, Long id)
        throws EntidadNoEncontradaException {
    Country p = repoCountry.findOne(id);

    if (p != null) {
        return new ResponseEntity(p, HttpStatus.OK);
    } else {// w  ww .ja v  a 2  s  .c o  m
        throw new EntidadNoEncontradaException("Entity User");
    }
}

From source file:com.ar.dev.tierra.api.controller.NotaCreditoController.java

@RequestMapping(value = "/all", method = RequestMethod.GET)
public ResponseEntity<?> getAll() {
    List<NotaCredito> list = facadeService.getNotaCreditoDAO().getAll();
    if (!list.isEmpty()) {
        return new ResponseEntity<>(list, HttpStatus.OK);
    } else {/*from  w  w w .ja v  a2 s  .  c  o m*/
        return new ResponseEntity<>(HttpStatus.NOT_FOUND);
    }
}

From source file:com.ar.dev.tierra.api.controller.ClienteController.java

@RequestMapping(value = "/list", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<?> getAll() {
    List<Cliente> list = facadeService.getClienteDAO().getAll();
    if (!list.isEmpty()) {
        return new ResponseEntity<>(list, HttpStatus.OK);
    } else {//  w ww . java2s  .  com
        return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
    }
}

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

@RequestMapping(value = "/{username}", method = RequestMethod.PUT, headers = {
        "Content-type=application/json" })
@ResponseBody/*from w w  w.j a v  a2s . c o  m*/
public ResponseEntity<String> updateUser(@RequestBody User update, @PathVariable("username") String username) {
    User user = userDao.getUserByUsername(username);

    if (user == null) {
        return new ResponseEntity<String>("Username does not exist.", HttpStatus.BAD_REQUEST);
    }

    if (username.equals("admin")) {
        return new ResponseEntity<String>("You are not authenticated to perform this operation.",
                HttpStatus.FORBIDDEN);
    }

    // Update user details
    if (update.getUsername() != null) {
        // Check username is available
        if (userDao.getUserByUsername(user.getUsername()) != null) {
            return new ResponseEntity<String>("Username already exists.", HttpStatus.NOT_ACCEPTABLE);
        } else {
            user.setUsername(update.getUsername());
        }
    }

    if (update.getPassword() != null) {
        user.setPassword(update.getPassword());
    }

    if (update.getEnabled() != null) {
        user.setEnabled(update.getEnabled());
    }

    // Update database
    if (!userDao.updateUser(user, username)) {
        LogService.getInstance().addLogEntry(LogService.Level.ERROR, CLASS_NAME,
                "Error updating user '" + user.getUsername() + "'.", null);
        return new ResponseEntity<String>("Error updating user details.", HttpStatus.INTERNAL_SERVER_ERROR);
    }

    LogService.getInstance().addLogEntry(LogService.Level.INFO, CLASS_NAME,
            "User '" + user.getUsername() + "' updated successfully.", null);
    return new ResponseEntity<String>("User details updated successfully.", HttpStatus.ACCEPTED);
}