You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by se...@apache.org on 2012/10/17 11:58:29 UTC

svn commit: r1399171 - in /cxf/branches/2.5.x-fixes: ./ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/codegen/ systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/ tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/ tools/wad...

Author: sergeyb
Date: Wed Oct 17 09:58:28 2012
New Revision: 1399171

URL: http://svn.apache.org/viewvc?rev=1399171&view=rev
Log:
Merged revisions 1399158 via svnmerge from 
https://svn.apache.org/repos/asf/cxf/branches/2.6.x-fixes

................
  r1399158 | sergeyb | 2012-10-17 10:19:03 +0100 (Wed, 17 Oct 2012) | 9 lines
  
  Merged revisions 1398831 via svnmerge from 
  https://svn.apache.org/repos/asf/cxf/trunk
  
  ........
    r1398831 | sergeyb | 2012-10-16 15:54:37 +0100 (Tue, 16 Oct 2012) | 1 line
    
    [CXF-4573] Better effort at trying to establish the class name from imported types, also adding noVoidForEmptyResponses switch
  ........
................

Modified:
    cxf/branches/2.5.x-fixes/   (props changed)
    cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/codegen/SourceGenerator.java
    cxf/branches/2.5.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerSpringBookTest.java
    cxf/branches/2.5.x-fixes/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/WadlToolConstants.java
    cxf/branches/2.5.x-fixes/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/JAXRSContainer.java
    cxf/branches/2.5.x-fixes/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/jaxrs-toolspec.xml
    cxf/branches/2.5.x-fixes/tools/wadlto/jaxrs/src/test/java/org/apache/cxf/tools/wadlto/jaxrs/JAXRSContainerTest.java
    cxf/branches/2.5.x-fixes/tools/wadlto/jaxrs/src/test/resources/wadl/bookstoreInlinedSchemaWithImport.xml

Propchange: cxf/branches/2.5.x-fixes/
------------------------------------------------------------------------------
  Merged /cxf/trunk:r1398831
  Merged /cxf/branches/2.6.x-fixes:r1399158

Propchange: cxf/branches/2.5.x-fixes/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.

Modified: cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/codegen/SourceGenerator.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/codegen/SourceGenerator.java?rev=1399171&r1=1399170&r2=1399171&view=diff
==============================================================================
--- cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/codegen/SourceGenerator.java (original)
+++ cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/codegen/SourceGenerator.java Wed Oct 17 09:58:28 2012
@@ -177,6 +177,7 @@ public class SourceGenerator {
     private boolean generateEnums;
     private boolean skipSchemaGeneration;
     private boolean inheritResourceParams;
+    private boolean useVoidForEmptyResponses = true;
     
     private Map<String, String> properties; 
     
@@ -213,6 +214,10 @@ public class SourceGenerator {
     public String getWadlNamespace() {
         return wadlNamespace;
     }
+
+    public void setUseVoidForEmptyResponses(boolean use) {
+        this.useVoidForEmptyResponses = use;
+    }
     
     public void setGenerateEnums(boolean generate) {
         this.generateEnums = generate;
@@ -381,8 +386,7 @@ public class SourceGenerator {
         for (Element el : elementEls) {
             String type = el.getAttribute("type");
             if (type.length() > 0) {
-                String[] pair = type.split(":");
-                elementTypeMap.put(el.getAttribute("name"), pair.length == 1 ? pair[0] : pair[1]);
+                elementTypeMap.put(el.getAttribute("name"), type);
             }
         }
         Element includeEl = DOMUtils.getFirstChildWithName(schemaEl, 
@@ -827,7 +831,12 @@ public class SourceGenerator {
         }
         
         if (repElements.size() == 0) {    
-            sbCode.append("void ");
+            if (useVoidForEmptyResponses) {
+                sbCode.append("void ");
+            } else {
+                addImport(imports, Response.class.getName());
+                sbCode.append("Response ");
+            }
             return false;
         }
         String elementName = getElementRefName(
@@ -1145,10 +1154,22 @@ public class SourceGenerator {
                                       Set <String> typeClassNames) {
         String clsName = matchClassName(typeClassNames, packageName, localName);
         if (clsName == null && gInfo != null) {
-            String elementTypeName = gInfo.getElementTypeMap().get(localName);
-            clsName = matchClassName(typeClassNames, packageName, elementTypeName);
-            if (clsName == null && elementTypeName != null && elementTypeName.contains("_")) {
-                clsName = matchClassName(typeClassNames, packageName, elementTypeName.replaceAll("_", ""));
+            String prefixedElementTypeName = gInfo.getElementTypeMap().get(localName);
+            if (prefixedElementTypeName != null) {
+                String[] pair = prefixedElementTypeName.split(":");
+                String elementTypeName = pair.length == 2 ? pair[1] : pair[0];
+                clsName = matchClassName(typeClassNames, packageName, elementTypeName);
+                if (clsName == null && elementTypeName.contains("_")) {
+                    clsName = matchClassName(typeClassNames, packageName, elementTypeName.replaceAll("_", ""));
+                }
+                if (clsName == null && pair.length == 2) {
+                    String namespace = gInfo.getNsMap().get(pair[0]);
+                    if (namespace != null) {
+                        packageName = getPackageFromNamespace(namespace);
+                        clsName = matchClassName(typeClassNames, packageName, elementTypeName);
+                    }
+                }
+                
             }
         }
         if (clsName == null && javaTypeMap != null) {

Modified: cxf/branches/2.5.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerSpringBookTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.5.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerSpringBookTest.java?rev=1399171&r1=1399170&r2=1399171&view=diff
==============================================================================
--- cxf/branches/2.5.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerSpringBookTest.java (original)
+++ cxf/branches/2.5.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerSpringBookTest.java Wed Oct 17 09:58:28 2012
@@ -81,20 +81,22 @@ public class JAXRSClientServerSpringBook
     
     @Test
     public void testPostGeneratedBook() throws Exception {
-        String baseAddress = "http://localhost:" + PORT + "/the/generated/bookstore/books/1";
+        String baseAddress = "http://localhost:" + PORT + "/the/generated";
         JAXBElementProvider provider = new JAXBElementProvider();
         provider.setJaxbElementClassMap(Collections.singletonMap(
                                           "org.apache.cxf.systest.jaxrs.codegen.schema.Book", 
                                           "{http://superbooks}thebook"));
         
-        WebClient wc = WebClient.create(baseAddress,
-                                        Collections.singletonList(provider));
-        wc.type("application/xml");
+        org.apache.cxf.systest.jaxrs.codegen.service.BookStore bookStore = 
+            JAXRSClientFactory.create(baseAddress, 
+                org.apache.cxf.systest.jaxrs.codegen.service.BookStore.class,
+                Collections.singletonList(provider));
         
         org.apache.cxf.systest.jaxrs.codegen.schema.Book book = 
             new org.apache.cxf.systest.jaxrs.codegen.schema.Book();
         book.setId(123);
-        Response r = wc.post(book);
+        bookStore.addBook(123, book);
+        Response r = WebClient.client(bookStore).getResponse();
         assertEquals(204, r.getStatus());
     }
     

Modified: cxf/branches/2.5.x-fixes/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/WadlToolConstants.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.5.x-fixes/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/WadlToolConstants.java?rev=1399171&r1=1399170&r2=1399171&view=diff
==============================================================================
--- cxf/branches/2.5.x-fixes/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/WadlToolConstants.java (original)
+++ cxf/branches/2.5.x-fixes/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/WadlToolConstants.java Wed Oct 17 09:58:28 2012
@@ -45,6 +45,7 @@ public final class WadlToolConstants {
     public static final String CFG_BINDING = ToolConstants.CFG_BINDING;
     
     public static final String CFG_NO_TYPES = ToolConstants.CFG_NO_TYPES;
+    public static final String CFG_NO_VOID_FOR_EMPTY_RESPONSES = "noVoidForEmptyResponses";
     public static final String CFG_NO_ADDRESS_BINDING = ToolConstants.CFG_NO_ADDRESS_BINDING;
     
     public static final String CFG_WADL_NAMESPACE = "wadlNamespace";

Modified: cxf/branches/2.5.x-fixes/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/JAXRSContainer.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.5.x-fixes/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/JAXRSContainer.java?rev=1399171&r1=1399170&r2=1399171&view=diff
==============================================================================
--- cxf/branches/2.5.x-fixes/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/JAXRSContainer.java (original)
+++ cxf/branches/2.5.x-fixes/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/JAXRSContainer.java Wed Oct 17 09:58:28 2012
@@ -153,6 +153,11 @@ public class JAXRSContainer extends Abst
         sg.setInheritResourceParams(context.optionSet(WadlToolConstants.CFG_INHERIT_PARAMS));
         sg.setSkipSchemaGeneration(context.optionSet(WadlToolConstants.CFG_NO_TYPES));
         
+        boolean noVoidForEmptyResponses = context.optionSet(WadlToolConstants.CFG_NO_VOID_FOR_EMPTY_RESPONSES);
+        if (noVoidForEmptyResponses) {
+            sg.setUseVoidForEmptyResponses(false);
+        }
+        
         // generate
         String codeType = context.optionSet(WadlToolConstants.CFG_TYPES)
             ? SourceGenerator.CODE_TYPE_GRAMMAR : SourceGenerator.CODE_TYPE_PROXY;

Modified: cxf/branches/2.5.x-fixes/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/jaxrs-toolspec.xml
URL: http://svn.apache.org/viewvc/cxf/branches/2.5.x-fixes/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/jaxrs-toolspec.xml?rev=1399171&r1=1399170&r2=1399171&view=diff
==============================================================================
--- cxf/branches/2.5.x-fixes/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/jaxrs-toolspec.xml (original)
+++ cxf/branches/2.5.x-fixes/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/jaxrs-toolspec.xml Wed Oct 17 09:58:28 2012
@@ -183,6 +183,13 @@ Examples:
                 <switch>noTypes</switch>
             </option>
             
+            <option id="noVoidForEmptyResponses" maxOccurs="1">
+                <annotation>
+                   Use JAX-RS Response return type for methods with no response representation
+                </annotation>
+                <switch>noVoidForEmptyResponses</switch>
+            </option>
+            
             <option id="noAddressBinding" maxOccurs="1">
                 <annotation>
                     Specifies that the generator should not use the address jaxb binding file to map wsa:EndpointReferenceType 

Modified: cxf/branches/2.5.x-fixes/tools/wadlto/jaxrs/src/test/java/org/apache/cxf/tools/wadlto/jaxrs/JAXRSContainerTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.5.x-fixes/tools/wadlto/jaxrs/src/test/java/org/apache/cxf/tools/wadlto/jaxrs/JAXRSContainerTest.java?rev=1399171&r1=1399170&r2=1399171&view=diff
==============================================================================
--- cxf/branches/2.5.x-fixes/tools/wadlto/jaxrs/src/test/java/org/apache/cxf/tools/wadlto/jaxrs/JAXRSContainerTest.java (original)
+++ cxf/branches/2.5.x-fixes/tools/wadlto/jaxrs/src/test/java/org/apache/cxf/tools/wadlto/jaxrs/JAXRSContainerTest.java Wed Oct 17 09:58:28 2012
@@ -44,6 +44,7 @@ public class JAXRSContainerTest extends 
                         "application/xml=javax.xml.transform.Source");
             context.put(WadlToolConstants.CFG_MEDIA_TYPE_MAP, 
                         "multipart/form-data=org.apache.cxf.jaxrs.ext.multipart.MultipartBody");
+            context.put(WadlToolConstants.CFG_NO_VOID_FOR_EMPTY_RESPONSES, "true");
             context.put(WadlToolConstants.CFG_COMPILE, "true");
             
             container.setContext(context);

Modified: cxf/branches/2.5.x-fixes/tools/wadlto/jaxrs/src/test/resources/wadl/bookstoreInlinedSchemaWithImport.xml
URL: http://svn.apache.org/viewvc/cxf/branches/2.5.x-fixes/tools/wadlto/jaxrs/src/test/resources/wadl/bookstoreInlinedSchemaWithImport.xml?rev=1399171&r1=1399170&r2=1399171&view=diff
==============================================================================
--- cxf/branches/2.5.x-fixes/tools/wadlto/jaxrs/src/test/resources/wadl/bookstoreInlinedSchemaWithImport.xml (original)
+++ cxf/branches/2.5.x-fixes/tools/wadlto/jaxrs/src/test/resources/wadl/bookstoreInlinedSchemaWithImport.xml Wed Oct 17 09:58:28 2012
@@ -18,7 +18,8 @@
   under the License.
 -->
 <application xmlns="http://wadl.dev.java.net/2009/02" xmlns:xs="http://www.w3.org/2001/XMLSchema" 
-  xmlns:prefix1="http://superbooks">
+  xmlns:prefix1="http://superbooks"
+  xmlns:ch="http://superchapters">
 
  <grammars>
    <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" 
@@ -35,6 +36,8 @@
             <xs:element ref="ch:thechapter"/>
         </xs:sequence>
       </xs:complexType>
+      
+      <xs:element name="bookchapter" type="ch:chapter"/>
     </xs:schema>
  </grammars>
  <resources base="http://localhost:8080/baz">
@@ -48,6 +51,13 @@
        <representation mediaType="application/xml" element="prefix1:thebook"/>
       </request>
      </method>
+     
+     <method name="PUT" id="addChapter">
+      <request>
+       <representation mediaType="application/xml" element="prefix1:bookchapter"/>
+      </request>
+     </method>
+     
     </resource>
    </resource>
 </resources>