Merge branch '5.3.x' into main

Remove use of Mockito spy proxies, which don't work on Java 17.
This commit is contained in:
rstoyanchev
2022-02-02 17:35:54 +00:00
24 changed files with 189 additions and 143 deletions

View File

@@ -45,6 +45,7 @@ import org.springframework.http.MediaType;
import org.springframework.http.StreamingHttpOutputMessage;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.StreamUtils;
import org.springframework.util.StringUtils;
/**
@@ -207,6 +208,7 @@ public class BufferedImageHttpMessageConverter implements HttpMessageConverter<B
}
private ImageInputStream createImageInputStream(InputStream is) throws IOException {
is = StreamUtils.nonClosing(is);
if (this.cacheDir != null) {
return new FileCacheImageInputStream(is, this.cacheDir);
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2022 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,6 +17,7 @@
package org.springframework.http.converter.feed;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.Reader;
@@ -35,6 +36,7 @@ import org.springframework.http.MediaType;
import org.springframework.http.converter.AbstractHttpMessageConverter;
import org.springframework.http.converter.HttpMessageNotReadableException;
import org.springframework.http.converter.HttpMessageNotWritableException;
import org.springframework.util.StreamUtils;
import org.springframework.util.StringUtils;
/**
@@ -74,7 +76,8 @@ public abstract class AbstractWireFeedHttpMessageConverter<T extends WireFeed>
Charset charset = (contentType != null && contentType.getCharset() != null ?
contentType.getCharset() : DEFAULT_CHARSET);
try {
Reader reader = new InputStreamReader(inputMessage.getBody(), charset);
InputStream inputStream = StreamUtils.nonClosing(inputMessage.getBody());
Reader reader = new InputStreamReader(inputStream, charset);
return (T) feedInput.build(reader);
}
catch (FeedException ex) {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2021 the original author or authors.
* Copyright 2002-2022 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,6 +17,7 @@
package org.springframework.http.converter.json;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.Reader;
@@ -354,24 +355,25 @@ public abstract class AbstractJackson2HttpMessageConverter extends AbstractGener
"UTF-16".equals(charset.name()) ||
"UTF-32".equals(charset.name());
try {
InputStream inputStream = StreamUtils.nonClosing(inputMessage.getBody());
if (inputMessage instanceof MappingJacksonInputMessage mappingJacksonInputMessage) {
Class<?> deserializationView = mappingJacksonInputMessage.getDeserializationView();
if (deserializationView != null) {
ObjectReader objectReader = objectMapper.readerWithView(deserializationView).forType(javaType);
if (isUnicode) {
return objectReader.readValue(inputMessage.getBody());
return objectReader.readValue(inputStream);
}
else {
Reader reader = new InputStreamReader(inputMessage.getBody(), charset);
Reader reader = new InputStreamReader(inputStream, charset);
return objectReader.readValue(reader);
}
}
}
if (isUnicode) {
return objectMapper.readValue(inputMessage.getBody(), javaType);
return objectMapper.readValue(inputStream, javaType);
}
else {
Reader reader = new InputStreamReader(inputMessage.getBody(), charset);
Reader reader = new InputStreamReader(inputStream, charset);
return objectMapper.readValue(reader, javaType);
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2022 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,6 +17,7 @@
package org.springframework.http.converter.xml;
import java.io.IOException;
import java.io.InputStream;
import javax.xml.transform.Result;
import javax.xml.transform.Source;
@@ -33,6 +34,7 @@ import org.springframework.http.converter.AbstractHttpMessageConverter;
import org.springframework.http.converter.HttpMessageConversionException;
import org.springframework.http.converter.HttpMessageNotReadableException;
import org.springframework.http.converter.HttpMessageNotWritableException;
import org.springframework.util.StreamUtils;
/**
* Abstract base class for {@link org.springframework.http.converter.HttpMessageConverter HttpMessageConverters}
@@ -66,7 +68,8 @@ public abstract class AbstractXmlHttpMessageConverter<T> extends AbstractHttpMes
throws IOException, HttpMessageNotReadableException {
try {
return readFromSource(clazz, inputMessage.getHeaders(), new StreamSource(inputMessage.getBody()));
InputStream inputStream = StreamUtils.nonClosing(inputMessage.getBody());
return readFromSource(clazz, inputMessage.getHeaders(), new StreamSource(inputStream));
}
catch (IOException | HttpMessageConversionException ex) {
throw ex;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2021 the original author or authors.
* Copyright 2002-2022 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.
@@ -148,7 +148,7 @@ public class SourceHttpMessageConverter<T extends Source> extends AbstractHttpMe
protected T readInternal(Class<? extends T> clazz, HttpInputMessage inputMessage)
throws IOException, HttpMessageNotReadableException {
InputStream body = inputMessage.getBody();
InputStream body = StreamUtils.nonClosing(inputMessage.getBody());
if (DOMSource.class == clazz) {
return (T) readDOMSource(body, inputMessage);
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2021 the original author or authors.
* Copyright 2002-2022 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.
@@ -158,7 +158,9 @@ public class ServletServerHttpRequest implements ServerHttpRequest {
String requestContentType = this.servletRequest.getContentType();
if (StringUtils.hasLength(requestContentType)) {
contentType = MediaType.parseMediaType(requestContentType);
this.headers.setContentType(contentType);
if (contentType.isConcrete()) {
this.headers.setContentType(contentType);
}
}
}
if (contentType != null && contentType.getCharset() == null) {