Polishing
This commit is contained in:
@@ -162,7 +162,7 @@ public class HttpHeaders implements MultiValueMap<String, String>, Serializable
|
||||
*/
|
||||
public static final String CONTENT_ENCODING = "Content-Encoding";
|
||||
/**
|
||||
* The HTTP {@code Content-Disposition} header field name
|
||||
* The HTTP {@code Content-Disposition} header field name.
|
||||
* @see <a href="http://tools.ietf.org/html/rfc6266">RFC 6266</a>
|
||||
*/
|
||||
public static final String CONTENT_DISPOSITION = "Content-Disposition";
|
||||
@@ -368,7 +368,15 @@ public class HttpHeaders implements MultiValueMap<String, String>, Serializable
|
||||
public static final String WWW_AUTHENTICATE = "WWW-Authenticate";
|
||||
|
||||
/**
|
||||
* Date formats as specified in the HTTP RFC
|
||||
* Pattern matching ETag multiple field values in headers such as "If-Match", "If-None-Match".
|
||||
* @see <a href="https://tools.ietf.org/html/rfc7232#section-2.3">Section 2.3 of RFC 7232</a>
|
||||
*/
|
||||
private static final Pattern ETAG_HEADER_VALUE_PATTERN = Pattern.compile("\\*|\\s*((W\\/)?(\"[^\"]*\"))\\s*,?");
|
||||
|
||||
private static final TimeZone GMT = TimeZone.getTimeZone("GMT");
|
||||
|
||||
/**
|
||||
* Date formats as specified in the HTTP RFC.
|
||||
* @see <a href="https://tools.ietf.org/html/rfc7231#section-7.1.1.1">Section 7.1.1.1 of RFC 7231</a>
|
||||
*/
|
||||
private static final String[] DATE_FORMATS = new String[] {
|
||||
@@ -377,14 +385,6 @@ public class HttpHeaders implements MultiValueMap<String, String>, Serializable
|
||||
"EEE MMM dd HH:mm:ss yyyy"
|
||||
};
|
||||
|
||||
/**
|
||||
* Pattern matching ETag multiple field values in headers such as "If-Match", "If-None-Match"
|
||||
* @see <a href="https://tools.ietf.org/html/rfc7232#section-2.3">Section 2.3 of RFC 7232</a>
|
||||
*/
|
||||
private static final Pattern ETAG_HEADER_VALUE_PATTERN = Pattern.compile("\\*|\\s*((W\\/)?(\"[^\"]*\"))\\s*,?");
|
||||
|
||||
private static TimeZone GMT = TimeZone.getTimeZone("GMT");
|
||||
|
||||
|
||||
private final Map<String, List<String>> headers;
|
||||
|
||||
@@ -1052,7 +1052,7 @@ public class HttpHeaders implements MultiValueMap<String, String>, Serializable
|
||||
* {@link IllegalArgumentException} ({@code true}) or rather return -1
|
||||
* in that case ({@code false})
|
||||
* @return the parsed date header, or -1 if none (or invalid)
|
||||
*/
|
||||
*/
|
||||
private long getFirstDate(String headerName, boolean rejectInvalid) {
|
||||
String headerValue = getFirst(headerName);
|
||||
if (headerValue == null) {
|
||||
|
||||
@@ -189,7 +189,9 @@ public abstract class AbstractHttpMessageConverter<T> implements HttpMessageConv
|
||||
* Future implementations might add some default behavior, however.
|
||||
*/
|
||||
@Override
|
||||
public final T read(Class<? extends T> clazz, HttpInputMessage inputMessage) throws IOException {
|
||||
public final T read(Class<? extends T> clazz, HttpInputMessage inputMessage)
|
||||
throws IOException, HttpMessageNotReadableException {
|
||||
|
||||
return readInternal(clazz, inputMessage);
|
||||
}
|
||||
|
||||
@@ -235,7 +237,7 @@ public abstract class AbstractHttpMessageConverter<T> implements HttpMessageConv
|
||||
* {@link #getContentLength}, and sets the corresponding headers.
|
||||
* @since 4.2
|
||||
*/
|
||||
protected void addDefaultHeaders(HttpHeaders headers, T t, MediaType contentType) throws IOException{
|
||||
protected void addDefaultHeaders(HttpHeaders headers, T t, MediaType contentType) throws IOException {
|
||||
if (headers.getContentType() == null) {
|
||||
MediaType contentTypeToUse = contentType;
|
||||
if (contentType == null || contentType.isWildcardType() || contentType.isWildcardSubtype()) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2014 the original author or authors.
|
||||
* Copyright 2002-2018 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.
|
||||
@@ -74,7 +74,7 @@ public abstract class AbstractJaxb2HttpMessageConverter<T> extends AbstractXmlHt
|
||||
* @return the {@code Unmarshaller}
|
||||
* @throws HttpMessageConversionException in case of JAXB errors
|
||||
*/
|
||||
protected final Unmarshaller createUnmarshaller(Class<?> clazz) throws JAXBException {
|
||||
protected final Unmarshaller createUnmarshaller(Class<?> clazz) {
|
||||
try {
|
||||
JAXBContext jaxbContext = getJaxbContext(clazz);
|
||||
Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
|
||||
@@ -104,7 +104,7 @@ public abstract class AbstractJaxb2HttpMessageConverter<T> extends AbstractXmlHt
|
||||
* @throws HttpMessageConversionException in case of JAXB errors
|
||||
*/
|
||||
protected final JAXBContext getJaxbContext(Class<?> clazz) {
|
||||
Assert.notNull(clazz, "'clazz' must not be null");
|
||||
Assert.notNull(clazz, "Class must not be null");
|
||||
JAXBContext jaxbContext = this.jaxbContexts.get(clazz);
|
||||
if (jaxbContext == null) {
|
||||
try {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2010 the original author or authors.
|
||||
* Copyright 2002-2018 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.
|
||||
@@ -29,7 +29,8 @@ import org.springframework.http.HttpInputMessage;
|
||||
import org.springframework.http.HttpOutputMessage;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.converter.AbstractHttpMessageConverter;
|
||||
import org.springframework.http.converter.HttpMessageConversionException;
|
||||
import org.springframework.http.converter.HttpMessageNotReadableException;
|
||||
import org.springframework.http.converter.HttpMessageNotWritableException;
|
||||
|
||||
/**
|
||||
* Abstract base class for {@link org.springframework.http.converter.HttpMessageConverter HttpMessageConverters}
|
||||
@@ -57,12 +58,16 @@ public abstract class AbstractXmlHttpMessageConverter<T> extends AbstractHttpMes
|
||||
|
||||
|
||||
@Override
|
||||
public final T readInternal(Class<? extends T> clazz, HttpInputMessage inputMessage) throws IOException {
|
||||
public final T readInternal(Class<? extends T> clazz, HttpInputMessage inputMessage)
|
||||
throws IOException, HttpMessageNotReadableException {
|
||||
|
||||
return readFromSource(clazz, inputMessage.getHeaders(), new StreamSource(inputMessage.getBody()));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected final void writeInternal(T t, HttpOutputMessage outputMessage) throws IOException {
|
||||
protected final void writeInternal(T t, HttpOutputMessage outputMessage)
|
||||
throws IOException, HttpMessageNotWritableException {
|
||||
|
||||
writeToResult(t, outputMessage.getHeaders(), new StreamResult(outputMessage.getBody()));
|
||||
}
|
||||
|
||||
@@ -84,10 +89,10 @@ public abstract class AbstractXmlHttpMessageConverter<T> extends AbstractHttpMes
|
||||
* @param source the HTTP input body
|
||||
* @return the converted object
|
||||
* @throws IOException in case of I/O errors
|
||||
* @throws org.springframework.http.converter.HttpMessageConversionException in case of conversion errors
|
||||
* @throws HttpMessageNotReadableException in case of conversion errors
|
||||
*/
|
||||
protected abstract T readFromSource(Class<? extends T> clazz, HttpHeaders headers, Source source)
|
||||
throws IOException;
|
||||
throws IOException, HttpMessageNotReadableException;
|
||||
|
||||
/**
|
||||
* Abstract template method called from {@link #writeInternal(Object, HttpOutputMessage)}.
|
||||
@@ -95,9 +100,9 @@ public abstract class AbstractXmlHttpMessageConverter<T> extends AbstractHttpMes
|
||||
* @param headers the HTTP output headers
|
||||
* @param result the HTTP output body
|
||||
* @throws IOException in case of I/O errors
|
||||
* @throws HttpMessageConversionException in case of conversion errors
|
||||
* @throws HttpMessageNotWritableException in case of conversion errors
|
||||
*/
|
||||
protected abstract void writeToResult(T t, HttpHeaders headers, Result result)
|
||||
throws IOException;
|
||||
throws IOException, HttpMessageNotWritableException;
|
||||
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
* Copyright 2002-2018 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
|
||||
* 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,
|
||||
@@ -169,7 +169,7 @@ public class Jaxb2CollectionHttpMessageConverter<T extends Collection>
|
||||
"Could not unmarshal to [" + elementClass + "]: " + ex.getMessage(), ex);
|
||||
}
|
||||
catch (JAXBException ex) {
|
||||
throw new HttpMessageConversionException("Could not instantiate JAXBContext: " + ex.getMessage(), ex);
|
||||
throw new HttpMessageConversionException("Invalid JAXB setup: " + ex.getMessage(), ex);
|
||||
}
|
||||
catch (XMLStreamException ex) {
|
||||
throw new HttpMessageConversionException(ex.getMessage(), ex);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
* Copyright 2002-2018 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.
|
||||
@@ -146,10 +146,9 @@ public class Jaxb2RootElementHttpMessageConverter extends AbstractJaxb2HttpMessa
|
||||
}
|
||||
catch (UnmarshalException ex) {
|
||||
throw new HttpMessageNotReadableException("Could not unmarshal to [" + clazz + "]: " + ex.getMessage(), ex);
|
||||
|
||||
}
|
||||
catch (JAXBException ex) {
|
||||
throw new HttpMessageConversionException("Could not instantiate JAXBContext: " + ex.getMessage(), ex);
|
||||
throw new HttpMessageConversionException("Invalid JAXB setup: " + ex.getMessage(), ex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -189,7 +188,7 @@ public class Jaxb2RootElementHttpMessageConverter extends AbstractJaxb2HttpMessa
|
||||
throw new HttpMessageNotWritableException("Could not marshal [" + o + "]: " + ex.getMessage(), ex);
|
||||
}
|
||||
catch (JAXBException ex) {
|
||||
throw new HttpMessageConversionException("Could not instantiate JAXBContext: " + ex.getMessage(), ex);
|
||||
throw new HttpMessageConversionException("Invalid JAXB setup: " + ex.getMessage(), ex);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user