public static String buildAgentUrl(String hostname, String subPath) { UriComponentsBuilder ub = UriComponentsBuilder.newInstance(); ub.scheme(ApplianceVmGlobalProperty.AGENT_URL_SCHEME); if (CoreGlobalProperty.UNIT_TEST_ON) { ub.host("localhost"); } else { ub.host(hostname); } ub.port(ApplianceVmGlobalProperty.AGENT_PORT); if (!"".equals(ApplianceVmGlobalProperty.AGENT_URL_ROOT_PATH)) { ub.path(ApplianceVmGlobalProperty.AGENT_URL_ROOT_PATH); } ub.path(subPath); return ub.build().toUriString(); }