cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject git commit: [CXF-5974] Setting a default representation media type to */*
Date Wed, 27 Aug 2014 12:35:32 GMT
Repository: cxf
Updated Branches:
  refs/heads/3.0.x-fixes 4383951cc -> 0189ff6cb


[CXF-5974] Setting a default representation media type to */*


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

Branch: refs/heads/3.0.x-fixes
Commit: 0189ff6cbe2be511b1940e4dfa6ab90d92f23113
Parents: 4383951
Author: Sergey Beryozkin <sberyozkin@talend.com>
Authored: Wed Aug 27 13:31:33 2014 +0100
Committer: Sergey Beryozkin <sberyozkin@talend.com>
Committed: Wed Aug 27 13:35:04 2014 +0100

----------------------------------------------------------------------
 .../cxf/jaxrs/model/wadl/WadlGenerator.java     | 28 ++++++++++++++++----
 1 file changed, 23 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/0189ff6c/rt/rs/description/src/main/java/org/apache/cxf/jaxrs/model/wadl/WadlGenerator.java
----------------------------------------------------------------------
diff --git a/rt/rs/description/src/main/java/org/apache/cxf/jaxrs/model/wadl/WadlGenerator.java
b/rt/rs/description/src/main/java/org/apache/cxf/jaxrs/model/wadl/WadlGenerator.java
index 8800f5b..b376bbe 100644
--- a/rt/rs/description/src/main/java/org/apache/cxf/jaxrs/model/wadl/WadlGenerator.java
+++ b/rt/rs/description/src/main/java/org/apache/cxf/jaxrs/model/wadl/WadlGenerator.java
@@ -120,7 +120,6 @@ public class WadlGenerator implements ContainerRequestFilter {
     public static final MediaType WADL_TYPE = JAXRSUtils.toMediaType("application/vnd.sun.wadl+xml");
     public static final String WADL_NS = "http://wadl.dev.java.net/2009/02";
 
-    private static final MediaType DEFAULT_MEDIA_TYPE = MediaType.APPLICATION_XML_TYPE;
     private static final Logger LOG = LogUtils.getL7dLogger(WadlGenerator.class);
     private static final String JAXB_DEFAULT_NAMESPACE = "##default";
     private static final String JAXB_DEFAULT_NAME = "##default";
@@ -151,7 +150,8 @@ public class WadlGenerator implements ContainerRequestFilter {
     private List<String> privateAddresses;
     private String applicationTitle;
     private String nsPrefix = DEFAULT_NS_PREFIX;
-    private MediaType defaultMediaType = DEFAULT_MEDIA_TYPE;
+    private MediaType defaultWadlResponseMediaType = MediaType.APPLICATION_XML_TYPE;
+    private MediaType defaultRepMediaType = MediaType.WILDCARD_TYPE;
     private Bus bus;
     private DocumentationProvider docProvider;
         
@@ -195,7 +195,8 @@ public class WadlGenerator implements ContainerRequestFilter {
         HttpHeaders headers = new HttpHeadersImpl(m);
         List<MediaType> accepts = headers.getAcceptableMediaTypes();
         MediaType type = accepts.contains(WADL_TYPE) ? WADL_TYPE : accepts
-            .contains(MediaType.APPLICATION_JSON_TYPE) ? MediaType.APPLICATION_JSON_TYPE
: defaultMediaType;
+            .contains(MediaType.APPLICATION_JSON_TYPE) ? MediaType.APPLICATION_JSON_TYPE

+                : defaultWadlResponseMediaType;
 
         Response response = getExistingWadl(m, ui, type);
         if (response != null) {
@@ -834,7 +835,7 @@ public class WadlGenerator implements ContainerRequestFilter {
         if (MultivaluedMap.class.isAssignableFrom(type)) {
             types = Collections.singletonList(MediaType.APPLICATION_FORM_URLENCODED_TYPE);
         } else if (isWildcard(types)) {
-            types = Collections.singletonList(MediaType.APPLICATION_OCTET_STREAM_TYPE);
+            types = Collections.singletonList(defaultRepMediaType);
         }
 
         Method opMethod = getMethod(ori);
@@ -1889,8 +1890,25 @@ public class WadlGenerator implements ContainerRequestFilter {
         this.supportCollections = support;
     }
 
+    /**
+     * Set the default WADL response media type.
+     * For example, a browser may display WADL better if Content-Type 
+     * is set application/xml which is a default response content type. 
+     * Users may set it to application/vnd.sun.wadl+xml or other type.
+     * @param mt WADL response media type 
+     */
     public void setDefaultMediaType(String mt) {
-        this.defaultMediaType = JAXRSUtils.toMediaType(mt);
+        this.defaultWadlResponseMediaType = JAXRSUtils.toMediaType(mt);
+    }
+    
+    /**
+     * Set the default representation media type to be used 
+     * if JAX-RS Produces or Consumes annotation is missing.
+     * Wild-card media type is used by default in such cases.
+     * @param mt the default representation media type 
+     */
+    public void setDefaultRepresentationMediaType(String mt) {
+        this.defaultWadlResponseMediaType = JAXRSUtils.toMediaType(mt);
     }
 
     public void setSupportJaxbXmlType(boolean supportJaxbXmlType) {


Mime
View raw message