Update to Boot 1.5.12
This commit is contained in:
13
pom.xml
13
pom.xml
@@ -10,7 +10,7 @@
|
||||
<parent>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-build</artifactId>
|
||||
<version>1.3.8.RELEASE</version>
|
||||
<version>1.3.9.RELEASE</version>
|
||||
<relativePath />
|
||||
</parent>
|
||||
|
||||
@@ -18,8 +18,8 @@
|
||||
<java.version>1.8</java.version>
|
||||
<spring-cloud-stream.version>Ditmars.SR3</spring-cloud-stream.version>
|
||||
<spring-cloud-task.version>1.1.2.RELEASE</spring-cloud-task.version>
|
||||
<wrapper.version>1.0.9.RELEASE</wrapper.version>
|
||||
<spring-boot.version>1.5.11.RELEASE</spring-boot.version>
|
||||
<wrapper.version>1.0.10.RELEASE</wrapper.version>
|
||||
<spring-boot.version>1.5.12.RELEASE</spring-boot.version>
|
||||
<docs.main>spring-cloud-function</docs.main>
|
||||
</properties>
|
||||
|
||||
@@ -46,6 +46,13 @@
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-dependencies</artifactId>
|
||||
<version>${spring-boot.version}</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
|
||||
@@ -1,221 +0,0 @@
|
||||
/*
|
||||
* Copyright 2016-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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.function.web.flux;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.io.Reader;
|
||||
import java.lang.reflect.Type;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonIOException;
|
||||
import com.google.gson.JsonParseException;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
|
||||
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||
import org.springframework.boot.autoconfigure.web.HttpMessageConverters;
|
||||
import org.springframework.boot.autoconfigure.web.HttpMessageConvertersAutoConfiguration;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpInputMessage;
|
||||
import org.springframework.http.HttpOutputMessage;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.converter.AbstractGenericHttpMessageConverter;
|
||||
import org.springframework.http.converter.HttpMessageConverter;
|
||||
import org.springframework.http.converter.HttpMessageNotReadableException;
|
||||
import org.springframework.http.converter.HttpMessageNotWritableException;
|
||||
import org.springframework.http.converter.json.GsonHttpMessageConverter;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
// TODO: remove this when https://jira.spring.io/browse/SPR-16529 is resolved
|
||||
@Configuration
|
||||
@ConditionalOnClass(HttpMessageConverters.class)
|
||||
@AutoConfigureBefore(HttpMessageConvertersAutoConfiguration.class)
|
||||
public class GsonHttpMessageConvertersAutoConfiguration {
|
||||
|
||||
@Bean
|
||||
public HttpMessageConverters httpMessageConverters(Gson gson) {
|
||||
List<HttpMessageConverter<?>> converters = new ArrayList<>();
|
||||
for (HttpMessageConverter<?> converter : new HttpMessageConverters()
|
||||
.getConverters()) {
|
||||
if (converter instanceof GsonHttpMessageConverter) {
|
||||
BetterGsonHttpMessageConverter gsonConverter = new BetterGsonHttpMessageConverter();
|
||||
gsonConverter.setGson(gson);
|
||||
converters.add(gsonConverter);
|
||||
}
|
||||
else {
|
||||
converters.add(converter);
|
||||
}
|
||||
}
|
||||
return new HttpMessageConverters(false, converters);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class BetterGsonHttpMessageConverter extends AbstractGenericHttpMessageConverter<Object> {
|
||||
|
||||
public static final Charset DEFAULT_CHARSET = Charset.forName("UTF-8");
|
||||
|
||||
private Gson gson = new Gson();
|
||||
|
||||
private String jsonPrefix;
|
||||
|
||||
/**
|
||||
* Construct a new {@code GsonHttpMessageConverter}.
|
||||
*/
|
||||
public BetterGsonHttpMessageConverter() {
|
||||
super(MediaType.APPLICATION_JSON, new MediaType("application", "*+json"));
|
||||
this.setDefaultCharset(DEFAULT_CHARSET);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the {@code Gson} instance to use. If not set, a default {@link Gson#Gson()
|
||||
* Gson} instance is used.
|
||||
* <p>
|
||||
* Setting a custom-configured {@code Gson} is one way to take further control of the
|
||||
* JSON serialization process.
|
||||
*/
|
||||
public void setGson(Gson gson) {
|
||||
Assert.notNull(gson, "'gson' is required");
|
||||
this.gson = gson;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the configured {@code Gson} instance for this converter.
|
||||
*/
|
||||
public Gson getGson() {
|
||||
return this.gson;
|
||||
}
|
||||
|
||||
/**
|
||||
* Specify a custom prefix to use for JSON output. Default is none.
|
||||
* @see #setPrefixJson
|
||||
*/
|
||||
public void setJsonPrefix(String jsonPrefix) {
|
||||
this.jsonPrefix = jsonPrefix;
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicate whether the JSON output by this view should be prefixed with ")]}', ".
|
||||
* Default is {@code false}.
|
||||
* <p>
|
||||
* Prefixing the JSON string in this manner is used to help prevent JSON Hijacking.
|
||||
* The prefix renders the string syntactically invalid as a script so that it cannot
|
||||
* be hijacked. This prefix should be stripped before parsing the string as JSON.
|
||||
* @see #setJsonPrefix
|
||||
*/
|
||||
public void setPrefixJson(boolean prefixJson) {
|
||||
this.jsonPrefix = (prefixJson ? ")]}', " : null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object read(Type type, Class<?> contextClass, HttpInputMessage inputMessage)
|
||||
throws IOException, HttpMessageNotReadableException {
|
||||
|
||||
TypeToken<?> token = getTypeToken(type);
|
||||
return readTypeToken(token, inputMessage);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object readInternal(Class<?> clazz, HttpInputMessage inputMessage)
|
||||
throws IOException, HttpMessageNotReadableException {
|
||||
|
||||
TypeToken<?> token = getTypeToken(clazz);
|
||||
return readTypeToken(token, inputMessage);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the Gson {@link TypeToken} for the specified type.
|
||||
* <p>
|
||||
* The default implementation returns {@code TypeToken.get(type)}, but this can be
|
||||
* overridden in subclasses to allow for custom generic collection handling. For
|
||||
* instance:
|
||||
*
|
||||
* <pre class="code">
|
||||
* protected TypeToken<?> getTypeToken(Type type) {
|
||||
* if (type instanceof Class && List.class.isAssignableFrom((Class<?>) type)) {
|
||||
* return new TypeToken<ArrayList<MyBean>>() {
|
||||
* };
|
||||
* }
|
||||
* else {
|
||||
* return super.getTypeToken(type);
|
||||
* }
|
||||
* }
|
||||
* </pre>
|
||||
*
|
||||
* @param type the type for which to return the TypeToken
|
||||
* @return the type token
|
||||
* @deprecated as of Spring Framework 4.3.8, in favor of signature-based resolution
|
||||
*/
|
||||
@Deprecated
|
||||
protected TypeToken<?> getTypeToken(Type type) {
|
||||
return TypeToken.get(type);
|
||||
}
|
||||
|
||||
private Object readTypeToken(TypeToken<?> token, HttpInputMessage inputMessage)
|
||||
throws IOException {
|
||||
Reader json = new InputStreamReader(inputMessage.getBody(),
|
||||
getCharset(inputMessage.getHeaders()));
|
||||
try {
|
||||
return this.gson.fromJson(json, token.getType());
|
||||
}
|
||||
catch (JsonParseException ex) {
|
||||
throw new HttpMessageNotReadableException(
|
||||
"JSON parse error: " + ex.getMessage(), ex);
|
||||
}
|
||||
}
|
||||
|
||||
private Charset getCharset(HttpHeaders headers) {
|
||||
if (headers == null || headers.getContentType() == null
|
||||
|| headers.getContentType().getCharset() == null) {
|
||||
return DEFAULT_CHARSET;
|
||||
}
|
||||
return headers.getContentType().getCharset();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void writeInternal(Object o, Type type, HttpOutputMessage outputMessage)
|
||||
throws IOException, HttpMessageNotWritableException {
|
||||
|
||||
Charset charset = getCharset(outputMessage.getHeaders());
|
||||
OutputStreamWriter writer = new OutputStreamWriter(outputMessage.getBody(),
|
||||
charset);
|
||||
try {
|
||||
if (this.jsonPrefix != null) {
|
||||
writer.append(this.jsonPrefix);
|
||||
}
|
||||
if (type != null) {
|
||||
this.gson.toJson(o, type, writer);
|
||||
}
|
||||
else {
|
||||
this.gson.toJson(o, writer);
|
||||
}
|
||||
writer.flush();
|
||||
}
|
||||
catch (JsonIOException ex) {
|
||||
throw new HttpMessageNotWritableException(
|
||||
"Could not write JSON: " + ex.getMessage(), ex);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,3 +1,2 @@
|
||||
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
|
||||
org.springframework.cloud.function.web.flux.ReactorAutoConfiguration,\
|
||||
org.springframework.cloud.function.web.flux.GsonHttpMessageConvertersAutoConfiguration
|
||||
org.springframework.cloud.function.web.flux.ReactorAutoConfiguration
|
||||
|
||||
Reference in New Issue
Block a user