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:com.oembedler.moon.graphql.boot.GraphQLServerController.java

@RequestMapping(method = RequestMethod.POST, consumes = "application/graphql")
public ResponseEntity<Map<String, Object>> postGraphQL(@RequestBody String query,
        @RequestParam(value = DEFAULT_OPERATION_NAME_KEY, required = false) String operationName,
        @RequestHeader(value = HEADER_SCHEMA_NAME, required = false) String graphQLSchemaName,
        HttpServletRequest httpServletRequest) {

    final GraphQLContext graphQLContext = new GraphQLContext();
    graphQLContext.setHttpRequest(httpServletRequest);

    final Map<String, Object> result = evaluateAndBuildResponseMap(query, operationName, graphQLContext,
            new HashMap<>(), graphQLSchemaName);
    return ResponseEntity.ok(result);
}

From source file:blankd.acme.pet.licensing.rest.controller.LicenseRestController.java

@RequestMapping(value = "/assign/{id}", method = RequestMethod.POST)
public ResponseEntity<?> assignPetToLicense(@PathVariable String id, @RequestParam Long petId,
        @RequestParam String username) {
    License ret = this.repo.findOne(id);

    if (ret != null && (this.isLicenseExpired(ret) && ret.getPetOwner() == null)) {

        Pet pet = this.pRepo.findById(petId);
        if (pet == null) {
            ErrorMessage err = new ErrorMessage("Could not find pet");
            return ResponseEntity.ok(err);
        }/* ww  w  .  j  a  v  a  2 s  .c  om*/

        Account owner = this.aRepo.findByUsername(username);

        if (owner == null) {
            ErrorMessage err = new ErrorMessage("Could not find Account");
            return ResponseEntity.ok(err);
        }

        ret.setPet(pet);
        ret.setPetOwner(owner);
        ret.setExpires(this.generateExpireDate());

        return ResponseEntity.ok(this.repo.save(ret));
    } else {
        if (ret.getPetOwner() != null) {
            ErrorMessage err = new ErrorMessage("License is already assigned");
            return ResponseEntity.ok(err);
        } else if (!this.isLicenseExpired(ret)) {
            ErrorMessage err = new ErrorMessage("License is not expired");
            return ResponseEntity.ok(err);
        } else {
            ErrorMessage err = new ErrorMessage("Could not assign license");
            return ResponseEntity.ok(err);
        }
    }
}

From source file:de.codecentric.boot.admin.registry.StatusUpdaterTest.java

@Test
@SuppressWarnings("rawtypes")
public void test_updateStatusForApplications() {
    Application app1 = Application.create("foo").withId("id-1").withHealthUrl("health-1").build();
    store.save(app1);/*from   w  ww.jav  a2  s .  c o  m*/

    Application app2 = Application.create("foo").withId("id-2").withHealthUrl("health-2")
            .withStatusInfo(StatusInfo.valueOf("UP", 0L)).build();
    store.save(app2);

    when(template.getForEntity("health-2", Map.class)).thenReturn(ResponseEntity.ok((Map) null));

    updater.updateStatusForAllApplications();

    verify(template, never()).getForEntity("health-1", Map.class);
}

From source file:org.awesomeagile.testing.google.FakeGoogleController.java

@RequestMapping(value = "/oauth2/token", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<?> getToken(@RequestParam("code") String code,
        @RequestParam("redirect_uri") String redirectUri, @RequestParam("grant_type") String grantType) {
    if (AUTHORIZATION_CODE.equals(grantType)) {
        if (!prefixMatches(redirectUri)) {
            return wrongRedirectUriResponse();
        }/*from  w  w w. j a v a 2 s.c o  m*/
        if (!codeToToken.containsKey(code)) {
            return ResponseEntity.<String>badRequest().body("Wrong code!");
        }
        AccessToken accessToken = codeToToken.get(code);
        knownTokens.add(accessToken.getAccessToken());
        return ResponseEntity.ok(accessToken);
    }
    return ResponseEntity.<String>badRequest().body("Wrong grant_type!");
}

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

@RequestMapping(path = "", method = { RequestMethod.GET, RequestMethod.POST,
        RequestMethod.DELETE }, produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity rootJson(@RequestBody @Valid QueryRequest _request, Authentication _authentication,
        HttpServletResponse _response) {

    User user = (User) _authentication.getPrincipal();

    List<Query> queries;

    try {//from w  w  w  .j ava 2s. c  o m
        queries = parseQuery(vhosts.byId(user.getVhost()), _request);
    } catch (ParsingQueryException ex) {
        return new ErrorResponse(mapper, HttpStatus.BAD_REQUEST, ex.getMessage(), ex).response();
    }

    File f;
    FileOutputStream fos;
    try {
        f = File.createTempFile("lynx.", ".tmp");
        fos = new FileOutputStream(f);
    } catch (IOException ex) {
        return new ErrorResponse(mapper, HttpStatus.INTERNAL_SERVER_ERROR, ex.getMessage(), ex).response();
    }

    try {
        saveResponse(fos, queries);
    } catch (IOException ex) {
        return new ErrorResponse(mapper, HttpStatus.INTERNAL_SERVER_ERROR, ex.getMessage(), ex).response();
    }

    try {
        return ResponseEntity.ok(new InputStreamResource(new FileInputStream(f)));
    } catch (FileNotFoundException ex) {
        return new ErrorResponse(mapper, HttpStatus.INTERNAL_SERVER_ERROR, ex.getMessage(), ex).response();
    } finally {
        f.delete();
    }
}

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

@Transactional(readOnly = true)
@RequestMapping(method = GET, value = "/{id}", produces = HAL_JSON_VALUE)
public ResponseEntity read(@PathVariable Long id) {
    Chaos chaos = this.chaosRepository.getOne(id);
    return ResponseEntity.ok(this.chaosResourceAssembler.toResource(chaos));
}

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

@RequestMapping(value = "/{userLogin}", method = RequestMethod.PUT, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity updateUser(Authentication _authentication, @PathVariable("userLogin") String userLogin,
        @RequestBody @Valid UserUpdateRequest _ucr, BindingResult _bindingResult) {

    if (_bindingResult.hasErrors()) {
        ArrayList<String> errors = new ArrayList();
        _bindingResult.getFieldErrors().forEach((FieldError t) -> {
            errors.add(t.getField() + ": " + t.getDefaultMessage());
        });/*ww w  .  j  a v  a  2 s  . c  o  m*/
        return new ErrorResponse(mapper, HttpStatus.BAD_REQUEST, errors.toString()).response();
    }

    User user = users.byLogin(userLogin);
    if (user == null) {
        return new ErrorResponse(mapper, HttpStatus.BAD_REQUEST, "User does not exist.", null).response();
    }

    if (_ucr.password != null && !_ucr.password.isEmpty()) {
        user.setPassword(_ucr.password);
    }
    if (_ucr.rank != null) {
        user.setRank(_ucr.rank);
    }

    users.save(user);

    return ResponseEntity.ok(user);
}

From source file:ch.ge.ve.protopoc.controller.impl.AuthenticationController.java

@Override
public ResponseEntity<?> renewAuthenticationToken(HttpServletRequest request) {
    String token = request.getHeader(tokenHeader);

    if (jwtTokenUtil.canTokenBeRefreshed(token)) {
        String refreshedToken = jwtTokenUtil.refreshToken(token);
        return ResponseEntity.ok(new JwtAuthenticationResponse(refreshedToken));
    } else {/*ww w . j  a  v a 2  s .  c o m*/
        return ResponseEntity.badRequest().body(null);
    }
}

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

@PreAuthorize("hasAuthority('admin') or hasAuthority('super_admin')")
@RequestMapping(value = { "/role" }, method = RequestMethod.POST)
@ApiOperation(value = "Create a new role", notes = "", response = Role.class, nickname = "createRole")
@ApiResponses(value = { @ApiResponse(code = 400, message = "Bad Request"),
        @ApiResponse(code = 409, message = "Conflict") })
public ResponseEntity<?> create(@AuthenticationPrincipal RaptorUserDetailsService.RaptorUserDetails currentUser,
        @RequestBody Role rawRole) {

    if ((rawRole.getName().isEmpty() || rawRole.getName() == null)) {
        return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Name property is missing");
    }/*from  w ww .  j a  v a  2s  . c  o m*/

    Role role2 = roleService.getByName(rawRole.getName());
    if (role2 != null) {
        return ResponseEntity.status(HttpStatus.CONFLICT).body(null);
    }

    Role role = roleService.create(rawRole);
    if (role == null) {
        return ResponseEntity.status(HttpStatus.CONFLICT).body(null);
    }

    logger.debug("Created role {}", role.getName());
    return ResponseEntity.ok(role);
}

From source file:cn.org.once.cstack.controller.ServerController.java

@RequestMapping(value = "/volume/containerName/{containerName}", method = RequestMethod.GET)
public ResponseEntity<?> getVolume(@PathVariable("containerName") String containerName)
        throws ServiceException, CheckException {
    List<VolumeResource> resource = volumeService.loadAllByContainerName(containerName).stream()
            .map(VolumeResource::new).collect(Collectors.toList());
    return ResponseEntity.ok(resource);
}