Java Code Examples for org.springframework.web.util.UriComponents#toString()
The following examples show how to use
org.springframework.web.util.UriComponents#toString() .
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: ResponseLinksMapper.java From moserp with Apache License 2.0 | 6 votes |
Object fixLink(Object value) { if (!(value instanceof String)) { return value; } String href = (String) value; Matcher urlWithServiceNameMatcher = urlWithServiceNamePattern.matcher(href); Matcher standardUrlMatcher = standardUrlPattern.matcher(href); if (!standardUrlMatcher.matches() && urlWithServiceNameMatcher.matches()) { String possibleServiceName = urlWithServiceNameMatcher.group(1); log.debug("Possible service name: " + possibleServiceName); if (services.contains(possibleServiceName)) { log.debug("Service found"); String gatewayPath = serviceRouteMapper.apply(possibleServiceName); String originalRestPath = urlWithServiceNameMatcher.group(2); ServletUriComponentsBuilder servletUriComponentsBuilder = ServletUriComponentsBuilder.fromCurrentRequest(); UriComponents uriComponents = servletUriComponentsBuilder.replacePath(gatewayPath).path(originalRestPath).build(); log.debug("Mapping " + value + " to " + uriComponents); return uriComponents.toString(); } } return href; }
Example 3
Source File: HttpRequestTools.java From WeBASE-Node-Manager with Apache License 2.0 | 5 votes |
/** * convert map to query params * ex: uri:permission, * params: (groupId, 1) (address, 0x01) * * result: permission?groupId=1&address=0x01 */ public static String getQueryUri(String uriHead, Map<String, String> map) { MultiValueMap<String, String> params = new LinkedMultiValueMap<String, String>(); for (Map.Entry<String, String> entry : map.entrySet()) { params.add(entry.getKey(), entry.getValue()); } UriComponents uriComponents = UriComponentsBuilder.newInstance() .queryParams(params).build(); return uriHead + uriComponents.toString(); }
Example 4
Source File: DataModelServiceStub.java From wecube-platform with Apache License 2.0 | 5 votes |
/** * Issue a request from request url with place holders and param map * * @param requestUrl request url with place holders * @param paramMap generated param map * @return common response dto */ public UrlToResponseDto initiateGetRequest(String requestUrl, Map<String, Object> paramMap) { UrlToResponseDto responseDto; // combine url with param map UriComponentsBuilder uriComponentsBuilder = UriComponentsBuilder.fromUriString(requestUrl); UriComponents uriComponents = uriComponentsBuilder.buildAndExpand(paramMap); String uriStr = uriComponents.toString(); responseDto = sendGetRequest(uriStr); return responseDto; }
Example 5
Source File: DataModelServiceStub.java From wecube-platform with Apache License 2.0 | 5 votes |
/** * Issue a request from request url with place holders and param map * * @param requestUrl request url with place holders * @param paramMap generated param map * @Param chainRequestDto chain request dto scope */ public UrlToResponseDto initiatePostRequest(String requestUrl, Map<String, Object> paramMap, List<Map<String, Object>> requestBodyParamMap) { UrlToResponseDto urlToResponseDto; // combine url with param map UriComponentsBuilder uriComponentsBuilder = UriComponentsBuilder.fromUriString(requestUrl); UriComponents uriComponents = uriComponentsBuilder.buildAndExpand(paramMap); String uriStr = uriComponents.toString(); urlToResponseDto = sendPostRequest(uriStr, requestBodyParamMap); return urlToResponseDto; }
Example 6
Source File: OpenIdAuthenticationManager.java From alf.io with GNU General Public License v3.0 | 5 votes |
public String buildLogoutUrl() { UriComponents uri = UriComponentsBuilder.newInstance() .scheme("https") .host(openIdConfiguration().getDomain()) .path(openIdConfiguration().getLogoutUrl()) .queryParam("redirect_uri", openIdConfiguration().getLogoutRedirectUrl()) .build(); return uri.toString(); }
Example 7
Source File: HttpUtils.java From openemm with GNU Affero General Public License v3.0 | 4 votes |
public static String resolveRelativeUri(URL base, final String value0) { final String value = value0.replaceAll("^\\s+", ""); try { final URI uri = new URI(value); final UriComponentsBuilder builder = UriComponentsBuilder.fromUri(uri); UriComponents components = null; if (uri.getScheme() == null) { builder.scheme(base.getProtocol()); } if (uri.getHost() == null && uri.getPath() != null) { builder.host(base.getHost()).port(base.getPort()); String path; if (value.startsWith(base.getHost() + "/")) { // Special case when URI starts with a hostname but has no schema // so that hostname is treated as a leading part of a path. // It is possible to resolve that ambiguity when a base URL has the // same hostname. path = uri.getPath().substring(base.getHost().length() - 1); } else { if (value.startsWith("/")) { // Base path is ignored when a URI starts with a slash path = uri.getPath(); } else { if (base.getPath() != null) { path = base.getPath() + "/" + uri.getPath(); } else { path = uri.getPath(); } } } Deque<String> segments = new ArrayDeque<>(); for (String segment : path.split("/")) { switch (segment) { case "": case ".": // Remove duplicating slashes and redundant "." operator break; case "..": // Remove previous segment if possible or append another ".." operator String last = segments.peekLast(); if (last != null && !last.equals("..")) { segments.removeLast(); } else { segments.addLast(segment); } break; default: segments.addLast(segment); break; } } components = builder.replacePath("/" + StringUtils.join(segments, "/")).build(); } if (components != null) { return components.toString(); } } catch (URISyntaxException e) { logger.error("Error occurred: " + e.getMessage(), e); } return value; }