org.springframework.web.servlet.mvc.method.annotation.MvcUriComponentsBuilder Java Examples
The following examples show how to use
org.springframework.web.servlet.mvc.method.annotation.MvcUriComponentsBuilder.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MottoController.java From Spring-Boot-2-Fundamentals with MIT License | 6 votes |
/** Append to list of mottos, but only if the motto is unique */ @PostMapping public ResponseEntity<Message> uniqueAppend(@RequestBody Message message, UriComponentsBuilder uriBuilder) { // Careful, this lookup is O(n) if (motto.contains(message)) { return ResponseEntity.status(HttpStatus.CONFLICT).build(); } else { motto.add(message); UriComponents location = MvcUriComponentsBuilder .fromMethodCall(on(MottoController.class).retrieveById(motto.size())) .build(); return ResponseEntity .created(location.toUri()) .header("X-Copyright", "Packt 2018") .body(new Message("Accepted #" + motto.size())); } }
Example #2
Source File: PeopleController.java From sdn-rx with Apache License 2.0 | 5 votes |
@PostMapping String updatePerson(PersonEntity updatedPerson) { this.personRepository.findByName(updatedPerson.getName()).ifPresent(p -> { p.setBorn(updatedPerson.getBorn()); this.personRepository.save(p); }); return "redirect:" + MvcUriComponentsBuilder.fromMethodName( this.getClass(), "showPersonForm", updatedPerson).build(); }
Example #3
Source File: HandlerAssertionTests.java From spring-analysis-note with MIT License | 5 votes |
@Test public void methodCallOnNonMock() throws Exception { assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> this.mockMvc.perform(get("/")).andExpect(handler().methodCall("bogus"))) .withMessageContaining("The supplied object [bogus] is not an instance of") .withMessageContaining(MvcUriComponentsBuilder.MethodInvocationInfo.class.getName()) .withMessageContaining("Ensure that you invoke the handler method via MvcUriComponentsBuilder.on()"); }
Example #4
Source File: HandlerAssertionTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void methodCallOnNonMock() throws Exception { exception.expect(AssertionError.class); exception.expectMessage("The supplied object [bogus] is not an instance of"); exception.expectMessage(MvcUriComponentsBuilder.MethodInvocationInfo.class.getName()); exception.expectMessage("Ensure that you invoke the handler method via MvcUriComponentsBuilder.on()"); this.mockMvc.perform(get("/")).andExpect(handler().methodCall("bogus")); }
Example #5
Source File: FileUploadController.java From spring-boot-tutorial with Creative Commons Attribution Share Alike 4.0 International | 5 votes |
@GetMapping("/") public String listUploadedFiles(Model model) { model.addAttribute("files", storageService.loadAll() .map(path -> MvcUriComponentsBuilder.fromMethodName(FileUploadController.class, "serveFile", path.getFileName().toString()).build().toString()) .collect(Collectors.toList())); return "uploadForm"; }
Example #6
Source File: FileUploadController.java From spring-guides with Apache License 2.0 | 5 votes |
@GetMapping("/") public String listUploadedFiles(Model model) throws IOException { model.addAttribute("files", storageService.loadAll().map( path -> MvcUriComponentsBuilder.fromMethodName(FileUploadController.class, "serveFile", path.getFileName().toString()).build().toString()) .collect(Collectors.toList())); return "uploadForm"; }
Example #7
Source File: FooController.java From friendly-id with Apache License 2.0 | 5 votes |
@PostMapping public HttpEntity<FooResource> create(@RequestBody FooResource fooResource) { HttpHeaders headers = new HttpHeaders(); Foo entity = new Foo(fooResource.getUuid(), "Foo"); // ... URI location = MvcUriComponentsBuilder.fromMethodCall(on(getClass()) .get(fooResource.getUuid())) .buildAndExpand() .toUri(); headers.setLocation(location); return new ResponseEntity<>(headers, HttpStatus.CREATED); }
Example #8
Source File: MethodToUrlTest.java From FastBootWeixin with Apache License 2.0 | 4 votes |
public static void main(String[] args) throws JsonProcessingException { UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl("http://api.wx.com"); MvcUriComponentsBuilder.fromMethod(builder, WxBuildinVerifyService.class, ClassUtils.getMethod(WxBuildinVerifyService.class, "verify", null), "a", "a", "a", "a"); System.out.println(builder); }