List of usage examples for org.springframework.web.servlet.support ServletUriComponentsBuilder fromCurrentServletMapping
public static ServletUriComponentsBuilder fromCurrentServletMapping()
From source file:com.bennavetta.appsite.webapi.SettingsController.java
@RequestMapping(method = POST, value = "/{name}") public ResponseEntity<String> putSetting(@PathVariable String name, @RequestBody String value) { settings.set(name, value);/*from w ww .jav a 2 s . c om*/ log.trace("Setting {} = {}", name, value); HttpHeaders headers = new HttpHeaders(); URI location = ServletUriComponentsBuilder.fromCurrentServletMapping().path("/settings/{name}").build() .expand(name).toUri(); headers.setLocation(location); return new ResponseEntity<String>(headers, HttpStatus.CREATED); }
From source file:com.coffeebeans.services.controller.base.BaseController.java
protected URI buildLocationFromCurrentServletMapping(String mapping, String username) { URI location = ServletUriComponentsBuilder.fromCurrentServletMapping().path("/").path(mapping).path("/") .path(username).build().toUri(); return location; }
From source file:io.spring.initializr.web.project.AbstractInitializrController.java
/** * Generate a full URL of the service, mostly for use in templates. * @return the app URL//from w w w. j a v a 2 s. c o m * @see io.spring.initializr.metadata.InitializrConfiguration.Env#isForceSsl() */ protected String generateAppUrl() { ServletUriComponentsBuilder builder = ServletUriComponentsBuilder.fromCurrentServletMapping(); if (isForceSsl()) { builder.scheme("https"); } return builder.build().toString(); }
From source file:com.couchbase.trombi.controllers.CoworkerController.java
@RequestMapping(value = "/", method = RequestMethod.POST) public ResponseEntity<?> createCoworker(@RequestBody Map<String, Object> body) { String name;/*from ww w . j ava 2s . com*/ String description; String team; Set<String> skills = new HashSet<>(); Map<String, String> imHandles; Location mainLocation; try { if (body.containsKey("skills")) { skills.addAll((Collection<String>) body.get("skills")); } imHandles = (Map<String, String>) body.get("imHandles"); Map<String, Object> mainLocationMap = (Map<String, Object>) body.get("mainLocation"); Map<String, Object> mainLocationCoord = (Map<String, Object>) mainLocationMap.get("coordinates"); double x = ((Number) mainLocationCoord.get("x")).doubleValue(); double y = ((Number) mainLocationCoord.get("y")).doubleValue(); mainLocation = new Location((String) mainLocationMap.get("name"), (String) mainLocationMap.get("description"), (int) mainLocationMap.get("timeZoneOffset"), new Point(x, y)); name = (String) body.get("name"); description = (String) body.get("description"); team = (String) body.get("team"); } catch (Exception e) { return ResponseEntity.badRequest().body("Malformed Coworker creation data, error: " + e.toString()); } //generate an ID Long sequence = bucket.counter("coworkerSequence", 1, TrombinoscopeApplication.RESERVED_IDS + 1).content(); String id = CoworkerRepository.PREFIX + sequence.longValue(); Coworker coworker = new Coworker(id, name, description, team, skills, imHandles, mainLocation, null); repository.save(coworker); final URI location = ServletUriComponentsBuilder.fromCurrentServletMapping().path("/{id}").build() .expand(id).toUri(); return ResponseEntity.created(location).body(coworker); }
From source file:org.wallride.web.support.DefaultModelAttributeInterceptor.java
private Map<String, String> buildLanguageLinks(String currentLanguage, List<String> languages, HttpServletRequest request) {/* w w w .java 2s.c om*/ UrlPathHelper pathHelper = new UrlPathHelper(); Map<String, String> languageLinks = new LinkedHashMap<>(); String path = pathHelper.getPathWithinServletMapping(request); if (path.startsWith("/" + currentLanguage + "/")) { path = path.substring(currentLanguage.length() + 1); } UriComponentsBuilder uriComponentsBuilder = ServletUriComponentsBuilder.fromCurrentServletMapping() .path("/{language}").path(path).query(pathHelper.getOriginatingQueryString(request)); if (languages != null) { for (String language : languages) { languageLinks.put(language, uriComponentsBuilder.buildAndExpand(language).toUriString()); } } return languageLinks; }
From source file:edu.cmu.cs.lti.discoursedb.api.browsing.controller.BrowsingRestController.java
public static Link makeLink1Arg(String dest, String rel, String key, String value) { String path = ServletUriComponentsBuilder.fromCurrentServletMapping() //.fromCurrentRequestUri() .replacePath(dest).replaceQueryParam(key, URLEncoder.encode(value)).build().toUriString(); Link link = new Link(path, rel); return link;// w w w . ja v a 2 s .c o m }
From source file:edu.cmu.cs.lti.discoursedb.api.browsing.controller.BrowsingRestController.java
public static Link makeLink2Arg(String dest, String rel, String key, String value, String key2, String value2) { String path = ServletUriComponentsBuilder.fromCurrentServletMapping() //.fromCurrentRequestUri() .replacePath(dest).replaceQueryParam(key, URLEncoder.encode(value)) .replaceQueryParam(key2, URLEncoder.encode(value2)).build().toUriString(); Link link = new Link(path, rel); return link;//from ww w. j ava2 s. c o m }
From source file:edu.cmu.cs.lti.discoursedb.api.browsing.controller.BrowsingRestController.java
public static Link makeLightsideExportNameLink(String dest, Boolean withAnnotations, String rel, String filename, String dpid) { String path = ServletUriComponentsBuilder.fromCurrentServletMapping() //.fromCurrentRequestUri() .replacePath(dest).replaceQueryParam("dpId", URLEncoder.encode(dpid)) .replaceQueryParam("withAnnotations", withAnnotations).build().toUriString(); Link link = new Link(path + "{?exportFilename}", rel); return link;//from w w w . j a v a2 s. c o m }
From source file:edu.cmu.cs.lti.discoursedb.api.browsing.controller.BrowsingRestController.java
public static Link makeLightsideDownloadLink(String dest, Boolean annotated, String rel, String key, String value) {//from w w w . ja va2 s. c om String path = ServletUriComponentsBuilder.fromCurrentServletMapping() //.fromCurrentRequestUri() .replacePath(dest + "/" + value + ".csv") .replaceQueryParam("withAnnotations", annotated ? "true" : "false").build().toUriString(); Link link = new Link(path, rel); return link; }
From source file:edu.cmu.cs.lti.discoursedb.api.browsing.controller.BrowsingRestController.java
public static Link makeBratExportNameLink(String dest, String rel, String filename, String dpid) { String path = ServletUriComponentsBuilder.fromCurrentServletMapping() //fromCurrentRequestUri() .replacePath(dest).replaceQueryParam("dpId", URLEncoder.encode(dpid)).build().toUriString(); Link link = new Link(path + "{?exportDirectory}", rel); return link;/*from w w w . j ava2 s . c om*/ }