This is an automated email from the ASF dual-hosted git repository.

mpapirkovskyy pushed a commit to branch branch-2.7
in repository https://gitbox.apache.org/repos/asf/ambari.git


The following commit(s) were added to refs/heads/branch-2.7 by this push:
     new dacfd92  AMBARI-25341 SmartSense API call fails with Unsupported Media 
Type (#3057)
dacfd92 is described below

commit dacfd92e07e2cedf7d172c637cfeeb1a39611d66
Author: payert <35402259+pay...@users.noreply.github.com>
AuthorDate: Mon Jul 29 13:42:41 2019 +0200

    AMBARI-25341 SmartSense API call fails with Unsupported Media Type (#3057)
---
 .../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 dcfa2da..701f66b 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;
@@ -62,7 +63,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 {
 
@@ -133,7 +134,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);
 
@@ -161,7 +162,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;
                                 }
                             }
@@ -173,10 +174,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() {
     }

Reply via email to