diff --git a/org.springframework.web/src/main/java/org/springframework/http/converter/AbstractHttpMessageConverter.java b/org.springframework.web/src/main/java/org/springframework/http/converter/AbstractHttpMessageConverter.java
index 75782d74484..5b303a2a516 100644
--- a/org.springframework.web/src/main/java/org/springframework/http/converter/AbstractHttpMessageConverter.java
+++ b/org.springframework.web/src/main/java/org/springframework/http/converter/AbstractHttpMessageConverter.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2009 the original author or authors.
+ * Copyright 2002-2010 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.
@@ -34,11 +34,12 @@ import org.springframework.util.Assert;
/**
* Abstract base class for most {@link HttpMessageConverter} implementations.
*
- *
This base class adds support for setting supported {@code MediaTypes}, through the {@link
- * #setSupportedMediaTypes(List) supportedMediaTypes} bean property. It also adds support for {@code Content-Type} and
- * {@code Content-Length} when writing to output messages.
+ *
This base class adds support for setting supported {@code MediaTypes}, through the
+ * {@link #setSupportedMediaTypes(List) supportedMediaTypes} bean property. It also adds
+ * support for {@code Content-Type} and {@code Content-Length} when writing to output messages.
*
* @author Arjen Poutsma
+ * @author Juergen Hoeller
* @since 3.0
*/
public abstract class AbstractHttpMessageConverter implements HttpMessageConverter {
@@ -48,9 +49,9 @@ public abstract class AbstractHttpMessageConverter implements HttpMessageConv
private List supportedMediaTypes = Collections.emptyList();
+
/**
* Construct an {@code AbstractHttpMessageConverter} with no supported media types.
- *
* @see #setSupportedMediaTypes
*/
protected AbstractHttpMessageConverter() {
@@ -58,7 +59,6 @@ public abstract class AbstractHttpMessageConverter implements HttpMessageConv
/**
* Construct an {@code AbstractHttpMessageConverter} with one supported media type.
- *
* @param supportedMediaType the supported media type
*/
protected AbstractHttpMessageConverter(MediaType supportedMediaType) {
@@ -67,14 +67,16 @@ public abstract class AbstractHttpMessageConverter implements HttpMessageConv
/**
* Construct an {@code AbstractHttpMessageConverter} with multiple supported media type.
- *
* @param supportedMediaTypes the supported media types
*/
protected AbstractHttpMessageConverter(MediaType... supportedMediaTypes) {
setSupportedMediaTypes(Arrays.asList(supportedMediaTypes));
}
- /** Set the list of {@link MediaType} objects supported by this converter. */
+
+ /**
+ * Set the list of {@link MediaType} objects supported by this converter.
+ */
public void setSupportedMediaTypes(List supportedMediaTypes) {
Assert.notEmpty(supportedMediaTypes, "'supportedMediaTypes' must not be empty");
this.supportedMediaTypes = new ArrayList(supportedMediaTypes);
@@ -84,21 +86,20 @@ public abstract class AbstractHttpMessageConverter implements HttpMessageConv
return Collections.unmodifiableList(this.supportedMediaTypes);
}
+
/**
* {@inheritDoc}
- *
- *
This implementation checks if the given class is {@linkplain #supports(Class) supported}, and if the {@linkplain
- * #getSupportedMediaTypes() supported media types} {@linkplain MediaType#includes(MediaType) include} the given media
- * type.
+ *
This implementation checks if the given class is {@linkplain #supports(Class) supported},
+ * and if the {@linkplain #getSupportedMediaTypes() supported media types}
+ * {@linkplain MediaType#includes(MediaType) include} the given media type.
*/
public boolean canRead(Class> clazz, MediaType mediaType) {
return supports(clazz) && canRead(mediaType);
}
/**
- * Returns true if any of the {@linkplain #setSupportedMediaTypes(List) supported media types} include the given media
- * type.
- *
+ * Returns true if any of the {@linkplain #setSupportedMediaTypes(List) supported media types}
+ * include the given media type.
* @param mediaType the media type
* @return true if the supported media types include the media type, or if the media type is {@code null}
*/
@@ -116,10 +117,9 @@ public abstract class AbstractHttpMessageConverter implements HttpMessageConv
/**
* {@inheritDoc}
- *
- *
This implementation checks if the given class is {@linkplain #supports(Class) supported}, and if the {@linkplain
- * #getSupportedMediaTypes() supported media types} {@linkplain MediaType#includes(MediaType) include} the given media
- * type.
+ *
This implementation checks if the given class is {@linkplain #supports(Class) supported},
+ * and if the {@linkplain #getSupportedMediaTypes() supported media types}
+ * {@linkplain MediaType#includes(MediaType) include} the given media type.
*/
public boolean canWrite(Class> clazz, MediaType mediaType) {
return supports(clazz) && canWrite(mediaType);
@@ -128,7 +128,6 @@ public abstract class AbstractHttpMessageConverter implements HttpMessageConv
/**
* Returns true if the given media type includes any of the
* {@linkplain #setSupportedMediaTypes(List) supported media types}.
- *
* @param mediaType the media type
* @return true if the supported media types include the media type, or if the media type is {@code null}
*/
@@ -144,45 +143,24 @@ public abstract class AbstractHttpMessageConverter implements HttpMessageConv
return false;
}
- /**
- * Indicates whether the given class is supported by this converter.
- *
- * @param clazz the class to test for support
- * @return true if supported; false otherwise
- */
- protected abstract boolean supports(Class> clazz);
-
/**
* {@inheritDoc}
- *
- *
This implementation simple delegates to {@link #readInternal(Class, HttpInputMessage)}. Future implementations
- * might add some default behavior, however.
+ *
This implementation simple delegates to {@link #readInternal(Class, HttpInputMessage)}.
+ * Future implementations might add some default behavior, however.
*/
- public final T read(Class clazz, HttpInputMessage inputMessage) throws IOException {
+ public final T read(Class extends T> clazz, HttpInputMessage inputMessage) throws IOException {
return readInternal(clazz, inputMessage);
}
- /**
- * Abstract template method that reads the actualy object. Invoked from {@link #read(Class, HttpInputMessage)}.
- *
- * @param clazz the type of object to return
- * @param inputMessage the HTTP input message to read from
- * @return the converted object
- * @throws IOException in case of I/O errors
- * @throws HttpMessageNotReadableException in case of conversion errors
- */
- protected abstract T readInternal(Class clazz, HttpInputMessage inputMessage)
- throws IOException, HttpMessageNotReadableException;
-
/**
* {@inheritDoc}
- *
- *
This implementation delegates to {@link #getDefaultContentType(Object)} if a content type was not provided, calls
- * {@link #getContentLength}, and sets the corresponding headers on the output message. It then calls {@link
- * #writeInternal}.
+ *
This implementation delegates to {@link #getDefaultContentType(Object)} if a content
+ * type was not provided, calls {@link #getContentLength}, and sets the corresponding headers
+ * on the output message. It then calls {@link #writeInternal}.
*/
public final void write(T t, MediaType contentType, HttpOutputMessage outputMessage)
throws IOException, HttpMessageNotWritableException {
+
HttpHeaders headers = outputMessage.getHeaders();
if (contentType == null || contentType.isWildcardType() || contentType.isWildcardSubtype()) {
contentType = getDefaultContentType(t);
@@ -199,12 +177,11 @@ public abstract class AbstractHttpMessageConverter implements HttpMessageConv
}
/**
- * Returns the default content type for the given type. Called when {@link #write} is invoked without a specified
- * content type parameter.
- *
- *
By default, this returns the first element of the {@link #setSupportedMediaTypes(List) supportedMediaTypes}
- * property, if any. Can be overriden in subclasses.
- *
+ * Returns the default content type for the given type. Called when {@link #write}
+ * is invoked without a specified content type parameter.
+ *
By default, this returns the first element of the
+ * {@link #setSupportedMediaTypes(List) supportedMediaTypes} property, if any.
+ * Can be overridden in subclasses.
* @param t the type to return the content type for
* @return the content type, or null if not known
*/
@@ -215,10 +192,8 @@ public abstract class AbstractHttpMessageConverter implements HttpMessageConv
/**
* Returns the content length for the given type.
- *
- *
By default, this returns {@code null}, meaning that the content length is unknown. Can be overriden in
- * subclasses.
- *
+ *
By default, this returns {@code null}, meaning that the content length is unknown.
+ * Can be overridden in subclasses.
* @param t the type to return the content length for
* @return the content length, or {@code null} if not known
*/
@@ -226,9 +201,27 @@ public abstract class AbstractHttpMessageConverter implements HttpMessageConv
return null;
}
+
+ /**
+ * Indicates whether the given class is supported by this converter.
+ * @param clazz the class to test for support
+ * @return true if supported; false otherwise
+ */
+ protected abstract boolean supports(Class> clazz);
+
+ /**
+ * Abstract template method that reads the actualy object. Invoked from {@link #read}.
+ * @param clazz the type of object to return
+ * @param inputMessage the HTTP input message to read from
+ * @return the converted object
+ * @throws IOException in case of I/O errors
+ * @throws HttpMessageNotReadableException in case of conversion errors
+ */
+ protected abstract T readInternal(Class extends T> clazz, HttpInputMessage inputMessage)
+ throws IOException, HttpMessageNotReadableException;
+
/**
* Abstract template method that writes the actual body. Invoked from {@link #write}.
- *
* @param t the object to write to the output message
* @param outputMessage the message to write to
* @throws IOException in case of I/O errors
diff --git a/org.springframework.web/src/main/java/org/springframework/http/converter/BufferedImageHttpMessageConverter.java b/org.springframework.web/src/main/java/org/springframework/http/converter/BufferedImageHttpMessageConverter.java
index 838a7c6f80b..b9392d0d95d 100644
--- a/org.springframework.web/src/main/java/org/springframework/http/converter/BufferedImageHttpMessageConverter.java
+++ b/org.springframework.web/src/main/java/org/springframework/http/converter/BufferedImageHttpMessageConverter.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2009 the original author or authors.
+ * Copyright 2002-2010 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.
@@ -62,37 +62,27 @@ import org.springframework.util.Assert;
*/
public class BufferedImageHttpMessageConverter implements HttpMessageConverter {
- private List readableMediaTypes = new ArrayList();
+ private final List readableMediaTypes = new ArrayList();
private MediaType defaultContentType;
private File cacheDir;
+
public BufferedImageHttpMessageConverter() {
String[] readerMediaTypes = ImageIO.getReaderMIMETypes();
for (String mediaType : readerMediaTypes) {
- readableMediaTypes.add(MediaType.parseMediaType(mediaType));
+ this.readableMediaTypes.add(MediaType.parseMediaType(mediaType));
}
String[] writerMediaTypes = ImageIO.getWriterMIMETypes();
if (writerMediaTypes.length > 0) {
- defaultContentType = MediaType.parseMediaType(writerMediaTypes[0]);
+ this.defaultContentType = MediaType.parseMediaType(writerMediaTypes[0]);
}
}
- /**
- * Returns the default {@code Content-Type} to be used for writing. Called when {@link #write} is invoked without a
- * specified content type parameter.
- *
- * @return the default content type
- */
- public MediaType getDefaultContentType() {
- return defaultContentType;
- }
-
/**
* Sets the default {@code Content-Type} to be used for writing.
- *
* @throws IllegalArgumentException if the given content type is not supported by the Java Image I/O API
*/
public void setDefaultContentType(MediaType defaultContentType) {
@@ -106,20 +96,27 @@ public class BufferedImageHttpMessageConverter implements HttpMessageConverter clazz, MediaType mediaType) {
- if (BufferedImage.class.equals(clazz)) {
- return isReadable(mediaType);
- }
- else {
- return false;
- }
+ return (BufferedImage.class.equals(clazz) && isReadable(mediaType));
}
private boolean isReadable(MediaType mediaType) {
@@ -131,12 +128,7 @@ public class BufferedImageHttpMessageConverter implements HttpMessageConverter clazz, MediaType mediaType) {
- if (BufferedImage.class.equals(clazz)) {
- return isWritable(mediaType);
- }
- else {
- return false;
- }
+ return (BufferedImage.class.equals(clazz) && isWritable(mediaType));
}
private boolean isWritable(MediaType mediaType) {
@@ -148,11 +140,12 @@ public class BufferedImageHttpMessageConverter implements HttpMessageConverter getSupportedMediaTypes() {
- return Collections.unmodifiableList(readableMediaTypes);
+ return Collections.unmodifiableList(this.readableMediaTypes);
}
- public BufferedImage read(Class clazz, HttpInputMessage inputMessage)
+ public BufferedImage read(Class extends BufferedImage> clazz, HttpInputMessage inputMessage)
throws IOException, HttpMessageNotReadableException {
+
ImageInputStream imageInputStream = null;
ImageReader imageReader = null;
try {
@@ -187,7 +180,7 @@ public class BufferedImageHttpMessageConverter implements HttpMessageConverterDefault implementation is empty.
*/
protected void process(ImageReadParam irp) {
@@ -254,9 +248,9 @@ public class BufferedImageHttpMessageConverter implements HttpMessageConverterDefault implementation is empty.
*/
protected void process(ImageWriteParam iwp) {
}
+
}
diff --git a/org.springframework.web/src/main/java/org/springframework/http/converter/ByteArrayHttpMessageConverter.java b/org.springframework.web/src/main/java/org/springframework/http/converter/ByteArrayHttpMessageConverter.java
index d113e07f042..93517ea81e1 100644
--- a/org.springframework.web/src/main/java/org/springframework/http/converter/ByteArrayHttpMessageConverter.java
+++ b/org.springframework.web/src/main/java/org/springframework/http/converter/ByteArrayHttpMessageConverter.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2009 the original author or authors.
+ * Copyright 2002-2010 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.
@@ -47,7 +47,7 @@ public class ByteArrayHttpMessageConverter extends AbstractHttpMessageConverter<
}
@Override
- public byte[] readInternal(Class clazz, HttpInputMessage inputMessage) throws IOException {
+ public byte[] readInternal(Class clazz, HttpInputMessage inputMessage) throws IOException {
long contentLength = inputMessage.getHeaders().getContentLength();
if (contentLength >= 0) {
ByteArrayOutputStream bos = new ByteArrayOutputStream((int) contentLength);
diff --git a/org.springframework.web/src/main/java/org/springframework/http/converter/FormHttpMessageConverter.java b/org.springframework.web/src/main/java/org/springframework/http/converter/FormHttpMessageConverter.java
index c9b17a7ab5e..f042d82d512 100644
--- a/org.springframework.web/src/main/java/org/springframework/http/converter/FormHttpMessageConverter.java
+++ b/org.springframework.web/src/main/java/org/springframework/http/converter/FormHttpMessageConverter.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2009 the original author or authors.
+ * Copyright 2002-2010 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,19 +50,20 @@ public class FormHttpMessageConverter extends AbstractHttpMessageConverter clazz) {
return MultiValueMap.class.isAssignableFrom(clazz);
}
@Override
- public MultiValueMap readInternal(Class> clazz,
- HttpInputMessage inputMessage) throws IOException {
+ public MultiValueMap readInternal(Class clazz, HttpInputMessage inputMessage) throws IOException {
MediaType contentType = inputMessage.getHeaders().getContentType();
Charset charset = contentType.getCharSet() != null ? contentType.getCharSet() : DEFAULT_CHARSET;
String body = FileCopyUtils.copyToString(new InputStreamReader(inputMessage.getBody(), charset));
@@ -112,4 +113,5 @@ public class FormHttpMessageConverter extends AbstractHttpMessageConverter {
@@ -55,23 +56,24 @@ public interface HttpMessageConverter {
/**
* Read an object of the given type form the given input message, and returns it.
- * @param clazz the type of object to return. This type must have previously been passed to the {@link #canRead
- * canRead} method of this interface, which must have returned {@code true}.
+ * @param clazz the type of object to return. This type must have previously been passed to the
+ * {@link #canRead canRead} method of this interface, which must have returned {@code true}.
* @param inputMessage the HTTP input message to read from
* @return the converted object
* @throws IOException in case of I/O errors
* @throws HttpMessageNotReadableException in case of conversion errors
*/
- T read(Class clazz, HttpInputMessage inputMessage) throws IOException, HttpMessageNotReadableException;
+ T read(Class extends T> clazz, HttpInputMessage inputMessage)
+ throws IOException, HttpMessageNotReadableException;
/**
* Write an given object to the given output message.
- *
- * @param t the object to write to the output message. The type of this object must have previously been passed to the
- * {@link #canWrite canWrite} method of this interface, which must have returned {@code true}.
- * @param contentType the content type to use when writing. May be {@code null} to indicate that the the default
- * content type of the converter must be used. If not {@code null}, this media type must have previously been passed to
- * the {@link #canWrite canWrite} method of this interface, which must have returned {@code true}.
+ * @param t the object to write to the output message. The type of this object must have previously been
+ * passed to the {@link #canWrite canWrite} method of this interface, which must have returned {@code true}.
+ * @param contentType the content type to use when writing. May be {@code null} to indicate that the
+ * default content type of the converter must be used. If not {@code null}, this media type must have
+ * previously been passed to the {@link #canWrite canWrite} method of this interface, which must have
+ * returned {@code true}.
* @param outputMessage the message to write to
* @throws IOException in case of I/O errors
* @throws HttpMessageNotWritableException in case of conversion errors
diff --git a/org.springframework.web/src/main/java/org/springframework/http/converter/StringHttpMessageConverter.java b/org.springframework.web/src/main/java/org/springframework/http/converter/StringHttpMessageConverter.java
index 842479a3479..a71c88ce3e4 100644
--- a/org.springframework.web/src/main/java/org/springframework/http/converter/StringHttpMessageConverter.java
+++ b/org.springframework.web/src/main/java/org/springframework/http/converter/StringHttpMessageConverter.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2009 the original author or authors.
+ * Copyright 2002-2010 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.
@@ -56,7 +56,7 @@ public class StringHttpMessageConverter extends AbstractHttpMessageConverter clazz, HttpInputMessage inputMessage) throws IOException {
+ protected String readInternal(Class clazz, HttpInputMessage inputMessage) throws IOException {
MediaType contentType = inputMessage.getHeaders().getContentType();
Charset charset = contentType.getCharSet() != null ? contentType.getCharSet() : DEFAULT_CHARSET;
return FileCopyUtils.copyToString(new InputStreamReader(inputMessage.getBody(), charset));
diff --git a/org.springframework.web/src/main/java/org/springframework/http/converter/json/MappingJacksonHttpMessageConverter.java b/org.springframework.web/src/main/java/org/springframework/http/converter/json/MappingJacksonHttpMessageConverter.java
index c8ce393d905..00635716e07 100644
--- a/org.springframework.web/src/main/java/org/springframework/http/converter/json/MappingJacksonHttpMessageConverter.java
+++ b/org.springframework.web/src/main/java/org/springframework/http/converter/json/MappingJacksonHttpMessageConverter.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2009 the original author or authors.
+ * Copyright 2002-2010 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.
@@ -35,18 +35,17 @@ import org.springframework.http.converter.HttpMessageNotWritableException;
import org.springframework.util.Assert;
/**
- * Implementation of {@link org.springframework.http.converter.HttpMessageConverter HttpMessageConverter} that can read
- * and write JSON using Jackson's {@link ObjectMapper}.
+ * Implementation of {@link org.springframework.http.converter.HttpMessageConverter HttpMessageConverter}
+ * that can read and write JSON using Jackson's {@link ObjectMapper}.
*
*
This converter can be used to bind to typed beans, or untyped {@link java.util.HashMap HashMap} instances.
*
- *
By default, this converter supports {@code application/json}. This can be overridden by setting the {@link
- * #setSupportedMediaTypes(List) supportedMediaTypes} property.
- * method.
+ *
By default, this converter supports {@code application/json}. This can be overridden by setting the
+ * {@link #setSupportedMediaTypes(List) supportedMediaTypes} property.
*
* @author Arjen Poutsma
- * @see org.springframework.web.servlet.view.json.BindingJacksonJsonView
* @since 3.0
+ * @see org.springframework.web.servlet.view.json.BindingJacksonJsonView
*/
public class MappingJacksonHttpMessageConverter extends AbstractHttpMessageConverter