|
9 | 9 | import org.apache.commons.lang3.StringUtils; |
10 | 10 |
|
11 | 11 | import java.net.URI; |
12 | | -import java.net.URISyntaxException; |
13 | 12 | import java.util.List; |
14 | 13 | import java.util.Map; |
| 14 | +import java.util.Objects; |
15 | 15 | import java.util.stream.Collectors; |
16 | 16 |
|
17 | 17 | public abstract class CoverageFilter implements OrderedFilter { |
18 | 18 |
|
19 | 19 | protected CoverageInfo collectCoverageInfo(FilterableRequestSpecification requestSpec, Response response) { |
20 | 20 | Integer statusCode = response.statusCode(); |
21 | 21 | Map<String, String> unnamedPathParams = requestSpec.getUnnamedPathParams(); |
22 | | - String uri = removeHostFromUri(requestSpec.getURI()); |
| 22 | + URI requestURI = convertUriStringToURI(requestSpec.getURI()); |
| 23 | + |
| 24 | + String uri = removeHostFromUri(Objects.requireNonNull(requestURI)); |
23 | 25 | String basePath = requestSpec.getBasePath(); |
24 | | - String path = UrlPath.getPath(requestSpec.getUserDefinedPath(), unnamedPathParams); |
| 26 | + String path = requestURI.getPath(); |
25 | 27 |
|
26 | 28 | String method = requestSpec.getMethod(); |
27 | 29 |
|
@@ -61,19 +63,21 @@ protected CoverageInfo collectCoverageInfo(FilterableRequestSpecification reques |
61 | 63 | return coverageInfo; |
62 | 64 | } |
63 | 65 |
|
64 | | - private String removeHostFromUri(String uri) { |
| 66 | + private URI convertUriStringToURI(String uri) { |
65 | 67 | try { |
66 | | - URI url = new URI(uri); |
67 | | - String query = url.getQuery(); |
68 | | - String path = url.getPath(); |
69 | | - if (StringUtils.isBlank(query)) { |
70 | | - return path; |
71 | | - } |
72 | | - return path + "?" + query; |
73 | | - } catch (URISyntaxException e) { |
74 | | - e.printStackTrace(); |
| 68 | + return new URI(uri); |
| 69 | + } catch (Exception e) { |
| 70 | + throw new RuntimeException("Can not parse URI " + uri + " " + e); |
| 71 | + } |
| 72 | + } |
| 73 | + |
| 74 | + private String removeHostFromUri(URI uri) { |
| 75 | + String query = uri.getQuery(); |
| 76 | + String path = uri.getPath(); |
| 77 | + if (StringUtils.isBlank(query)) { |
| 78 | + return path; |
75 | 79 | } |
76 | | - return ""; |
| 80 | + return path + "?" + query; |
77 | 81 | } |
78 | 82 |
|
79 | 83 | @Override |
|
0 commit comments