@Test public void blowsUpWhenFileNameDoesNotMatch() throws IOException { String file1Content = "hello world"; String file2Content = "bonjour"; MultiValueMap<String, Object> map = new LinkedMultiValueMap<>(); map.add("file1", new FileSystemResource(newFile(file1Content).getAbsolutePath())); map.add("unmatched name", new FileSystemResource(newFile(file2Content).getAbsolutePath())); HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.MULTIPART_FORM_DATA); try { restTemplate.postForObject( codeFirstUrl + "uploadWithoutAnnotation", new HttpEntity<>(map, headers), String.class); expectFailing(UnknownHttpStatusCodeException.class); } catch (RestClientException ignored) { } }
@Test public void ensureServerBlowsUp() { try { restTemplate.getForObject( controllerUrl + "sayhi?name=throwexception", String.class); fail("Exception expected, but threw nothing"); } catch (UnknownHttpStatusCodeException e) { assertThat(e.getRawStatusCode(), is(590)); } }
protected HttpStatus getHttpStatusCode(ClientHttpResponse response) throws IOException { try { return response.getStatusCode(); } catch (IllegalArgumentException ex) { throw new UnknownHttpStatusCodeException(response.getRawStatusCode(), response.getStatusText(), response.getHeaders(), getResponseBody(response), getCharset(response)); } }
private HttpStatus getHttpStatusCode(ClientHttpResponse response) throws IOException { HttpStatus statusCode; try { statusCode = response.getStatusCode(); } catch (IllegalArgumentException ex) { throw new UnknownHttpStatusCodeException(response.getRawStatusCode(), response.getStatusText(), response.getHeaders(), getResponseBody(response), getCharset(response)); } return statusCode; }
private HttpStatus getHttpStatusCode(ClientHttpResponse response) throws IOException { HttpStatus statusCode; try { statusCode = response.getStatusCode(); } catch (IllegalArgumentException ex) { if (L.isDebugEnabled()) { L.debug(R.getString("D-SPRINGMVC-REST-CLIENT-HANDLER#0014"), ex); } throw new UnknownHttpStatusCodeException(response.getRawStatusCode(), response.getStatusText(), response.getHeaders(), getResponseBody(response), getCharset(response)); } return statusCode; }
private HttpStatus getHttpStatusCode(ClientHttpResponse response) throws IOException { final HttpStatus statusCode; try { statusCode = response.getStatusCode(); } catch (IllegalArgumentException ex) { throw new UnknownHttpStatusCodeException(response.getRawStatusCode(), response.getStatusText(), response.getHeaders(), getResponseBody(response), getCharset(response)); } return statusCode; }
@RequestMapping("/throwServerUnknownHttpStatusCodeException") public void throwServerUnknownHttpStatusCodeException() { UnknownHttpStatusCodeException serverResponseEx = new UnknownHttpStatusCodeException(42, null, null, null, null); throw new ServerUnknownHttpStatusCodeException(new Exception("Intentional test exception"), "FOO", serverResponseEx, serverResponseEx.getRawStatusCode(), serverResponseEx.getResponseHeaders(), serverResponseEx.getResponseBodyAsString()); }