This is an automated email from the ASF dual-hosted git repository. dmvolod pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/master by this push: new 3d35740 CAMEL-14746: Additional specificationScheme validation Closing #3654 3d35740 is described below commit 3d3574001dfce055c1695ea447ef0fd52b4ded1e Author: Dmitry Volodin <dmvo...@gmail.com> AuthorDate: Fri Mar 20 09:39:16 2020 +0300 CAMEL-14746: Additional specificationScheme validation Closing #3654 --- .../camel/component/rest/swagger/RestSwaggerEndpoint.java | 12 ++++++------ .../component/rest/swagger/RestSwaggerEndpointTest.java | 2 ++ 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/components/camel-rest-swagger/src/main/java/org/apache/camel/component/rest/swagger/RestSwaggerEndpoint.java b/components/camel-rest-swagger/src/main/java/org/apache/camel/component/rest/swagger/RestSwaggerEndpoint.java index aa88ca8..8883adb 100644 --- a/components/camel-rest-swagger/src/main/java/org/apache/camel/component/rest/swagger/RestSwaggerEndpoint.java +++ b/components/camel-rest-swagger/src/main/java/org/apache/camel/component/rest/swagger/RestSwaggerEndpoint.java @@ -434,7 +434,7 @@ public final class RestSwaggerEndpoint extends DefaultEndpoint { } final String specificationScheme = specificationUri.getScheme(); - if (specificationUri.isAbsolute() && specificationScheme.toLowerCase().startsWith("http")) { + if (specificationUri.isAbsolute() && specificationScheme.toLowerCase().startsWith(Scheme.HTTP.toValue())) { try { return new URI(specificationUri.getScheme(), specificationUri.getUserInfo(), specificationUri.getHost(), specificationUri.getPort(), null, null, null).toString(); @@ -583,8 +583,8 @@ public final class RestSwaggerEndpoint extends DefaultEndpoint { } final StringBuilder answer = new StringBuilder(scheme).append("://").append(host); - if (port > 0 && !("http".equalsIgnoreCase(scheme) && port == 80) - && !("https".equalsIgnoreCase(scheme) && port == 443)) { + if (port > 0 && !(Scheme.HTTP.toValue().equalsIgnoreCase(scheme) && port == 80) + && !(Scheme.HTTPS.toValue().equalsIgnoreCase(scheme) && port == 443)) { answer.append(':').append(port); } @@ -653,15 +653,15 @@ public final class RestSwaggerEndpoint extends DefaultEndpoint { static String pickBestScheme(final String specificationScheme, final List<Scheme> schemes) { if (schemes != null && !schemes.isEmpty()) { if (schemes.contains(Scheme.HTTPS)) { - return "https"; + return Scheme.HTTPS.toValue(); } if (schemes.contains(Scheme.HTTP)) { - return "http"; + return Scheme.HTTP.toValue(); } } - if (specificationScheme != null) { + if (specificationScheme != null && (Scheme.HTTP.toValue().contains(specificationScheme) || Scheme.HTTPS.toValue().contains(specificationScheme))) { return specificationScheme; } diff --git a/components/camel-rest-swagger/src/test/java/org/apache/camel/component/rest/swagger/RestSwaggerEndpointTest.java b/components/camel-rest-swagger/src/test/java/org/apache/camel/component/rest/swagger/RestSwaggerEndpointTest.java index fb82e4f..0a6d289 100644 --- a/components/camel-rest-swagger/src/test/java/org/apache/camel/component/rest/swagger/RestSwaggerEndpointTest.java +++ b/components/camel-rest-swagger/src/test/java/org/apache/camel/component/rest/swagger/RestSwaggerEndpointTest.java @@ -347,6 +347,8 @@ public class RestSwaggerEndpointTest { assertThat(RestSwaggerEndpoint.pickBestScheme(null, Collections.emptyList())).isNull(); assertThat(RestSwaggerEndpoint.pickBestScheme(null, null)).isNull(); + + assertThat(RestSwaggerEndpoint.pickBestScheme("file", null)).isNull(); } @Test(expected = IllegalArgumentException.class)