Polishing

This commit is contained in:
Juergen Hoeller 2019-07-30 16:59:01 +02:00
parent 9a36027ae1
commit c4622dbebc
17 changed files with 40 additions and 52 deletions

View File

@ -430,7 +430,7 @@ public class DependencyDescriptor extends InjectionPoint implements Serializable
@Override @Override
public int hashCode() { public int hashCode() {
return 31 * super.hashCode() + ObjectUtils.nullSafeHashCode(this.containingClass); return (31 * super.hashCode() + ObjectUtils.nullSafeHashCode(this.containingClass));
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2018 the original author or authors. * Copyright 2002-2019 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -144,7 +144,7 @@ public class ObjectError extends DefaultMessageSourceResolvable {
@Override @Override
public int hashCode() { public int hashCode() {
return super.hashCode() * 29 + getObjectName().hashCode(); return (29 * super.hashCode() + getObjectName().hashCode());
} }
@Override @Override

View File

@ -591,7 +591,7 @@ public class CachingConnectionFactory extends SingleConnectionFactory {
@Override @Override
public int hashCode() { public int hashCode() {
return 31 * super.hashCode() + ObjectUtils.nullSafeHashCode(this.selector); return (31 * super.hashCode() + ObjectUtils.nullSafeHashCode(this.selector));
} }
@Override @Override

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2018 the original author or authors. * Copyright 2002-2019 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -110,9 +110,8 @@ public class HandlerMethodArgumentResolverComposite implements HandlerMethodArgu
public Object resolveArgument(MethodParameter parameter, Message<?> message) throws Exception { public Object resolveArgument(MethodParameter parameter, Message<?> message) throws Exception {
HandlerMethodArgumentResolver resolver = getArgumentResolver(parameter); HandlerMethodArgumentResolver resolver = getArgumentResolver(parameter);
if (resolver == null) { if (resolver == null) {
throw new IllegalStateException( throw new IllegalArgumentException("Unsupported parameter type [" +
"Unsupported parameter type [" + parameter.getParameterType().getName() + "]." + parameter.getParameterType().getName() + "]. supportsParameter should be called first.");
" supportsParameter should be called first.");
} }
return resolver.resolveArgument(parameter, message); return resolver.resolveArgument(parameter, message);
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2017 the original author or authors. * Copyright 2002-2019 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -178,7 +178,7 @@ public class WebMergedContextConfiguration extends MergedContextConfiguration {
*/ */
@Override @Override
public int hashCode() { public int hashCode() {
return super.hashCode() * 31 + this.resourceBasePath.hashCode(); return (31 * super.hashCode() + this.resourceBasePath.hashCode());
} }
/** /**

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2018 the original author or authors. * Copyright 2002-2019 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -447,6 +447,7 @@ public enum HttpStatus {
* Whether this status code is in the HTTP series * Whether this status code is in the HTTP series
* {@link org.springframework.http.HttpStatus.Series#INFORMATIONAL}. * {@link org.springframework.http.HttpStatus.Series#INFORMATIONAL}.
* This is a shortcut for checking the value of {@link #series()}. * This is a shortcut for checking the value of {@link #series()}.
* @since 4.0
* @see #series() * @see #series()
*/ */
public boolean is1xxInformational() { public boolean is1xxInformational() {
@ -457,6 +458,7 @@ public enum HttpStatus {
* Whether this status code is in the HTTP series * Whether this status code is in the HTTP series
* {@link org.springframework.http.HttpStatus.Series#SUCCESSFUL}. * {@link org.springframework.http.HttpStatus.Series#SUCCESSFUL}.
* This is a shortcut for checking the value of {@link #series()}. * This is a shortcut for checking the value of {@link #series()}.
* @since 4.0
* @see #series() * @see #series()
*/ */
public boolean is2xxSuccessful() { public boolean is2xxSuccessful() {
@ -467,6 +469,7 @@ public enum HttpStatus {
* Whether this status code is in the HTTP series * Whether this status code is in the HTTP series
* {@link org.springframework.http.HttpStatus.Series#REDIRECTION}. * {@link org.springframework.http.HttpStatus.Series#REDIRECTION}.
* This is a shortcut for checking the value of {@link #series()}. * This is a shortcut for checking the value of {@link #series()}.
* @since 4.0
* @see #series() * @see #series()
*/ */
public boolean is3xxRedirection() { public boolean is3xxRedirection() {
@ -477,6 +480,7 @@ public enum HttpStatus {
* Whether this status code is in the HTTP series * Whether this status code is in the HTTP series
* {@link org.springframework.http.HttpStatus.Series#CLIENT_ERROR}. * {@link org.springframework.http.HttpStatus.Series#CLIENT_ERROR}.
* This is a shortcut for checking the value of {@link #series()}. * This is a shortcut for checking the value of {@link #series()}.
* @since 4.0
* @see #series() * @see #series()
*/ */
public boolean is4xxClientError() { public boolean is4xxClientError() {
@ -487,6 +491,7 @@ public enum HttpStatus {
* Whether this status code is in the HTTP series * Whether this status code is in the HTTP series
* {@link org.springframework.http.HttpStatus.Series#SERVER_ERROR}. * {@link org.springframework.http.HttpStatus.Series#SERVER_ERROR}.
* This is a shortcut for checking the value of {@link #series()}. * This is a shortcut for checking the value of {@link #series()}.
* @since 4.0
* @see #series() * @see #series()
*/ */
public boolean is5xxServerError() { public boolean is5xxServerError() {

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2018 the original author or authors. * Copyright 2002-2019 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -169,7 +169,7 @@ public class ResponseEntity<T> extends HttpEntity<T> {
@Override @Override
public int hashCode() { public int hashCode() {
return (super.hashCode() * 29 + ObjectUtils.nullSafeHashCode(this.status)); return (29 * super.hashCode() + ObjectUtils.nullSafeHashCode(this.status));
} }
@Override @Override

View File

@ -109,7 +109,7 @@ public abstract class AbstractServerHttpResponse implements ServerHttpResponse {
@Override @Override
@Nullable @Nullable
public HttpStatus getStatusCode() { public HttpStatus getStatusCode() {
return this.statusCode != null ? HttpStatus.resolve(this.statusCode) : null; return (this.statusCode != null ? HttpStatus.resolve(this.statusCode) : null);
} }
/** /**

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2018 the original author or authors. * Copyright 2002-2019 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -19,7 +19,6 @@ package org.springframework.http.server.reactive;
import java.nio.file.Path; import java.nio.file.Path;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.handler.codec.http.HttpResponseStatus;
import io.netty.handler.codec.http.cookie.Cookie; import io.netty.handler.codec.http.cookie.Cookie;
import io.netty.handler.codec.http.cookie.DefaultCookie; import io.netty.handler.codec.http.cookie.DefaultCookie;
import org.reactivestreams.Publisher; import org.reactivestreams.Publisher;
@ -62,14 +61,9 @@ class ReactorServerHttpResponse extends AbstractServerHttpResponse implements Ze
} }
@Override @Override
@SuppressWarnings("ConstantConditions")
public HttpStatus getStatusCode() { public HttpStatus getStatusCode() {
HttpStatus httpStatus = super.getStatusCode(); HttpStatus httpStatus = super.getStatusCode();
if (httpStatus == null) { return (httpStatus != null ? httpStatus : HttpStatus.resolve(this.response.status().code()));
HttpResponseStatus status = this.response.status();
httpStatus = status != null ? HttpStatus.resolve(status.code()) : null;
}
return httpStatus;
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2018 the original author or authors. * Copyright 2002-2019 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -100,7 +100,7 @@ class ServletServerHttpResponse extends AbstractListenerServerHttpResponse {
@Override @Override
public HttpStatus getStatusCode() { public HttpStatus getStatusCode() {
HttpStatus httpStatus = super.getStatusCode(); HttpStatus httpStatus = super.getStatusCode();
return httpStatus != null ? httpStatus : HttpStatus.resolve(this.response.getStatus()); return (httpStatus != null ? httpStatus : HttpStatus.resolve(this.response.getStatus()));
} }
@Override @Override

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2018 the original author or authors. * Copyright 2002-2019 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -69,8 +69,7 @@ class UndertowServerHttpResponse extends AbstractListenerServerHttpResponse impl
} }
private static HttpHeaders createHeaders(HttpServerExchange exchange) { private static HttpHeaders createHeaders(HttpServerExchange exchange) {
UndertowHeadersAdapter headersMap = UndertowHeadersAdapter headersMap = new UndertowHeadersAdapter(exchange.getResponseHeaders());
new UndertowHeadersAdapter(exchange.getResponseHeaders());
return new HttpHeaders(headersMap); return new HttpHeaders(headersMap);
} }
@ -84,7 +83,7 @@ class UndertowServerHttpResponse extends AbstractListenerServerHttpResponse impl
@Override @Override
public HttpStatus getStatusCode() { public HttpStatus getStatusCode() {
HttpStatus httpStatus = super.getStatusCode(); HttpStatus httpStatus = super.getStatusCode();
return httpStatus != null ? httpStatus : HttpStatus.resolve(this.exchange.getStatusCode()); return (httpStatus != null ? httpStatus : HttpStatus.resolve(this.exchange.getStatusCode()));
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2018 the original author or authors. * Copyright 2002-2019 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -119,9 +119,8 @@ public class HandlerMethodArgumentResolverComposite implements HandlerMethodArgu
HandlerMethodArgumentResolver resolver = getArgumentResolver(parameter); HandlerMethodArgumentResolver resolver = getArgumentResolver(parameter);
if (resolver == null) { if (resolver == null) {
throw new IllegalArgumentException( throw new IllegalArgumentException("Unsupported parameter type [" +
"Unsupported parameter type [" + parameter.getParameterType().getName() + "]." + parameter.getParameterType().getName() + "]. supportsParameter should be called first.");
" supportsParameter should be called first.");
} }
return resolver.resolveArgument(parameter, mavContainer, webRequest, binderFactory); return resolver.resolveArgument(parameter, mavContainer, webRequest, binderFactory);
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2018 the original author or authors. * Copyright 2002-2019 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -40,7 +40,7 @@ public class HandlerMethodArgumentResolverCompositeTests {
@Before @Before
public void setUp() throws Exception { public void setup() throws Exception {
this.resolverComposite = new HandlerMethodArgumentResolverComposite(); this.resolverComposite = new HandlerMethodArgumentResolverComposite();
Method method = getClass().getDeclaredMethod("handle", Integer.class, String.class); Method method = getClass().getDeclaredMethod("handle", Integer.class, String.class);
@ -50,7 +50,7 @@ public class HandlerMethodArgumentResolverCompositeTests {
@Test @Test
public void supportsParameter() { public void supportsParameter() throws Exception {
this.resolverComposite.addResolver(new StubArgumentResolver(Integer.class)); this.resolverComposite.addResolver(new StubArgumentResolver(Integer.class));
assertTrue(this.resolverComposite.supportsParameter(paramInt)); assertTrue(this.resolverComposite.supportsParameter(paramInt));

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2018 the original author or authors. * Copyright 2002-2019 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -30,6 +30,7 @@ import static org.mockito.Mockito.when;
/** /**
* Test fixture with {@link HandlerMethodReturnValueHandlerComposite}. * Test fixture with {@link HandlerMethodReturnValueHandlerComposite}.
*
* @author Rossen Stoyanchev * @author Rossen Stoyanchev
*/ */
@SuppressWarnings("unused") @SuppressWarnings("unused")
@ -47,8 +48,7 @@ public class HandlerMethodReturnValueHandlerCompositeTests {
@Before @Before
public void setUp() throws Exception { public void setup() throws Exception {
this.integerType = new MethodParameter(getClass().getDeclaredMethod("handleInteger"), -1); this.integerType = new MethodParameter(getClass().getDeclaredMethod("handleInteger"), -1);
this.stringType = new MethodParameter(getClass().getDeclaredMethod("handleString"), -1); this.stringType = new MethodParameter(getClass().getDeclaredMethod("handleString"), -1);
@ -61,6 +61,7 @@ public class HandlerMethodReturnValueHandlerCompositeTests {
mavContainer = new ModelAndViewContainer(); mavContainer = new ModelAndViewContainer();
} }
@Test @Test
public void supportsReturnType() throws Exception { public void supportsReturnType() throws Exception {
assertTrue(this.handlers.supportsReturnType(this.integerType)); assertTrue(this.handlers.supportsReturnType(this.integerType));
@ -84,9 +85,8 @@ public class HandlerMethodReturnValueHandlerCompositeTests {
verifyNoMoreInteractions(anotherIntegerHandler); verifyNoMoreInteractions(anotherIntegerHandler);
} }
@Test // SPR-13083 @Test // SPR-13083
public void handleReturnValueWithAsyncHandler() throws Exception { public void handleReturnValueWithAsyncHandler() throws Exception {
Promise<Integer> promise = new Promise<>(); Promise<Integer> promise = new Promise<>();
MethodParameter promiseType = new MethodParameter(getClass().getDeclaredMethod("handlePromise"), -1); MethodParameter promiseType = new MethodParameter(getClass().getDeclaredMethod("handlePromise"), -1);

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2018 the original author or authors. * Copyright 2002-2019 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -129,13 +129,11 @@ final class DefaultClientResponseBuilder implements ClientResponse.Builder {
@Override @Override
public ClientResponse build() { public ClientResponse build() {
ClientHttpResponse httpResponse = ClientHttpResponse httpResponse =
new BuiltClientHttpResponse(this.statusCode, this.headers, this.cookies, this.body); new BuiltClientHttpResponse(this.statusCode, this.headers, this.cookies, this.body);
// When building ClientResponse manually, the ClientRequest.logPrefix() has to be passed, // When building ClientResponse manually, the ClientRequest.logPrefix() has to be passed,
// e.g. via ClientResponse.Builder, but this (builder) is not used currently. // e.g. via ClientResponse.Builder, but this (builder) is not used currently.
return new DefaultClientResponse(httpResponse, this.strategies, ""); return new DefaultClientResponse(httpResponse, this.strategies, "");
} }

View File

@ -423,7 +423,7 @@ class DefaultWebClient implements WebClient {
private static IntPredicate toIntPredicate(Predicate<HttpStatus> predicate) { private static IntPredicate toIntPredicate(Predicate<HttpStatus> predicate) {
return value -> { return value -> {
HttpStatus status = HttpStatus.resolve(value); HttpStatus status = HttpStatus.resolve(value);
return (status != null) && predicate.test(status); return (status != null && predicate.test(status));
}; };
} }
@ -436,7 +436,6 @@ class DefaultWebClient implements WebClient {
} }
this.statusHandlers.add(new StatusHandler(statusCodePredicate, this.statusHandlers.add(new StatusHandler(statusCodePredicate,
(clientResponse, request) -> exceptionFunction.apply(clientResponse))); (clientResponse, request) -> exceptionFunction.apply(clientResponse)));
return this; return this;
} }
@ -539,8 +538,6 @@ class DefaultWebClient implements WebClient {
public StatusHandler(IntPredicate predicate, public StatusHandler(IntPredicate predicate,
BiFunction<ClientResponse, HttpRequest, Mono<? extends Throwable>> exceptionFunction) { BiFunction<ClientResponse, HttpRequest, Mono<? extends Throwable>> exceptionFunction) {
Assert.notNull(predicate, "Predicate must not be null");
Assert.notNull(exceptionFunction, "Function must not be null");
this.predicate = predicate; this.predicate = predicate;
this.exceptionFunction = exceptionFunction; this.exceptionFunction = exceptionFunction;
} }
@ -552,8 +549,6 @@ class DefaultWebClient implements WebClient {
public Mono<? extends Throwable> apply(ClientResponse response, HttpRequest request) { public Mono<? extends Throwable> apply(ClientResponse response, HttpRequest request) {
return this.exceptionFunction.apply(response, request); return this.exceptionFunction.apply(response, request);
} }
} }
} }

View File

@ -583,6 +583,7 @@ public interface WebClient {
RequestHeadersSpec<?> syncBody(Object body); RequestHeadersSpec<?> syncBody(Object body);
} }
/** /**
* Contract for specifying response operations following the exchange. * Contract for specifying response operations following the exchange.
*/ */
@ -666,24 +667,22 @@ public interface WebClient {
* status code is 4xx or 5xx * status code is 4xx or 5xx
*/ */
<T> Flux<T> bodyToFlux(ParameterizedTypeReference<T> typeReference); <T> Flux<T> bodyToFlux(ParameterizedTypeReference<T> typeReference);
} }
/** /**
* Contract for specifying request headers and URI for a request. * Contract for specifying request headers and URI for a request.
*
* @param <S> a self reference to the spec type * @param <S> a self reference to the spec type
*/ */
interface RequestHeadersUriSpec<S extends RequestHeadersSpec<S>> interface RequestHeadersUriSpec<S extends RequestHeadersSpec<S>>
extends UriSpec<S>, RequestHeadersSpec<S> { extends UriSpec<S>, RequestHeadersSpec<S> {
} }
/** /**
* Contract for specifying request headers, body and URI for a request. * Contract for specifying request headers, body and URI for a request.
*/ */
interface RequestBodyUriSpec extends RequestBodySpec, RequestHeadersUriSpec<RequestBodySpec> { interface RequestBodyUriSpec extends RequestBodySpec, RequestHeadersUriSpec<RequestBodySpec> {
} }
} }