Fix StringIndexOutOfBoundsException in RestTemplate.doExecute IOException handler when query string is an empty string
This commit is contained in:
committed by
Rossen Stoyanchev
parent
26284cac4f
commit
81dfadcb16
@@ -729,6 +729,32 @@ public class RestTemplateTests {
|
||||
ex.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void ioExceptionWithEmptyQueryString() throws Exception {
|
||||
|
||||
String scheme = "http";
|
||||
String authority = "example.com";
|
||||
String path = "/resource";
|
||||
URI uri = new URI(scheme, authority, path, "", null); // http://example.com/resource?
|
||||
|
||||
given(converter.canRead(String.class, null)).willReturn(true);
|
||||
MediaType mediaType = new MediaType("foo", "bar");
|
||||
given(converter.getSupportedMediaTypes()).willReturn(Collections.singletonList(mediaType));
|
||||
given(requestFactory.createRequest(uri, HttpMethod.GET)).willReturn(request);
|
||||
given(request.getHeaders()).willReturn(new HttpHeaders());
|
||||
given(request.execute()).willThrow(new IOException("Socket failure"));
|
||||
|
||||
try {
|
||||
template.getForObject(uri, String.class);
|
||||
fail("RestClientException expected");
|
||||
}
|
||||
catch (ResourceAccessException ex) {
|
||||
assertEquals("I/O error on GET request for \"http://example.com/resource\": " +
|
||||
"Socket failure; nested exception is java.io.IOException: Socket failure",
|
||||
ex.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void exchange() throws Exception {
|
||||
|
||||
Reference in New Issue
Block a user