Java Code Examples for org.springframework.web.util.UriComponentsBuilder#host()
The following examples show how to use
org.springframework.web.util.UriComponentsBuilder#host() .
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: VirtualRouterManagerImpl.java From zstack with Apache License 2.0 | 6 votes |
@Override public String buildUrl(String mgmtNicIp, String subPath) { UriComponentsBuilder ub = UriComponentsBuilder.newInstance(); ub.scheme(VirtualRouterGlobalProperty.AGENT_URL_SCHEME); if (CoreGlobalProperty.UNIT_TEST_ON) { ub.host("localhost"); } else { ub.host(mgmtNicIp); } ub.port(VirtualRouterGlobalProperty.AGENT_PORT); if (!"".equals(VirtualRouterGlobalProperty.AGENT_URL_ROOT_PATH)) { ub.path(VirtualRouterGlobalProperty.AGENT_URL_ROOT_PATH); } ub.path(subPath); return ub.build().toUriString(); }
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: SftpBackupStorage.java From zstack with Apache License 2.0 | 6 votes |
public String buildUrl(String subPath) { UriComponentsBuilder ub = UriComponentsBuilder.newInstance(); ub.scheme(SftpBackupStorageGlobalProperty.AGENT_URL_SCHEME); if (CoreGlobalProperty.UNIT_TEST_ON) { ub.host("localhost"); } else { ub.host(getSelf().getHostname()); } 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 4
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 5
Source File: LoginUrlAuthenticationEntryPoint.java From graviteeio-access-management with Apache License 2.0 | 5 votes |
@Override protected String buildRedirectUrlToLoginPage(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException) { String url = super.buildRedirectUrlToLoginPage(request, response, authException); UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(url); String scheme = request.getHeader(HttpHeaders.X_FORWARDED_PROTO); if (scheme != null && !scheme.isEmpty()) { builder.scheme(scheme); } 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); } } // handle forwarded path String forwardedPath = request.getHeader(X_FORWARDED_PREFIX); if (forwardedPath != null && !forwardedPath.isEmpty()) { String path = builder.build().getPath(); // remove trailing slash forwardedPath = forwardedPath.substring(0, forwardedPath.length() - (forwardedPath.endsWith("/") ? 1 : 0)); builder.replacePath(forwardedPath + path); } return builder.toUriString(); }
Example 6
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 7
Source File: CephAgentUrl.java From zstack with Apache License 2.0 | 5 votes |
public static String primaryStorageUrl(String ip, String path) { UriComponentsBuilder ub = UriComponentsBuilder.newInstance(); ub.scheme("http"); ub.host(ip); ub.port(CephGlobalProperty.PRIMARY_STORAGE_AGENT_PORT); if (!"".equals(CephGlobalProperty.PRIMARY_STORAGE_AGENT_URL_ROOT_PATH)) { ub.path(CephGlobalProperty.PRIMARY_STORAGE_AGENT_URL_ROOT_PATH); } ub.path(path); return ub.build().toUriString(); }
Example 8
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 9
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 10
Source File: KVMHost.java From zstack with Apache License 2.0 | 5 votes |
private String buildUrl(String path) { UriComponentsBuilder ub = UriComponentsBuilder.newInstance(); ub.scheme(KVMGlobalProperty.AGENT_URL_SCHEME); ub.host(self.getManagementIp()); ub.port(KVMGlobalProperty.AGENT_PORT); if (!"".equals(KVMGlobalProperty.AGENT_URL_ROOT_PATH)) { ub.path(KVMGlobalProperty.AGENT_URL_ROOT_PATH); } ub.path(path); return ub.build().toUriString(); }
Example 11
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 12
Source File: Force10BaremetalSwitchBackend.java From cloudstack with Apache License 2.0 | 5 votes |
private String buildLink(String switchIp, String path) { UriComponentsBuilder builder = UriComponentsBuilder.newInstance(); builder.scheme("http"); builder.host(switchIp); builder.port(8008); builder.path(path); return builder.build().toUriString(); }
Example 13
Source File: XForwardedAwareRedirectStrategy.java From graviteeio-access-management with Apache License 2.0 | 4 votes |
@Override public void sendRedirect(HttpServletRequest request, HttpServletResponse response, String url) throws IOException { String redirectUrl = calculateRedirectUrl(request.getContextPath(), url); UriComponentsBuilder builder; if (UrlUtils.isAbsoluteUrl(redirectUrl)) { builder = UriComponentsBuilder.fromHttpUrl(redirectUrl); } else { builder = UriComponentsBuilder.fromUriString(redirectUrl); } String scheme = request.getHeader(HttpHeaders.X_FORWARDED_PROTO); if (scheme != null && !scheme.isEmpty()) { builder.scheme(scheme); } 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); } } // handle forwarded path String forwardedPath = request.getHeader(X_FORWARDED_PREFIX); if (forwardedPath != null && !forwardedPath.isEmpty()) { String path = builder.build().getPath(); // remove trailing slash forwardedPath = forwardedPath.substring(0, forwardedPath.length() - (forwardedPath.endsWith("/") ? 1 : 0)); builder.replacePath(forwardedPath + path); } redirectUrl = response.encodeRedirectURL(builder.build(false).toUriString()); if (logger.isDebugEnabled()) { logger.debug("Redirecting to '{}'", redirectUrl); } response.sendRedirect(redirectUrl); }