Nullability refinements and related polishing
This commit is contained in:
@@ -69,6 +69,7 @@ public class RequestEntity<T> extends HttpEntity<T> {
|
||||
@Nullable
|
||||
private final HttpMethod method;
|
||||
|
||||
@Nullable
|
||||
private final URI url;
|
||||
|
||||
@Nullable
|
||||
@@ -138,7 +139,7 @@ public class RequestEntity<T> extends HttpEntity<T> {
|
||||
* @since 4.3
|
||||
*/
|
||||
public RequestEntity(@Nullable T body, @Nullable MultiValueMap<String, String> headers,
|
||||
@Nullable HttpMethod method, URI url, @Nullable Type type) {
|
||||
@Nullable HttpMethod method, @Nullable URI url, @Nullable Type type) {
|
||||
|
||||
super(body, headers);
|
||||
this.method = method;
|
||||
@@ -160,6 +161,9 @@ public class RequestEntity<T> extends HttpEntity<T> {
|
||||
* Return the URL of the request.
|
||||
*/
|
||||
public URI getUrl() {
|
||||
if (this.url == null) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
return this.url;
|
||||
}
|
||||
|
||||
@@ -679,14 +683,13 @@ public class RequestEntity<T> extends HttpEntity<T> {
|
||||
*/
|
||||
public static class UriTemplateRequestEntity<T> extends RequestEntity<T> {
|
||||
|
||||
String uriTemplate;
|
||||
private final String uriTemplate;
|
||||
|
||||
@Nullable
|
||||
private Object[] uriVarsArray;
|
||||
private final Object[] uriVarsArray;
|
||||
|
||||
@Nullable
|
||||
Map<String, ?> uriVarsMap;
|
||||
|
||||
private final Map<String, ?> uriVarsMap;
|
||||
|
||||
UriTemplateRequestEntity(
|
||||
@Nullable T body, @Nullable MultiValueMap<String, String> headers,
|
||||
@@ -699,7 +702,6 @@ public class RequestEntity<T> extends HttpEntity<T> {
|
||||
this.uriVarsMap = uriVarsMap;
|
||||
}
|
||||
|
||||
|
||||
public String getUriTemplate() {
|
||||
return this.uriTemplate;
|
||||
}
|
||||
@@ -714,11 +716,6 @@ public class RequestEntity<T> extends HttpEntity<T> {
|
||||
return this.uriVarsMap;
|
||||
}
|
||||
|
||||
@Override
|
||||
public URI getUrl() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return format(getMethod(), getUriTemplate(), getBody(), getHeaders());
|
||||
|
||||
@@ -667,9 +667,15 @@ public class RestTemplate extends InterceptingHttpAccessor implements RestOperat
|
||||
private URI resolveUrl(RequestEntity<?> entity) {
|
||||
if (entity instanceof RequestEntity.UriTemplateRequestEntity) {
|
||||
RequestEntity.UriTemplateRequestEntity<?> ext = (RequestEntity.UriTemplateRequestEntity<?>) entity;
|
||||
return (ext.getVars() != null ?
|
||||
this.uriTemplateHandler.expand(ext.getUriTemplate(), ext.getVars()) :
|
||||
this.uriTemplateHandler.expand(ext.getUriTemplate(), ext.getVarsMap()));
|
||||
if (ext.getVars() != null) {
|
||||
return this.uriTemplateHandler.expand(ext.getUriTemplate(), ext.getVars());
|
||||
}
|
||||
else if (ext.getVarsMap() != null) {
|
||||
return this.uriTemplateHandler.expand(ext.getUriTemplate(), ext.getVarsMap());
|
||||
}
|
||||
else {
|
||||
throw new IllegalStateException("No variables specified for URI template: " + ext.getUriTemplate());
|
||||
}
|
||||
}
|
||||
else {
|
||||
return entity.getUrl();
|
||||
|
||||
@@ -137,19 +137,19 @@ public class ForwardedHeaderTransformer implements Function<ServerHttpRequest, S
|
||||
private static String getForwardedPrefix(ServerHttpRequest request) {
|
||||
HttpHeaders headers = request.getHeaders();
|
||||
String header = headers.getFirst("X-Forwarded-Prefix");
|
||||
if (header != null) {
|
||||
StringBuilder prefix = new StringBuilder(header.length());
|
||||
String[] rawPrefixes = StringUtils.tokenizeToStringArray(header, ",");
|
||||
for (String rawPrefix : rawPrefixes) {
|
||||
int endIndex = rawPrefix.length();
|
||||
while (endIndex > 1 && rawPrefix.charAt(endIndex - 1) == '/') {
|
||||
endIndex--;
|
||||
}
|
||||
prefix.append((endIndex != rawPrefix.length() ? rawPrefix.substring(0, endIndex) : rawPrefix));
|
||||
}
|
||||
return prefix.toString();
|
||||
if (header == null) {
|
||||
return null;
|
||||
}
|
||||
return header;
|
||||
StringBuilder prefix = new StringBuilder(header.length());
|
||||
String[] rawPrefixes = StringUtils.tokenizeToStringArray(header, ",");
|
||||
for (String rawPrefix : rawPrefixes) {
|
||||
int endIndex = rawPrefix.length();
|
||||
while (endIndex > 1 && rawPrefix.charAt(endIndex - 1) == '/') {
|
||||
endIndex--;
|
||||
}
|
||||
prefix.append((endIndex != rawPrefix.length() ? rawPrefix.substring(0, endIndex) : rawPrefix));
|
||||
}
|
||||
return prefix.toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user