|
1 | 1 | /* |
2 | | - * Copyright 2012-2017 the original author or authors. |
| 2 | + * Copyright 2012-2018 the original author or authors. |
3 | 3 | * |
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | 5 | * you may not use this file except in compliance with the License. |
@@ -70,23 +70,28 @@ public void onStartup(ServletContext servletContext) |
70 | 70 |
|
71 | 71 | }); |
72 | 72 | jetty.start(); |
73 | | - int port = jetty.getPort(); |
74 | | - RestTemplate restTemplate = new RestTemplate(); |
75 | | - restTemplate.setErrorHandler(new ResponseErrorHandler() { |
76 | | - |
77 | | - @Override |
78 | | - public boolean hasError(ClientHttpResponse response) throws IOException { |
79 | | - return false; |
80 | | - } |
81 | | - |
82 | | - @Override |
83 | | - public void handleError(ClientHttpResponse response) throws IOException { |
84 | | - } |
85 | | - |
86 | | - }); |
87 | | - ResponseEntity<String> response = restTemplate |
88 | | - .getForEntity("http://localhost:" + port, String.class); |
89 | | - assertThat(response.getBody()).isEqualTo("An error occurred"); |
| 73 | + try { |
| 74 | + int port = jetty.getPort(); |
| 75 | + RestTemplate restTemplate = new RestTemplate(); |
| 76 | + restTemplate.setErrorHandler(new ResponseErrorHandler() { |
| 77 | + |
| 78 | + @Override |
| 79 | + public boolean hasError(ClientHttpResponse response) throws IOException { |
| 80 | + return false; |
| 81 | + } |
| 82 | + |
| 83 | + @Override |
| 84 | + public void handleError(ClientHttpResponse response) throws IOException { |
| 85 | + } |
| 86 | + |
| 87 | + }); |
| 88 | + ResponseEntity<String> response = restTemplate |
| 89 | + .getForEntity("http://localhost:" + port, String.class); |
| 90 | + assertThat(response.getBody()).isEqualTo("An error occurred"); |
| 91 | + } |
| 92 | + finally { |
| 93 | + jetty.stop(); |
| 94 | + } |
90 | 95 | } |
91 | 96 |
|
92 | 97 | private static final class TestServlet extends HttpServlet { |
|
0 commit comments