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:uk.gov.nationalarchives.discovery.taxonomy.ws.controller.TaxonomyExceptionHandler.java

@ExceptionHandler(TaxonomyException.class)
public ResponseEntity<TaxonomyErrorResponse> handleTaxonomyException(TaxonomyException ex,
        WebRequest webRequest) {//  ww  w .  j  ava  2  s. com
    TaxonomyErrorResponse errorResponse = new TaxonomyErrorResponse(ex.getTaxonomyErrorType(), ex.getMessage());
    logger.error("{} < {}", extractPathFromWebRequest(webRequest), errorResponse.toString());
    return new ResponseEntity<TaxonomyErrorResponse>(errorResponse, HttpStatus.BAD_REQUEST);
}

From source file:com.seb.aws.demo.tomcat.web.SampleController.java

@RequestMapping(value = "/flood/{flood}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody/* w w w. j  a  va2  s  .  com*/
public ResponseEntity<String> flood(@PathVariable(value = "flood") int flood) {
    LOG.info("Flood {}", flood);
    Map<Integer, Integer[]> squares = new HashMap<Integer, Integer[]>();
    for (int i = 0; i < flood; ++i) {
        squares.put(i, new Integer[] { i ^ 2, i ^ 3 });
    }
    return new ResponseEntity<String>("Ca Flood x2/x3..." + squares.size(), HttpStatus.OK);
}

From source file:com._8x8.presentation.restfulController.ZPayRestfulController.java

@RequestMapping(value = "/decryptQRCode/{qrCode}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<String> decryptQRCode(@PathVariable("qrCode") String qrCode) {

    try {/*from   w  w w . j a  va2 s  . com*/

        String code = _encryptorService.decryptCode(qrCode);
        return new ResponseEntity<String>(code, HttpStatus.OK);

    } catch (Exception ex) {
        Logger.getLogger(ZPayRestfulController.class.getName()).log(Level.SEVERE, null, ex);
        return new ResponseEntity<String>(HttpStatus.NOT_FOUND);
    }

}

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

@RequestMapping(value = "/healthchecks/{healthchecks}/statistics", method = RequestMethod.GET)
@ResponseBody//from   w w w . j a v  a 2 s . c  o m
public HttpEntity<String> statistics(@PathVariable String api,
        @RequestParam(value = "period", required = false, defaultValue = "2m") String period) {
    return new ResponseEntity<>("hello", HttpStatus.OK);
}

From source file:org.farrukh.template.rest.exception.GlobalExceptionHandler.java

/**
 * Handles an error belonging to the application.
 *
 * @param error the type of the error.//from   ww w .ja v a 2s . c  o  m
 * @return the response error.
 */
@ExceptionHandler(AbstractError.class)
public ResponseEntity<ErrorBlock> handleApplicationException(final AbstractError error) {
    ErrorBlock errorBlock = new ErrorBlock(error.getCode(), error.getMessage());
    return new ResponseEntity<>(errorBlock, error.getHttpStatus());
}

From source file:com.opensearchserver.hadse.cluster.ClusterController.java

/**
 * /*from w  ww  .j av  a2  s  .  co  m*/
 * Add a node to the cluster
 * 
 * @param addresse
 * @return
 */
@RequestMapping(method = RequestMethod.PUT, value = "/_cluster")
@ResponseBody
public HttpEntity<?> add(@RequestParam(value = "addr", required = true) String... addresses) {
    try {
        List<String> adressList = new ArrayList<String>(addresses.length);
        for (String ad : addresses)
            adressList.add(ad);
        return ClusterCatalog.add(adressList);
    } catch (Throwable t) {
        return new ResponseEntity<String>(t.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
    }
}

From source file:com.hp.autonomy.frontend.find.hod.configuration.HodConfigurationController.java

@SuppressWarnings("ProhibitedExceptionDeclared")
@RequestMapping(value = "/config", method = { RequestMethod.POST, RequestMethod.PUT })
@ResponseBody//from w ww. j av  a 2s .  c  o m
public ResponseEntity<?> saveConfig(@RequestBody final ConfigResponse<HodFindConfig> configResponse)
        throws Exception {
    try {
        log.info(Markers.AUDIT, "REQUESTED CHANGE APPLICATION CONFIGURATION");
        configService.updateConfig(configResponse.getConfig());
        log.info(Markers.AUDIT, "CHANGED APPLICATION CONFIGURATION");
        return new ResponseEntity<>(configService.getConfigResponse(), HttpStatus.OK);
    } catch (final ConfigException ce) {
        log.info(Markers.AUDIT, "CHANGE APPLICATION CONFIGURATION FAILED");
        return new ResponseEntity<>(Collections.singletonMap("exception", ce.getMessage()),
                HttpStatus.NOT_ACCEPTABLE);
    } catch (final ConfigValidationException cve) {
        log.info(Markers.AUDIT, "CHANGE APPLICATION CONFIGURATION FAILED");
        return new ResponseEntity<>(Collections.singletonMap("validation", cve.getValidationErrors()),
                HttpStatus.NOT_ACCEPTABLE);
    }
}

From source file:fi.helsinki.opintoni.web.rest.privateapi.TestResource.java

@RequestMapping(value = "/whatismyip", method = RequestMethod.GET)
@Timed// w w  w .  jav  a 2 s  .c  o m
public ResponseEntity<String> whatIsMyIp(HttpServletRequest httpServletRequest) {
    return new ResponseEntity<>(httpServletRequest.getRemoteAddr(), HttpStatus.OK);
}

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

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