cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject cxf git commit: Updating Request preprocessor to ignore the swagger2 queries
Date Mon, 19 Dec 2016 12:47:45 GMT
Repository: cxf
Updated Branches:
  refs/heads/master 5a6a30faa -> 0e391a6a0


Updating Request preprocessor to ignore the swagger2 queries


Project: http://git-wip-us.apache.org/repos/asf/cxf/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/0e391a6a
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/0e391a6a
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/0e391a6a

Branch: refs/heads/master
Commit: 0e391a6a020d6825001adb231a9a431779b2d6f9
Parents: 5a6a30f
Author: Sergey Beryozkin <sberyozkin@gmail.com>
Authored: Mon Dec 19 12:47:29 2016 +0000
Committer: Sergey Beryozkin <sberyozkin@gmail.com>
Committed: Mon Dec 19 12:47:29 2016 +0000

----------------------------------------------------------------------
 .../cxf/jaxrs/impl/RequestPreprocessor.java     | 35 ++++++++++++--------
 .../AbstractSwagger2ServiceDescriptionTest.java |  3 ++
 2 files changed, 25 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/0e391a6a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/RequestPreprocessor.java
----------------------------------------------------------------------
diff --git a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/RequestPreprocessor.java
b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/RequestPreprocessor.java
index ada66e3..d01f956 100644
--- a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/RequestPreprocessor.java
+++ b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/RequestPreprocessor.java
@@ -21,8 +21,10 @@ package org.apache.cxf.jaxrs.impl;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.HashMap;
+import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
 
 import javax.ws.rs.core.HttpHeaders;
 import javax.ws.rs.core.MultivaluedMap;
@@ -39,17 +41,21 @@ public class RequestPreprocessor {
     private static final String METHOD_QUERY = "_method";
     private static final String METHOD_HEADER = "X-HTTP-Method-Override";
     
+    private static final Set<String> PATHS_TO_SKIP;
+    private static final Map<String, String> MEDIA_TYPE_SHORTCUTS;
     
-    private static final Map<String, String> SHORTCUTS;
     static {
-        SHORTCUTS = new HashMap<String, String>();
-        SHORTCUTS.put("json", "application/json");
-        SHORTCUTS.put("text", "text/*");
-        SHORTCUTS.put("xml", "application/xml");
-        SHORTCUTS.put("atom", "application/atom+xml");
-        SHORTCUTS.put("html", "text/html");
-        SHORTCUTS.put("wadl", "application/vnd.sun.wadl+xml");
-        // more to come
+        MEDIA_TYPE_SHORTCUTS = new HashMap<String, String>();
+        MEDIA_TYPE_SHORTCUTS.put("json", "application/json");
+        MEDIA_TYPE_SHORTCUTS.put("text", "text/*");
+        MEDIA_TYPE_SHORTCUTS.put("xml", "application/xml");
+        MEDIA_TYPE_SHORTCUTS.put("atom", "application/atom+xml");
+        MEDIA_TYPE_SHORTCUTS.put("html", "text/html");
+        MEDIA_TYPE_SHORTCUTS.put("wadl", "application/vnd.sun.wadl+xml");
+        
+        PATHS_TO_SKIP = new HashSet<String>();
+        PATHS_TO_SKIP.add("swagger.json");
+        PATHS_TO_SKIP.add("swagger.yaml");
     }
     
     private Map<Object, Object> languageMappings;
@@ -99,6 +105,9 @@ public class RequestPreprocessor {
         }
         PathSegmentImpl ps = new PathSegmentImpl(uriInfo.getPath(false), false);
         String path = ps.getPath();
+        if (PATHS_TO_SKIP.contains(path)) {
+            return;
+        }
         for (Map.Entry<?, ?> entry : extensionMappings.entrySet()) {
             String key = entry.getKey().toString();
             if (path.endsWith("." + key)) {
@@ -160,8 +169,8 @@ public class RequestPreprocessor {
     private void handleTypeQuery(Message m, MultivaluedMap<String, String> queries)
{
         String type = queries.getFirst(ACCEPT_QUERY);
         if (type != null) {
-            if (SHORTCUTS.containsKey(type)) {
-                type = SHORTCUTS.get(type);
+            if (MEDIA_TYPE_SHORTCUTS.containsKey(type)) {
+                type = MEDIA_TYPE_SHORTCUTS.get(type);
             }
             updateAcceptTypeHeader(m, type);
         }
@@ -170,8 +179,8 @@ public class RequestPreprocessor {
     private void handleCType(Message m, MultivaluedMap<String, String> queries) {
         String type = queries.getFirst(CTYPE_QUERY);
         if (type != null) {
-            if (SHORTCUTS.containsKey(type)) {
-                type = SHORTCUTS.get(type);
+            if (MEDIA_TYPE_SHORTCUTS.containsKey(type)) {
+                type = MEDIA_TYPE_SHORTCUTS.get(type);
             }
             m.put(Message.CONTENT_TYPE, type);
         }

http://git-wip-us.apache.org/repos/asf/cxf/blob/0e391a6a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/description/AbstractSwagger2ServiceDescriptionTest.java
----------------------------------------------------------------------
diff --git a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/description/AbstractSwagger2ServiceDescriptionTest.java
b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/description/AbstractSwagger2ServiceDescriptionTest.java
index 3dfdb99..6ea3a0b 100644
--- a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/description/AbstractSwagger2ServiceDescriptionTest.java
+++ b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/description/AbstractSwagger2ServiceDescriptionTest.java
@@ -21,6 +21,7 @@ package org.apache.cxf.systest.jaxrs.description;
 import java.io.IOException;
 import java.io.InputStream;
 import java.util.Arrays;
+import java.util.Collections;
 import java.util.List;
 import java.util.Map;
 
@@ -76,6 +77,8 @@ public abstract class AbstractSwagger2ServiceDescriptionTest extends AbstractBus
             feature.setRunAsFilter(runAsFilter);
             sf.setFeatures(Arrays.asList(feature));
             sf.setAddress("http://localhost:" + port + "/");
+            sf.setExtensionMappings(
+                 Collections.singletonMap("json", "application/json;charset=UTF-8"));
             sf.create();
         }
         


Mime
View raw message