Example usage for org.springframework.http ResponseEntity badRequest

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

Introduction

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

Prototype

public static BodyBuilder badRequest() 

Source Link

Document

Create a builder with a HttpStatus#BAD_REQUEST BAD_REQUEST status.

Usage

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 {/*from  w w  w  .j  av a 2 s .c  o m*/
        return ResponseEntity.badRequest().build();
    }
}

From source file:org.kelvmiao.sevenwonders.web.controller.UserController.java

@RequestMapping(method = RequestMethod.GET, value = "/logout")
ResponseEntity logout() {//from   w  w  w. j  a  va2  s .  c o  m
    if (httpSession.getAttribute("uid") != null) {
        httpSession.invalidate();
        return ResponseEntity.noContent().build();
    }
    return ResponseEntity.badRequest().build();
}

From source file:com.greglturnquist.springagram.fileservice.s3.ApplicationController.java

@RequestMapping(method = RequestMethod.POST, value = "/files")
public ResponseEntity<?> newFile(@RequestParam("name") String filename,
        @RequestParam("file") MultipartFile file) {

    try {/*from  w  w  w  .ja va  2s  .  c o m*/
        this.fileService.saveFile(file.getInputStream(), file.getSize(), filename);

        Link link = linkTo(methodOn(ApplicationController.class).getFile(filename)).withRel(filename);
        return ResponseEntity.created(new URI(link.getHref())).build();

    } catch (IOException | URISyntaxException e) {
        return ResponseEntity.badRequest().body("Couldn't process the request");
    }
}

From source file:de.codecentric.boot.admin.notify.filter.web.NotificationFilterController.java

@RequestMapping(path = "/api/notifications/filters", method = {
        RequestMethod.POST }, produces = MimeTypeUtils.APPLICATION_JSON_VALUE)
public ResponseEntity<?> addFilter(@RequestParam(name = "id", required = false) String id,
        @RequestParam(name = "name", required = false) String name,
        @RequestParam(name = "ttl", required = false, defaultValue = "-1") long ttl) {
    if (hasText(id) || hasText(name)) {
        NotificationFilter filter = createFilter(id, name, ttl);
        String filterId = filteringNotifier.addFilter(filter);
        return ResponseEntity.ok(Collections.singletonMap(filterId, filter));
    } else {//from w w  w .  j  a  va 2s. co  m
        return ResponseEntity.badRequest().body("Either 'id' or 'name' must be set");
    }
}

From source file:com.greglturnquist.springagram.fileservice.mongodb.ApplicationController.java

@RequestMapping(method = RequestMethod.POST, value = "/files")
public ResponseEntity<?> newFile(@RequestParam("name") String filename,
        @RequestParam("file") MultipartFile file) {

    if (!file.isEmpty()) {
        try {/*  w w  w .  java  2 s.c om*/
            this.fileService.saveFile(file.getInputStream(), filename);

            Link link = linkTo(methodOn(ApplicationController.class).getFile(filename)).withRel(filename);
            return ResponseEntity.created(new URI(link.getHref())).build();

        } catch (IOException | URISyntaxException e) {
            return ResponseEntity.badRequest().body("Couldn't process the request");
        }
    } else {
        return ResponseEntity.status(HttpStatus.NOT_ACCEPTABLE).body("File is empty");
    }
}

From source file:me.j360.trace.example.consumer2.ZipkinServerConfiguration.java

DeferredResult<ResponseEntity<?>> validateAndStoreSpans(String encoding, Codec codec, byte[] body) {
    DeferredResult<ResponseEntity<?>> result = new DeferredResult<>();
    metrics.incrementMessages();/* ww  w  .j  a  va  2  s .com*/
    if (encoding != null && encoding.contains("gzip")) {
        try {
            body = gunzip(body);
        } catch (IOException e) {
            metrics.incrementMessagesDropped();
            result.setResult(ResponseEntity.badRequest().body("Cannot gunzip spans: " + e.getMessage() + "\n"));
            return result;
        }
    }
    collector.acceptSpans(body, codec, new Callback<Void>() {
        @Override
        public void onSuccess(@Nullable Void value) {
            result.setResult(SUCCESS);
        }

        @Override
        public void onError(Throwable t) {
            String message = t.getMessage();
            result.setErrorResult(
                    message.startsWith("Cannot store") ? ResponseEntity.status(500).body(message + "\n")
                            : ResponseEntity.status(400).body(message + "\n"));
        }
    });
    return result;
}

From source file:com.greglturnquist.HomeController.java

private ResponseEntity<?> getRawImage() {
    try {/*from w ww  .  j a v  a 2 s  . c  o  m*/
        Resource file = resourceLoader.getResource("file:upload-dir/keep-calm-and-learn-javascript.jpg");
        return ResponseEntity.ok().contentLength(file.contentLength()).contentType(MediaType.IMAGE_JPEG)
                .body(new InputStreamResource(file.getInputStream()));
    } catch (IOException e) {
        return ResponseEntity.badRequest().body("Couldn't find it => " + e.getMessage());
    }
}

From source file:com.greglturnquist.springagram.fileservice.s3.ApplicationController.java

@RequestMapping(method = RequestMethod.GET, value = "/files")
public ResponseEntity<?> listFiles() {

    try {//w  w w .  j a v  a 2 s .com
        Resource[] files = this.fileService.findAll();

        ResourceSupport resources = new ResourceSupport();

        for (Resource file : files) {
            resources.add(linkTo(methodOn(ApplicationController.class).getFile(file.getFilename()))
                    .withRel(file.getFilename()));
        }

        return ResponseEntity.ok(resources);
    } catch (IOException e) {
        return ResponseEntity.badRequest().body(e.getMessage());
    }
}

From source file:zipkin.server.ZipkinHttpCollector.java

ListenableFuture<ResponseEntity<?>> validateAndStoreSpans(String encoding, Codec codec, byte[] body) {
    SettableListenableFuture<ResponseEntity<?>> result = new SettableListenableFuture<>();
    metrics.incrementMessages();//from w ww .  j  a  v a  2 s .co  m
    if (encoding != null && encoding.contains("gzip")) {
        try {
            body = gunzip(body);
        } catch (IOException e) {
            metrics.incrementMessagesDropped();
            result.set(ResponseEntity.badRequest().body("Cannot gunzip spans: " + e.getMessage() + "\n"));
        }
    }
    collector.acceptSpans(body, codec, new Callback<Void>() {
        @Override
        public void onSuccess(@Nullable Void value) {
            result.set(SUCCESS);
        }

        @Override
        public void onError(Throwable t) {
            String message = t.getMessage() == null ? t.getClass().getSimpleName() : t.getMessage();
            result.set(t.getMessage() == null || message.startsWith("Cannot store")
                    ? ResponseEntity.status(500).body(message + "\n")
                    : ResponseEntity.status(400).body(message + "\n"));
        }
    });
    return result;
}

From source file:com.jevontech.wabl.controllers.AuthenticationController.java

@CrossOrigin
@RequestMapping(value = "/refresh", method = RequestMethod.GET)
public ResponseEntity<?> authenticationRequest(HttpServletRequest request) {
    String token = request.getHeader(this.tokenHeader);
    String username = this.tokenUtils.getUsernameFromToken(token);
    SecurityUser user = (SecurityUser) this.userDetailsService.loadUserByUsername(username);
    if (this.tokenUtils.canTokenBeRefreshed(token, user.getLastPasswordReset())) {
        String refreshedToken = this.tokenUtils.refreshToken(token);
        return ResponseEntity.ok(new AuthenticationResponse(refreshedToken));
    } else {/*from   w ww . j  av a  2s .  co  m*/
        return ResponseEntity.badRequest().body(null);
    }
}