Search in sources :

Example 71 with UriComponentsBuilder

use of org.springframework.web.util.UriComponentsBuilder in project libresonic by Libresonic.

the class LibresonicContentDirectory method createResourceForSong.

protected Res createResourceForSong(MediaFile song) {
    Player player = playerService.getGuestPlayer(null);
    UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(getBaseUrl() + "/ext/stream").queryParam("id", song.getId()).queryParam("player", player.getId());
    if (song.isVideo()) {
        builder.queryParam("format", TranscodingService.FORMAT_RAW);
    }
    jwtSecurityService.addJWTToken(builder);
    String url = builder.toUriString();
    String suffix = song.isVideo() ? FilenameUtils.getExtension(song.getPath()) : transcodingService.getSuffix(player, song, null);
    String mimeTypeString = StringUtil.getMimeType(suffix);
    MimeType mimeType = mimeTypeString == null ? null : MimeType.valueOf(mimeTypeString);
    Res res = new Res(mimeType, null, url);
    res.setDuration(formatDuration(song.getDurationSeconds()));
    return res;
}
Also used : Res(org.fourthline.cling.support.model.Res) Player(org.libresonic.player.domain.Player) UriComponentsBuilder(org.springframework.web.util.UriComponentsBuilder) MimeType(org.seamless.util.MimeType)

Example 72 with UriComponentsBuilder

use of org.springframework.web.util.UriComponentsBuilder in project geode by apache.

the class ClientHttpRequest method getURL.

/**
   * Gets the URL for the client's HTTP request.
   * <p/>
   * 
   * @param uriVariables a Map of URI path variables to values in order to expand the URI template
   *        into a URI.
   * @return a URL as a URI referring to the location of the resource requested by the client via
   *         HTTP.
   * @see #getURI()
   * @see java.net.URI
   * @see org.springframework.web.util.UriComponents
   * @see org.springframework.web.util.UriComponentsBuilder
   */
public URI getURL(final Map<String, ?> uriVariables) {
    final UriComponentsBuilder uriBuilder = UriComponentsBuilder.fromUriString(UriUtils.decode(getURI().toString()));
    if (isGet() || isDelete()) {
        final List<String> pathVariables = getPathVariables();
        // get query parameters to append to the URI/URL based on the request parameters that are not
        // path variables...
        final Map<String, List<Object>> queryParameters = CollectionUtils.removeKeys(new LinkedMultiValueMap<String, Object>(getParameters()), new Filter<Map.Entry<String, List<Object>>>() {

            @Override
            public boolean accept(final Map.Entry<String, List<Object>> entry) {
                // so that it won't interfere with the expand() call afterwards
                if (entry.getKey().contains(CLIMultiStepHelper.STEP_ARGS)) {
                    List<Object> stepArgsList = entry.getValue();
                    if (stepArgsList != null) {
                        String stepArgs = (String) stepArgsList.remove(0);
                        stepArgsList.add(UriUtils.encode(stepArgs));
                    }
                }
                return !pathVariables.contains(entry.getKey());
            }
        });
        for (final String queryParameterName : queryParameters.keySet()) {
            uriBuilder.queryParam(queryParameterName, getParameters().get(queryParameterName).toArray());
        }
    }
    return uriBuilder.build().expand(UriUtils.encode(new HashMap<String, Object>(uriVariables))).encode().toUri();
}
Also used : HashMap(java.util.HashMap) UriComponentsBuilder(org.springframework.web.util.UriComponentsBuilder) List(java.util.List) MultiValueMap(org.springframework.util.MultiValueMap) HashMap(java.util.HashMap) Map(java.util.Map) LinkedMultiValueMap(org.springframework.util.LinkedMultiValueMap)

Example 73 with UriComponentsBuilder

use of org.springframework.web.util.UriComponentsBuilder in project java-chassis by ServiceComb.

the class CseUriTemplateHandler method expandInternal.

@Override
protected URI expandInternal(String uriTemplate, Object... uriVariables) {
    UriComponentsBuilder uriComponentsBuilder = initUriComponentsBuilder(uriTemplate);
    UriComponents uriComponents = expandAndEncode(uriComponentsBuilder, uriVariables);
    return createUri(uriTemplate, uriComponentsBuilder, uriComponents);
}
Also used : UriComponents(org.springframework.web.util.UriComponents) UriComponentsBuilder(org.springframework.web.util.UriComponentsBuilder)

Example 74 with UriComponentsBuilder

use of org.springframework.web.util.UriComponentsBuilder in project java-chassis by ServiceComb.

the class CseUriTemplateHandler method expandInternal.

@Override
protected URI expandInternal(String uriTemplate, Map<String, ?> uriVariables) {
    UriComponentsBuilder uriComponentsBuilder = initUriComponentsBuilder(uriTemplate);
    UriComponents uriComponents = expandAndEncode(uriComponentsBuilder, uriVariables);
    return createUri(uriTemplate, uriComponentsBuilder, uriComponents);
}
Also used : UriComponents(org.springframework.web.util.UriComponents) UriComponentsBuilder(org.springframework.web.util.UriComponentsBuilder)

Example 75 with UriComponentsBuilder

use of org.springframework.web.util.UriComponentsBuilder in project dhis2-core by dhis2.

the class BulkSmsGateway method sendBatch.

// -------------------------------------------------------------------------
// Implementation
// -------------------------------------------------------------------------
@Override
public List<OutboundMessageResponse> sendBatch(OutboundMessageBatch smsBatch, SmsGatewayConfig config) {
    BulkSmsGatewayConfig bulkSmsConfig = (BulkSmsGatewayConfig) config;
    UriComponentsBuilder uriBuilder = buildBaseUrl(bulkSmsConfig, SubmissionType.BATCH);
    uriBuilder.queryParam("batch_data", buildCsvUrl(smsBatch.getMessages()));
    return Lists.newArrayList(send(uriBuilder));
}
Also used : UriComponentsBuilder(org.springframework.web.util.UriComponentsBuilder)

Aggregations

UriComponentsBuilder (org.springframework.web.util.UriComponentsBuilder)131 Test (org.junit.Test)34 UriComponents (org.springframework.web.util.UriComponents)23 ServletUriComponentsBuilder (org.springframework.web.servlet.support.ServletUriComponentsBuilder)12 URI (java.net.URI)9 Test (org.junit.jupiter.api.Test)9 SearchRequest (org.nzbhydra.searching.searchrequests.SearchRequest)8 MvcUriComponentsBuilder (org.springframework.web.servlet.mvc.method.annotation.MvcUriComponentsBuilder)8 ArrayList (java.util.ArrayList)7 LinkedMultiValueMap (org.springframework.util.LinkedMultiValueMap)7 List (java.util.List)6 User (com.serotonin.m2m2.vo.User)5 RestProcessResult (com.serotonin.m2m2.web.mvc.rest.v1.message.RestProcessResult)5 ApiOperation (com.wordnik.swagger.annotations.ApiOperation)5 HashMap (java.util.HashMap)5 HttpEntity (org.springframework.http.HttpEntity)5 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)5 HttpClientErrorException (org.springframework.web.client.HttpClientErrorException)5 IOException (java.io.IOException)4 Map (java.util.Map)4