Skip to content

Remove DataAccessResourceFailureException in xml related classes #4147

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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