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 BodyBuilder ok() 

Source Link

Document

Create a builder with the status set to HttpStatus#OK OK .

Usage

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

@RequestMapping(value = "/{id}", method = RequestMethod.PATCH, consumes = "application/json;charset=UTF-8")
public ResponseEntity<?> update(@PathVariable String id, @RequestBody List<FilePatch> patches) {

    CompilationReport report = compilerService.patchAndCompileTestSource(id, patches);
    if (report == null) {
        return ResponseEntity.noContent().build();
    }/* ww  w  . j a  va  2  s.  c  o  m*/
    return ResponseEntity.ok().body(report);
}

From source file:com.consol.citrus.admin.connector.WebSocketPushMessageListenerTest.java

@Test
public void testNoContext() throws Exception {
    Message inbound = new DefaultMessage("Hello Citrus!");

    reset(restTemplate, context);//from   w w  w .ja va2s.  c  om
    when(restTemplate.exchange(eq("http://localhost:8080/connector/message/inbound?processId="),
            eq(HttpMethod.POST), any(HttpEntity.class), eq(String.class))).thenAnswer(invocation -> {
                HttpEntity request = (HttpEntity) invocation.getArguments()[2];

                Assert.assertEquals(request.getBody().toString(), inbound.toString());

                return ResponseEntity.ok().build();
            });

    pushMessageListener.onInboundMessage(inbound, null);
    pushMessageListener.onInboundMessage(inbound, context);

    verify(restTemplate, times(2)).exchange(eq("http://localhost:8080/connector/message/inbound?processId="),
            eq(HttpMethod.POST), any(HttpEntity.class), eq(String.class));
}

From source file:me.j360.trace.autoconfiguration.ui.ZipkinUiAutoConfiguration.java

@RequestMapping(value = "/config.json", method = GET, produces = APPLICATION_JSON_VALUE)
public ResponseEntity<ZipkinUiProperties> serveUiConfig() {
    return ResponseEntity.ok().cacheControl(CacheControl.maxAge(10, TimeUnit.MINUTES)).body(ui);
}

From source file:io.kahu.hawaii.util.spring.HawaiiControllerExceptionHandler.java

private ResponseEntity<String> handleException(Throwable throwable, int httpStatusCode, JSONObject error) {
    HttpHeaders headers = new HttpHeaders();
    headers.setContentType(MediaType.APPLICATION_JSON);
    Object hawaiiTxId = LoggingContext.get().get("tx.id");
    if (hawaiiTxId != null) {
        headers.set(X_HAWAII_TRANSACTION_ID_HEADER, hawaiiTxId.toString());
    }/*  www  . j  a va2  s  . co  m*/
    JSONObject json = new JSONObject();
    try {
        json.put("status", httpStatusCode);
        json.put("data", new JSONArray());
        json.put("error", error);
    } catch (JSONException exc) {
        logManager.debug(CoreLoggers.SERVER_EXCEPTION, exc.getMessage(), exc);
    }

    log(throwable);

    return ResponseEntity.ok().headers(headers).body(json.toString());
}

From source file:me.j360.trace.autoconfiguration.ui.ZipkinUiAutoConfiguration.java

@RequestMapping(value = "/index.html", method = GET)
public ResponseEntity<Resource> serveIndex() {
    return ResponseEntity.ok().cacheControl(CacheControl.maxAge(1, TimeUnit.MINUTES)).body(indexHtml);
}

From source file:br.edu.ifpb.controllers.TopicController.java

@RequestMapping(value = "/image/{id}", method = RequestMethod.GET)
@ResponseBody/*from w  w w. ja  v  a2s  .  com*/
public ResponseEntity<InputStreamResource> getImage(@PathVariable String id) {

    byte[] file = ImageTopicRepository.getTopicImage2(id);

    return ResponseEntity.ok().contentLength(file.length)
            //                .contentType(MediaType.parseMediaType(file.getGridFSFile().getMetadata().getString("content-type")))
            .body(new InputStreamResource(new ByteArrayInputStream(file)));
}

From source file:com.todo.backend.web.rest.UserApi.java

@RequestMapping(value = "/user-todos", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
@Timed/*from ww  w  . j  a  v a 2 s. c  om*/
@Transactional(readOnly = true)
@PreAuthorize("hasAuthority('ADMIN')")
public ResponseEntity<List<UserTodosResponse>> userTodos(@RequestParam("userId") Long userId) {
    log.debug("GET /user-todos");
    final List<Todo> result = todoRepository.userTodos(userId);
    return ResponseEntity.ok()
            .body(result.stream().map(this::convertToUserTodosResponse).collect(Collectors.toList()));
}

From source file:com.saasovation.identityaccess.resource.UserResource.java

private ResponseEntity<String> userResponse(User aUser) {

    String eTag = this.userETag(aUser);

    ResponseEntity<String> response;
    //        ResponseBuilder conditionalBuilder = aRequest.evaluatePreconditions(eTag);
    //// www  .  j  a  v  a 2  s  .co  m
    //        if (conditionalBuilder != null) {
    //            response =
    //                    conditionalBuilder
    //                        .cacheControl(this.cacheControlFor(3600))
    //                        .tag(eTag)
    //                        .build();
    //        } else {
    String representation = ObjectSerializer.instance().serialize(new UserRepresentation(aUser));

    response = ResponseEntity.ok().cacheControl(this.cacheControlFor(3600)).eTag(eTag).body(representation);
    //        }

    return response;
}

From source file:io.restassured.examples.springmvc.controller.FileUploadController.java

@RequestMapping(value = "/textAndReturnHeader", method = POST, consumes = "multipart/mixed", produces = APPLICATION_JSON_VALUE)
public ResponseEntity<String> fileUploadWithControlNameEqualToSomething(
        @RequestHeader("Content-Type") String requestContentType,
        @RequestParam(value = "something") MultipartFile file) {
    return ResponseEntity.ok().header(APPLICATION_JSON_VALUE).header("X-Request-Header", requestContentType)
            .body("{ \"size\" : " + file.getSize() + ", \"name\" : \"" + file.getName()
                    + "\", \"originalName\" : \"" + file.getOriginalFilename() + "\", \"mimeType\" : \""
                    + file.getContentType() + "\" }");
}

From source file:io.spring.initializr.web.project.MainController.java

@RequestMapping(path = "/", produces = "text/plain")
public ResponseEntity<String> serviceCapabilitiesText(
        @RequestHeader(value = HttpHeaders.USER_AGENT, required = false) String userAgent) {
    String appUrl = generateAppUrl();
    InitializrMetadata metadata = this.metadataProvider.get();

    BodyBuilder builder = ResponseEntity.ok().contentType(MediaType.TEXT_PLAIN);
    if (userAgent != null) {
        Agent agent = Agent.fromUserAgent(userAgent);
        if (agent != null) {
            if (AgentId.CURL.equals(agent.getId())) {
                String content = this.commandLineHelpGenerator.generateCurlCapabilities(metadata, appUrl);
                return builder.eTag(createUniqueId(content)).body(content);
            }//ww w.ja va 2 s  . c o  m
            if (AgentId.HTTPIE.equals(agent.getId())) {
                String content = this.commandLineHelpGenerator.generateHttpieCapabilities(metadata, appUrl);
                return builder.eTag(createUniqueId(content)).body(content);
            }
            if (AgentId.SPRING_BOOT_CLI.equals(agent.getId())) {
                String content = this.commandLineHelpGenerator.generateSpringBootCliCapabilities(metadata,
                        appUrl);
                return builder.eTag(createUniqueId(content)).body(content);
            }
        }
    }
    String content = this.commandLineHelpGenerator.generateGenericCapabilities(metadata, appUrl);
    return builder.eTag(createUniqueId(content)).body(content);
}