Example usage for org.springframework.http ResponseEntity status

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

Introduction

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

Prototype

Object status

To view the source code for org.springframework.http ResponseEntity status.

Click Source Link

Usage

From source file:com.github.gregwhitaker.asyncshowdown.HelloController.java

/**
 * Asynchronously waits a random random number of milliseconds, within the specified minimum and maximum, before
 * returning a 200 HTTP response with the body containing the string "Hello World!"
 *
 * @param minSleep minimum sleep time in milliseconds
 * @param maxSleep maximum sleep time in milliseconds
 * @return A 200 HTTP response with the body containing the string "Hello World!"
 *///from w  w w. j  a  v a 2s .  co m
@RequestMapping(value = "/hello", method = RequestMethod.GET)
public DeferredResult<ResponseEntity<String>> hello(
        @RequestParam(name = "minSleepMs", defaultValue = "500") long minSleep,
        @RequestParam(name = "maxSleepMs", defaultValue = "500") long maxSleep) {
    final DeferredResult<ResponseEntity<String>> deferredResult = new DeferredResult<>();

    final FutureTask<String> helloTask = new FutureTask(new HelloGenerator(minSleep, maxSleep));
    Observable.<String>create(sub -> {
        String message = null;
        try {
            helloTask.run();
            message = helloTask.get();
        } catch (Exception e) {
            sub.onError(e);
        }
        sub.onNext(message);
        sub.onCompleted();
    }).last().subscribeOn(Schedulers.io()).subscribe(
            message -> deferredResult.setResult(ResponseEntity.ok(message)),
            error -> deferredResult.setResult(ResponseEntity.status(500).body(error.getMessage())));

    return deferredResult;
}

From source file:ch.heigvd.gamification.api.AuthEndpoint.java

@Override
@RequestMapping(method = RequestMethod.POST)
public ResponseEntity authenticateApplicationAndGetToken(
        @ApiParam(value = "The info required to authenticate an application", required = true) @RequestBody Credentials body) {

    Application app1 = applicationsRepository.findByName(body.getApplicationName());

    if (app1 != null) {

        String password = body.getPassword();

        try {/*w  w  w . j a  v  a2s. c o  m*/
            password = Application.doHash(password, app1.getSel());

        } catch (UnsupportedEncodingException | NoSuchAlgorithmException ex) {
            Logger.getLogger(AuthEndpoint.class.getName()).log(Level.SEVERE, null, ex);
        }

        Application app = applicationsRepository.findByPassword(password);

        if (app != null) {
            Token token = new Token();
            AuthenKey appKey = authenrepository.findByApp(app);
            token.setApplicationName(appKey.getAppKey());
            return ResponseEntity.ok(token);
        } else {

            return ResponseEntity.status(HttpStatus.UNAUTHORIZED).build();

        }

    }

    return ResponseEntity.status(HttpStatus.UNAUTHORIZED).build();

}

From source file:com.github.lynxdb.server.api.http.handlers.EpStats.java

@RequestMapping(path = "/threads", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity threads() {
    return ResponseEntity.status(HttpStatus.NOT_IMPLEMENTED).build();
}

From source file:com.github.lynxdb.server.api.http.handlers.EpTree.java

@RequestMapping(path = "/rule", method = { RequestMethod.GET, RequestMethod.POST, RequestMethod.DELETE,
        RequestMethod.PUT }, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity rule() {
    return ResponseEntity.status(HttpStatus.NOT_IMPLEMENTED).build();
}

From source file:br.com.s2it.snakes.controllers.CarController.java

@CrossOrigin("*")
@RequestMapping(value = "/checklist/{licensePlate}", method = RequestMethod.PUT)
public ResponseEntity<Car> doChecklist(final @RequestBody CarCheckList checklist,
        final @PathVariable(value = "licensePlate") String licensePlate) {
    if (licensePlate == null || licensePlate.isEmpty() || checklist == null)
        return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(null);

    try {/* w  w w .ja v a2 s .  co  m*/
        Car car = service.findByLicensePlate(licensePlate);

        if (car.getChecklist() == null)
            car.setChecklist(new ArrayList<>());

        car.getChecklist().add(checklist);

        return ResponseEntity.status(HttpStatus.OK).body(service.save(car));
    } catch (Exception e) {
        return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(null);
    }
}

From source file:org.createnet.raptor.auth.service.controller.UserController.java

@PreAuthorize("hasAuthority('admin') or hasAuthority('super_admin')")
@RequestMapping(value = { "/user" }, method = RequestMethod.POST)
@ApiOperation(value = "Create a new user", notes = "", response = User.class, nickname = "createUser")
public ResponseEntity<User> create(
        @AuthenticationPrincipal RaptorUserDetailsService.RaptorUserDetails currentUser,
        @RequestBody User rawUser) {//from  w w w.j ava  2s  . c  o  m

    boolean exists = userService.exists(rawUser);

    if (exists) {
        return ResponseEntity.status(403).body(null);
    }

    return ResponseEntity.ok(userService.create(rawUser));
}

From source file:feign.form.Server.java

@RequestMapping(value = "/upload/{id}", method = POST)
@ResponseStatus(OK)/* w  w  w .  jav a2  s.  c o m*/
public ResponseEntity<Long> upload(@PathVariable("id") Integer id, @RequestParam("public") Boolean isPublic,
        @RequestParam("file") MultipartFile file) {
    HttpStatus status;
    if (id == null || id != 10) {
        status = LOCKED;
    } else if (isPublic == null || !isPublic) {
        status = FORBIDDEN;
    } else if (file.getSize() == 0) {
        status = I_AM_A_TEAPOT;
    } else if (file.getOriginalFilename() == null || file.getOriginalFilename().trim().isEmpty()) {
        status = CONFLICT;
    } else {
        status = OK;
    }
    return ResponseEntity.status(status).body(file.getSize());
}

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 . j  ava2s.  c  o  m
            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:br.com.uol.runas.controller.JUnitController.java

private ResponseEntity<String> runJUnit(String path, String[] suites) throws Exception {
    final JUnitServiceResponse response = jUnitService.runTests(path, suites);

    HttpStatus status;/*from w w w.j av a  2s .  c om*/

    if (response.getResult().wasSuccessful() && response.getResult().getIgnoreCount() == 0) {
        status = HttpStatus.OK;
    } else if (response.getResult().getFailureCount() > 0) {
        status = HttpStatus.EXPECTATION_FAILED;
    } else {
        status = HttpStatus.PARTIAL_CONTENT;
    }

    return ResponseEntity.status(status).contentType(response.getMediaType()).body(response.getLog());
}

From source file:org.lecture.controller.UserController.java

/**
 * Creates a new User//from  w  ww . j a  v  a2s.c om
 * @param entity the user from the post-request. This user is deserialized by
 *              jackson.
 * @return A respoonse containing a link to the new resource.
 */
@RequestMapping(method = RequestMethod.POST, consumes = "application/json;charset=UTF-8")
public ResponseEntity<?> create(@RequestBody User entity) {
    User user = this.userRepository.findByUsername(entity.getUsername());
    if (user == null) {
        this.userRepository.save(entity);
        nats.publish("authentication-service.user-created", entity.getId());
        return ResponseEntity.noContent().build();
    }
    return ResponseEntity.status(HttpStatus.CONFLICT).build();
}