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:reconf.server.services.product.ReadProductService.java

@RequestMapping(value = "/product/{prod}", method = RequestMethod.GET)
@Transactional(readOnly = true)/*from   www.  j  a  va 2  s . c  o  m*/
public ResponseEntity<ProductResult> doIt(@PathVariable("prod") String product, HttpServletRequest request,
        Authentication auth) {

    Product reqProduct = new Product(product, null);

    List<String> errors = DomainValidator.checkForErrors(reqProduct);
    if (!errors.isEmpty()) {
        return new ResponseEntity<ProductResult>(new ProductResult(reqProduct, errors), HttpStatus.BAD_REQUEST);
    }

    Product dbProduct = products.findOne(reqProduct.getName());
    if (dbProduct == null) {
        return new ResponseEntity<ProductResult>(new ProductResult(reqProduct, Product.NOT_FOUND),
                HttpStatus.NOT_FOUND);
    }

    if (ApplicationSecurity.isRoot(auth)) {
        for (UserProduct userProduct : userProducts.findByKeyProduct(reqProduct.getName())) {
            dbProduct.addUser(userProduct.getKey().getUsername());
        }
    }

    return new ResponseEntity<ProductResult>(new ProductResult(dbProduct, CrudServiceUtils.getBaseUrl(request)),
            HttpStatus.OK);
}

From source file:info.losd.galenweb.api.GalenWebApiController.java

@RequestMapping(value = "/healthchecks/{healthcheck}", method = RequestMethod.GET)
@ResponseBody/*from w  w  w.  j  av a 2 s.  c  o  m*/
public HttpEntity<String> healthCheck(@PathVariable String healthcheck) {
    return new ResponseEntity<>("hello", HttpStatus.OK);
}

From source file:reconf.server.services.property.DeletePropertyService.java

@RequestMapping(value = "/product/{prod}/component/{comp}/property/{prop}", method = RequestMethod.DELETE)
@Transactional/* ww w. ja va2 s  . c  om*/
public ResponseEntity<PropertyResult> global(@PathVariable("prod") String product,
        @PathVariable("comp") String component, @PathVariable("prop") String property, Authentication auth) {

    PropertyKey key = new PropertyKey(product, component, property);
    Property reqProperty = new Property(key, null);

    List<String> errors = DomainValidator.checkForErrors(key);
    if (!errors.isEmpty()) {
        return new ResponseEntity<PropertyResult>(new PropertyResult(reqProperty, errors),
                HttpStatus.BAD_REQUEST);
    }

    if (!properties.exists(key)) {
        return new ResponseEntity<PropertyResult>(new PropertyResult(reqProperty, Property.NOT_FOUND),
                HttpStatus.NOT_FOUND);
    }
    properties.delete(key);
    return new ResponseEntity<PropertyResult>(HttpStatus.OK);
}

From source file:com.softcrylic.dockeryamlcatalog.controller.tomcat7jdk7.java

@RequestMapping(value = "/tm7jd7", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE)
public @ResponseBody ResponseEntity<String> post_Tomcat7Jdk7_Yml(@RequestBody String inputJson) {

    FigCommandClassDef fccd = new FigCommandClassDef();

    StringBuilder sb = new StringBuilder();

    try {//  ww  w . j  av  a 2 s  .c  om
        /**
         * Get the Json and Assigned to class definition
         */
        fccd = gson.fromJson(inputJson, FigCommandClassDef.class);

        /**
         * Check parent should be present
         */
        if (fccd.getContainer_id().equals("") || fccd.getContainer_id().equals(null)) {
            return new ResponseEntity<String>("Container_Id can't be null or left blank",
                    HttpStatus.BAD_REQUEST);
        }

        /**
         * Generate the Yaml
         */

        sb = YmlBuilder.buildYaml(fccd);

    } catch (Exception e) {
        return new ResponseEntity<String>(e.getMessage(), HttpStatus.BAD_REQUEST);
    }
    return new ResponseEntity<String>(sb.toString(), HttpStatus.OK);
}

From source file:springfox.documentation.swagger.web.ApiResourceController.java

@RequestMapping(value = "/configuration/security")
@ResponseBody/*w  w  w .  jav a 2s.  c  o m*/
ResponseEntity<SecurityConfiguration> securityConfiguration() {
    return new ResponseEntity<SecurityConfiguration>(
            Optional.fromNullable(securityConfiguration).or(SecurityConfiguration.DEFAULT), HttpStatus.OK);
}

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

/**
 *
 * @param idTienda//from w w  w .ja  v a2  s .c om
 * @param idProducto
 * @return
 */
@RequestMapping(value = "/{idTienda}-{idProducto}", method = RequestMethod.GET)
@ResponseBody
public ResponseEntity<ProductosTiendas> getProductoTiendaById(@PathVariable("idTienda") Integer idTienda,
        @PathVariable("idProducto") Integer idProducto) {
    ProductosTiendas u = se.getProductoTiendaById(idTienda, idProducto);
    return new ResponseEntity<>(u, HttpStatus.OK);
}

From source file:com.arya.latihan.controller.CustomerController.java

@RequestMapping(method = RequestMethod.POST)
@Transactional(readOnly = false)//from  w ww .  j a  va2s .c om
public ResponseEntity<Customer> saveCustomer(@Valid Customer customer) {
    customer = customerRepository.save(customer);
    URI location = ServletUriComponentsBuilder.fromCurrentRequest().path("/{id}")
            .buildAndExpand(customer.getId()).toUri();
    HttpHeaders headers = new HttpHeaders();
    headers.setLocation(location);
    return new ResponseEntity<Customer>(headers, HttpStatus.CREATED);
}

From source file:com.company.eleave.leave.rest.HolidayController.java

@RequestMapping(method = RequestMethod.GET)
public ResponseEntity<List<HolidayDTO>> getAll() {
    List<HolidayDTO> holidays = holidayService.getAll().stream().map(holiday -> mapper.toDto(holiday))
            .collect(Collectors.toList());

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

From source file:edu.eci.arsw.blindway.controller.SalasController.java

@RequestMapping(path = "/choose/{nick}/{id}", method = RequestMethod.GET)
public ResponseEntity<?> manejadorUnionSalas(@PathVariable String nick, @PathVariable Integer id) {
    try {/*from   ww w .  j av a 2 s .c o  m*/
        Usuario u = StubUsuario.getInstance().cargarUsuarioPorNick(nick);
        Sala s = salas.obtenerSala(id);
        return new ResponseEntity<>(s.ingresarSala(u, ""), HttpStatus.ACCEPTED);
    } catch (CreacionSalaException | RegistroUsuarioException ex) {
        return new ResponseEntity<>(HttpStatus.NOT_ACCEPTABLE);
    }
}