cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject git commit: [CXF-5944] Better support for multipart representations, patch from Alexey Markevich applied with modifications
Date Wed, 13 Aug 2014 20:37:10 GMT
Repository: cxf
Updated Branches:
  refs/heads/master ae44ed7e5 -> 77d7a4628


[CXF-5944] Better support for multipart representations, patch from Alexey Markevich applied
with modifications


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

Branch: refs/heads/master
Commit: 77d7a46286ddd45896ab8a939d6278fb66127c95
Parents: ae44ed7
Author: Sergey Beryozkin <sberyozkin@talend.com>
Authored: Wed Aug 13 21:36:45 2014 +0100
Committer: Sergey Beryozkin <sberyozkin@talend.com>
Committed: Wed Aug 13 21:36:45 2014 +0100

----------------------------------------------------------------------
 .../cxf/tools/wadlto/jaxrs/SourceGenerator.java | 46 +++++++++++++-------
 .../tools/wadlto/jaxrs/JAXRSContainerTest.java  | 28 ++++++------
 .../cxf/tools/wadlto/jaxrs/WADLToJavaTest.java  |  2 +-
 .../jaxrs/src/test/resources/wadl/bookstore.xml | 29 +++++++++++-
 4 files changed, 73 insertions(+), 32 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/77d7a462/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/SourceGenerator.java
----------------------------------------------------------------------
diff --git a/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/SourceGenerator.java
b/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/SourceGenerator.java
index 65646a3..1706053 100644
--- a/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/SourceGenerator.java
+++ b/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/SourceGenerator.java
@@ -90,6 +90,8 @@ import org.apache.cxf.common.xmlschema.SchemaCollection;
 import org.apache.cxf.helpers.CastUtils;
 import org.apache.cxf.helpers.DOMUtils;
 import org.apache.cxf.helpers.JavaUtils;
+import org.apache.cxf.jaxrs.ext.multipart.Multipart;
+import org.apache.cxf.jaxrs.ext.multipart.MultipartBody;
 import org.apache.cxf.jaxrs.model.wadl.WadlGenerator;
 import org.apache.cxf.jaxrs.utils.JAXRSUtils;
 import org.apache.cxf.jaxrs.utils.ResourceUtils;
@@ -175,6 +177,7 @@ public class SourceGenerator {
         XSD_SPECIFIC_TYPE_MAP.put("date", "java.util.Date");
         XSD_SPECIFIC_TYPE_MAP.put("dateTime", "java.util.Date");
         XSD_SPECIFIC_TYPE_MAP.put("time", "java.util.Date");
+        XSD_SPECIFIC_TYPE_MAP.put("anyType", "String");
     }
 
     private Comparator<String> importsComparator;
@@ -576,7 +579,7 @@ public class SourceGenerator {
     private void writeImplementsInterface(StringBuilder sb, String clsName, 
                                              boolean interfaceIsGenerated) {
         if (generateInterfaces && !interfaceIsGenerated) {
-            sb.append(" implements " + clsName);
+            sb.append(" implements " + StringUtils.capitalize(clsName));
         }
     }
     
@@ -861,13 +864,15 @@ public class SourceGenerator {
         sbCode.append("}");
     }
     
-    private boolean addFormParameters(List<Element> inParamElements, Element requestEl)
{
-        List<Element> repElements = getWadlElements(requestEl, "representation");
- 
+    private boolean addFormParameters(List<Element> inParamElements, 
+                                      Element requestEl,
+                                      List<Element> repElements) {
         if (repElements.size() == 1) {
             String mediaType = repElements.get(0).getAttribute("mediaType");
-            if (MediaType.APPLICATION_FORM_URLENCODED.equals(mediaType)) { 
-                inParamElements.addAll(getWadlElements(repElements.get(0), "param"));
+            if (MediaType.APPLICATION_FORM_URLENCODED.equals(mediaType) || mediaType.startsWith("multipart/"))
{
+                if (!mediaTypesMap.containsKey(mediaType)) {
+                    inParamElements.addAll(getWadlElements(repElements.get(0), "param"));
+                }
                 return true;
             }
         }
@@ -971,12 +976,19 @@ public class SourceGenerator {
                                    boolean suspendedAsync) {
     //CHECKSTYLE:ON    
         boolean form = false;
-        boolean formParamsAvailable = false;
+        boolean multipart = false;
+        boolean formOrMultipartParamsAvailable = false;
+        String requestMediaType = null;
         if (requestEl != null) {
             inParamEls.addAll(getWadlElements(requestEl, "param"));
             int currentSize = inParamEls.size();
-            form = addFormParameters(inParamEls, requestEl);
-            formParamsAvailable = currentSize < inParamEls.size(); 
+            List<Element> repElements = getWadlElements(requestEl, "representation");
+            form = addFormParameters(inParamEls, requestEl, repElements);
+            if (form) {
+                formOrMultipartParamsAvailable = currentSize < inParamEls.size();
+                requestMediaType = repElements.get(0).getAttribute("mediaType");
+                multipart = form && requestMediaType.startsWith("multipart/");
+            }
         }
                   
         for (int i = 0; i < inParamEls.size(); i++) {
@@ -984,8 +996,8 @@ public class SourceGenerator {
             Element paramEl = inParamEls.get(i);
             
             Class<?> paramAnn = getParamAnnotation(paramEl.getAttribute("style"));
-            if (paramAnn == QueryParam.class && form) {
-                paramAnn = FormParam.class; 
+            if (paramAnn == QueryParam.class && formOrMultipartParamsAvailable) {
+                paramAnn = !multipart ? FormParam.class : Multipart.class; 
             } 
             String name = paramEl.getAttribute("name");
             boolean enumCreated = false;
@@ -1049,10 +1061,14 @@ public class SourceGenerator {
                 elementParamType = Source.class.getSimpleName();
                 elementParamName = "source";
             }
-        } else if (!formParamsAvailable) {
-            addImport(imports, MultivaluedMap.class.getName());
-            elementParamType = MultivaluedMap.class.getSimpleName();
-            elementParamName = "map";
+        } else if (!formOrMultipartParamsAvailable) {
+            if (requestMediaType != null && mediaTypesMap.containsKey(requestMediaType))
{
+                elementParamType = addImportsAndGetSimpleName(imports, mediaTypesMap.get(requestMediaType));
+            } else {
+                String fullClassName = !multipart ? MultivaluedMap.class.getName() : MultipartBody.class.getName();
+                elementParamType =  addImportsAndGetSimpleName(imports, fullClassName);
+            }
+            elementParamName = !multipart ? "map" : "body";
         }
         if (elementParamType != null) {
             if (inParamEls.size() > 0) {

http://git-wip-us.apache.org/repos/asf/cxf/blob/77d7a462/tools/wadlto/jaxrs/src/test/java/org/apache/cxf/tools/wadlto/jaxrs/JAXRSContainerTest.java
----------------------------------------------------------------------
diff --git a/tools/wadlto/jaxrs/src/test/java/org/apache/cxf/tools/wadlto/jaxrs/JAXRSContainerTest.java
b/tools/wadlto/jaxrs/src/test/java/org/apache/cxf/tools/wadlto/jaxrs/JAXRSContainerTest.java
index b82fca6..61ee5cd 100644
--- a/tools/wadlto/jaxrs/src/test/java/org/apache/cxf/tools/wadlto/jaxrs/JAXRSContainerTest.java
+++ b/tools/wadlto/jaxrs/src/test/java/org/apache/cxf/tools/wadlto/jaxrs/JAXRSContainerTest.java
@@ -80,8 +80,8 @@ public class JAXRSContainerTest extends ProcessorTestBase {
 
             assertNotNull(output.list());
             
-            verifyFiles("java", true, false, "superbooks", "org.apache.cxf.jaxrs.model.wadl",
10, true);
-            verifyFiles("class", true, false, "superbooks", "org.apache.cxf.jaxrs.model.wadl",
10, true);
+            verifyFiles("java", true, false, "superbooks", "org.apache.cxf.jaxrs.model.wadl",
11, true);
+            verifyFiles("class", true, false, "superbooks", "org.apache.cxf.jaxrs.model.wadl",
11, true);
             
         } catch (Exception e) {
             e.printStackTrace();
@@ -130,8 +130,8 @@ public class JAXRSContainerTest extends ProcessorTestBase {
 
             assertNotNull(output.list());
             
-            verifyFiles("java", true, false, "superbooks", "org.apache.cxf.jaxrs.model.wadl",
10, true);
-            verifyFiles("class", true, false, "superbooks", "org.apache.cxf.jaxrs.model.wadl",
10, true);
+            verifyFiles("java", true, false, "superbooks", "org.apache.cxf.jaxrs.model.wadl",
11, true);
+            verifyFiles("class", true, false, "superbooks", "org.apache.cxf.jaxrs.model.wadl",
11, true);
             
         } catch (Exception e) {
             e.printStackTrace();
@@ -155,8 +155,8 @@ public class JAXRSContainerTest extends ProcessorTestBase {
 
             assertNotNull(output.list());
             
-            verifyFiles("java", true, false, "superbooks", "org.apache.cxf.jaxrs.model.wadl",
10, true);
-            verifyFiles("class", true, false, "superbooks", "org.apache.cxf.jaxrs.model.wadl",
10, true);
+            verifyFiles("java", true, false, "superbooks", "org.apache.cxf.jaxrs.model.wadl",
11, true);
+            verifyFiles("class", true, false, "superbooks", "org.apache.cxf.jaxrs.model.wadl",
11, true);
             
         } catch (Exception e) {
             e.printStackTrace();
@@ -551,8 +551,8 @@ public class JAXRSContainerTest extends ProcessorTestBase {
 
             assertNotNull(output.list());
             
-            verifyFiles("java", true, false, "superbooks", "custom.books", 10, true);
-            verifyFiles("class", true, false, "superbooks", "custom.books", 10, true);
+            verifyFiles("java", true, false, "superbooks", "custom.books", 11, true);
+            verifyFiles("class", true, false, "superbooks", "custom.books", 11, true);
             
         } catch (Exception e) {
             e.printStackTrace();
@@ -577,8 +577,8 @@ public class JAXRSContainerTest extends ProcessorTestBase {
 
             assertNotNull(output.list());
             
-            verifyFiles("java", true, false, "custom.books.schema", "custom.books.service",
10, true);
-            verifyFiles("class", true, false, "custom.books.schema", "custom.books.service",
10, true);
+            verifyFiles("java", true, false, "custom.books.schema", "custom.books.service",
11, true);
+            verifyFiles("class", true, false, "custom.books.schema", "custom.books.service",
11, true);
             
         } catch (Exception e) {
             e.printStackTrace();
@@ -602,8 +602,8 @@ public class JAXRSContainerTest extends ProcessorTestBase {
 
             assertNotNull(output.list());
             
-            verifyFiles("java", true, false, "superbooks", "org.apache.cxf.jaxrs.model.wadl",
10, true);
-            verifyFiles("class", true, false, "superbooks", "org.apache.cxf.jaxrs.model.wadl",
10, true);
+            verifyFiles("java", true, false, "superbooks", "org.apache.cxf.jaxrs.model.wadl",
11, true);
+            verifyFiles("class", true, false, "superbooks", "org.apache.cxf.jaxrs.model.wadl",
11, true);
         } catch (Exception e) {
             fail();
             e.printStackTrace();
@@ -627,8 +627,8 @@ public class JAXRSContainerTest extends ProcessorTestBase {
 
             assertNotNull(output.list());
             
-            verifyFiles("java", true, true, "superbooks", "org.apache.cxf.jaxrs.model.wadl",
12, true);
-            verifyFiles("class", true, true, "superbooks", "org.apache.cxf.jaxrs.model.wadl",
12, true);
+            verifyFiles("java", true, true, "superbooks", "org.apache.cxf.jaxrs.model.wadl",
14, true);
+            verifyFiles("class", true, true, "superbooks", "org.apache.cxf.jaxrs.model.wadl",
14, true);
         } catch (Exception e) {
             fail();
             e.printStackTrace();

http://git-wip-us.apache.org/repos/asf/cxf/blob/77d7a462/tools/wadlto/jaxrs/src/test/java/org/apache/cxf/tools/wadlto/jaxrs/WADLToJavaTest.java
----------------------------------------------------------------------
diff --git a/tools/wadlto/jaxrs/src/test/java/org/apache/cxf/tools/wadlto/jaxrs/WADLToJavaTest.java
b/tools/wadlto/jaxrs/src/test/java/org/apache/cxf/tools/wadlto/jaxrs/WADLToJavaTest.java
index 892c8ab..51c3fbd 100644
--- a/tools/wadlto/jaxrs/src/test/java/org/apache/cxf/tools/wadlto/jaxrs/WADLToJavaTest.java
+++ b/tools/wadlto/jaxrs/src/test/java/org/apache/cxf/tools/wadlto/jaxrs/WADLToJavaTest.java
@@ -151,7 +151,7 @@ public class WADLToJavaTest extends ProcessorTestBase {
     private void verifyFiles(String ext, boolean subresourceExpected, boolean interfacesAndImpl,

                              String schemaPackage, String resourcePackage) {    
         List<File> files = FileUtils.getFilesRecurse(output, ".+\\." + ext + "$");
-        int size = interfacesAndImpl ? 11 : 9;
+        int size = interfacesAndImpl ? 11 : 10;
         if (!subresourceExpected) {
             size--;
         }

http://git-wip-us.apache.org/repos/asf/cxf/blob/77d7a462/tools/wadlto/jaxrs/src/test/resources/wadl/bookstore.xml
----------------------------------------------------------------------
diff --git a/tools/wadlto/jaxrs/src/test/resources/wadl/bookstore.xml b/tools/wadlto/jaxrs/src/test/resources/wadl/bookstore.xml
index 3488e0f..ebf8bcd 100644
--- a/tools/wadlto/jaxrs/src/test/resources/wadl/bookstore.xml
+++ b/tools/wadlto/jaxrs/src/test/resources/wadl/bookstore.xml
@@ -182,7 +182,7 @@
                 <param name="bookid" style="template" type="xs:int"/>
                 <param name="mid" style="matrix" type="xs:int"/>
             </resource>
-            <resource path="/booksubresource" id="{http://superbooks}thebook">
+            <resource path="/booksubresource" id="{http://superbooks}thebooksub">
                 <doc>Book subresource</doc>
                 <param name="id" style="template" type="xs:int"/>
                 <param name="mid" style="matrix" type="xs:int"/>
@@ -240,7 +240,32 @@
                         </response>
                     </method>
                     <resource path="/form" id="org.apache.cxf.jaxrs.model.wadl.FormInterface">
-                        <resource path="/recursive" id="org.apache.cxf.jaxrs.model.wadl.FormInterface"/>
+                        <resource path="/multipart">
+		                    <method name="POST" id="multipart1">
+		                        <request>
+		                            <representation mediaType="multipart/mixed">
+		                                <param name="field1" style="query" type="xs:string"/>
+		                                <param name="field2" style="query" type="xs:anyType"/>
+		                            </representation>
+		                        </request>
+		                        <response>
+		                            <representation mediaType="text/plain">
+		                                <param name="result" style="plain" type="xs:string"/>
+		                            </representation>
+		                        </response>
+		                    </method>
+		                    <method name="PUT" id="multipart2">
+		                        <request>
+		                            <representation mediaType="multipart/form-data"/>
+		                        </request>
+		                        <response>
+		                            <representation mediaType="text/plain">
+		                                <param name="result" style="plain" type="xs:string"/>
+		                            </representation>
+		                        </response>
+		                    </method>
+		                </resource>
+                    	<resource path="/recursive" id="org.apache.cxf.jaxrs.model.wadl.FormInterface"/>
                         <resource path="/c">
                             <resource path="/formSub" id="org.apache.cxf.jaxrs.model.wadl.FormInterface2">
                                 <param name="formid" style="template" type="xs:int"/>


Mime
View raw message