Revisit Assert to avoid single-arg assert methods (with refined messages)

Issue: SPR-15196
This commit is contained in:
Juergen Hoeller
2017-01-30 22:15:53 +01:00
parent 768802fa96
commit 1b2dc3638f
118 changed files with 708 additions and 828 deletions

View File

@@ -23,8 +23,7 @@ import java.nio.charset.StandardCharsets;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
import static java.nio.charset.StandardCharsets.ISO_8859_1;
import static java.nio.charset.StandardCharsets.UTF_8;
import static java.nio.charset.StandardCharsets.*;
/**
* Represent the content disposition type and parameters as defined in RFC 2183.
@@ -121,7 +120,7 @@ public class ContentDisposition {
*/
public static ContentDisposition parse(String contentDisposition) {
String[] parts = StringUtils.tokenizeToStringArray(contentDisposition, ";");
Assert.isTrue(parts.length >= 1);
Assert.isTrue(parts.length >= 1, "Content-Disposition header must not be empty");
String type = parts[0];
String name = null;
String filename = null;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2015 the original author or authors.
* Copyright 2002-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.http;
import java.time.Duration;
@@ -50,7 +51,7 @@ public final class ResponseCookie extends HttpCookie {
String path, boolean secure, boolean httpOnly) {
super(name, value);
Assert.notNull(maxAge);
Assert.notNull(maxAge, "Max age must not be null");
this.maxAge = maxAge;
this.domain = Optional.ofNullable(domain);
this.path = Optional.ofNullable(path);
@@ -61,7 +62,6 @@ public final class ResponseCookie extends HttpCookie {
/**
* Return the cookie "Max-Age" attribute in seconds.
*
* <p>A positive value indicates when the cookie expires relative to the
* current time. A value of 0 means the cookie should expire immediately.
* A negative value means no "Max-Age" attribute in which case the cookie
@@ -100,13 +100,6 @@ public final class ResponseCookie extends HttpCookie {
return this.httpOnly;
}
@Override
public int hashCode() {
int result = super.hashCode();
result = 31 * result + ObjectUtils.nullSafeHashCode(this.domain);
result = 31 * result + ObjectUtils.nullSafeHashCode(this.path);
return result;
}
@Override
public boolean equals(Object other) {
@@ -122,6 +115,14 @@ public final class ResponseCookie extends HttpCookie {
ObjectUtils.nullSafeEquals(this.domain, otherCookie.getDomain()));
}
@Override
public int hashCode() {
int result = super.hashCode();
result = 31 * result + ObjectUtils.nullSafeHashCode(this.domain);
result = 31 * result + ObjectUtils.nullSafeHashCode(this.path);
return result;
}
/**
* Factory method to obtain a builder for a server-defined cookie that starts
@@ -144,7 +145,6 @@ public final class ResponseCookie extends HttpCookie {
private boolean httpOnly;
@Override
public ResponseCookieBuilder maxAge(Duration maxAge) {
this.maxAge = maxAge;
@@ -189,6 +189,7 @@ public final class ResponseCookie extends HttpCookie {
};
}
/**
* A builder for a server-defined HttpCookie with attributes.
*/

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -177,7 +177,9 @@ public class SimpleClientHttpRequestFactory implements ClientHttpRequestFactory,
*/
protected HttpURLConnection openConnection(URL url, Proxy proxy) throws IOException {
URLConnection urlConnection = (proxy != null ? url.openConnection(proxy) : url.openConnection());
Assert.isInstanceOf(HttpURLConnection.class, urlConnection);
if (!HttpURLConnection.class.isInstance(urlConnection)) {
throw new IllegalStateException("HttpURLConnection required for [" + url + "] but got: " + urlConnection);
}
return (HttpURLConnection) urlConnection;
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -49,6 +49,7 @@ public abstract class AbstractClientHttpRequest implements ClientHttpRequest {
*/
private enum State {NEW, COMMITTING, COMMITTED}
private final HttpHeaders headers;
private final MultiValueMap<String, HttpCookie> cookies;
@@ -63,7 +64,7 @@ public abstract class AbstractClientHttpRequest implements ClientHttpRequest {
}
public AbstractClientHttpRequest(HttpHeaders headers) {
Assert.notNull(headers);
Assert.notNull(headers, "HttpHeaders must not be null");
this.headers = headers;
this.cookies = new LinkedMultiValueMap<>();
}
@@ -124,7 +125,7 @@ public abstract class AbstractClientHttpRequest implements ClientHttpRequest {
@Override
public void beforeCommit(Supplier<? extends Mono<Void>> action) {
Assert.notNull(action);
Assert.notNull(action, "Action must not be null");
this.commitActions.add(action);
}
@@ -140,5 +141,4 @@ public abstract class AbstractClientHttpRequest implements ClientHttpRequest {
*/
protected abstract void applyCookies();
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -58,16 +58,17 @@ public class MappingJackson2CborHttpMessageConverter extends AbstractJackson2Htt
*/
public MappingJackson2CborHttpMessageConverter(ObjectMapper objectMapper) {
super(objectMapper, new MediaType("application", "cbor"));
Assert.isAssignable(CBORFactory.class, objectMapper.getFactory().getClass());
Assert.isInstanceOf(CBORFactory.class, objectMapper.getFactory(), "CBORFactory required");
}
/**
* {@inheritDoc}
* The {@code objectMapper} parameter must be configured with a {@code CBORFactory} instance.
* The {@code ObjectMapper} must be configured with a {@code CBORFactory} instance.
*/
@Override
public void setObjectMapper(ObjectMapper objectMapper) {
Assert.isAssignable(CBORFactory.class, objectMapper.getFactory().getClass());
Assert.isInstanceOf(CBORFactory.class, objectMapper.getFactory(), "CBORFactory required");
super.setObjectMapper(objectMapper);
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -58,16 +58,17 @@ public class MappingJackson2SmileHttpMessageConverter extends AbstractJackson2Ht
*/
public MappingJackson2SmileHttpMessageConverter(ObjectMapper objectMapper) {
super(objectMapper, new MediaType("application", "x-jackson-smile"));
Assert.isAssignable(SmileFactory.class, objectMapper.getFactory().getClass());
Assert.isInstanceOf(SmileFactory.class, objectMapper.getFactory(), "SmileFactory required");
}
/**
* {@inheritDoc}
* The {@code objectMapper} parameter must be configured with a {@code SmileFactory} instance.
* The {@code ObjectMapper} must be configured with a {@code SmileFactory} instance.
*/
@Override
public void setObjectMapper(ObjectMapper objectMapper) {
Assert.isAssignable(SmileFactory.class, objectMapper.getFactory().getClass());
Assert.isInstanceOf(SmileFactory.class, objectMapper.getFactory(), "SmileFactory required");
super.setObjectMapper(objectMapper);
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -60,16 +60,17 @@ public class MappingJackson2XmlHttpMessageConverter extends AbstractJackson2Http
super(objectMapper, new MediaType("application", "xml"),
new MediaType("text", "xml"),
new MediaType("application", "*+xml"));
Assert.isAssignable(XmlMapper.class, objectMapper.getClass());
Assert.isInstanceOf(XmlMapper.class, objectMapper, "XmlMapper required");
}
/**
* {@inheritDoc}
* The {@code objectMapper} parameter must be a {@link XmlMapper} instance.
* The {@code ObjectMapper} parameter must be a {@link XmlMapper} instance.
*/
@Override
public void setObjectMapper(ObjectMapper objectMapper) {
Assert.isAssignable(XmlMapper.class, objectMapper.getClass());
Assert.isInstanceOf(XmlMapper.class, objectMapper, "XmlMapper required");
super.setObjectMapper(objectMapper);
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -181,7 +181,9 @@ public class ServletServerHttpRequest implements ServerHttpRequest {
@Override
public ServerHttpAsyncRequestControl getAsyncRequestControl(ServerHttpResponse response) {
if (this.asyncRequestControl == null) {
Assert.isInstanceOf(ServletServerHttpResponse.class, response);
if (!ServletServerHttpResponse.class.isInstance(response)) {
throw new IllegalArgumentException("Response must be a ServletServerHttpResponse: " + response.getClass());
}
ServletServerHttpResponse servletServerResponse = (ServletServerHttpResponse) response;
this.asyncRequestControl = new ServletServerHttpAsyncRequestControl(this, servletServerResponse);
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,7 +17,6 @@
package org.springframework.http.server.reactive;
import java.io.IOException;
import java.util.Objects;
import java.util.concurrent.atomic.AtomicLongFieldUpdater;
import java.util.concurrent.atomic.AtomicReference;
@@ -28,6 +27,8 @@ import org.reactivestreams.Subscriber;
import org.reactivestreams.Subscription;
import reactor.core.publisher.Operators;
import org.springframework.util.Assert;
/**
* Abstract base class for {@code Publisher} implementations that bridge between
* event-listener read APIs and Reactive Streams.
@@ -48,6 +49,7 @@ public abstract class AbstractListenerReadPublisher<T> implements Publisher<T> {
private final AtomicReference<State> state = new AtomicReference<>(State.UNSUBSCRIBED);
@SuppressWarnings("unused")
private volatile long demand;
@SuppressWarnings("rawtypes")
@@ -196,7 +198,8 @@ public abstract class AbstractListenerReadPublisher<T> implements Publisher<T> {
UNSUBSCRIBED {
@Override
<T> void subscribe(AbstractListenerReadPublisher<T> publisher, Subscriber<? super T> subscriber) {
Objects.requireNonNull(subscriber);
Assert.notNull(publisher, "Publisher must not be null");
Assert.notNull(subscriber, "Subscriber must not be null");
if (publisher.changeState(this, NO_DEMAND)) {
Subscription subscription = new ReadSubscription(publisher);
publisher.subscriber = subscriber;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,7 +17,6 @@
package org.springframework.http.server.reactive;
import java.io.IOException;
import java.util.Objects;
import java.util.concurrent.atomic.AtomicReference;
import org.apache.commons.logging.Log;
@@ -27,6 +26,8 @@ import org.reactivestreams.Publisher;
import org.reactivestreams.Subscriber;
import org.reactivestreams.Subscription;
import org.springframework.util.Assert;
/**
* An alternative to {@link AbstractListenerWriteProcessor} but instead writing
* a {@code Publisher<Publisher<T>>} with flush boundaries enforces after
@@ -127,10 +128,9 @@ public abstract class AbstractListenerWriteFlushProcessor<T> implements Processo
private enum State {
UNSUBSCRIBED {
@Override
public <T> void onSubscribe(AbstractListenerWriteFlushProcessor<T> processor, Subscription subscription) {
Objects.requireNonNull(subscription, "Subscription cannot be null");
Assert.notNull(subscription, "Subscription must not be null");
if (processor.changeState(this, REQUESTED)) {
processor.subscription = subscription;
subscription.request(1);
@@ -140,8 +140,8 @@ public abstract class AbstractListenerWriteFlushProcessor<T> implements Processo
}
}
},
REQUESTED {
REQUESTED {
@Override
public <T> void onNext(AbstractListenerWriteFlushProcessor<T> processor, Publisher<? extends T> chunk) {
if (processor.changeState(this, RECEIVED)) {
@@ -150,7 +150,6 @@ public abstract class AbstractListenerWriteFlushProcessor<T> implements Processo
chunkProcessor.subscribe(new WriteSubscriber(processor));
}
}
@Override
public <T> void onComplete(AbstractListenerWriteFlushProcessor<T> processor) {
if (processor.changeState(this, COMPLETED)) {
@@ -158,8 +157,8 @@ public abstract class AbstractListenerWriteFlushProcessor<T> implements Processo
}
}
},
RECEIVED {
RECEIVED {
@Override
public <T> void writeComplete(AbstractListenerWriteFlushProcessor<T> processor) {
try {
@@ -169,7 +168,6 @@ public abstract class AbstractListenerWriteFlushProcessor<T> implements Processo
processor.cancel();
processor.onError(ex);
}
if (processor.subscriberCompleted) {
if (processor.changeState(this, COMPLETED)) {
processor.resultPublisher.publishComplete();
@@ -181,26 +179,21 @@ public abstract class AbstractListenerWriteFlushProcessor<T> implements Processo
}
}
}
@Override
public <T> void onComplete(AbstractListenerWriteFlushProcessor<T> processor) {
processor.subscriberCompleted = true;
}
},
COMPLETED {
@Override
public <T> void onNext(AbstractListenerWriteFlushProcessor<T> processor,
Publisher<? extends T> publisher) {
public <T> void onNext(AbstractListenerWriteFlushProcessor<T> processor, Publisher<? extends T> publisher) {
// ignore
}
@Override
public <T> void onError(AbstractListenerWriteFlushProcessor<T> processor, Throwable t) {
// ignore
}
@Override
public <T> void onComplete(AbstractListenerWriteFlushProcessor<T> processor) {
// ignore
@@ -234,7 +227,6 @@ public abstract class AbstractListenerWriteFlushProcessor<T> implements Processo
private final AbstractListenerWriteFlushProcessor<?> processor;
public WriteSubscriber(AbstractListenerWriteFlushProcessor<?> processor) {
this.processor = processor;
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,7 +17,6 @@
package org.springframework.http.server.reactive;
import java.io.IOException;
import java.util.Objects;
import java.util.concurrent.atomic.AtomicReference;
import org.apache.commons.logging.Log;
@@ -120,7 +119,9 @@ public abstract class AbstractListenerWriteProcessor<T> implements Processor<T,
* Called when a data item is received via {@link Subscriber#onNext(Object)}
*/
protected void receiveData(T data) {
Assert.state(this.currentData == null);
if (this.currentData != null) {
throw new IllegalStateException("Current data not processed yet: " + this.currentData);
}
this.currentData = data;
}
@@ -185,10 +186,9 @@ public abstract class AbstractListenerWriteProcessor<T> implements Processor<T,
* #REQUESTED}.
*/
UNSUBSCRIBED {
@Override
public <T> void onSubscribe(AbstractListenerWriteProcessor<T> processor, Subscription subscription) {
Objects.requireNonNull(subscription, "Subscription cannot be null");
Assert.notNull(subscription, "Subscription must not be null");
if (processor.changeState(this, REQUESTED)) {
processor.subscription = subscription;
subscription.request(1);
@@ -198,6 +198,7 @@ public abstract class AbstractListenerWriteProcessor<T> implements Processor<T,
}
}
},
/**
* State that gets entered after a data has been
* {@linkplain Subscription#request(long) requested}. Responds to {@code onNext}
@@ -205,7 +206,6 @@ public abstract class AbstractListenerWriteProcessor<T> implements Processor<T,
* changing state to {@link #COMPLETED}.
*/
REQUESTED {
@Override
public <T> void onNext(AbstractListenerWriteProcessor<T> processor, T data) {
if (processor.isDataEmpty(data)) {
@@ -218,7 +218,6 @@ public abstract class AbstractListenerWriteProcessor<T> implements Processor<T,
}
}
}
@Override
public <T> void onComplete(AbstractListenerWriteProcessor<T> processor) {
if (processor.changeState(this, COMPLETED)) {
@@ -226,6 +225,7 @@ public abstract class AbstractListenerWriteProcessor<T> implements Processor<T,
}
}
},
/**
* State that gets entered after a data has been
* {@linkplain Subscriber#onNext(Object) received}. Responds to
@@ -233,10 +233,9 @@ public abstract class AbstractListenerWriteProcessor<T> implements Processor<T,
* the state to {@link #WRITING}. If it can be written completely,
* changes the state to either {@link #REQUESTED} if the subscription
* has not been completed; or {@link #COMPLETED} if it has. If it cannot
* be written completely the state will be changed to {@link #RECEIVED}.
* be written completely the state will be changed to {@code #RECEIVED}.
*/
RECEIVED {
@Override
public <T> void onWritePossible(AbstractListenerWriteProcessor<T> processor) {
if (processor.changeState(this, WRITING)) {
@@ -265,38 +264,35 @@ public abstract class AbstractListenerWriteProcessor<T> implements Processor<T,
}
}
}
@Override
public <T> void onComplete(AbstractListenerWriteProcessor<T> processor) {
processor.subscriberCompleted = true;
}
},
/**
* State that gets entered after a writing of the current data has been
* {@code onWritePossible started}.
*/
WRITING {
@Override
public <T> void onComplete(AbstractListenerWriteProcessor<T> processor) {
processor.subscriberCompleted = true;
}
},
/**
* The terminal completed state. Does not respond to any events.
*/
COMPLETED {
@Override
public <T> void onNext(AbstractListenerWriteProcessor<T> processor, T data) {
// ignore
}
@Override
public <T> void onError(AbstractListenerWriteProcessor<T> processor, Throwable ex) {
// ignore
}
@Override
public <T> void onComplete(AbstractListenerWriteProcessor<T> processor) {
// ignore

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -89,7 +89,7 @@ public abstract class AbstractServerHttpResponse implements ServerHttpResponse {
@Override
public boolean setStatusCode(HttpStatus statusCode) {
Assert.notNull(statusCode);
Assert.notNull(statusCode, "Status code must not be null");
if (this.state.get() == State.COMMITTED) {
if (logger.isDebugEnabled()) {
logger.debug("Can't set the status " + statusCode.toString() +

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.http.server.reactive;
import java.util.LinkedHashMap;
@@ -57,11 +58,9 @@ public abstract class HttpHandlerAdapterSupport {
/**
* Constructor with {@code HttpHandler}s mapped to distinct context paths.
* Context paths must start but not end with "/" and must be encoded.
*
* <p>At request time context paths are compared against the "raw" path of
* the request URI in the order in which they are provided. The first one
* to match is chosen. If none match the response status is set to 404.
*
* @param handlerMap map with context paths and {@code HttpHandler}s.
* @see ServerHttpRequest#getContextPath()
*/
@@ -85,9 +84,8 @@ public abstract class HttpHandlerAdapterSupport {
private final Map<String, HttpHandler> handlerMap;
public CompositeHttpHandler(Map<String, HttpHandler> handlerMap) {
Assert.notEmpty(handlerMap);
Assert.notEmpty(handlerMap, "Handler map must not be empty");
this.handlerMap = initHandlerMap(handlerMap);
}
@@ -97,10 +95,10 @@ public abstract class HttpHandlerAdapterSupport {
}
private static void validateContextPath(String contextPath) {
Assert.hasText(contextPath, "contextPath must not be empty");
Assert.hasText(contextPath, "Context path must not be empty");
if (!contextPath.equals("/")) {
Assert.isTrue(contextPath.startsWith("/"), "contextPath must begin with '/'");
Assert.isTrue(!contextPath.endsWith("/"), "contextPath must not end with '/'");
Assert.isTrue(contextPath.startsWith("/"), "Context path must begin with '/'");
Assert.isTrue(!contextPath.endsWith("/"), "Context path must not end with '/'");
}
}
@@ -124,7 +122,9 @@ public abstract class HttpHandlerAdapterSupport {
});
}
/** Strip the context path from native request if any */
/**
* Strip the context path from the native request, if any.
*/
private String getPathToUse(ServerHttpRequest request) {
String path = request.getURI().getRawPath();
String contextPath = request.getContextPath();

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -50,12 +50,12 @@ public class ServletHttpHandlerAdapter extends HttpHandlerAdapterSupport impleme
private static final int DEFAULT_BUFFER_SIZE = 8192;
private int bufferSize = DEFAULT_BUFFER_SIZE;
// Servlet is based on blocking I/O, hence the usage of non-direct, heap-based buffers
// (i.e. 'false' as constructor argument)
private DataBufferFactory dataBufferFactory = new DefaultDataBufferFactory(false);
private int bufferSize = DEFAULT_BUFFER_SIZE;
public ServletHttpHandlerAdapter(HttpHandler httpHandler) {
super(httpHandler);
@@ -66,21 +66,12 @@ public class ServletHttpHandlerAdapter extends HttpHandlerAdapterSupport impleme
}
public void setDataBufferFactory(DataBufferFactory dataBufferFactory) {
Assert.notNull(dataBufferFactory, "'dataBufferFactory' must not be null");
this.dataBufferFactory = dataBufferFactory;
}
public DataBufferFactory getDataBufferFactory() {
return this.dataBufferFactory;
}
/**
* Set the size of the input buffer used for reading in bytes.
* <p>By default this is set to 8192.
*/
public void setBufferSize(int bufferSize) {
Assert.isTrue(bufferSize > 0);
Assert.isTrue(bufferSize > 0, "Buffer size must be larger than zero");
this.bufferSize = bufferSize;
}
@@ -91,10 +82,20 @@ public class ServletHttpHandlerAdapter extends HttpHandlerAdapterSupport impleme
return this.bufferSize;
}
public void setDataBufferFactory(DataBufferFactory dataBufferFactory) {
Assert.notNull(dataBufferFactory, "DataBufferFactory must not be null");
this.dataBufferFactory = dataBufferFactory;
}
public DataBufferFactory getDataBufferFactory() {
return this.dataBufferFactory;
}
// The Servlet.service method
@Override
public void service(ServletRequest request, ServletResponse response) throws IOException {
// Start async before Read/WriteListener registration
AsyncContext asyncContext = request.startAsync();
@@ -105,18 +106,15 @@ public class ServletHttpHandlerAdapter extends HttpHandlerAdapterSupport impleme
getHttpHandler().handle(httpRequest, httpResponse).subscribe(subscriber);
}
protected ServerHttpRequest createRequest(HttpServletRequest request, AsyncContext context)
throws IOException {
protected ServerHttpRequest createRequest(HttpServletRequest request, AsyncContext context) throws IOException {
return new ServletServerHttpRequest(request, context, getDataBufferFactory(), getBufferSize());
}
protected ServerHttpResponse createResponse(HttpServletResponse response, AsyncContext context)
throws IOException {
protected ServerHttpResponse createResponse(HttpServletResponse response, AsyncContext context) throws IOException {
return new ServletServerHttpResponse(response, context, getDataBufferFactory(), getBufferSize());
}
// Other Servlet methods...
@Override
@@ -142,7 +140,6 @@ public class ServletHttpHandlerAdapter extends HttpHandlerAdapterSupport impleme
private final AsyncContext asyncContext;
public HandlerResultSubscriber(AsyncContext asyncContext) {
this.asyncContext = asyncContext;
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -43,6 +43,7 @@ import org.springframework.util.Assert;
/**
* Adapt {@link ServerHttpResponse} to the Servlet {@link HttpServletResponse}.
*
* @author Rossen Stoyanchev
* @since 5.0
*/
@@ -66,7 +67,7 @@ public class ServletServerHttpResponse extends AbstractListenerServerHttpRespons
Assert.notNull(response, "HttpServletResponse must not be null");
Assert.notNull(bufferFactory, "DataBufferFactory must not be null");
Assert.isTrue(bufferSize > 0, "'bufferSize' must be greater than 0");
Assert.isTrue(bufferSize > 0, "Buffer size must be greater than 0");
this.response = response;
this.bufferSize = bufferSize;
@@ -210,6 +211,7 @@ public class ServletServerHttpResponse extends AbstractListenerServerHttpRespons
}
}
private class ResponseBodyWriteListener implements WriteListener {
@Override
@@ -228,6 +230,7 @@ public class ServletServerHttpResponse extends AbstractListenerServerHttpRespons
}
}
private class ResponseBodyFlushProcessor extends AbstractListenerWriteFlushProcessor<DataBuffer> {
@Override
@@ -251,11 +254,11 @@ public class ServletServerHttpResponse extends AbstractListenerServerHttpRespons
}
}
private class ResponseBodyProcessor extends AbstractListenerWriteProcessor<DataBuffer> {
private final ServletOutputStream outputStream;
public ResponseBodyProcessor(ServletOutputStream outputStream) {
this.outputStream = outputStream;
}
@@ -268,7 +271,7 @@ public class ServletServerHttpResponse extends AbstractListenerServerHttpRespons
@Override
protected void releaseData() {
if (logger.isTraceEnabled()) {
logger.trace("releaseBuffer: " + this.currentData);
logger.trace("releaseData: " + this.currentData);
}
DataBufferUtils.release(this.currentData);
this.currentData = null;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -30,7 +30,6 @@ import io.undertow.server.handlers.CookieImpl;
import io.undertow.util.HttpString;
import org.reactivestreams.Processor;
import org.reactivestreams.Publisher;
import org.xnio.ChannelListener;
import org.xnio.channels.StreamSinkChannel;
import reactor.core.publisher.Mono;
@@ -60,7 +59,7 @@ public class UndertowServerHttpResponse extends AbstractListenerServerHttpRespon
public UndertowServerHttpResponse(HttpServerExchange exchange, DataBufferFactory bufferFactory) {
super(bufferFactory);
Assert.notNull(exchange, "'exchange' is required.");
Assert.notNull(exchange, "HttpServerExchange is required");
this.exchange = exchange;
}
@@ -69,6 +68,7 @@ public class UndertowServerHttpResponse extends AbstractListenerServerHttpRespon
return this.exchange;
}
@Override
protected void applyStatusCode() {
HttpStatus statusCode = this.getStatusCode();
@@ -145,15 +145,13 @@ public class UndertowServerHttpResponse extends AbstractListenerServerHttpRespon
private volatile ByteBuffer byteBuffer;
public ResponseBodyProcessor(StreamSinkChannel channel) {
Assert.notNull(channel, "StreamSinkChannel must not be null");
this.channel = channel;
}
public void registerListener() {
this.channel.getWriteSetter().set((ChannelListener<StreamSinkChannel>) c -> onWritePossible());
this.channel.getWriteSetter().set(c -> onWritePossible());
this.channel.resumeWrites();
}
@@ -199,7 +197,7 @@ public class UndertowServerHttpResponse extends AbstractListenerServerHttpRespon
@Override
protected void releaseData() {
if (logger.isTraceEnabled()) {
logger.trace("releaseBuffer: " + this.currentData);
logger.trace("releaseData: " + this.currentData);
}
DataBufferUtils.release(this.currentData);
this.currentData = null;
@@ -209,10 +207,11 @@ public class UndertowServerHttpResponse extends AbstractListenerServerHttpRespon
@Override
protected boolean isDataEmpty(DataBuffer dataBuffer) {
return dataBuffer.readableByteCount() == 0;
return (dataBuffer.readableByteCount() == 0);
}
}
private class ResponseBodyFlushProcessor extends AbstractListenerWriteFlushProcessor<DataBuffer> {
@Override

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,7 +16,6 @@
package org.springframework.http.server.reactive;
import java.util.Objects;
import java.util.concurrent.atomic.AtomicReference;
import org.apache.commons.logging.Log;
@@ -26,6 +25,8 @@ import org.reactivestreams.Subscriber;
import org.reactivestreams.Subscription;
import reactor.core.publisher.Operators;
import org.springframework.util.Assert;
/**
* Publisher returned from {@link ServerHttpResponse#writeWith(Publisher)}.
*
@@ -113,12 +114,10 @@ class WriteResultPublisher implements Publisher<Void> {
UNSUBSCRIBED {
@Override
void subscribe(WriteResultPublisher publisher,
Subscriber<? super Void> subscriber) {
Objects.requireNonNull(subscriber);
void subscribe(WriteResultPublisher publisher, Subscriber<? super Void> subscriber) {
Assert.notNull(subscriber, "Subscriber must not be null");
if (publisher.changeState(this, SUBSCRIBED)) {
Subscription subscription =
new ResponseBodyWriteResultSubscription(publisher);
Subscription subscription = new ResponseBodyWriteResultSubscription(publisher);
publisher.subscriber = subscriber;
subscriber.onSubscribe(subscription);
if (publisher.publisherCompleted) {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -136,15 +136,15 @@ public class PathExtensionContentNegotiationStrategy extends AbstractMappingCont
/**
* A public method exposing the knowledge of the path extension strategy to
* resolve file extensions to a MediaType in this case for a given
* resolve file extensions to a {@link MediaType} in this case for a given
* {@link Resource}. The method first looks up any explicitly registered
* file extensions first and then falls back on JAF if available.
* @param resource the resource to look up
* @return the MediaType for the extension or {@code null}.
* @return the MediaType for the extension, or {@code null} if none found
* @since 4.3
*/
public MediaType getMediaTypeForResource(Resource resource) {
Assert.notNull(resource);
Assert.notNull(resource, "Resource must not be null");
MediaType mediaType = null;
String filename = resource.getFilename();
String extension = StringUtils.getFilenameExtension(filename);

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2015 the original author or authors.
* Copyright 2002-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -64,7 +64,7 @@ public class UnsatisfiedServletRequestParameterException extends ServletRequestB
Map<String, String[]> actualParams) {
super("");
Assert.isTrue(!CollectionUtils.isEmpty(paramConditions));
Assert.notEmpty(paramConditions, "Parameter conditions must not be empty");
this.paramConditions = paramConditions;
this.actualParams = actualParams;
}

View File

@@ -37,7 +37,6 @@ import org.springframework.core.annotation.AnnotationAwareOrderComparator;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.support.PropertiesLoaderUtils;
import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;
@@ -480,7 +479,10 @@ public class ContextLoader {
private Class<ApplicationContextInitializer<ConfigurableApplicationContext>> loadInitializerClass(String className) {
try {
Class<?> clazz = ClassUtils.forName(className, ClassUtils.getDefaultClassLoader());
Assert.isAssignable(ApplicationContextInitializer.class, clazz);
if (!ApplicationContextInitializer.class.isAssignableFrom(clazz)) {
throw new ApplicationContextException(
"Initializer class does not implement ApplicationContextInitializer interface: " + clazz);
}
return (Class<ApplicationContextInitializer<ConfigurableApplicationContext>>) clazz;
}
catch (ClassNotFoundException ex) {

View File

@@ -816,7 +816,7 @@ final class HierarchicalUriComponents extends UriComponents {
private final List<PathComponent> pathComponents;
public PathComponentComposite(List<PathComponent> pathComponents) {
Assert.notNull(pathComponents);
Assert.notNull(pathComponents, "PathComponent List must not be null");
this.pathComponents = pathComponents;
}