Search in sources :

Example 16 with UriComponentsBuilder

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

the class JWTSecurityServiceTest method addJWTToken.

@Test
public void addJWTToken() throws Exception {
    UriComponentsBuilder builder = UriComponentsBuilder.fromUriString(uriString);
    String actualUri = service.addJWTToken(builder).build().toUriString();
    String jwtToken = UriComponentsBuilder.fromUriString(actualUri).build().getQueryParams().getFirst(JWTSecurityService.JWT_PARAM_NAME);
    DecodedJWT verify = verifier.verify(jwtToken);
    Claim claim = verify.getClaim(JWTSecurityService.CLAIM_PATH);
    assertEquals(expectedClaimString, claim.asString());
}
Also used : UriComponentsBuilder(org.springframework.web.util.UriComponentsBuilder) DecodedJWT(com.auth0.jwt.interfaces.DecodedJWT) Claim(com.auth0.jwt.interfaces.Claim) Test(org.junit.Test)

Example 17 with UriComponentsBuilder

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

the class HLSController method generateVariantPlaylist.

private void generateVariantPlaylist(HttpServletRequest request, int id, Player player, List<Pair<Integer, Dimension>> bitRates, PrintWriter writer) {
    writer.println("#EXTM3U");
    writer.println("#EXT-X-VERSION:1");
    //        writer.println("#EXT-X-TARGETDURATION:" + SEGMENT_DURATION);
    String contextPath = getContextPath(request);
    for (Pair<Integer, Dimension> bitRate : bitRates) {
        Integer kbps = bitRate.getFirst();
        writer.println("#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=" + kbps * 1000L);
        UriComponentsBuilder url = (UriComponentsBuilder.fromUriString(contextPath + "ext/hls/hls.m3u8").queryParam("id", id).queryParam("player", player.getId()).queryParam("bitRate", kbps));
        jwtSecurityService.addJWTToken(url);
        writer.print(url.toUriString());
        Dimension dimension = bitRate.getSecond();
        if (dimension != null) {
            writer.print("@" + dimension.width + "x" + dimension.height);
        }
        writer.println();
    }
//        writer.println("#EXT-X-ENDLIST");
}
Also used : UriComponentsBuilder(org.springframework.web.util.UriComponentsBuilder)

Example 18 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 19 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 20 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)

Aggregations

UriComponentsBuilder (org.springframework.web.util.UriComponentsBuilder)25 UriComponents (org.springframework.web.util.UriComponents)10 Test (org.junit.Test)8 MvcUriComponentsBuilder (org.springframework.web.servlet.mvc.method.annotation.MvcUriComponentsBuilder)7 Map (java.util.Map)2 ServletUriComponentsBuilder (org.springframework.web.servlet.support.ServletUriComponentsBuilder)2 Claim (com.auth0.jwt.interfaces.Claim)1 DecodedJWT (com.auth0.jwt.interfaces.DecodedJWT)1 IOException (java.io.IOException)1 URI (java.net.URI)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Random (java.util.Random)1 Res (org.fourthline.cling.support.model.Res)1 OutboundMessageResponse (org.hisp.dhis.outboundmessage.OutboundMessageResponse)1 Player (org.libresonic.player.domain.Player)1 MimeType (org.seamless.util.MimeType)1 MockServletContext (org.springframework.mock.web.test.MockServletContext)1 AccessDeniedException (org.springframework.security.access.AccessDeniedException)1 InsufficientAuthenticationException (org.springframework.security.authentication.InsufficientAuthenticationException)1