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

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

Introduction

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

Prototype

@Override
public UriComponentsBuilder queryParam(String name, @Nullable Collection<?> values) 

Source Link

Document

Append the given query parameter to the existing query parameters.

Usage

From source file:org.openlmis.fulfillment.service.request.RequestHelper.java

/**
 * Creates a {@link URI} from the given string representation and with the given parameters.
 *//*  w  ww .j av a  2s  .  c  om*/
public static URI createUri(String url, RequestParameters parameters) {
    UriComponentsBuilder builder = UriComponentsBuilder.newInstance().uri(URI.create(url));

    RequestParameters.init().setAll(parameters).forEach(e -> e.getValue().forEach(one -> {
        try {
            builder.queryParam(e.getKey(),
                    UriUtils.encodeQueryParam(String.valueOf(one), StandardCharsets.UTF_8.name()));
        } catch (UnsupportedEncodingException ex) {
            throw new EncodingException(ex);
        }
    }));

    return builder.build(true).toUri();
}

From source file:com.rsa.redchallenge.standaloneapp.utils.RestInteractor.java

/**
 * Helper function to create the URL to be called
 *
 * @param params   parameter for the call
 * @param restPath path of the interface in the REST server to be called
 * @return URL to be called//from  www . jav a2  s. c o m
 */
private static String populatePath(Map<String, Object> params, String restPath) {
    String uri = null;
    if (params != null && !params.isEmpty()) {
        String url = restPath;
        UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(url);

        for (Map.Entry<String, Object> param : params.entrySet())
            builder.queryParam(param.getKey(), param.getValue());

        uri = builder.build().toUriString();
    } else {
        uri = restPath;
    }

    return uri;
}

From source file:org.terasoluna.gfw.web.el.Functions.java

/**
 * build query string from map./*ww w . j a  v a2  s .  c o  m*/
 * <p>
 * query string is encoded with "UTF-8".
 * </p>
 * @see ObjectToMapConverter
 * @param map map
 * @return query string. if map is not empty, return query string. ex) name1=value&amp;name2=value&amp;...
 */
public static String mapToQuery(Map<String, Object> map) {
    if (map == null || map.isEmpty()) {
        return "";
    }
    UriComponentsBuilder builder = UriComponentsBuilder.fromPath("");
    for (Map.Entry<String, Object> e : map.entrySet()) {
        String name = e.getKey();
        Object value = e.getValue();
        builder.queryParam(name, value);
    }
    String query = builder.build().encode().toString();
    // remove the beginning symbol character('?') of the query string.
    return query.substring(1);
}

From source file:org.kmnet.com.fw.web.el.Functions.java

/**
 * build query string from map with the specified {@link BeanWrapper}.
 * <p>//  w w w  .ja  v a2 s.  c om
 * query string is encoded with "UTF-8".
 * </p>
 * @param map map
 * @param beanWrapper beanWrapper which has the definition of each field.
 * @return query string. if map is not empty, return query string. ex) name1=value&name2=value&...
 */
public static String mapToQuery(Map<String, Object> map, BeanWrapper beanWrapper) {
    if (map == null || map.isEmpty()) {
        return "";
    }
    UriComponentsBuilder builder = UriComponentsBuilder.fromPath("");
    Map<String, Object> uriVariables = new HashMap<String, Object>();
    for (Map.Entry<String, Object> e : map.entrySet()) {
        String name = e.getKey();
        Object value = e.getValue();
        builder.queryParam(name, "{" + name + "}");
        TypeDescriptor sourceType;
        if (beanWrapper != null) {
            sourceType = beanWrapper.getPropertyTypeDescriptor(name);
        } else {
            sourceType = TypeDescriptor.forObject(value);
        }
        uriVariables.put(name, CONVERSION_SERVICE.convert(value, sourceType, STRING_DESC));
    }
    String query = builder.buildAndExpand(uriVariables).encode().toString();
    // remove the beginning symbol character('?') of the query string.
    return query.substring(1);
}

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>/* w w  w. j  a  v a  2s  .c  o m*/
 * 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.terasoluna.gfw.web.el.Functions.java

/**
 * build query string from map with the specified {@link BeanWrapper}.
 * <p>/*from ww w .j  av  a2s .  com*/
 * query string is encoded with "UTF-8".<br>
 * <strong>Use {@link #mapToQuery(Map)} instead of this method.</strong>
 * </p>
 * @see ObjectToMapConverter
 * @param map map
 * @param beanWrapper beanWrapper which has the definition of each field.
 * @return query string. if map is not empty, return query string. ex) name1=value&amp;name2=value&amp;...
 * @deprecated (since 5.0.1, to support nested fields in f:query, Use {@link #mapToQuery(Map)} instead of this method.)
 */
@Deprecated
public static String mapToQuery(Map<String, Object> map, BeanWrapper beanWrapper) {
    if (map == null || map.isEmpty()) {
        return "";
    }
    UriComponentsBuilder builder = UriComponentsBuilder.fromPath("");
    for (Map.Entry<String, Object> e : map.entrySet()) {
        String name = e.getKey();
        Object value = e.getValue();
        TypeDescriptor sourceType;
        if (beanWrapper != null) {
            sourceType = beanWrapper.getPropertyTypeDescriptor(name);
        } else {
            sourceType = TypeDescriptor.forObject(value);
        }
        builder.queryParam(name, CONVERSION_SERVICE.convert(value, sourceType, STRING_DESC));
    }
    String query = builder.build().encode().toString();
    // remove the beginning symbol character('?') of the query string.
    return query.substring(1);
}

From source file:com.playhaven.android.req.MetadataRequest.java

@Override
protected UriComponentsBuilder createUrl(Context context) throws PlayHavenException {
    UriComponentsBuilder builder = super.createUrl(context);
    builder.queryParam("metadata", 1);
    return builder;
}

From source file:com.playhaven.android.req.ContentUnitRequest.java

@Override
protected UriComponentsBuilder createUrl(Context context) throws PlayHavenException {
    UriComponentsBuilder builder = super.createUrl(context);
    builder.queryParam(PushReceiver.PushParams.message_id.name(), messageId);
    builder.queryParam(PushReceiver.PushParams.content_id.name(), contentUnitId);
    return builder;
}

From source file:com.playhaven.android.req.PushTrackingRequest.java

@Override
protected UriComponentsBuilder createUrl(Context context) throws PlayHavenException {
    UriComponentsBuilder builder = super.createUrl(context);
    builder.queryParam(PushReceiver.PushParams.push_token.name(), mPushToken); // aka GCM registration id. 
    builder.queryParam(PushReceiver.PushParams.message_id.name(), mMessageId);
    builder.queryParam(PushReceiver.PushParams.content_id.name(), mContentId);
    return builder;
}

From source file:com.playhaven.android.req.PurchaseTrackingRequest.java

protected void addNonNull(UriComponentsBuilder builder, String name, String value) {
    builder.queryParam(name, value == null ? "" : value);
}