Skip to content

Commit e863f9a

Browse files
committed
SPR-5380: MarshallingView should override AbstractView instead of AbstractUrlBasedView
1 parent e966fd9 commit e863f9a

File tree

2 files changed

+14
-10
lines changed

2 files changed

+14
-10
lines changed

org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/view/xml/MarshallingView.java

+13-9
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,16 @@
1919
import java.io.ByteArrayOutputStream;
2020
import java.util.Map;
2121
import javax.servlet.ServletException;
22-
import javax.servlet.ServletOutputStream;
2322
import javax.servlet.http.HttpServletRequest;
2423
import javax.servlet.http.HttpServletResponse;
2524
import javax.xml.transform.stream.StreamResult;
2625

2726
import org.springframework.beans.BeansException;
2827
import org.springframework.oxm.Marshaller;
2928
import org.springframework.util.Assert;
29+
import org.springframework.util.FileCopyUtils;
3030
import org.springframework.web.servlet.View;
31-
import org.springframework.web.servlet.view.AbstractUrlBasedView;
31+
import org.springframework.web.servlet.view.AbstractView;
3232

3333
/**
3434
* Spring-MVC {@link View} that allows for response context to be rendered as the result of marshalling by a {@link
@@ -41,9 +41,11 @@
4141
* @author Arjen Poutsma
4242
* @since 3.0
4343
*/
44-
public class MarshallingView extends AbstractUrlBasedView {
44+
public class MarshallingView extends AbstractView {
4545

46-
/** Default content type. Overridable as bean property. */
46+
/**
47+
* Default content type. Overridable as bean property.
48+
*/
4749
public static final String DEFAULT_CONTENT_TYPE = "application/xml";
4850

4951
private Marshaller marshaller;
@@ -58,14 +60,18 @@ public MarshallingView() {
5860
setContentType(DEFAULT_CONTENT_TYPE);
5961
}
6062

61-
/** Constructs a new <code>MarshallingView</code> with the given {@link Marshaller} set. */
63+
/**
64+
* Constructs a new <code>MarshallingView</code> with the given {@link Marshaller} set.
65+
*/
6266
public MarshallingView(Marshaller marshaller) {
6367
Assert.notNull(marshaller, "'marshaller' must not be null");
6468
setContentType(DEFAULT_CONTENT_TYPE);
6569
this.marshaller = marshaller;
6670
}
6771

68-
/** Sets the {@link Marshaller} to be used by this view. */
72+
/**
73+
* Sets the {@link Marshaller} to be used by this view.
74+
*/
6975
public void setMarshaller(Marshaller marshaller) {
7076
Assert.notNull(marshaller, "'marshaller' must not be null");
7177
this.marshaller = marshaller;
@@ -99,9 +105,7 @@ protected void renderMergedOutputModel(Map model, HttpServletRequest request, Ht
99105
response.setContentType(getContentType());
100106
response.setContentLength(bos.size());
101107

102-
ServletOutputStream out = response.getOutputStream();
103-
bos.writeTo(out);
104-
out.flush();
108+
FileCopyUtils.copy(bos.toByteArray(), response.getOutputStream());
105109
}
106110

107111
/**

org.springframework.web.servlet/src/test/java/org/springframework/web/servlet/view/xml/MarshallingViewTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public void createView() throws Exception {
4444
}
4545

4646
@Test
47-
public void testGetContentType() {
47+
public void getContentType() {
4848
assertEquals("Invalid content type", "application/xml", view.getContentType());
4949
}
5050

0 commit comments

Comments
 (0)