Wrap IOException as HttpMessageNotReadableException for RestTemplate usage
In the 4.3.x line, conversion exceptions do not get wrapped as RestClientException yet, so the expectation remains to receive a HttpMessageNotReadableException for conversion-level IOExceptions. Issue: SPR-13592
This commit is contained in:
@@ -17,7 +17,6 @@
|
||||
package org.springframework.http.converter.xml;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.nio.charset.Charset;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonView;
|
||||
@@ -27,11 +26,10 @@ import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.http.HttpOutputMessage;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.MockHttpInputMessage;
|
||||
import org.springframework.http.MockHttpOutputMessage;
|
||||
import org.springframework.http.converter.AbstractHttpMessageConverter;
|
||||
import org.springframework.http.converter.HttpMessageNotReadableException;
|
||||
import org.springframework.http.converter.json.MappingJacksonValue;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.*;
|
||||
@@ -102,7 +100,7 @@ public class MappingJackson2XmlHttpMessageConverterTests {
|
||||
outputMessage.getHeaders().getContentType());
|
||||
}
|
||||
|
||||
@Test(expected = IOException.class)
|
||||
@Test(expected = HttpMessageNotReadableException.class)
|
||||
public void readInvalidXml() throws IOException {
|
||||
String body = "FooBar";
|
||||
MockHttpInputMessage inputMessage = new MockHttpInputMessage(body.getBytes("UTF-8"));
|
||||
@@ -129,7 +127,7 @@ public class MappingJackson2XmlHttpMessageConverterTests {
|
||||
|
||||
MappingJacksonValue jacksonValue = new MappingJacksonValue(bean);
|
||||
jacksonValue.setSerializationView(MyJacksonView1.class);
|
||||
this.writeInternal(jacksonValue, outputMessage);
|
||||
this.converter.write(jacksonValue, null, outputMessage);
|
||||
|
||||
String result = outputMessage.getBodyAsString(Charset.forName("UTF-8"));
|
||||
assertThat(result, containsString("<withView1>with</withView1>"));
|
||||
@@ -154,7 +152,7 @@ public class MappingJackson2XmlHttpMessageConverterTests {
|
||||
MockHttpInputMessage inputMessage = new MockHttpInputMessage(body.getBytes("UTF-8"));
|
||||
inputMessage.getHeaders().setContentType(new MediaType("application", "xml"));
|
||||
|
||||
this.thrown.expect(IOException.class);
|
||||
this.thrown.expect(HttpMessageNotReadableException.class);
|
||||
this.converter.read(MyBean.class, inputMessage);
|
||||
}
|
||||
|
||||
@@ -181,19 +179,11 @@ public class MappingJackson2XmlHttpMessageConverterTests {
|
||||
MockHttpInputMessage inputMessage = new MockHttpInputMessage(body.getBytes("UTF-8"));
|
||||
inputMessage.getHeaders().setContentType(new MediaType("application", "xml"));
|
||||
|
||||
this.thrown.expect(IOException.class);
|
||||
this.thrown.expect(HttpMessageNotReadableException.class);
|
||||
this.converter.read(MyBean.class, inputMessage);
|
||||
}
|
||||
|
||||
|
||||
private void writeInternal(Object object, HttpOutputMessage outputMessage) throws Exception {
|
||||
Method method = AbstractHttpMessageConverter.class.getDeclaredMethod(
|
||||
"writeInternal", Object.class, HttpOutputMessage.class);
|
||||
method.setAccessible(true);
|
||||
method.invoke(this.converter, object, outputMessage);
|
||||
}
|
||||
|
||||
|
||||
public static class MyBean {
|
||||
|
||||
private String string;
|
||||
|
||||
Reference in New Issue
Block a user