List of usage examples for org.springframework.http ResponseEntity ok
public static <T> ResponseEntity<T> ok(T body)
From source file:de.codecentric.boot.admin.registry.StatusUpdaterTest.java
@Test @SuppressWarnings("rawtypes") public void test_update_noBody() { // HTTP 200 - UP when(template.getForEntity("health", Map.class)).thenReturn(ResponseEntity.ok((Map) null)); updater.updateStatus(Application.create("foo").withId("id").withHealthUrl("health").build()); assertThat(store.find("id").getStatusInfo().getStatus(), is("UP")); // HTTP != 200 - DOWN when(template.getForEntity("health", Map.class)).thenReturn(ResponseEntity.status(503).body((Map) null)); updater.updateStatus(Application.create("foo").withId("id").withHealthUrl("health").build()); assertThat(store.find("id").getStatusInfo().getStatus(), is("DOWN")); }
From source file:com.greglturnquist.springagram.fileservice.s3.ApplicationController.java
@RequestMapping(method = RequestMethod.GET, value = "/files") public ResponseEntity<?> listFiles() { try {//from w w w .ja v a 2s . c o m Resource[] files = this.fileService.findAll(); ResourceSupport resources = new ResourceSupport(); for (Resource file : files) { resources.add(linkTo(methodOn(ApplicationController.class).getFile(file.getFilename())) .withRel(file.getFilename())); } return ResponseEntity.ok(resources); } catch (IOException e) { return ResponseEntity.badRequest().body(e.getMessage()); } }
From source file:de.codecentric.boot.admin.registry.web.RegistryController.java
/** * Get a single application out of the registry. * * @param id The application identifier. * @return The registered application.//w ww . ja v a2 s . com */ @RequestMapping(value = "/api/applications/{id}", method = RequestMethod.GET) public ResponseEntity<?> get(@PathVariable String id) { LOGGER.debug("Deliver registered application with ID '{}'", id); Application application = registry.getApplication(id); if (application != null) { return ResponseEntity.ok(application); } else { return ResponseEntity.notFound().build(); } }
From source file:de.msg.controller.RouteController.java
@RequestMapping("search/findByDeparture") @PreAuthorize("isAuthenticated() and hasPermission('de.msg.domain.route.Route', 'read')") public ResponseEntity<Iterable<Route>> findByDeparture(@RequestParam(value = "departure") String departure) { return ResponseEntity.ok(service.findByDeparture(departure)); }
From source file:org.farrukh.template.rest.inbound.RestInboundGateway.java
@RequestMapping("/{id}") public ResponseEntity<?> retrieveLibrary(@PathVariable final String id) { try {//from ww w .ja v a2 s. c om Library library = coreService.getLibraryById(id); LibraryResource libraryResource = assembler.toResource(library); return ResponseEntity.ok(libraryResource); } catch (Exception e) { throw new LibraryRetrievalError(RestFeedbackContext.SOME_FEEDBACK, e); } }
From source file:org.leandreck.endpoints.examples.lombok.LombokTypeScriptEndpoint.java
@RequestMapping(value = "/foo/{idPathVariable}/{typeRef}", method = POST, consumes = APPLICATION_JSON_VALUE, produces = APPLICATION_JSON_VALUE) public ResponseEntity<LombokResponse<List<RootType>, List<Object>, Boolean, SubType, RootType>> setResponseEntity( @PathVariable(name = "idPathVariable") Long id, @PathVariable String typeRef, @RequestParam(name = "queryRequestParam", required = false) Optional<String> queryParameter, @RequestBody(required = false) LombokRequest body) { // do something return ResponseEntity.ok(new LombokResponse<>()); }
From source file:uk.urchinly.wabi.ingest.UploadController.java
@RequestMapping(method = RequestMethod.POST, value = "/upload") public ResponseEntity<String> upload(@RequestParam("file") MultipartFile file) { if (file.isEmpty()) { logger.debug("Upload file is empty."); return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Failed with empty file"); }/*from w ww .ja va2s .c o m*/ BufferedOutputStream outputStream = null; try { File outputFile = new File(appSharePath + "/" + file.getOriginalFilename()); outputStream = new BufferedOutputStream(new FileOutputStream(outputFile)); FileCopyUtils.copy(file.getInputStream(), outputStream); Asset asset = new Asset(file.getOriginalFilename(), file.getOriginalFilename(), (double) file.getSize(), file.getContentType(), Collections.emptyList()); this.saveAsset(asset); } catch (Exception e) { logger.warn(e.getMessage(), e); return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Failed with error"); } finally { IOUtils.closeQuietly(outputStream); } return ResponseEntity.ok("File accepted"); }
From source file:com.github.lynxdb.server.api.http.handlers.EpVhost.java
@RequestMapping(value = "", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE) public ResponseEntity createVhost(Authentication _authentication, @RequestBody @Valid VhostCreationRequest _vcr, BindingResult _bindingResult) {//w w w .j a v a 2 s. c om if (_bindingResult.hasErrors()) { ArrayList<String> errors = new ArrayList(); _bindingResult.getFieldErrors().forEach((FieldError t) -> { errors.add(t.getField() + ": " + t.getDefaultMessage()); }); return new ErrorResponse(mapper, HttpStatus.BAD_REQUEST, errors.toString()).response(); } Vhost v = new Vhost(_vcr); vhosts.save(v); return ResponseEntity.ok(v); }
From source file:com.orange.clara.pivotaltrackermirror.controllers.MirrorReferenceController.java
@ApiOperation(value = "Get a specific mirror referenced by its id", response = MirrorReference.class) @RequestMapping(method = RequestMethod.GET, value = "/{id:[0-9]*}", produces = MediaType.APPLICATION_JSON_VALUE) public ResponseEntity<?> get(@PathVariable Integer id) { MirrorReference mirrorReference = this.mirrorReferenceRepo.findOne(id); if (mirrorReference == null) { return ResponseEntity.notFound().build(); }/* w w w . j a v a 2 s . c om*/ return ResponseEntity.ok(mirrorReference); }
From source file:io.pivotal.strepsirrhini.chaosloris.web.ApplicationController.java
@Transactional(readOnly = true) @RequestMapping(method = GET, value = "", produces = HAL_JSON_VALUE) public ResponseEntity list(Pageable pageable, PagedResourcesAssembler<Application> pagedResourcesAssembler) { Page<Application> applications = this.applicationRepository.findAll(pageable); return ResponseEntity .ok(pagedResourcesAssembler.toResource(applications, this.applicationResourceAssembler)); }