This is an automated email from the ASF dual-hosted git repository. wuzhiguo pushed a commit to branch trunk in repository https://gitbox.apache.org/repos/asf/ambari.git
The following commit(s) were added to refs/heads/trunk by this push: new bfe07cdd6b AMBARI-25341: SmartSense API call fails with Unsupported Media Type (#3510) bfe07cdd6b is described below commit bfe07cdd6b3c551c4edcf5c3c65cb5cba2bd9e77 Author: Zhiguo Wu <wuzhi...@apache.org> AuthorDate: Wed Nov 16 09:43:26 2022 +0800 AMBARI-25341: SmartSense API call fails with Unsupported Media Type (#3510) --- .../ambari/server/api/ContentTypeOverrideFilter.java | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/ambari-server/src/main/java/org/apache/ambari/server/api/ContentTypeOverrideFilter.java b/ambari-server/src/main/java/org/apache/ambari/server/api/ContentTypeOverrideFilter.java index f69d124a3b..0ea6069cf7 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/api/ContentTypeOverrideFilter.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/api/ContentTypeOverrideFilter.java @@ -23,6 +23,7 @@ import java.util.Collections; import java.util.Enumeration; import java.util.HashSet; import java.util.Set; +import java.util.regex.Pattern; import javax.servlet.Filter; import javax.servlet.FilterChain; @@ -61,7 +62,7 @@ public class ContentTypeOverrideFilter implements Filter { private static final Logger logger = LoggerFactory.getLogger(ContentTypeOverrideFilter.class); - private final Set<String> excludedUrls = new HashSet<>(); + private final Set<Pattern> excludedUrls = new HashSet<>(); class ContentTypeOverrideRequestWrapper extends HttpServletRequestWrapper { @@ -132,7 +133,7 @@ public class ContentTypeOverrideFilter implements Filter { HttpServletRequest httpServletRequest = (HttpServletRequest) request; String contentType = httpServletRequest.getContentType(); - if (contentType != null && contentType.startsWith(MediaType.APPLICATION_JSON) && !excludedUrls.contains(httpServletRequest.getPathInfo())) { + if (contentType != null && contentType.startsWith(MediaType.APPLICATION_JSON) && !isUrlExcluded(httpServletRequest.getPathInfo())) { ContentTypeOverrideRequestWrapper requestWrapper = new ContentTypeOverrideRequestWrapper(httpServletRequest); ContentTypeOverrideResponseWrapper responseWrapper = new ContentTypeOverrideResponseWrapper((HttpServletResponse) response); @@ -160,7 +161,7 @@ public class ContentTypeOverrideFilter implements Filter { Consumes consumesAnnotation = method.getAnnotation(Consumes.class); for (String consume : consumesAnnotation.value()) { if (MediaType.APPLICATION_JSON.equals(consume)) { - excludedUrls.add(path.value()); + excludedUrls.add(Pattern.compile(path.value())); continue restart; } } @@ -172,10 +173,16 @@ public class ContentTypeOverrideFilter implements Filter { logger.error("Failed to discover URLs that are excluded from Content-Type override. Falling back to pre-defined list of exluded URLs.", e); /* Do not fail here, but fallback to manual definition of excluded endpoints. */ - excludedUrls.add("/bootstrap"); + excludedUrls.add(Pattern.compile("/bootstrap")); + } finally { + excludedUrls.add(Pattern.compile("/views/.*")); } } + private boolean isUrlExcluded(String pathInfo) { + return excludedUrls.stream().anyMatch(p -> p.matcher(pathInfo).matches()); + } + @Override public void destroy() { } --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@ambari.apache.org For additional commands, e-mail: commits-h...@ambari.apache.org