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 4af8446005..6579fdc3ef 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 @@ -52,7 +52,6 @@ import org.springframework.batch.support.transaction.TransactionAwareBufferedWriter; import org.springframework.beans.factory.InitializingBean; import org.springframework.core.io.WritableResource; -import org.springframework.dao.DataAccessResourceFailureException; import org.springframework.oxm.Marshaller; import org.springframework.oxm.XmlMappingException; import org.springframework.util.Assert; @@ -458,7 +457,7 @@ private void open(long position) { setPosition(position); } catch (IOException ioe) { - throw new DataAccessResourceFailureException("Unable to write to file resource: [" + resource + "]", ioe); + throw new ItemStreamException("Unable to write to file resource: [" + resource + "]", ioe); } XMLOutputFactory outputFactory = createXmlOutputFactory(); @@ -506,14 +505,14 @@ public void run() { } } catch (XMLStreamException xse) { - throw new DataAccessResourceFailureException("Unable to write to file resource: [" + resource + "]", xse); + throw new ItemStreamException("Unable to write to file resource: [" + resource + "]", xse); } catch (UnsupportedEncodingException e) { - throw new DataAccessResourceFailureException( + throw new ItemStreamException( "Unable to write to file resource: [" + resource + "] with encoding=[" + encoding + "]", e); } catch (IOException e) { - throw new DataAccessResourceFailureException("Unable to write to file resource: [" + resource + "]", e); + throw new ItemStreamException("Unable to write to file resource: [" + resource + "]", e); } } @@ -673,7 +672,7 @@ protected void endDocument(XMLEventWriter writer) throws XMLStreamException { bufferedWriter.write(""); } catch (IOException ioe) { - throw new DataAccessResourceFailureException("Unable to close file resource: [" + resource + "]", ioe); + throw new XMLStreamException("Unable to close file resource: [" + resource + "]", ioe); } } @@ -825,7 +824,7 @@ private long getPosition() { } } catch (Exception e) { - throw new DataAccessResourceFailureException("Unable to write to file resource: [" + resource + "]", e); + throw new ItemStreamException("Unable to write to file resource: [" + resource + "]", e); } return position; @@ -842,7 +841,7 @@ private void setPosition(long newPosition) { channel.position(newPosition); } catch (IOException e) { - throw new DataAccessResourceFailureException("Unable to write to file resource: [" + resource + "]", e); + throw new ItemStreamException("Unable to write to file resource: [" + resource + "]", e); } } diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/xml/stax/DefaultFragmentEventReader.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/xml/stax/DefaultFragmentEventReader.java index bf35e85d11..d7c75784b7 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/xml/stax/DefaultFragmentEventReader.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/xml/stax/DefaultFragmentEventReader.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2007 the original author or authors. + * Copyright 2006-2022 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. @@ -28,7 +28,7 @@ import javax.xml.stream.events.StartElement; import javax.xml.stream.events.XMLEvent; -import org.springframework.dao.DataAccessResourceFailureException; +import org.springframework.batch.item.ItemStreamException; /** * Default implementation of {@link FragmentEventReader} @@ -71,7 +71,7 @@ public DefaultFragmentEventReader(XMLEventReader wrappedEventReader) { startDocumentEvent = (StartDocument) wrappedEventReader.peek(); } catch (XMLStreamException e) { - throw new DataAccessResourceFailureException("Error reading start document from event reader", e); + throw new ItemStreamException("Error reading start document from event reader", e); } endDocumentEvent = XMLEventFactory.newInstance().createEndDocument(); @@ -91,7 +91,7 @@ public boolean hasNext() { } } catch (XMLStreamException e) { - throw new DataAccessResourceFailureException("Error reading XML stream", e); + throw new ItemStreamException("Error reading XML stream", e); } return false; } @@ -102,7 +102,7 @@ public Object next() { return nextEvent(); } catch (XMLStreamException e) { - throw new DataAccessResourceFailureException("Error reading XML stream", e); + throw new ItemStreamException("Error reading XML stream", e); } } @@ -185,7 +185,7 @@ public void markFragmentProcessed() { } } catch (XMLStreamException e) { - throw new DataAccessResourceFailureException("Error reading XML stream", e); + throw new ItemStreamException("Error reading XML stream", e); } } fakeDocumentEnd = false; diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/xml/stax/UnopenedElementClosingEventWriter.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/xml/stax/UnopenedElementClosingEventWriter.java index 96086abdbc..5098784aa2 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/xml/stax/UnopenedElementClosingEventWriter.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/xml/stax/UnopenedElementClosingEventWriter.java @@ -1,5 +1,5 @@ /* - * Copyright 2014 the original author or authors. + * Copyright 2014-2022 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. @@ -26,7 +26,6 @@ import javax.xml.stream.XMLStreamException; import javax.xml.stream.events.XMLEvent; -import org.springframework.dao.DataAccessResourceFailureException; import org.springframework.util.StringUtils; /** @@ -68,7 +67,7 @@ public void add(XMLEvent event) throws XMLStreamException { ioWriter.flush(); } catch (IOException ioe) { - throw new DataAccessResourceFailureException("Unable to close tag: " + element, ioe); + throw new XMLStreamException("Unable to close tag: " + element, ioe); } } else { diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/xml/stax/UnopenedElementClosingEventWriterTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/xml/stax/UnopenedElementClosingEventWriterTests.java index 39e5bfd1fb..9d19024c86 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/xml/stax/UnopenedElementClosingEventWriterTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/xml/stax/UnopenedElementClosingEventWriterTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2014 the original author or authors. + * Copyright 2014-2022 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. @@ -27,6 +27,7 @@ import javax.xml.namespace.QName; import javax.xml.stream.XMLEventFactory; import javax.xml.stream.XMLEventWriter; +import javax.xml.stream.XMLStreamException; import javax.xml.stream.events.EndElement; import javax.xml.stream.events.StartElement; import javax.xml.stream.events.XMLEvent; @@ -34,7 +35,6 @@ import org.junit.Before; import org.junit.Test; import org.mockito.Mockito; -import org.springframework.dao.DataAccessResourceFailureException; /** * Tests for {@link UnopenedElementClosingEventWriter} @@ -122,7 +122,7 @@ public void testOtherEvent() throws Exception { verify(wrappedWriter).add(event); } - @Test(expected = DataAccessResourceFailureException.class) + @Test(expected = XMLStreamException.class) public void testIOException() throws Exception { EndElement endElementB = eventFactory.createEndElement(unopenedB, null); Mockito.doThrow(new IOException("Simulated IOException")).when(ioWriter).write("");