Example usage for org.springframework.web.util UriComponentsBuilder path

List of usage examples for org.springframework.web.util UriComponentsBuilder path

Introduction

In this page you can find the example usage for org.springframework.web.util UriComponentsBuilder path.

Prototype

@Override
public UriComponentsBuilder path(String path) 

Source Link

Document

Append the given path to the existing path of this builder.

Usage

From source file:cherry.example.web.util.ViewNameUtil.java

public static String fromMethodCall(Object invocationInfo) {

    MethodInvocationInfo info = (MethodInvocationInfo) invocationInfo;
    Method method = info.getControllerMethod();
    Class<?> type = method.getDeclaringClass();

    UriComponentsBuilder ucb = UriComponentsBuilder.newInstance();
    String typePath = getMappedPath(type.getAnnotation(RequestMapping.class));
    if (StringUtils.isNotEmpty(typePath)) {
        ucb.path(typePath);
    }// www  .  j  av a2s  .  co  m

    String methodPath = getMappedPath(method.getAnnotation(RequestMapping.class));
    if (StringUtils.isNotEmpty(methodPath)) {
        ucb.pathSegment(methodPath);
    }

    String path = ucb.build().getPath();
    if (path.startsWith("/")) {
        return path.substring(1);
    }
    return path;
}

From source file:com.neiljbrown.brighttalk.channels.reportingapi.client.spring.SpringApiClientImpl.java

/**
 * Builds an absolute HTTP URL from a supplied base URI, a relative path an an optional map of request parameters.
 * <p>//from w  ww  .jav a2 s  .c  om
 * Supports building URLs before URL template variables have been expanded - template variable placeholders ({...})
 * will _not_ be encoded.
 * 
 * @param baseUri The {@link URL base URI}.
 * @param relativeUrlPath The relative path to be appended to the base URI.
 * @param requestParams An optional, map representation of request parameters to be appended to the URL. Can be null.
 * @return A String representation of the absolute URL. A return type of String rather than {@link java.net.URI} is
 * used to avoid encoding the URL before any template variables have been replaced.
 */
private static String buildAbsoluteHttpUrl(URI baseUri, String relativeUrlPath,
        Map<String, List<String>> requestParams) {
    UriComponentsBuilder uriBuilder = UriComponentsBuilder.fromUri(baseUri);
    uriBuilder.path(relativeUrlPath);
    if (requestParams != null) {
        for (String paramName : requestParams.keySet()) {
            for (String paramValue : requestParams.get(paramName)) {
                uriBuilder.queryParam(paramName, paramValue);
            }
        }
    }
    UriComponents uriComponents = uriBuilder.build();
    return uriComponents.toUriString();
}

From source file:org.mitre.discovery.util.WebfingerURLNormalizer.java

/**
 * Normalize the resource string as per OIDC Discovery.
 * @param identifier//  w  w w .j a va 2s. c o m
 * @return the normalized string, or null if the string can't be normalized
 */
public static UriComponents normalizeResource(String identifier) {
    // try to parse the URI
    // NOTE: we can't use the Java built-in URI class because it doesn't split the parts appropriately

    if (Strings.isNullOrEmpty(identifier)) {
        logger.warn("Can't normalize null or empty URI: " + identifier);
        return null; // nothing we can do
    } else {

        //UriComponentsBuilder builder = UriComponentsBuilder.fromUriString(identifier);
        UriComponentsBuilder builder = UriComponentsBuilder.newInstance();

        Matcher m = pattern.matcher(identifier);
        if (m.matches()) {
            builder.scheme(m.group(2));
            builder.userInfo(m.group(6));
            builder.host(m.group(8));
            String port = m.group(10);
            if (!Strings.isNullOrEmpty(port)) {
                builder.port(Integer.parseInt(port));
            }
            builder.path(m.group(11));
            builder.query(m.group(13));
            builder.fragment(m.group(15)); // we throw away the hash, but this is the group it would be if we kept it
        } else {
            // doesn't match the pattern, throw it out
            logger.warn("Parser couldn't match input: " + identifier);
            return null;
        }

        UriComponents n = builder.build();

        if (Strings.isNullOrEmpty(n.getScheme())) {
            if (!Strings.isNullOrEmpty(n.getUserInfo()) && Strings.isNullOrEmpty(n.getPath())
                    && Strings.isNullOrEmpty(n.getQuery()) && n.getPort() < 0) {

                // scheme empty, userinfo is not empty, path/query/port are empty
                // set to "acct" (rule 2)
                builder.scheme("acct");

            } else {
                // scheme is empty, but rule 2 doesn't apply
                // set scheme to "https" (rule 3)
                builder.scheme("https");
            }
        }

        // fragment must be stripped (rule 4)
        builder.fragment(null);

        return builder.build();
    }

}

From source file:org.moserp.common.structure.factories.ResourceAssociationPropertyFactory.java

private String calculateValueListUri(PropertyFactoryContext context) {
    ResourceAssociation resourceAssociation = getAnnotation(context, ResourceAssociation.class);
    String resourceName = resourceAssociation.value();

    final BaseUri baseUri = new BaseUri("http://" + moduleRegistry.getModuleForResource(resourceName));
    UriComponentsBuilder builder = baseUri.getUriComponentsBuilder();
    return builder.path(resourceName).build().toUriString();
}

From source file:org.moserp.common.structure.factories.AssociationPropertyFactory.java

private String calculateUri(PropertyFactoryContext context) {
    ResourceMetadata mapping = mappings.getMetadataFor(context.getPersistentProperty().getType());
    final BaseUri baseUri = new BaseUri("http://" + moduleRegistry.getModuleForResource(mapping.getRel()));
    UriComponentsBuilder builder = baseUri.getUriComponentsBuilder();
    return builder.path(mapping.getPath().toString()).build().toUriString();
}

From source file:com.orange.clara.cloud.cf.servicebroker.log.infrastructure.SplunkDashboardUrlFactory.java

@Override
public String getAllAppsDashboardUrl() {
    UriComponentsBuilder urlBuilder = UriComponentsBuilder.fromHttpUrl(logServerUrl);
    urlBuilder.path(SEARCH_PATH);
    urlBuilder.queryParam("q", "search index=\"*\" source=\"tcp:12345\"");
    return urlBuilder.build().encode().toUriString();
}

From source file:com.orange.clara.cloud.cf.servicebroker.log.infrastructure.SplunkDashboardUrlFactory.java

@Override
public String getAppDashboardUrl(String appGuid) {
    UriComponentsBuilder urlBuilder = UriComponentsBuilder.fromHttpUrl(logServerUrl);
    urlBuilder.path(SEARCH_PATH);
    //uncomment to enable auto pause mode
    //urlBuilder.queryParam("auto_pause", "true");
    urlBuilder.queryParam("q", "search index=\"*\" source=\"tcp:12345\" appname=\"" + appGuid + "\"");
    return urlBuilder.build().encode().toUriString();
}

From source file:org.wallride.web.support.Users.java

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();
    }/*from  ww w. j ava2s . c  om*/
    return components.toUriString();
}

From source file:springfox.documentation.spring.web.AbstractPathProvider.java

/**
 * The relative path to the operation, from the basePath, which this operation describes.
 * The value SHOULD be in a relative (URL) path format.
 * /* w  w  w  .j av  a2 s  . c  o m*/
 * Includes the apiResourcePrefix
 *
 * @param operationPath
 * @return the relative path to the api operation
 * @see AbstractPathProvider#getApplicationBasePath()
 */
@Override
public String getOperationPath(String operationPath) {
    UriComponentsBuilder uriComponentsBuilder = UriComponentsBuilder.fromPath("/");
    return sanitiseUrl(uriComponentsBuilder.path(operationPath).build().toString());
}

From source file:springfox.documentation.spring.web.paths.AbstractPathProvider.java

/**
 * The relative path to the operation, from the basePath, which this operation describes.
 * The value SHOULD be in a relative (URL) path format.
 *
 * Includes the apiResourcePrefix//from  w  w w .j  a v a 2 s. c om
 *
 * @param operationPath
 * @return the relative path to the api operation
 * @see AbstractPathProvider#getApplicationBasePath()
 */
@Override
public String getOperationPath(String operationPath) {
    UriComponentsBuilder uriComponentsBuilder = UriComponentsBuilder.fromPath("/");
    return removeAdjacentForwardSlashes(uriComponentsBuilder.path(operationPath).build().toString());
}