Browse Source

Polishing

pull/30537/head
Juergen Hoeller 3 years ago
parent
commit
5441796675
  1. 8
      spring-context/src/main/java/org/springframework/validation/Validator.java
  2. 2
      spring-expression/src/main/java/org/springframework/expression/spel/ast/FunctionReference.java
  3. 3
      spring-expression/src/main/java/org/springframework/expression/spel/support/ReflectionHelper.java
  4. 2
      spring-test/src/main/java/org/springframework/test/context/junit/jupiter/SpringExtension.java
  5. 24
      spring-web/src/main/java/org/springframework/http/server/reactive/observation/ServerRequestObservationContext.java
  6. 27
      spring-web/src/main/java/org/springframework/web/server/adapter/HttpWebHandlerAdapter.java
  7. 4
      spring-web/src/main/java/org/springframework/web/server/adapter/WebHttpHandlerBuilder.java

8
spring-context/src/main/java/org/springframework/validation/Validator.java

@ -92,9 +92,8 @@ public interface Validator {
/** /**
* Return a {@code Validator} that checks whether the target object * Return a {@code Validator} that checks whether the target object
* {@linkplain Class#isAssignableFrom(Class) is an instance of} * {@linkplain Class#isAssignableFrom(Class) is an instance of}
* {@code targetClass}, resorting to {@code delegate} to populate * {@code targetClass}, applying the given {@code delegate} to populate
* {@link Errors} if it is. * {@link Errors} if it is.
*
* <p>For instance: * <p>For instance:
* <pre class="code">Validator passwordEqualsValidator = Validator.forInstanceOf(PasswordResetForm.class, (form, errors) -> { * <pre class="code">Validator passwordEqualsValidator = Validator.forInstanceOf(PasswordResetForm.class, (form, errors) -> {
* if (!Objects.equals(form.getPassword(), form.getConfirmPassword())) { * if (!Objects.equals(form.getPassword(), form.getConfirmPassword())) {
@ -116,9 +115,8 @@ public interface Validator {
/** /**
* Return a {@code Validator} that checks whether the target object's class * Return a {@code Validator} that checks whether the target object's class
* is identical to {@code targetClass}, resorting to {@code delegate} to * is identical to {@code targetClass}, applying the given {@code delegate}
* populate {@link Errors} if it is. * to populate {@link Errors} if it is.
*
* <p>For instance: * <p>For instance:
* <pre class="code">Validator passwordEqualsValidator = Validator.forType(PasswordResetForm.class, (form, errors) -> { * <pre class="code">Validator passwordEqualsValidator = Validator.forType(PasswordResetForm.class, (form, errors) -> {
* if (!Objects.equals(form.getPassword(), form.getConfirmPassword())) { * if (!Objects.equals(form.getPassword(), form.getConfirmPassword())) {

2
spring-expression/src/main/java/org/springframework/expression/spel/ast/FunctionReference.java

@ -159,7 +159,7 @@ public class FunctionReference extends SpelNodeImpl {
* @param methodHandle the method to invoke * @param methodHandle the method to invoke
* @return the return value of the invoked Java method * @return the return value of the invoked Java method
* @throws EvaluationException if there is any problem invoking the method * @throws EvaluationException if there is any problem invoking the method
* @since 6.1.0 * @since 6.1
*/ */
private TypedValue executeFunctionBoundMethodHandle(ExpressionState state, MethodHandle methodHandle) throws EvaluationException { private TypedValue executeFunctionBoundMethodHandle(ExpressionState state, MethodHandle methodHandle) throws EvaluationException {
Object[] functionArgs = getArguments(state); Object[] functionArgs = getArguments(state);

3
spring-expression/src/main/java/org/springframework/expression/spel/support/ReflectionHelper.java

@ -343,10 +343,11 @@ public abstract class ReflectionHelper {
* ({@code null} if not varargs) * ({@code null} if not varargs)
* @return {@code true} if some kind of conversion occurred on an argument * @return {@code true} if some kind of conversion occurred on an argument
* @throws EvaluationException if a problem occurs during conversion * @throws EvaluationException if a problem occurs during conversion
* @since 6.1.0 * @since 6.1
*/ */
public static boolean convertAllMethodHandleArguments(TypeConverter converter, Object[] arguments, public static boolean convertAllMethodHandleArguments(TypeConverter converter, Object[] arguments,
MethodHandle methodHandle, @Nullable Integer varargsPosition) throws EvaluationException { MethodHandle methodHandle, @Nullable Integer varargsPosition) throws EvaluationException {
boolean conversionOccurred = false; boolean conversionOccurred = false;
final MethodType methodHandleArgumentTypes = methodHandle.type(); final MethodType methodHandleArgumentTypes = methodHandle.type();
if (varargsPosition == null) { if (varargsPosition == null) {

2
spring-test/src/main/java/org/springframework/test/context/junit/jupiter/SpringExtension.java

@ -182,7 +182,7 @@ public class SpringExtension implements BeforeAllCallback, AfterAllCallback, Tes
* application events in a parallel mode that makes it non-deterministic * application events in a parallel mode that makes it non-deterministic
* ({@code @TestInstance(PER_CLASS)} and {@code @Execution(CONCURRENT)} * ({@code @TestInstance(PER_CLASS)} and {@code @Execution(CONCURRENT)}
* combination). * combination).
* @since 6.1.0 * @since 6.1
*/ */
private void validateRecordApplicationEventsConfig(ExtensionContext context) { private void validateRecordApplicationEventsConfig(ExtensionContext context) {
// We save the result in the ExtensionContext.Store so that we don't // We save the result in the ExtensionContext.Store so that we don't

24
spring-web/src/main/java/org/springframework/http/server/reactive/observation/ServerRequestObservationContext.java

@ -40,10 +40,11 @@ public class ServerRequestObservationContext extends RequestReplyReceiverContext
/** /**
* Name of the request attribute holding the {@link ServerRequestObservationContext context} for the current observation. * Name of the request attribute holding the {@link ServerRequestObservationContext context} for the current observation.
* @since 6.1.0 * @since 6.1
*/ */
public static final String CURRENT_OBSERVATION_CONTEXT_ATTRIBUTE = ServerRequestObservationContext.class.getName() + ".context"; public static final String CURRENT_OBSERVATION_CONTEXT_ATTRIBUTE = ServerRequestObservationContext.class.getName() + ".context";
private final Map<String, Object> attributes; private final Map<String, Object> attributes;
@Nullable @Nullable
@ -51,6 +52,7 @@ public class ServerRequestObservationContext extends RequestReplyReceiverContext
private boolean connectionAborted; private boolean connectionAborted;
public ServerRequestObservationContext(ServerHttpRequest request, ServerHttpResponse response, Map<String, Object> attributes) { public ServerRequestObservationContext(ServerHttpRequest request, ServerHttpResponse response, Map<String, Object> attributes) {
super((req, key) -> req.getHeaders().getFirst(key)); super((req, key) -> req.getHeaders().getFirst(key));
setCarrier(request); setCarrier(request);
@ -58,15 +60,6 @@ public class ServerRequestObservationContext extends RequestReplyReceiverContext
this.attributes = Collections.unmodifiableMap(attributes); this.attributes = Collections.unmodifiableMap(attributes);
} }
/**
* Get the current {@link ServerRequestObservationContext observation context} from the given exchange, if available.
* @param exchange the current exchange
* @return the current observation context
* @since 6.1.0
*/
public static Optional<ServerRequestObservationContext> findCurrent(ServerWebExchange exchange) {
return Optional.ofNullable(exchange.getAttribute(CURRENT_OBSERVATION_CONTEXT_ATTRIBUTE));
}
/** /**
* Return an immutable map of the current request attributes. * Return an immutable map of the current request attributes.
@ -115,4 +108,15 @@ public class ServerRequestObservationContext extends RequestReplyReceiverContext
this.connectionAborted = connectionAborted; this.connectionAborted = connectionAborted;
} }
/**
* Get the current {@link ServerRequestObservationContext observation context} from the given exchange, if available.
* @param exchange the current exchange
* @return the current observation context
* @since 6.1
*/
public static Optional<ServerRequestObservationContext> findCurrent(ServerWebExchange exchange) {
return Optional.ofNullable(exchange.getAttribute(CURRENT_OBSERVATION_CONTEXT_ATTRIBUTE));
}
} }

27
spring-web/src/main/java/org/springframework/web/server/adapter/HttpWebHandlerAdapter.java

@ -85,7 +85,8 @@ public class HttpWebHandlerAdapter extends WebHandlerDecorator implements HttpHa
private static final Set<String> DISCONNECTED_CLIENT_EXCEPTIONS = private static final Set<String> DISCONNECTED_CLIENT_EXCEPTIONS =
Set.of("AbortedException", "ClientAbortException", "EOFException", "EofException"); Set.of("AbortedException", "ClientAbortException", "EOFException", "EofException");
private static final ServerRequestObservationConvention DEFAULT_OBSERVATION_CONVENTION = new DefaultServerRequestObservationConvention(); private static final ServerRequestObservationConvention DEFAULT_OBSERVATION_CONVENTION =
new DefaultServerRequestObservationConvention();
private static final Log logger = LogFactory.getLog(HttpWebHandlerAdapter.class); private static final Log logger = LogFactory.getLog(HttpWebHandlerAdapter.class);
@ -103,11 +104,9 @@ public class HttpWebHandlerAdapter extends WebHandlerDecorator implements HttpHa
@Nullable @Nullable
private ForwardedHeaderTransformer forwardedHeaderTransformer; private ForwardedHeaderTransformer forwardedHeaderTransformer;
@Nullable private ObservationRegistry observationRegistry = ObservationRegistry.NOOP;
private ObservationRegistry observationRegistry;
@Nullable private ServerRequestObservationConvention observationConvention = DEFAULT_OBSERVATION_CONVENTION;
private ServerRequestObservationConvention observationConvention;
@Nullable @Nullable
private ApplicationContext applicationContext; private ApplicationContext applicationContext;
@ -196,8 +195,7 @@ public class HttpWebHandlerAdapter extends WebHandlerDecorator implements HttpHa
* @param transformer the transformer to use * @param transformer the transformer to use
* @since 5.1 * @since 5.1
*/ */
public void setForwardedHeaderTransformer(ForwardedHeaderTransformer transformer) { public void setForwardedHeaderTransformer(@Nullable ForwardedHeaderTransformer transformer) {
Assert.notNull(transformer, "ForwardedHeaderTransformer is required");
this.forwardedHeaderTransformer = transformer; this.forwardedHeaderTransformer = transformer;
} }
@ -214,7 +212,7 @@ public class HttpWebHandlerAdapter extends WebHandlerDecorator implements HttpHa
* Configure a {@link ObservationRegistry} for recording server exchange observations. * Configure a {@link ObservationRegistry} for recording server exchange observations.
* By default, a {@link ObservationRegistry#NOOP no-op} instance will be used. * By default, a {@link ObservationRegistry#NOOP no-op} instance will be used.
* @param observationRegistry the observation registry to use * @param observationRegistry the observation registry to use
* @since 6.1.0 * @since 6.1
*/ */
public void setObservationRegistry(ObservationRegistry observationRegistry) { public void setObservationRegistry(ObservationRegistry observationRegistry) {
this.observationRegistry = observationRegistry; this.observationRegistry = observationRegistry;
@ -222,9 +220,8 @@ public class HttpWebHandlerAdapter extends WebHandlerDecorator implements HttpHa
/** /**
* Return the configured {@link ObservationRegistry}. * Return the configured {@link ObservationRegistry}.
* @since 6.1.0 * @since 6.1
*/ */
@Nullable
public ObservationRegistry getObservationRegistry() { public ObservationRegistry getObservationRegistry() {
return this.observationRegistry; return this.observationRegistry;
} }
@ -233,7 +230,7 @@ public class HttpWebHandlerAdapter extends WebHandlerDecorator implements HttpHa
* Configure a {@link ServerRequestObservationConvention} for server exchanges observations. * Configure a {@link ServerRequestObservationConvention} for server exchanges observations.
* By default, a {@link DefaultServerRequestObservationConvention} instance will be used. * By default, a {@link DefaultServerRequestObservationConvention} instance will be used.
* @param observationConvention the observation convention to use * @param observationConvention the observation convention to use
* @since 6.1.0 * @since 6.1
*/ */
public void setObservationConvention(ServerRequestObservationConvention observationConvention) { public void setObservationConvention(ServerRequestObservationConvention observationConvention) {
this.observationConvention = observationConvention; this.observationConvention = observationConvention;
@ -241,9 +238,8 @@ public class HttpWebHandlerAdapter extends WebHandlerDecorator implements HttpHa
/** /**
* Return the Observation convention configured for server exchanges observations. * Return the Observation convention configured for server exchanges observations.
* @since 6.1.0 * @since 6.1
*/ */
@Nullable
public ServerRequestObservationConvention getObservationConvention() { public ServerRequestObservationConvention getObservationConvention() {
return this.observationConvention; return this.observationConvention;
} }
@ -331,8 +327,8 @@ public class HttpWebHandlerAdapter extends WebHandlerDecorator implements HttpHa
} }
private Publisher<Void> transform(ServerWebExchange exchange, ServerRequestObservationContext observationContext, Mono<Void> call) { private Publisher<Void> transform(ServerWebExchange exchange, ServerRequestObservationContext observationContext, Mono<Void> call) {
Observation observation = ServerHttpObservationDocumentation.HTTP_REACTIVE_SERVER_REQUESTS.observation(this.observationConvention, Observation observation = ServerHttpObservationDocumentation.HTTP_REACTIVE_SERVER_REQUESTS.observation(
DEFAULT_OBSERVATION_CONVENTION, () -> observationContext, this.observationRegistry); this.observationConvention, DEFAULT_OBSERVATION_CONVENTION, () -> observationContext, this.observationRegistry);
observation.start(); observation.start();
return call return call
.doOnSuccess(aVoid -> { .doOnSuccess(aVoid -> {
@ -439,5 +435,4 @@ public class HttpWebHandlerAdapter extends WebHandlerDecorator implements HttpHa
}); });
} }
} }

4
spring-web/src/main/java/org/springframework/web/server/adapter/WebHttpHandlerBuilder.java

@ -374,7 +374,7 @@ public final class WebHttpHandlerBuilder {
* Configure a {@link ObservationRegistry} for recording server exchange observations. * Configure a {@link ObservationRegistry} for recording server exchange observations.
* By default, a {@link ObservationRegistry#NOOP no-op} registry will be configured. * By default, a {@link ObservationRegistry#NOOP no-op} registry will be configured.
* @param observationRegistry the observation registry * @param observationRegistry the observation registry
* @since 6.1.0 * @since 6.1
*/ */
public WebHttpHandlerBuilder observationRegistry(ObservationRegistry observationRegistry) { public WebHttpHandlerBuilder observationRegistry(ObservationRegistry observationRegistry) {
this.observationRegistry = observationRegistry; this.observationRegistry = observationRegistry;
@ -385,7 +385,7 @@ public final class WebHttpHandlerBuilder {
* Configure a {@link ServerRequestObservationConvention} to use for server observations. * Configure a {@link ServerRequestObservationConvention} to use for server observations.
* By default, a {@link DefaultServerRequestObservationConvention} will be used. * By default, a {@link DefaultServerRequestObservationConvention} will be used.
* @param observationConvention the convention to use for all recorded observations * @param observationConvention the convention to use for all recorded observations
* @since 6.1.0 * @since 6.1
*/ */
public WebHttpHandlerBuilder observationConvention(ServerRequestObservationConvention observationConvention) { public WebHttpHandlerBuilder observationConvention(ServerRequestObservationConvention observationConvention) {
this.observationConvention = observationConvention; this.observationConvention = observationConvention;

Loading…
Cancel
Save