List of usage examples for org.springframework.web.util UriComponentsBuilder path
@Override
public UriComponentsBuilder path(String path)
From source file:org.wallride.web.support.Posts.java
public String ogImage(Post post) { String path = thumbnail(post); if (path == null) { return null; }/*from w w w . ja va 2 s . c om*/ UriComponentsBuilder builder = ServletUriComponentsBuilder.fromCurrentContextPath(); builder.path(path); return builder.buildAndExpand().encode().toUriString(); }
From source file:net.paslavsky.springrest.UriBuilder.java
private UriComponentsBuilder createOrAdd(UriComponentsBuilder builder, String path) { if (StringUtils.hasText(path)) { if (builder != null) { if (!path.startsWith("/")) { builder.path("/"); }/*from w ww.j a v a2s .c o m*/ builder.path(path); } else { builder = UriComponentsBuilder.fromHttpUrl(path); } } return builder; }
From source file:com.minlia.cloud.framework.common.web.listeners.ResourceCreatedDiscoverabilityListener.java
/** * - note: at this point, the URI is transformed into plural (added `s`) in a hardcoded way - this will change in the future */// w w w . j a v a 2s.c o m protected void addLinkHeaderOnEntityCreation(final UriComponentsBuilder uriBuilder, final HttpServletResponse response, final String idOfNewEntity, final Class clazz) { final String path = calculatePathToResource(clazz); final String locationValue = uriBuilder.path(path).build().expand(idOfNewEntity).encode().toUriString(); response.setHeader(HttpHeaders.LOCATION, locationValue); }
From source file:com.fns.grivet.controller.NamedQueryController.java
@PreAuthorize("hasAuthority('write:query')") @PostMapping("/api/v1/query") public ResponseEntity<?> createNamedQuery(@RequestBody NamedQuery query) { ResponseEntity<?> result = ResponseEntity.unprocessableEntity().build(); Assert.isTrue(StringUtils.isNotBlank(query.getName()), "Query name must not be null, empty or blank."); Assert.notNull(query.getQuery(), "Query string must not be null!"); Assert.isTrue(isSupportedQuery(query), "Query must start with either CALL or SELECT"); // check for named parameters; but only if they exist if (!query.getParams().isEmpty()) { query.getParams().keySet()/* w w w .java 2 s. c o m*/ .forEach(k -> Assert.isTrue(query.getQuery().contains(String.format(":%s", k)), String.format("Query must contain named parameter [%s]", k))); } namedQueryService.create(query); log.info("Named Query \n\n{}\n\n successfully registered!", query); UriComponentsBuilder ucb = UriComponentsBuilder.newInstance(); if (query.getParams().isEmpty()) { result = ResponseEntity .created(ucb.path("/api/v1/query/{name}").buildAndExpand(query.getName()).toUri()).build(); } else { result = ResponseEntity.noContent().build(); } return result; }
From source file:web.EventLogRESTController.java
/** * Adds an event to the Event Log through REST API * @param el/* ww w .java 2 s .co m*/ * @param ucBuilder * @return */ @RequestMapping(value = "/api/eventlog/", method = RequestMethod.POST) public ResponseEntity<Void> addEvent(@RequestBody EventLog el, UriComponentsBuilder ucBuilder) { dao.addEvent(el); //returns newly added Event info HttpHeaders headers = new HttpHeaders(); headers.setLocation(ucBuilder.path("/api/eventlog/{id}").buildAndExpand(el.getEventid()).toUri()); return new ResponseEntity<Void>(headers, HttpStatus.CREATED); }
From source file:org.obiba.mica.user.UserProfileService.java
private String getProfileServiceUrlByApp(String username, String application, String group) { UriComponentsBuilder urlBuilder = UriComponentsBuilder.fromHttpUrl(getAgateUrl()).path(DEFAULT_REST_PREFIX); if (Strings.isNullOrEmpty(username)) { urlBuilder.path(String.format("/application/%s/users", application)); } else {/*from ww w . ja v a 2 s. c o m*/ urlBuilder.path(String.format("/application/%s/user/%s", application, username)); } if (!Strings.isNullOrEmpty(group)) { urlBuilder.queryParam("group", group); } return urlBuilder.build().toUriString(); }
From source file:web.UsersRESTController.java
/** * Adds a user to the database through REST API * @param user//from ww w .ja va2 s . c om * @param ucBuilder * @return */ @RequestMapping(value = "/api/users/", method = RequestMethod.POST) public ResponseEntity<Void> addUser(@RequestBody Users user, UriComponentsBuilder ucBuilder) { dao.addUser(user); //returns newly added User info HttpHeaders headers = new HttpHeaders(); headers.setLocation(ucBuilder.path("/api/users/userinfo/{id}").buildAndExpand(user.getUserId()).toUri()); return new ResponseEntity<Void>(headers, HttpStatus.CREATED); }
From source file:doge.controller.UsersRestController.java
@RequestMapping(method = RequestMethod.POST, value = "{userId}/doge") public ResponseEntity<?> postDogePhoto(@PathVariable String userId, @RequestParam MultipartFile file, UriComponentsBuilder uriBuilder) throws IOException { Photo photo = file::getInputStream;//from w ww . java 2 s. co m User user = this.userRepository.findOne(userId); DogePhoto doge = this.dogeService.addDogePhoto(user, photo); URI uri = uriBuilder.path("/users/{userId}/doge/{dogeId}").buildAndExpand(userId, doge.getId()).toUri(); sendMessage(user, uri); return ResponseEntity.created(uri).build(); }
From source file:fi.hsl.parkandride.front.ContactController.java
@RequestMapping(method = POST, value = CONTACTS, produces = APPLICATION_JSON_VALUE) public ResponseEntity<Contact> createContact(@RequestBody Contact contact, User currentUser, UriComponentsBuilder builder) { log.info("createContact"); Contact newContact = contactService.createContact(contact, currentUser); log.info("createContact({})", newContact.id); HttpHeaders headers = new HttpHeaders(); headers.setLocation(builder.path(CONTACT).buildAndExpand(newContact.id).toUri()); return new ResponseEntity<>(newContact, headers, CREATED); }
From source file:fi.hsl.parkandride.front.HubController.java
@RequestMapping(method = POST, value = HUBS, produces = APPLICATION_JSON_VALUE) public ResponseEntity<Hub> createHub(@RequestBody Hub hub, User currentUser, UriComponentsBuilder builder) { log.info("createHub"); Hub newHub = hubService.createHub(hub, currentUser); log.info("createHub({})", newHub.id); HttpHeaders headers = new HttpHeaders(); headers.setLocation(builder.path(HUB).buildAndExpand(newHub.id).toUri()); return new ResponseEntity<>(newHub, headers, CREATED); }