Java Code Examples for org.springframework.web.util.UriComponentsBuilder#path()
The following examples show how to use
org.springframework.web.util.UriComponentsBuilder#path() .
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: OpencpsRestFacade.java From opencps-v2 with GNU Affero General Public License v3.0 | 7 votes |
/** * Helper method to build the url if the url is static and doesn't change * * @param httpUrl * @param pathComplete * @param queryParams * @return */ protected static String buildUrl(String httpUrl, String pathComplete, HashMap<String, String> queryParams) { UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(httpUrl); builder.path(pathComplete); if (null != queryParams) { // build the URL with all the params it needs builder = buildUrlParams(builder, queryParams); } UriComponents uriComponents = builder.build(); return uriComponents.toString(); }
Example 2
Source File: SftpBackupStorageMetaDataMaker.java From zstack with Apache License 2.0 | 6 votes |
private String buildUrl(String subPath, String hostName) { UriComponentsBuilder ub = UriComponentsBuilder.newInstance(); ub.scheme(SftpBackupStorageGlobalProperty.AGENT_URL_SCHEME); if (CoreGlobalProperty.UNIT_TEST_ON) { ub.host("localhost"); } else { ub.host(hostName); } ub.port(SftpBackupStorageGlobalProperty.AGENT_PORT); if (!"".equals(SftpBackupStorageGlobalProperty.AGENT_URL_ROOT_PATH)) { ub.path(SftpBackupStorageGlobalProperty.AGENT_URL_ROOT_PATH); } ub.path(subPath); return ub.build().toUriString(); }
Example 3
Source File: RssFeedView.java From wallride with Apache License 2.0 | 6 votes |
private String link(Article article) { UriComponentsBuilder builder = ServletUriComponentsBuilder.fromCurrentContextPath(); Map<String, Object> params = new HashMap<>(); Blog blog = blogService.getBlogById(Blog.DEFAULT_ID); if (blog.getLanguages().size() > 1) { builder.path("/{language}"); params.put("language", LocaleContextHolder.getLocale().getLanguage()); } builder.path("/{year}/{month}/{day}/{code}"); params.put("year", String.format("%04d", article.getDate().getYear())); params.put("month", String.format("%02d", article.getDate().getMonth().getValue())); params.put("day", String.format("%02d", article.getDate().getDayOfMonth())); params.put("code", article.getCode()); return builder.buildAndExpand(params).encode().toUriString(); }
Example 4
Source File: AtomFeedView.java From wallride with Apache License 2.0 | 6 votes |
private String link(Article article) { UriComponentsBuilder builder = ServletUriComponentsBuilder.fromCurrentContextPath(); Map<String, Object> params = new HashMap<>(); Blog blog = blogService.getBlogById(Blog.DEFAULT_ID); if (blog.getLanguages().size() > 1) { builder.path("/{language}"); params.put("language", LocaleContextHolder.getLocale().getLanguage()); } builder.path("/{year}/{month}/{day}/{code}"); params.put("year", String.format("%04d", article.getDate().getYear())); params.put("month", String.format("%02d", article.getDate().getMonth().getValue())); params.put("day", String.format("%02d", article.getDate().getDayOfMonth())); params.put("code", article.getCode()); return builder.buildAndExpand(params).encode().toUriString(); }
Example 5
Source File: TestKvmReconnectMe.java From zstack with Apache License 2.0 | 6 votes |
@Test public void test() throws InterruptedException { config.connectCmds.clear(); UriComponentsBuilder ub = UriComponentsBuilder.fromHttpUrl(restf.getBaseUrl()); ub.path(RESTConstant.COMMAND_CHANNEL_PATH); String url = ub.build().toUriString(); Map<String, String> header = map(e(RESTConstant.COMMAND_PATH, KVMConstant.KVM_RECONNECT_ME)); HostInventory host = deployer.hosts.get("host1"); ReconnectMeCmd cmd = new ReconnectMeCmd(); cmd.hostUuid = host.getUuid(); cmd.reason = "on purpose"; restf.syncJsonPost(url, JSONObjectUtil.toJsonString(cmd), header, String.class); TimeUnit.SECONDS.sleep(3); Assert.assertEquals(1, config.connectCmds.size()); }
Example 6
Source File: UiController.java From spring-boot-admin with Apache License 2.0 | 6 votes |
@ModelAttribute(value = "baseUrl", binding = false) public String getBaseUrl(UriComponentsBuilder uriBuilder) { UriComponents publicComponents = UriComponentsBuilder.fromUriString(this.publicUrl).build(); if (publicComponents.getScheme() != null) { uriBuilder.scheme(publicComponents.getScheme()); } if (publicComponents.getHost() != null) { uriBuilder.host(publicComponents.getHost()); } if (publicComponents.getPort() != -1) { uriBuilder.port(publicComponents.getPort()); } if (publicComponents.getPath() != null) { uriBuilder.path(publicComponents.getPath()); } return uriBuilder.path("/").toUriString(); }
Example 7
Source File: KVMHostFactory.java From zstack with Apache License 2.0 | 5 votes |
public KVMHostContext createHostContext(KVMHostVO vo) { UriComponentsBuilder ub = UriComponentsBuilder.newInstance(); ub.scheme(KVMGlobalProperty.AGENT_URL_SCHEME); ub.host(vo.getManagementIp()); ub.port(KVMGlobalProperty.AGENT_PORT); if (!"".equals(KVMGlobalProperty.AGENT_URL_ROOT_PATH)) { ub.path(KVMGlobalProperty.AGENT_URL_ROOT_PATH); } String baseUrl = ub.build().toUriString(); KVMHostContext context = new KVMHostContext(); context.setInventory(KVMHostInventory.valueOf(vo)); context.setBaseUrl(baseUrl); return context; }
Example 8
Source File: Users.java From wallride with Apache License 2.0 | 5 votes |
private String path(UriComponentsBuilder builder, User user, boolean encode) { Map<String, Object> params = new HashMap<>(); builder.path("/author/{code}"); params.put("code", user.getLoginId()); UriComponents components = builder.buildAndExpand(params); if (encode) { components = components.encode(); } return components.toUriString(); }
Example 9
Source File: KVMHostContext.java From zstack with Apache License 2.0 | 5 votes |
public String buildUrl(String...path) { UriComponentsBuilder ub = UriComponentsBuilder.fromHttpUrl(baseUrl); for (String p : path) { ub.path(p); } return ub.build().toString(); }
Example 10
Source File: ApplianceVmBase.java From zstack with Apache License 2.0 | 5 votes |
public static String buildAgentUrl(String hostname, String subPath, int port) { UriComponentsBuilder ub = UriComponentsBuilder.newInstance(); ub.scheme(ApplianceVmGlobalProperty.AGENT_URL_SCHEME); if (CoreGlobalProperty.UNIT_TEST_ON) { ub.host("localhost"); } else { ub.host(hostname); } ub.port(port); if (!"".equals(ApplianceVmGlobalProperty.AGENT_URL_ROOT_PATH)) { ub.path(ApplianceVmGlobalProperty.AGENT_URL_ROOT_PATH); } ub.path(subPath); return ub.build().toUriString(); }
Example 11
Source File: CephAgentUrl.java From zstack with Apache License 2.0 | 5 votes |
public static String backupStorageUrl(String ip, String path) { UriComponentsBuilder ub = UriComponentsBuilder.newInstance(); ub.scheme("http"); ub.host(ip); ub.port(CephGlobalProperty.BACKUP_STORAGE_AGENT_PORT); if (!"".equals(CephGlobalProperty.BACKUP_STORAGE_AGENT_URL_ROOT_PATH)) { ub.path(CephGlobalProperty.BACKUP_STORAGE_AGENT_URL_ROOT_PATH); } ub.path(path); return ub.build().toUriString(); }
Example 12
Source File: Posts.java From wallride with Apache License 2.0 | 5 votes |
public String ogImage(Post post) { String path = thumbnail(post); if (path == null) { return null; } UriComponentsBuilder builder = ServletUriComponentsBuilder.fromCurrentContextPath(); builder.path(path); return builder.buildAndExpand().encode().toUriString(); }
Example 13
Source File: LoginController.java From graviteeio-access-management with Apache License 2.0 | 5 votes |
private String buildRedirectUri(HttpServletRequest request, String identity) { UriComponentsBuilder builder = UriComponentsBuilder.newInstance(); String scheme = request.getHeader(HttpHeaders.X_FORWARDED_PROTO); if (scheme != null && !scheme.isEmpty()) { builder.scheme(scheme); } else { builder.scheme(request.getScheme()); } String host = request.getHeader(HttpHeaders.X_FORWARDED_HOST); if (host != null && !host.isEmpty()) { if (host.contains(":")) { // Forwarded host contains both host and port String[] parts = host.split(":"); builder.host(parts[0]); builder.port(parts[1]); } else { builder.host(host); } } else { builder.host(request.getServerName()); if (request.getServerPort() != 80 && request.getServerPort() != 443) { builder.port(request.getServerPort()); } } // append context path builder.path(request.getContextPath()); builder.pathSegment("auth/login/callback"); // append identity provider id builder.queryParam("provider", identity); return builder.build().toUriString(); }
Example 14
Source File: DefaultModelAttributeInterceptor.java From wallride with Apache License 2.0 | 5 votes |
private String buildGuestPath(String currentLanguage, List<String> languages) { UriComponentsBuilder builder = UriComponentsBuilder.fromPath(""); if (languages.size() > 1) { builder.path("/{language}"); } return builder.buildAndExpand(currentLanguage).toUriString(); }
Example 15
Source File: MvcUriComponentsBuilder.java From lams with GNU General Public License v2.0 | 5 votes |
private static UriComponentsBuilder fromMethodInternal(UriComponentsBuilder baseUrl, Class<?> controllerType, Method method, Object... args) { baseUrl = getBaseUrlToUse(baseUrl); String typePath = getTypeRequestMapping(controllerType); String methodPath = getMethodRequestMapping(method); String path = pathMatcher.combine(typePath, methodPath); baseUrl.path(path); UriComponents uriComponents = applyContributors(baseUrl, method, args); return UriComponentsBuilder.newInstance().uriComponents(uriComponents); }
Example 16
Source File: DefaultModelAttributeInterceptor.java From wallride with Apache License 2.0 | 4 votes |
private String buildAdminLink() { UriComponentsBuilder builder = ServletUriComponentsBuilder.fromCurrentContextPath(); builder.path("/_admin"); return builder.buildAndExpand().toUriString(); }
Example 17
Source File: PaginatedResultsRetrievedDiscoverabilityListener.java From tutorials with MIT License | 4 votes |
protected void plural(final UriComponentsBuilder uriBuilder, final Class clazz) { final String resourceName = clazz.getSimpleName() .toLowerCase() + "s"; uriBuilder.path("/" + resourceName); }
Example 18
Source File: DefaultModelAttributeInterceptor.java From wallride with Apache License 2.0 | 4 votes |
private String buildAdminPath(String currentLanguage) { // String contextPath = request.getContextPath(); UriComponentsBuilder builder = UriComponentsBuilder.fromPath(WallRideServletConfiguration.ADMIN_SERVLET_PATH); builder.path("/{language}"); return builder.buildAndExpand(currentLanguage).toUriString(); }
Example 19
Source File: MvcUriComponentsBuilder.java From spring4-understanding with Apache License 2.0 | 3 votes |
/** * An alternative to {@link #fromController(Class)} that accepts a * {@code UriComponentsBuilder} representing the base URL. This is useful * when using MvcUriComponentsBuilder outside the context of processing a * request or to apply a custom baseUrl not matching the current request. * @param builder the builder for the base URL; the builder will be cloned * and therefore not modified and may be re-used for further calls. * @param controllerType the controller to build a URI for * @return a UriComponentsBuilder instance (never {@code null}) */ public static UriComponentsBuilder fromController(UriComponentsBuilder builder, Class<?> controllerType) { builder = getBaseUrlToUse(builder); String mapping = getTypeRequestMapping(controllerType); return builder.path(mapping); }
Example 20
Source File: MvcUriComponentsBuilder.java From lams with GNU General Public License v2.0 | 3 votes |
/** * An alternative to {@link #fromController(Class)} that accepts a * {@code UriComponentsBuilder} representing the base URL. This is useful * when using MvcUriComponentsBuilder outside the context of processing a * request or to apply a custom baseUrl not matching the current request. * <p><strong>Note:</strong> This method extracts values from "Forwarded" * and "X-Forwarded-*" headers if found. See class-level docs. * @param builder the builder for the base URL; the builder will be cloned * and therefore not modified and may be re-used for further calls. * @param controllerType the controller to build a URI for * @return a UriComponentsBuilder instance (never {@code null}) */ public static UriComponentsBuilder fromController(UriComponentsBuilder builder, Class<?> controllerType) { builder = getBaseUrlToUse(builder); String mapping = getTypeRequestMapping(controllerType); return builder.path(mapping); }