diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/xml/StaxEventItemReader.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/xml/StaxEventItemReader.java index 8acf46f6b..9da16b274 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/xml/StaxEventItemReader.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/xml/StaxEventItemReader.java @@ -45,6 +45,7 @@ import org.springframework.oxm.Unmarshaller; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; import org.springframework.util.StringUtils; +import org.springframework.util.xml.StaxUtils; /** * Item reader for reading XML input based on StAX. @@ -81,7 +82,7 @@ ResourceAwareItemReaderItemStream, InitializingBean { private boolean strict = true; - private XMLInputFactory xmlInputFactory = StaxUtils.createXmlInputFactory(); + private XMLInputFactory xmlInputFactory = StaxUtils.createDefensiveInputFactory(); private String encoding = DEFAULT_ENCODING; @@ -269,7 +270,7 @@ ResourceAwareItemReaderItemStream, InitializingBean { try { @SuppressWarnings("unchecked") - T mappedFragment = (T) unmarshaller.unmarshal(StaxUtils.getSource(fragmentReader)); + T mappedFragment = (T) unmarshaller.unmarshal(StaxUtils.createStaxSource(fragmentReader)); item = mappedFragment; } finally { diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/xml/StaxEventItemWriter.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/xml/StaxEventItemWriter.java index 48afcb9fa..7405c0daf 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/xml/StaxEventItemWriter.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/xml/StaxEventItemWriter.java @@ -59,6 +59,7 @@ import org.springframework.util.Assert; import org.springframework.util.ClassUtils; import org.springframework.util.CollectionUtils; import org.springframework.util.StringUtils; +import org.springframework.util.xml.StaxUtils; /** * An implementation of {@link ItemWriter} which uses StAX and @@ -578,7 +579,7 @@ ResourceAwareItemWriterItemStream, InitializingBean { * @return a result for writing to */ protected Result createStaxResult() { - return StaxUtils.getResult(eventWriter); + return StaxUtils.createStaxResult(eventWriter); } /** diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/xml/StaxUtils.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/xml/StaxUtils.java index d6e816247..5c5dfa82b 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/xml/StaxUtils.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/xml/StaxUtils.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2019 the original author or authors. + * Copyright 2006-2020 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. @@ -33,8 +33,11 @@ import javax.xml.transform.stax.StAXSource; * * @author Josh Long * @author Mahmoud Ben Hassine + * + * @deprecated in favor of {@link org.springframework.util.xml.StaxUtils} * */ +@Deprecated public abstract class StaxUtils { public static Source getSource(XMLEventReader r) throws XMLStreamException { diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/xml/builder/StaxEventItemReaderBuilder.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/xml/builder/StaxEventItemReaderBuilder.java index 0b7d9c026..8d2819ab5 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/xml/builder/StaxEventItemReaderBuilder.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/xml/builder/StaxEventItemReaderBuilder.java @@ -22,11 +22,11 @@ import java.util.List; import javax.xml.stream.XMLInputFactory; import org.springframework.batch.item.xml.StaxEventItemReader; -import org.springframework.batch.item.xml.StaxUtils; import org.springframework.core.io.Resource; import org.springframework.oxm.Unmarshaller; import org.springframework.util.Assert; import org.springframework.util.StringUtils; +import org.springframework.util.xml.StaxUtils; /** * A fluent builder for the {@link StaxEventItemReader} @@ -54,7 +54,7 @@ public class StaxEventItemReaderBuilder { private int currentItemCount; - private XMLInputFactory xmlInputFactory = StaxUtils.createXmlInputFactory(); + private XMLInputFactory xmlInputFactory = StaxUtils.createDefensiveInputFactory(); private String encoding = StaxEventItemReader.DEFAULT_ENCODING; diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/xml/StaxEventItemReaderTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/xml/StaxEventItemReaderTests.java index 7d26143e3..0737324e3 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/xml/StaxEventItemReaderTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/xml/StaxEventItemReaderTests.java @@ -31,6 +31,7 @@ import org.springframework.oxm.Unmarshaller; import org.springframework.oxm.UnmarshallingFailureException; import org.springframework.oxm.XmlMappingException; import org.springframework.util.ClassUtils; +import org.springframework.util.xml.StaxUtils; import javax.xml.namespace.QName; import javax.xml.stream.FactoryConfigurationError; @@ -356,7 +357,7 @@ public class StaxEventItemReaderTests { @Test public void testMoveCursorToNextFragment() throws XMLStreamException, FactoryConfigurationError, IOException { Resource resource = new ByteArrayResource(xml.getBytes()); - XMLEventReader reader = StaxUtils.createXmlInputFactory().createXMLEventReader(resource.getInputStream()); + XMLEventReader reader = StaxUtils.createDefensiveInputFactory().createXMLEventReader(resource.getInputStream()); final int EXPECTED_NUMBER_OF_FRAGMENTS = 2; for (int i = 0; i < EXPECTED_NUMBER_OF_FRAGMENTS; i++) { @@ -373,7 +374,7 @@ public class StaxEventItemReaderTests { @Test public void testMoveCursorToNextFragmentOnEmpty() throws XMLStreamException, FactoryConfigurationError, IOException { Resource resource = new ByteArrayResource(emptyXml.getBytes()); - XMLEventReader reader = StaxUtils.createXmlInputFactory().createXMLEventReader(resource.getInputStream()); + XMLEventReader reader = StaxUtils.createDefensiveInputFactory().createXMLEventReader(resource.getInputStream()); assertFalse(source.moveCursorToNextFragment(reader)); } @@ -384,7 +385,7 @@ public class StaxEventItemReaderTests { @Test public void testMoveCursorToNextFragmentOnMissing() throws XMLStreamException, FactoryConfigurationError, IOException { Resource resource = new ByteArrayResource(missingXml.getBytes()); - XMLEventReader reader = StaxUtils.createXmlInputFactory().createXMLEventReader(resource.getInputStream()); + XMLEventReader reader = StaxUtils.createDefensiveInputFactory().createXMLEventReader(resource.getInputStream()); assertFalse(source.moveCursorToNextFragment(reader)); } diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/xml/stax/DefaultFragmentEventReaderTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/xml/stax/DefaultFragmentEventReaderTests.java index 325047725..5ef9092c5 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/xml/stax/DefaultFragmentEventReaderTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/xml/stax/DefaultFragmentEventReaderTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2008-2019 the original author or authors. + * Copyright 2008-2020 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. @@ -24,9 +24,9 @@ import javax.xml.stream.events.XMLEvent; import junit.framework.TestCase; import org.springframework.batch.item.xml.EventHelper; -import org.springframework.batch.item.xml.StaxUtils; import org.springframework.core.io.ByteArrayResource; import org.springframework.core.io.Resource; +import org.springframework.util.xml.StaxUtils; /** * Tests for {@link DefaultFragmentEventReader}. @@ -51,7 +51,7 @@ public class DefaultFragmentEventReaderTests extends TestCase { @Override protected void setUp() throws Exception { Resource input = new ByteArrayResource(xml.getBytes()); - eventReader = StaxUtils.createXmlInputFactory().createXMLEventReader( + eventReader = StaxUtils.createDefensiveInputFactory().createXMLEventReader( input.getInputStream()); fragmentReader = new DefaultFragmentEventReader(eventReader); }