1
1
/*
2
- * Copyright 2002-2013 the original author or authors.
2
+ * Copyright 2002-2014 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
25
25
26
26
import org .apache .commons .logging .Log ;
27
27
import org .apache .commons .logging .LogFactory ;
28
+
28
29
import org .springframework .http .HttpHeaders ;
29
30
import org .springframework .http .HttpInputMessage ;
30
31
import org .springframework .http .HttpOutputMessage ;
@@ -169,11 +170,12 @@ public final void write(final T t, MediaType contentType, HttpOutputMessage outp
169
170
170
171
final HttpHeaders headers = outputMessage .getHeaders ();
171
172
if (headers .getContentType () == null ) {
173
+ MediaType contentTypeToUse = contentType ;
172
174
if (contentType == null || contentType .isWildcardType () || contentType .isWildcardSubtype ()) {
173
- contentType = getDefaultContentType (t );
175
+ contentTypeToUse = getDefaultContentType (t );
174
176
}
175
- if (contentType != null ) {
176
- headers .setContentType (contentType );
177
+ if (contentTypeToUse != null ) {
178
+ headers .setContentType (contentTypeToUse );
177
179
}
178
180
}
179
181
if (headers .getContentLength () == -1 ) {
@@ -182,10 +184,10 @@ public final void write(final T t, MediaType contentType, HttpOutputMessage outp
182
184
headers .setContentLength (contentLength );
183
185
}
184
186
}
187
+
185
188
if (outputMessage instanceof StreamingHttpOutputMessage ) {
186
189
StreamingHttpOutputMessage streamingOutputMessage =
187
190
(StreamingHttpOutputMessage ) outputMessage ;
188
-
189
191
streamingOutputMessage .setBody (new StreamingHttpOutputMessage .Body () {
190
192
@ Override
191
193
public void writeTo (final OutputStream outputStream ) throws IOException {
@@ -194,7 +196,6 @@ public void writeTo(final OutputStream outputStream) throws IOException {
194
196
public OutputStream getBody () throws IOException {
195
197
return outputStream ;
196
198
}
197
-
198
199
@ Override
199
200
public HttpHeaders getHeaders () {
200
201
return headers ;
@@ -256,7 +257,7 @@ protected abstract T readInternal(Class<? extends T> clazz, HttpInputMessage inp
256
257
/**
257
258
* Abstract template method that writes the actual body. Invoked from {@link #write}.
258
259
* @param t the object to write to the output message
259
- * @param outputMessage the message to write to
260
+ * @param outputMessage the HTTP output message to write to
260
261
* @throws IOException in case of I/O errors
261
262
* @throws HttpMessageNotWritableException in case of conversion errors
262
263
*/
0 commit comments