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.github.woki.payments.adyen.simulator.web.controller.PaymentController.java

@RequestMapping(value = { "/pal/servlet/Payment/v30/authorise",
        "/pal/servlet/Payment/v30/authorise3d" }, method = RequestMethod.POST)
public ResponseEntity<PaymentResponse> authorize(@RequestBody PaymentRequest request) {
    PaymentResponse res = new PaymentResponse();
    if ("gimme_500".equals(request.getReference())) {
        res.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value());
        return new ResponseEntity<>(res, HttpStatus.INTERNAL_SERVER_ERROR);
    }//from ww w  .  j a va 2s.c o m
    if ("gimme_400".equals(request.getReference())) {
        res.setStatus(HttpStatus.BAD_REQUEST.value());
        return new ResponseEntity<>(res, HttpStatus.BAD_REQUEST);
    }
    if ("gimme_422".equals(request.getReference())) {
        res.setStatus(HttpStatus.UNPROCESSABLE_ENTITY.value());
        return new ResponseEntity<>(res, HttpStatus.UNPROCESSABLE_ENTITY);
    }
    if ("gimme_401".equals(request.getReference())) {
        res.setStatus(HttpStatus.UNAUTHORIZED.value());
        return new ResponseEntity<>(res, HttpStatus.UNAUTHORIZED);
    }
    if ("gimme_403".equals(request.getReference())) {
        res.setStatus(HttpStatus.FORBIDDEN.value());
        return new ResponseEntity<>(res, HttpStatus.FORBIDDEN);
    }
    if ("gimme_404".equals(request.getReference())) {
        res.setStatus(HttpStatus.NOT_FOUND.value());
        return new ResponseEntity<>(res, HttpStatus.NOT_FOUND);
    }
    if ("gimme_200".equals(request.getReference())) {
        res.setStatus(HttpStatus.OK.value());
        return new ResponseEntity<>(res, HttpStatus.OK);
    }
    res.setStatus(HttpStatus.NON_AUTHORITATIVE_INFORMATION.value());
    return new ResponseEntity<>(res, HttpStatus.NON_AUTHORITATIVE_INFORMATION);
}

From source file:hr.foi.sis.controllers.TestDataController.java

@RequestMapping(value = "/", method = RequestMethod.GET)
@PreAuthorize("hasRole('ROLE_ADMIN')")
public ResponseEntity<List<TestData>> retrieveAll() {

    Logger.getLogger("TestDataController.java").log(Level.INFO,
            "GET on /testData -- retrieving full list of testData");

    return new ResponseEntity(this.testDataRepository.findAll(), HttpStatus.OK);

}

From source file:marytts.http.controllers.MaryErrorController.java

@RequestMapping
@ResponseBody//from   w ww .  j a v  a  2s .  c  o  m
public ResponseEntity<Object> error(HttpServletRequest request) {
    HttpStatus status = getStatus(request);
    return new ResponseEntity<Object>(new ErrorResponse(status.value(), status.name()), status);
}

From source file:reconf.server.services.component.ReadAllComponentsService.java

@RequestMapping(value = "/product/{prod}/component", method = RequestMethod.GET)
@Transactional(readOnly = true)/*  ww  w.j a v a  2s.com*/
public ResponseEntity<AllComponentsResult> doIt(@PathVariable("prod") String productId,
        HttpServletRequest request, Authentication auth) {

    Product fromRequest = new Product(productId);

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

    Product dbProduct = products.findOne(fromRequest.getName());

    if (dbProduct == null) {
        return new ResponseEntity<AllComponentsResult>(new AllComponentsResult(productId, Product.NOT_FOUND),
                HttpStatus.NOT_FOUND);
    }

    List<ComponentResult> result = new ArrayList<>();
    for (Component component : components.findByKeyProductOrderByKeyNameAsc(dbProduct.getName())) {
        result.add(new ComponentResult(component, CrudServiceUtils.getBaseUrl(request)));
    }

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

From source file:org.khmeracademy.btb.auc.pojo.controller.Topup_controller.java

@RequestMapping(value = "/add-topup-log", method = RequestMethod.POST, produces = "application/json")
public ResponseEntity<Map<String, Object>> add_topup_log(@RequestBody Topup_log topup) {
    Map<String, Object> map = new HashMap<String, Object>();
    try {//  w w  w.  j  a  v a  2  s.c  o m

        if (topup_service.add(topup)) {
            map.put("MESSAGE", "User has been inserted.");
            map.put("STATUS", true);
        } else {
            map.put("MESSAGE", "Topup log has not been inserted.");
            map.put("STATUS", false);
        }
    } catch (Exception e) {
        map.put("MESSAGE", "Error!");
        map.put("STATUS", false);
        e.printStackTrace();
    }
    return new ResponseEntity<Map<String, Object>>(map, HttpStatus.OK);
}

From source file:net.eusashead.hateoas.hal.http.converter.RepresentationController.java

@ResponseBody
@RequestMapping(value = "/responseentity", method = RequestMethod.GET, produces = { "application/hal+json",
        "application/hal+xml" })
public ResponseEntity<ReadableRepresentation> responseEntity() {
    return new ResponseEntity<ReadableRepresentation>(
            HalTestUtils.halFromFile("src/test/resources/basket.json"), HttpStatus.OK);
}

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

@RequestMapping(method = RequestMethod.POST)
@Transactional(readOnly = false)/*from w  ww  .ja  va  2  s .  co m*/
public ResponseEntity<SalesOrder> saveSalesOrder(@Valid SalesOrder salesOrder) {
    salesOrder = salesOrderRepository.save(salesOrder);
    URI uri = ServletUriComponentsBuilder.fromCurrentRequest().path("/{id}").buildAndExpand(salesOrder.getId())
            .toUri();
    HttpHeaders headers = new HttpHeaders();
    headers.setLocation(uri);
    return new ResponseEntity<SalesOrder>(headers, HttpStatus.CREATED);
}

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

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

From source file:com.diagrama.repository.PeriodoController.java

@RequestMapping(value = "/periodo/{periodo_id}", method = RequestMethod.GET)
public ResponseEntity<?> BuscarPeriodo(@PathVariable int periodo_id) {
    PeriodosLectivos periodosLectivos = periodoRepository.findOne(periodo_id);
    return new ResponseEntity<>(periodosLectivos, HttpStatus.OK);
}

From source file:com.otz.plugin.transport.funnel.controller.StreamsController.java

@CrossOrigin
@RequestMapping(path = "/definitions")
@ResponseBody// w  w w. j a  v  a 2s. com
public ResponseEntity<StreamDefinitionNames> getStreams() {

    return new ResponseEntity(funnelService.getStreamDefinitionNames(), HttpStatus.OK);
}