BATCH-2054: StaxEventItemWriter fails on a NullPointerException with

Spring OXM 3.2.x.
This commit is contained in:
jpraet
2013-06-30 14:02:29 +02:00
committed by Michael Minella
parent a939b194fe
commit a65bcc48d1
4 changed files with 46 additions and 1 deletions

View File

@@ -658,7 +658,7 @@ ResourceAwareItemWriterItemStream<T>, InitializingBean {
finally {
try {
eventWriter.close();
delegateEventWriter.close();
}
catch (XMLStreamException e) {
log.error("Unable to close file resource: [" + resource + "] " + e);

View File

@@ -39,4 +39,10 @@ public class NoStartEndDocumentStreamWriter extends AbstractEventWriterWrapper {
wrappedEventWriter.add(event);
}
}
// prevents OXM Marshallers from closing the XMLEventWriter
@Override
public void close() throws XMLStreamException {
flush();
}
}

View File

@@ -726,6 +726,32 @@ public class StaxEventItemWriterTests {
assertEquals("Wrong content: " + content,
"<foo:root xmlns:foo=\"urn:org.test.foo\" xmlns:ns=\"http://www.springframework.org/test\"><ns:item/><ns:item/></foo:root>", content);
}
/**
* Test with OXM Marshaller that closes the XMLEventWriter.
*/
// BATCH-2054
@Test
public void testMarshallingClosingEventWriter() throws Exception {
writer.setMarshaller(new SimpleMarshaller() {
@Override
public void marshal(Object graph, Result result) throws XmlMappingException, IOException {
super.marshal(graph, result);
try {
StaxUtils.getXmlEventWriter(result).close();
} catch (Exception e) {
throw new RuntimeException("Exception while writing to output file", e);
}
}
});
writer.afterPropertiesSet();
writer.open(executionContext);
writer.write(items);
writer.write(items);
}
/**
* Writes object's toString representation as XML comment.

View File

@@ -7,6 +7,9 @@ import javax.xml.stream.events.XMLEvent;
import junit.framework.TestCase;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times;
/**
* Tests for {@link NoStartEndDocumentStreamWriter}
@@ -44,4 +47,14 @@ public class NoStartEndDocumentWriterTests extends TestCase {
writer.add(eventFactory.createEndDocument());
}
/**
* Close is not delegated to the wrapped writer. Instead, the wrapped writer is flushed.
*/
public void testClose() throws Exception {
writer.close();
verify(wrappedWriter, times(1)).flush();
verify(wrappedWriter, never()).close();
}
}