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());
}
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");
}
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;
}
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();
}
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);
}
Aggregations