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 <T> ResponseEntity<T> ok(T body) 

Source Link

Document

A shortcut for creating a ResponseEntity with the given body and the status set to HttpStatus#OK OK .

Usage

From source file:io.ignitr.dispatchr.manager.controller.client.ClientController.java

/**
 * Finds a specific client./*from w w w . j ava  2s.  c o m*/
 *
 * @param clientId client identifier
 * @return an HTTP 200 response containing the client metadata or an HTTP 404 if the client does not exist
 */
@RequestMapping(method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public DeferredResult<ResponseEntity<FindClientResponse>> findOne(@PathVariable("clientId") String clientId,
        HttpServletRequest httpRequest) {
    final DeferredResult<ResponseEntity<FindClientResponse>> deferredResult = new DeferredResult<>();

    service.findOne(clientId).lift(new RequestContextStashOperator<>()).last().map(FindClientResponse::from)
            .subscribeOn(Schedulers.io()).subscribe(body -> {
                deferredResult.setResult(ResponseEntity.ok(body));
            }, error -> {
                deferredResult.setErrorResult(errorHandler.handleError(httpRequest, error));
            });

    return deferredResult;
}

From source file:org.apache.ambari.view.web.controller.RepositoryController.java

@DeleteMapping("/{id}")
public ResponseEntity<Map<String, String>> destroy(@PathVariable("id") Long id) {
    repositoryService.destroy(id);//  www . j  av  a2  s. c  o m
    Map<String, String> emptyMap = new HashMap<>();
    return ResponseEntity.ok(emptyMap);
}

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

@PreAuthorize("hasAuthority('admin') or hasAuthority('super_admin')")
@RequestMapping(value = "/role", method = RequestMethod.GET)
@ApiOperation(value = "List available roles", notes = "", response = Role.class, responseContainer = "Iterable", nickname = "getRoles")
public ResponseEntity<?> getRoles() {
    Iterable<Role> list = roleService.list();
    return ResponseEntity.ok(list);
}

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 . ja  v  a2 s. 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: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 ww . j  a  va  2 s  . c o  m*/
        return ResponseEntity.badRequest().body("Either 'id' or 'name' must be set");
    }
}

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

@PreAuthorize("isAuthenticated()")
@RequestMapping("/token/{uuid}")
public ResponseEntity<?> getTokens(@AuthenticationPrincipal User user, @PathVariable String uuid) {
    // TODO add ACL checks
    if (!user.getUuid().equals(uuid) && !user.isSuperAdmin()) {
        return ResponseEntity.status(HttpStatus.UNAUTHORIZED)
                .body(new JsonErrorResponse(HttpStatus.UNAUTHORIZED.value(), "Not authorized"));
    }//from ww w  .j a  v a2s  .c o m

    return ResponseEntity.ok(tokenService.list(uuid));
}

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

@RequestMapping(value = "/read/", method = { RequestMethod.POST })
public ResponseEntity read(@RequestBody String code) {
    //code = code.replace("-", ".");

    ICDNummer entity = this.service.read(code);
    return ResponseEntity.ok(entity);
}

From source file:de.msg.controller.RouteController.java

@RequestMapping(value = "{id}", method = RequestMethod.POST)
@PreAuthorize("isAuthenticated() and hasPermission('de.msg.domain.route.Route', 'read')")
public ResponseEntity<Route> post(@Valid @RequestBody Route entity) {
    return ResponseEntity.ok(service.save(entity));
}

From source file:io.pivotal.strepsirrhini.chaosloris.web.EventController.java

@Transactional(readOnly = true)
@RequestMapping(method = GET, value = "/{id}", produces = HAL_JSON_VALUE)
public ResponseEntity read(@PathVariable Long id) {
    Event event = this.eventRepository.getOne(id);
    return ResponseEntity.ok(this.eventResourceAssembler.toResource(event));
}

From source file:alfio.controller.api.AttendeeApiController.java

@RequestMapping(value = "/sponsor-scan", method = RequestMethod.POST)
public ResponseEntity<TicketAndCheckInResult> scanBadge(@RequestBody SponsorScanRequest request,
        Principal principal) {/*from   w  w w.  j  a  v a  2s. c  o  m*/
    return ResponseEntity.ok(attendeeManager.registerSponsorScan(request.eventName, request.ticketIdentifier,
            principal.getName()));
}