Browse Source

Change ServerRequest.attribute(String) to return Object

This commit changes `ServerRequest.attribute(String)`` to return
`Optional<Object>` instead of `Optional<T>`, where `T` was infered
from a type parameter.
pull/1475/head
Arjen Poutsma 9 years ago
parent
commit
e11bb17aa6
  1. 6
      spring-test/src/main/java/org/springframework/mock/web/reactive/function/server/MockServerRequest.java
  2. 5
      spring-webflux/src/main/java/org/springframework/web/reactive/function/server/DefaultServerRequest.java
  3. 2
      spring-webflux/src/main/java/org/springframework/web/reactive/function/server/RequestPredicates.java
  4. 11
      spring-webflux/src/main/java/org/springframework/web/reactive/function/server/ServerRequest.java
  5. 2
      spring-webflux/src/main/java/org/springframework/web/reactive/function/server/support/ServerRequestWrapper.java
  6. 6
      spring-webflux/src/test/java/org/springframework/web/reactive/function/server/MockServerRequest.java

6
spring-test/src/main/java/org/springframework/mock/web/reactive/function/server/MockServerRequest.java

@ -156,12 +156,6 @@ public class MockServerRequest implements ServerRequest { @@ -156,12 +156,6 @@ public class MockServerRequest implements ServerRequest {
return (Flux<S>) this.body;
}
@SuppressWarnings("unchecked")
@Override
public <S> Optional<S> attribute(String name) {
return Optional.ofNullable((S) this.attributes.get(name));
}
@Override
public Map<String, Object> attributes() {
return this.attributes;

5
spring-webflux/src/main/java/org/springframework/web/reactive/function/server/DefaultServerRequest.java

@ -145,11 +145,6 @@ class DefaultServerRequest implements ServerRequest { @@ -145,11 +145,6 @@ class DefaultServerRequest implements ServerRequest {
return flux.onErrorMap(UnsupportedMediaTypeException.class, ERROR_MAPPER);
}
@Override
public <T> Optional<T> attribute(String name) {
return Optional.ofNullable(this.exchange.getAttribute(name));
}
@Override
public Map<String, Object> attributes() {
return this.exchange.getAttributes();

2
spring-webflux/src/main/java/org/springframework/web/reactive/function/server/RequestPredicates.java

@ -521,7 +521,7 @@ public abstract class RequestPredicates { @@ -521,7 +521,7 @@ public abstract class RequestPredicates {
}
@Override
public <T> Optional<T> attribute(String name) {
public Optional<Object> attribute(String name) {
return this.request.attribute(name);
}

11
spring-webflux/src/main/java/org/springframework/web/reactive/function/server/ServerRequest.java

@ -129,10 +129,17 @@ public interface ServerRequest { @@ -129,10 +129,17 @@ public interface ServerRequest {
/**
* Return the request attribute value if present.
* @param name the attribute name
* @param <T> the attribute type
* @return the attribute value
*/
<T> Optional<T> attribute(String name);
default Optional<Object> attribute(String name) {
Map<String, Object> attributes = attributes();
if (attributes.containsKey(name)) {
return Optional.of(attributes.get(name));
}
else {
return Optional.empty();
}
}
/**
* Return a mutable map of request attributes.

2
spring-webflux/src/main/java/org/springframework/web/reactive/function/server/support/ServerRequestWrapper.java

@ -124,7 +124,7 @@ public class ServerRequestWrapper implements ServerRequest { @@ -124,7 +124,7 @@ public class ServerRequestWrapper implements ServerRequest {
}
@Override
public <T> Optional<T> attribute(String name) {
public Optional<Object> attribute(String name) {
return this.delegate.attribute(name);
}

6
spring-webflux/src/test/java/org/springframework/web/reactive/function/server/MockServerRequest.java

@ -155,12 +155,6 @@ public class MockServerRequest implements ServerRequest { @@ -155,12 +155,6 @@ public class MockServerRequest implements ServerRequest {
return (Flux<S>) this.body;
}
@SuppressWarnings("unchecked")
@Override
public <S> Optional<S> attribute(String name) {
return Optional.ofNullable((S) this.attributes.get(name));
}
@Override
public Map<String, Object> attributes() {
return this.attributes;

Loading…
Cancel
Save