Java Code Examples for org.springframework.web.util.UriComponentsBuilder#newInstance()

The following examples show how to use org.springframework.web.util.UriComponentsBuilder#newInstance() . 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 vote down vote up
@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 vote down vote up
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 vote down vote up
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: LoginController.java    From graviteeio-access-management with Apache License 2.0 5 votes vote down vote up
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 5
Source File: CephAgentUrl.java    From zstack with Apache License 2.0 5 votes vote down vote up
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 6
Source File: CephAgentUrl.java    From zstack with Apache License 2.0 5 votes vote down vote up
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 7
Source File: ApplianceVmBase.java    From zstack with Apache License 2.0 5 votes vote down vote up
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 8
Source File: KVMHost.java    From zstack with Apache License 2.0 5 votes vote down vote up
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 9
Source File: KVMHostFactory.java    From zstack with Apache License 2.0 5 votes vote down vote up
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 10
Source File: URLBuilder.java    From zstack with Apache License 2.0 5 votes vote down vote up
public static String buildUrl(String scheme, String host, int port, String...paths) {
    UriComponentsBuilder builder = UriComponentsBuilder.newInstance();
    builder.scheme(scheme).host(host).port(port);
    for (String p : paths) {
        builder.path(p);
    }
    return builder.build().toUriString();
}
 
Example 11
Source File: Force10BaremetalSwitchBackend.java    From cloudstack with Apache License 2.0 5 votes vote down vote up
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 12
Source File: ServiceConfig.java    From dhis2-core with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Bean
public UriComponentsBuilder uriComponentsBuilder()
{
    return UriComponentsBuilder.newInstance();
}