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:cn.org.once.cstack.controller.MonitoringController.java

/**
 * Return the position into the architecture of the service
 * @return//ww  w.jav  a2 s .c  o  m
 */
@RequestMapping("/location")
public ResponseEntity<String> getServiceLocation(@Value("#{environment.CU_KIBANA_DOMAIN}") String location) {
    if (location != null && !location.startsWith("https")) {
        location = "https://" + location;
    }
    return ResponseEntity.ok(location);
}

From source file:org.icgc.dcc.metadata.server.resource.EntityResource.java

@RequestMapping(method = POST)
public ResponseEntity<Entity> save(@RequestBody @Valid Entity entity) {
    val existing = repository.findByGnosIdAndFileName(entity.getGnosId(), entity.getFileName());
    if (!existing.isEmpty()) {
        return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
    }//from  www  .  ja  v a2 s.c  o  m

    return ResponseEntity.ok(repository.save(entity));
}

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

@Transactional(readOnly = true)
@RequestMapping(method = GET, value = "", produces = HAL_JSON_VALUE)
public ResponseEntity list(Pageable pageable, PagedResourcesAssembler<Chaos> pagedResourcesAssembler) {
    Page<Chaos> chaoses = this.chaosRepository.findAll(pageable);
    return ResponseEntity.ok(pagedResourcesAssembler.toResource(chaoses, this.chaosResourceAssembler));
}

From source file:org.n52.tamis.rest.controller.processes.jobs.JobOutputsController.java

/**
 * Returns the result document containing outputs of a certain job.
 * //from   w ww. j  av  a2s.  c o m
 * @param serviceId
 *            inside the URL the variable
 *            {@link URL_Constants_TAMIS#SERVICE_ID_VARIABLE_NAME} specifies
 *            the id of the service.
 * @param processId
 *            inside the URL the variable
 *            {@link URL_Constants_TAMIS#PROCESS_ID_VARIABLE_NAME} specifies
 *            the id of the process.
 * @param jobId
 *            inside the URL the variable
 *            {@link URL_Constants_TAMIS#JOB_ID_VARIABLE_NAME} specifies the
 *            id of the job.
 * @param request
 * @return the status description
 */
@RequestMapping("")
@ResponseBody
public ResponseEntity<ResultDocument> getResultDocument(
        @PathVariable(URL_Constants_TAMIS.SERVICE_ID_VARIABLE_NAME) String serviceId,
        @PathVariable(URL_Constants_TAMIS.PROCESS_ID_VARIABLE_NAME) String processId,
        @PathVariable(URL_Constants_TAMIS.JOB_ID_VARIABLE_NAME) String jobId, HttpServletRequest request) {

    logger.info(
            "Received get outputs (result document) request for service id \"{}\", process id \"{}\" and job id \"{}\"!",
            serviceId, processId, jobId);

    parameterValueStore.addParameterValuePair(URL_Constants_TAMIS.SERVICE_ID_VARIABLE_NAME, serviceId);
    parameterValueStore.addParameterValuePair(URL_Constants_TAMIS.PROCESS_ID_VARIABLE_NAME, processId);
    parameterValueStore.addParameterValuePair(URL_Constants_TAMIS.JOB_ID_VARIABLE_NAME, jobId);

    ResultDocument resultDocument = jobOutputsRequestForwarder.forwardRequestToWpsProxy(request, null,
            parameterValueStore);

    return ResponseEntity.ok(resultDocument);
}

From source file:com.github.ukase.web.UkaseController.java

@RequestMapping(value = "/pdf", method = RequestMethod.POST, produces = "application/pdf")
public ResponseEntity<byte[]> generatePdf(@RequestBody @Valid UkasePayload payload)
        throws IOException, DocumentException, URISyntaxException {
    log.debug("Generate PDF POST for '{}' :\n{}\n", payload.getIndex(), payload.getData());
    return ResponseEntity.ok(taskBuilder.build(payload).call());
}

From source file:com.organization.projectname.controller.AuthenticationController.java

@RequestMapping(value = "${jwt.route.authentication.refresh}", method = RequestMethod.GET)
public ResponseEntity<?> refreshAndGetAuthenticationToken(HttpServletRequest request) throws Exception {

    userService.isIPOK();//from  w w w.j  av a  2  s  .co  m

    String token = request.getHeader(tokenHeader);
    String username = jwtTokenUtil.getUsernameFromToken(token);
    User user = (User) userService.loadUserByUsername(username);

    if (jwtTokenUtil.canTokenBeRefreshed(token, user.getLastPasswordResetDate())) {
        String refreshedToken = jwtTokenUtil.refreshToken(token);
        return ResponseEntity.ok(new AuthenticationResponse(refreshedToken));
    } else {
        return ResponseEntity.badRequest().body(null);
    }
}

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

@Transactional(readOnly = true)
@RequestMapping(method = GET, value = "/{id}", produces = HAL_JSON_VALUE)
public ResponseEntity read(@PathVariable Long id) {
    Schedule schedule = this.scheduleRepository.getOne(id);
    return ResponseEntity.ok(this.scheduleResourceAssembler.toResource(schedule));
}

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

@Override
public ResponseEntity<?> createAuthenticationToken(
        @RequestBody JwtAuthenticationRequest authenticationRequest) {
    logger.info(String.format("Attempting login for user [%s]", authenticationRequest.getUsername()));

    // Perform the security
    final Authentication authentication = authenticationManager
            .authenticate(new UsernamePasswordAuthenticationToken(authenticationRequest.getUsername(),
                    authenticationRequest.getPassword()));
    SecurityContextHolder.getContext().setAuthentication(authentication);

    // Reload password post-security so we can generate token
    final UserDetails userDetails = userDetailsService.loadUserByUsername(authenticationRequest.getUsername());
    final String token = jwtTokenUtil.generateToken(userDetails);

    // Return the token
    return ResponseEntity.ok(new JwtAuthenticationResponse(token));
}

From source file:org.n52.tamis.rest.controller.processes.jobs.StatusRequestController.java

/**
 * Returns the status description.// ww w .  ja v  a  2  s  .  co  m
 * 
 * @param serviceId
 *            inside the URL the variable
 *            {@link URL_Constants_TAMIS#SERVICE_ID_VARIABLE_NAME} specifies
 *            the id of the service.
 * @param processId
 *            inside the URL the variable
 *            {@link URL_Constants_TAMIS#PROCESS_ID_VARIABLE_NAME} specifies
 *            the id of the process.
 * @param jobId
 *            inside the URL the variable
 *            {@link URL_Constants_TAMIS#JOB_ID_VARIABLE_NAME} specifies the
 *            id of the job.
 * @param request
 * @return the status description
 */
@RequestMapping("")
@ResponseBody
public ResponseEntity<StatusDescription> getStatusDescription(
        @PathVariable(URL_Constants_TAMIS.SERVICE_ID_VARIABLE_NAME) String serviceId,
        @PathVariable(URL_Constants_TAMIS.PROCESS_ID_VARIABLE_NAME) String processId,
        @PathVariable(URL_Constants_TAMIS.JOB_ID_VARIABLE_NAME) String jobId, HttpServletRequest request) {

    logger.info(
            "Received status description request for service id \"{}\", process id \"{}\" and job id \"{}\"!",
            serviceId, processId, jobId);

    parameterValueStore.addParameterValuePair(URL_Constants_TAMIS.SERVICE_ID_VARIABLE_NAME, serviceId);
    parameterValueStore.addParameterValuePair(URL_Constants_TAMIS.PROCESS_ID_VARIABLE_NAME, processId);
    parameterValueStore.addParameterValuePair(URL_Constants_TAMIS.JOB_ID_VARIABLE_NAME, jobId);

    StatusDescription singleStatusDescription = statusRequestForwarder.forwardRequestToWpsProxy(request, null,
            parameterValueStore);

    return ResponseEntity.ok(singleStatusDescription);
}

From source file:io.pivotal.cla.mvc.github.GitHubHooksController.java

/**
 * @param request// ww  w . ja  v a  2 s . c  o m
 * @param body
 * @param cla
 * @param githubEvent
 * @return
 * @throws Exception
 */
@RequestMapping("/github/hooks/pull_request/{cla}")
public ResponseEntity<String> pullRequest(HttpServletRequest request, @RequestBody String body,
        @PathVariable String cla, @RequestHeader("X-GitHub-Event") String githubEvent) throws Exception {

    if (!ACCEPTED_EVENTS.contains(githubEvent)) {
        return ResponseEntity.badRequest()
                .body(String.format("X-Github-Event: %s not acceptable", githubEvent));
    }

    Gson gson = GsonUtils.createGson();
    RepositoryAware payload = gson.fromJson(body, PAYLOAD_TYPES.get(githubEvent));

    PullRequest pullRequest = getPullRequest(payload);

    if (pullRequest == null) {
        return ResponseEntity.badRequest().body("Not related to a Pull request");
    }

    User senderUser = getSender(payload);

    if (senderUser.getLogin().equals(gitHubApi.getGitHubClaUserLogin())) {
        return ResponseEntity.ok("Skipping self-events");
    }

    User user = getPullRequestUser(payload);

    Repository repository = payload.getRepository();
    RepositoryId repoId = RepositoryId
            .createFromId(repository.getOwner().getLogin() + "/" + repository.getName());
    String sha = getPullRequestSha(repoId, pullRequest);
    String gitHubLogin = user.getLogin();

    PullRequestStatus status = new PullRequestStatus();
    status.setGitHubUsername(gitHubLogin);
    status.setPullRequestId(pullRequest.getNumber());
    status.setPullRequestBody(pullRequest.getBody());
    status.setRepoId(repoId.generateId());
    status.setSha(sha);
    String signUrl = UrlBuilder.signUrl().request(request).claName(cla).repositoryId(status.getRepoId())
            .pullRequestId(status.getPullRequestId()).build();
    status.setUrl(signUrl);
    status.setPullRequestState(pullRequest.getState());

    String syncUrl = UrlBuilder.createSyncUrl(request, cla, status.getRepoId(), status.getPullRequestId());
    status.setSyncUrl(syncUrl);

    String faqUrl = UrlBuilder.createAboutUrl(request);
    status.setFaqUrl(faqUrl);

    ClaPullRequestStatusRequest pullRequestStatusRequest = new ClaPullRequestStatusRequest();
    pullRequestStatusRequest.setClaName(cla);
    pullRequestStatusRequest.setCommitStatus(status);
    claService.savePullRequestStatus(pullRequestStatusRequest);

    return ResponseEntity.ok("SUCCESS");
}