Example usage for org.springframework.http ResponseEntity ok

List of usage examples for org.springframework.http ResponseEntity ok

Introduction

In this page you can find the example usage for org.springframework.http ResponseEntity ok.

Prototype

public static BodyBuilder ok() 

Source Link

Document

Create a builder with the status set to HttpStatus#OK OK .

Usage

From source file:com.todo.backend.web.rest.AuthenticationApi.java

@RequestMapping(value = "/sign-in", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
@Timed//from w  w  w.  j ava 2 s . c o m
@Transactional
public ResponseEntity<SignInResponse> signIn(@Valid @RequestBody SignInRequest request) {
    log.debug("POST /sign-in {}", request);
    final SignInResponse response = userService.signIn(request.getUsername(), request.getPassword());
    return ResponseEntity.ok().body(response);
}

From source file:th.co.geniustree.intenship.advisor.controller.AdviseController.java

@RequestMapping(value = "/getfileadvise/{id}", method = RequestMethod.GET)
public ResponseEntity<InputStreamResource> getFile(@PathVariable("id") FileUpload fileUpload) {
    ResponseEntity<InputStreamResource> body = ResponseEntity.ok().contentLength(fileUpload.getContent().length)
            .contentType(MediaType.parseMediaType(fileUpload.getMimeType()))
            .header("Content-Disposition", "attachment; filename=\"" + fileUpload.getName() + "\"")
            .body(new InputStreamResource(new ByteArrayInputStream(fileUpload.getContent())));
    return body;/*from   w  w  w.j a v a 2 s  .c o  m*/
}

From source file:org.dawnsci.marketplace.controllers.FileController.java

@RequestMapping(value = "/{solution}/**", method = { RequestMethod.GET, RequestMethod.HEAD })
@ResponseBody//w  w  w  . j a v a 2 s  .com
public ResponseEntity<FileSystemResource> getFile(@PathVariable("solution") String solution,
        HttpServletRequest request) {
    String path = (String) request.getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE);
    String bestMatchPattern = (String) request.getAttribute(HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE);
    AntPathMatcher apm = new AntPathMatcher();
    path = apm.extractPathWithinPattern(bestMatchPattern, path);
    File file = fileService.getFile(solution, path);
    if (file.exists() && file.isFile()) {
        try {
            String detect = tika.detect(file);
            MediaType mediaType = MediaType.parseMediaType(detect);
            return ResponseEntity.ok().contentLength(file.length()).contentType(mediaType)
                    .lastModified(file.lastModified()).body(new FileSystemResource(file));
        } catch (IOException e) {
            e.printStackTrace();
        }
    } else {
        throw new ResourceNotFoundException();
    }
    return null;
}

From source file:com.consol.citrus.admin.web.ProjectController.java

@RequestMapping(value = "/settings/default", method = RequestMethod.POST)
@ResponseBody/*www  . j  a v a2 s .co m*/
public ResponseEntity saveProjectSettings(@RequestBody ProjectSettings settings) {
    projectService.applySettings(settings);
    return ResponseEntity.ok().build();
}

From source file:th.co.geniustree.intenship.advisor.controller.BehaviorController.java

@RequestMapping(value = "/getfilebehavior/{id}", method = RequestMethod.GET)
public ResponseEntity<InputStreamResource> getFile(@PathVariable("id") FileUpload fileUpload) {
    ResponseEntity<InputStreamResource> body = ResponseEntity.ok().contentLength(fileUpload.getContent().length)
            .contentType(MediaType.parseMediaType(fileUpload.getMimeType()))
            .header("Content-Disposition", "attachment; filename=\"" + fileUpload.getName() + "\"")
            .body(new InputStreamResource(new ByteArrayInputStream(fileUpload.getContent())));
    return body;/*from   ww  w.  j  a v a  2s  .  c o  m*/
}

From source file:de.document.controller.KrankheitController.java

@RequestMapping(value = "/{title}", method = { RequestMethod.DELETE })
public ResponseEntity delete(@PathVariable("title") String title) {

    this.service.delete(title);
    return ResponseEntity.ok().build();
}

From source file:com.consol.citrus.demo.voting.web.VotingServiceController.java

@RequestMapping(value = "/{id}/close", method = RequestMethod.PUT)
public ResponseEntity close(@PathVariable("id") String votingId) {
    votingService.close(votingService.get(votingId));
    return ResponseEntity.ok().build();
}

From source file:com.intuit.karate.demo.controller.HeadersController.java

@GetMapping("/{token:.+}")
public ResponseEntity validateToken(@CookieValue("time") String time,
        @RequestHeader("Authorization") String authorization, @PathVariable String token,
        @RequestParam String url) {
    String temp = tokens.get(token);
    if (temp.equals(time) && authorization.equals(token + time + url)) {
        return ResponseEntity.ok().build();
    } else {//w w  w.  j  av  a  2s  .c  o  m
        return ResponseEntity.badRequest().build();
    }
}

From source file:org.moserp.product.rest.ProductController.java

@ResponseBody
@RequestMapping(method = RequestMethod.GET, value = "/{productId}/ean")
public ResponseEntity<?> getProductEAN(@PathVariable String productId) throws WriterException, IOException {
    Product product = repository.findOne(productId);
    if (product == null) {
        return ResponseEntity.notFound().build();
    }// w  w w. j a va  2  s . c om
    EAN13Writer ean13Writer = new EAN13Writer();
    BitMatrix matrix = ean13Writer.encode(product.getEan(), BarcodeFormat.EAN_13, 300, 200);
    BufferedImage bufferedImage = MatrixToImageWriter.toBufferedImage(matrix);
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ImageIO.write(bufferedImage, "png", baos);
    byte[] imageData = baos.toByteArray();
    ByteArrayResource byteArrayResource = new ByteArrayResource(imageData);
    return ResponseEntity.ok().contentType(MediaType.IMAGE_PNG).body(byteArrayResource);
}

From source file:zipkin.autoconfigure.metrics.PrometheusMetricsAutoConfiguration.java

@RequestMapping(method = RequestMethod.GET)
public ResponseEntity<String> prometheusMetrics() {
    StringBuilder sb = new StringBuilder();

    for (PublicMetrics publicMetrics : this.publicMetrics) {
        for (Metric<?> metric : publicMetrics.metrics()) {
            final String sanitizedName = sanitizeMetricName(metric.getName());
            final String type = typeForName(sanitizedName);
            final String metricName = metricName(sanitizedName, type);
            double value = metric.getValue().doubleValue();

            sb.append(String.format("#TYPE %s %s\n", metricName, type));
            sb.append(String.format("#HELP %s %s\n", metricName, metricName));
            sb.append(String.format("%s %s\n", metricName, prometheusDouble(value)));
        }//from   ww w .ja  v  a  2 s. c o m
    }
    return ResponseEntity.ok().contentType(MediaType.parseMediaType("text/plain; version=0.0.4; charset=utf-8"))
            .body(sb.toString());

}