Skip to content

Commit

Permalink
Remove DataAccessResourceFailureException in xml related classes
Browse files Browse the repository at this point in the history
  • Loading branch information
lcmarvin committed Jul 7, 2022
1 parent 0b2a2c2 commit 82af6e0
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 20 deletions.
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -673,7 +672,7 @@ protected void endDocument(XMLEventWriter writer) throws XMLStreamException {
bufferedWriter.write("</" + nsPrefix + getRootTagName() + ">");
}
catch (IOException ioe) {
throw new DataAccessResourceFailureException("Unable to close file resource: [" + resource + "]", ioe);
throw new XMLStreamException("Unable to close file resource: [" + resource + "]", ioe);
}
}

Expand Down Expand Up @@ -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;
Expand All @@ -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);
}

}
Expand Down
@@ -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.
Expand Down Expand Up @@ -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}
Expand Down Expand Up @@ -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();
Expand All @@ -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;
}
Expand All @@ -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);
}
}

Expand Down Expand Up @@ -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;
Expand Down
@@ -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.
Expand All @@ -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;

/**
Expand Down Expand Up @@ -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 {
Expand Down
@@ -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.
Expand Down Expand Up @@ -27,14 +27,14 @@
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;

import org.junit.Before;
import org.junit.Test;
import org.mockito.Mockito;
import org.springframework.dao.DataAccessResourceFailureException;

/**
* Tests for {@link UnopenedElementClosingEventWriter}
Expand Down Expand Up @@ -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("</unopened-b>");
Expand Down

0 comments on commit 82af6e0

Please sign in to comment.