use of org.springframework.web.util.UriComponentsBuilder in project spring-security-oauth by spring-projects.
the class AuthorizationEndpoint method append.
private String append(String base, Map<String, ?> query, Map<String, String> keys, boolean fragment) {
UriComponentsBuilder template = UriComponentsBuilder.newInstance();
UriComponentsBuilder builder = UriComponentsBuilder.fromUriString(base);
URI redirectUri;
try {
// assume it's encoded to start with (if it came in over the wire)
redirectUri = builder.build(true).toUri();
} catch (Exception e) {
// ... but allow client registrations to contain hard-coded non-encoded values
redirectUri = builder.build().toUri();
builder = UriComponentsBuilder.fromUri(redirectUri);
}
template.scheme(redirectUri.getScheme()).port(redirectUri.getPort()).host(redirectUri.getHost()).userInfo(redirectUri.getUserInfo()).path(redirectUri.getPath());
if (fragment) {
StringBuilder values = new StringBuilder();
if (redirectUri.getFragment() != null) {
String append = redirectUri.getFragment();
values.append(append);
}
for (String key : query.keySet()) {
if (values.length() > 0) {
values.append("&");
}
String name = key;
if (keys != null && keys.containsKey(key)) {
name = keys.get(key);
}
values.append(name + "={" + key + "}");
}
if (values.length() > 0) {
template.fragment(values.toString());
}
UriComponents encoded = template.build().expand(query).encode();
builder.fragment(encoded.getFragment());
} else {
for (String key : query.keySet()) {
String name = key;
if (keys != null && keys.containsKey(key)) {
name = keys.get(key);
}
template.queryParam(name, "{" + key + "}");
}
template.fragment(redirectUri.getFragment());
UriComponents encoded = template.build().expand(query).encode();
builder.query(encoded.getQuery());
}
return builder.build().toUriString();
}
use of org.springframework.web.util.UriComponentsBuilder in project libresonic by Libresonic.
the class HLSController method createStreamUrl.
private String createStreamUrl(HttpServletRequest request, Player player, int id, int offset, int duration, Pair<Integer, Dimension> bitRate) {
UriComponentsBuilder builder = UriComponentsBuilder.fromUriString(getContextPath(request) + "ext/stream/stream.ts");
builder.queryParam("id", id);
builder.queryParam("hls", "true");
builder.queryParam("timeOffset", offset);
builder.queryParam("player", player.getId());
builder.queryParam("duration", duration);
if (bitRate != null) {
builder.queryParam("maxBitRate", bitRate.getFirst());
Dimension dimension = bitRate.getSecond();
if (dimension != null) {
builder.queryParam("size", dimension.width);
builder.queryParam("x", dimension.height);
}
}
jwtSecurityService.addJWTToken(builder);
return builder.toUriString();
}
use of org.springframework.web.util.UriComponentsBuilder in project cloudstack by apache.
the class Force10BaremetalSwitchBackend method buildLink.
private String buildLink(String switchIp, String path) {
UriComponentsBuilder builder = UriComponentsBuilder.newInstance();
builder.scheme("http");
builder.host(switchIp);
builder.port(8008);
builder.path(path);
return builder.build().toUriString();
}
use of org.springframework.web.util.UriComponentsBuilder in project dhis2-core by dhis2.
the class CorsFilter method isOriginWhitelisted.
private boolean isOriginWhitelisted(HttpServletRequest request, String origin) {
HttpServletRequestEncodingWrapper encodingWrapper = new HttpServletRequestEncodingWrapper(request);
UriComponentsBuilder uriBuilder = ServletUriComponentsBuilder.fromContextPath(encodingWrapper).replacePath("");
String forwardedProto = request.getHeader("X-Forwarded-Proto");
if (!StringUtils.isEmpty(forwardedProto)) {
uriBuilder.scheme(forwardedProto);
}
String localUrl = uriBuilder.build().toString();
return !StringUtils.isEmpty(origin) && (localUrl.equals(origin) || configurationService.isCorsWhitelisted(origin));
}
use of org.springframework.web.util.UriComponentsBuilder in project dhis2-core by dhis2.
the class SimplisticHttpGetGateWay method send.
@Override
public OutboundMessageResponse send(String subject, String text, Set<String> recipients, SmsGatewayConfig config) {
GenericHttpGatewayConfig genericHttpConfiguration = (GenericHttpGatewayConfig) config;
UriComponentsBuilder uri = buildUrl(genericHttpConfiguration, text, recipients);
OutboundMessageResponse status = new OutboundMessageResponse();
try {
HttpEntity<?> request = new HttpEntity<>(getRequestHeaderParameters(genericHttpConfiguration.getParameters()));
HttpStatus httpStatus = send(uri.build().encode("ISO-8859-1").toUriString(), request, String.class);
return wrapHttpStatus(httpStatus);
} catch (IOException e) {
log.error("Message failed: " + e.getMessage());
status.setResponseObject(GatewayResponse.RESULT_CODE_504);
status.setDescription(GatewayResponse.RESULT_CODE_504.getResponseMessage());
status.setOk(false);
return status;
}
}
Aggregations