List of usage examples for org.springframework.web.util UriComponentsBuilder newInstance
public static UriComponentsBuilder newInstance()
From source file:cherry.example.web.util.ViewNameUtil.java
public static String fromMethodCall(Object invocationInfo) { MethodInvocationInfo info = (MethodInvocationInfo) invocationInfo; Method method = info.getControllerMethod(); Class<?> type = method.getDeclaringClass(); UriComponentsBuilder ucb = UriComponentsBuilder.newInstance(); String typePath = getMappedPath(type.getAnnotation(RequestMapping.class)); if (StringUtils.isNotEmpty(typePath)) { ucb.path(typePath);/*w ww. j a v a 2 s . c o m*/ } String methodPath = getMappedPath(method.getAnnotation(RequestMapping.class)); if (StringUtils.isNotEmpty(methodPath)) { ucb.pathSegment(methodPath); } String path = ucb.build().getPath(); if (path.startsWith("/")) { return path.substring(1); } return path; }
From source file:org.openlmis.fulfillment.service.request.RequestHelper.java
/** * Creates a {@link URI} from the given string representation and with the given parameters. *///from w ww .j a v a 2s .c o m public static URI createUri(String url, RequestParameters parameters) { UriComponentsBuilder builder = UriComponentsBuilder.newInstance().uri(URI.create(url)); RequestParameters.init().setAll(parameters).forEach(e -> e.getValue().forEach(one -> { try { builder.queryParam(e.getKey(), UriUtils.encodeQueryParam(String.valueOf(one), StandardCharsets.UTF_8.name())); } catch (UnsupportedEncodingException ex) { throw new EncodingException(ex); } })); return builder.build(true).toUri(); }
From source file:com.nebhale.gpxconverter.GoogleMapsMapBuilder.java
@Override public URI build(List<Point> points, String maptype, int width, int height) { return UriComponentsBuilder.newInstance().scheme("http").host("maps.googleapis.com") .path("/maps/api/staticmap").queryParam("key", this.apiKey).queryParam("sensor", false) .queryParam("size", String.format("%dx%d", width, height)).queryParam("scale", 1) .queryParam("maptype", maptype) .queryParam("path", String.format("color:0xff0000ff|weight:1|enc:%s", this.encoder.encode(points))) .build().toUri();//from w w w . j av a 2 s. c o m }
From source file:org.unidle.controller.RedirectingConnectController.java
@Override protected String connectedView(final String providerId) { return REDIRECT_URL_PREFIX + UriComponentsBuilder.newInstance().path("/questions").build().encode().toUriString(); }
From source file:org.unidle.controller.RedirectingConnectController.java
@Override protected RedirectView connectionStatusRedirect(final String providerId, final NativeWebRequest request) { final String url = UriComponentsBuilder.newInstance().path("/questions").build().encode().toUriString(); return new RedirectView(url, true); }
From source file:org.mitre.discovery.util.WebfingerURLNormalizer.java
/** * Normalize the resource string as per OIDC Discovery. * @param identifier//from w w w. ja v a 2 s . co m * @return the normalized string, or null if the string can't be normalized */ public static UriComponents normalizeResource(String identifier) { // try to parse the URI // NOTE: we can't use the Java built-in URI class because it doesn't split the parts appropriately if (Strings.isNullOrEmpty(identifier)) { logger.warn("Can't normalize null or empty URI: " + identifier); return null; // nothing we can do } else { //UriComponentsBuilder builder = UriComponentsBuilder.fromUriString(identifier); UriComponentsBuilder builder = UriComponentsBuilder.newInstance(); Matcher m = pattern.matcher(identifier); if (m.matches()) { builder.scheme(m.group(2)); builder.userInfo(m.group(6)); builder.host(m.group(8)); String port = m.group(10); if (!Strings.isNullOrEmpty(port)) { builder.port(Integer.parseInt(port)); } builder.path(m.group(11)); builder.query(m.group(13)); builder.fragment(m.group(15)); // we throw away the hash, but this is the group it would be if we kept it } else { // doesn't match the pattern, throw it out logger.warn("Parser couldn't match input: " + identifier); return null; } UriComponents n = builder.build(); if (Strings.isNullOrEmpty(n.getScheme())) { if (!Strings.isNullOrEmpty(n.getUserInfo()) && Strings.isNullOrEmpty(n.getPath()) && Strings.isNullOrEmpty(n.getQuery()) && n.getPort() < 0) { // scheme empty, userinfo is not empty, path/query/port are empty // set to "acct" (rule 2) builder.scheme("acct"); } else { // scheme is empty, but rule 2 doesn't apply // set scheme to "https" (rule 3) builder.scheme("https"); } } // fragment must be stripped (rule 4) builder.fragment(null); return builder.build(); } }
From source file:org.wallride.web.controller.admin.user.UserDescribeController.java
@RequestMapping public String describe(@PathVariable String language, @RequestParam long id, String query, Model model) { User user = userService.getUserById(id); if (user == null) { throw new HttpNotFoundException(); }//from ww w. j a v a 2 s . c o m MutablePropertyValues mpvs = new MutablePropertyValues( UriComponentsBuilder.newInstance().query(query).build().getQueryParams()); for (Iterator<PropertyValue> i = mpvs.getPropertyValueList().iterator(); i.hasNext();) { PropertyValue pv = i.next(); boolean hasValue = false; for (String value : (List<String>) pv.getValue()) { if (StringUtils.hasText(value)) { hasValue = true; break; } } if (!hasValue) { i.remove(); } } BeanWrapperImpl beanWrapper = new BeanWrapperImpl(new UserSearchForm()); beanWrapper.setConversionService(conversionService); beanWrapper.setPropertyValues(mpvs, true, true); UserSearchForm form = (UserSearchForm) beanWrapper.getWrappedInstance(); List<Long> ids = userService.getUserIds(form.toUserSearchRequest()); if (!CollectionUtils.isEmpty(ids)) { int index = ids.indexOf(user.getId()); if (index < ids.size() - 1) { Long next = ids.get(index + 1); model.addAttribute("next", next); } if (index > 0) { Long prev = ids.get(index - 1); model.addAttribute("prev", prev); } } model.addAttribute("user", user); model.addAttribute("query", query); return "user/describe"; }
From source file:io.pivotal.strepsirrhini.chaoslemur.infrastructure.StandardDirectorUtils.java
@Autowired StandardDirectorUtils(@Value("${director.host}") String host, @Value("${director.username}") String username, @Value("${director.password}") String password, Set<ClientHttpRequestInterceptor> interceptors) throws GeneralSecurityException { this(createRestTemplate(host, username, password, interceptors), UriComponentsBuilder.newInstance().scheme("https").host(host).port(25555).build().toUri()); }
From source file:org.wallride.web.controller.admin.page.PageDescribeController.java
@RequestMapping public String describe(@PathVariable String language, @RequestParam long id, String query, Model model, RedirectAttributes redirectAttributes) { Page page = pageService.getPageById(id); if (page == null) { throw new HttpNotFoundException(); }// w w w . j a v a 2s.c o m if (!page.getLanguage().equals(language)) { Page target = pageService.getPageByCode(page.getCode(), language); if (target != null) { redirectAttributes.addAttribute("id", target.getId()); return "redirect:/_admin/{language}/pages/describe?id={id}"; } else { redirectAttributes.addFlashAttribute("original", page); redirectAttributes.addAttribute("code", page.getCode()); return "redirect:/_admin/{language}/pages/create?code={code}"; } } MutablePropertyValues mpvs = new MutablePropertyValues( UriComponentsBuilder.newInstance().query(query).build().getQueryParams()); for (Iterator<PropertyValue> i = mpvs.getPropertyValueList().iterator(); i.hasNext();) { PropertyValue pv = i.next(); boolean hasValue = false; for (String value : (List<String>) pv.getValue()) { if (StringUtils.hasText(value)) { hasValue = true; break; } } if (!hasValue) { i.remove(); } } BeanWrapperImpl beanWrapper = new BeanWrapperImpl(new PageSearchForm()); beanWrapper.setConversionService(conversionService); beanWrapper.setPropertyValues(mpvs, true, true); PageSearchForm form = (PageSearchForm) beanWrapper.getWrappedInstance(); List<Long> ids = pageService.getPageIds(form.toPageSearchRequest()); if (!CollectionUtils.isEmpty(ids)) { int index = ids.indexOf(page.getId()); if (index < ids.size() - 1) { Long next = ids.get(index + 1); model.addAttribute("next", next); } if (index > 0) { Long prev = ids.get(index - 1); model.addAttribute("prev", prev); } } model.addAttribute("page", page); model.addAttribute("query", query); return "page/describe"; }