Author: sergeyb
Date: Tue Oct 16 14:54:37 2012
New Revision: 1398831

URL: http://svn.apache.org/viewvc?rev=1398831&view=rev
Log:
[CXF-4573] Better effort at trying to establish the class name from imported 
types, also adding noVoidForEmptyResponses switch

Modified:
    
cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerSpringBookTest.java
    
cxf/trunk/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/WadlToolConstants.java
    
cxf/trunk/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/JAXRSContainer.java
    
cxf/trunk/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/SourceGenerator.java
    
cxf/trunk/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/jaxrs-toolspec.xml
    
cxf/trunk/tools/wadlto/jaxrs/src/test/java/org/apache/cxf/tools/wadlto/jaxrs/JAXRSContainerTest.java
    
cxf/trunk/tools/wadlto/jaxrs/src/test/resources/wadl/bookstoreInlinedSchemaWithImport.xml

Modified: 
cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerSpringBookTest.java
URL: 
http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerSpringBookTest.java?rev=1398831&r1=1398830&r2=1398831&view=diff
==============================================================================
--- 
cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerSpringBookTest.java
 (original)
+++ 
cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerSpringBookTest.java
 Tue Oct 16 14:54:37 2012
@@ -83,20 +83,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<Object>();
         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/trunk/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/WadlToolConstants.java
URL: 
http://svn.apache.org/viewvc/cxf/trunk/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/WadlToolConstants.java?rev=1398831&r1=1398830&r2=1398831&view=diff
==============================================================================
--- 
cxf/trunk/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/WadlToolConstants.java
 (original)
+++ 
cxf/trunk/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/WadlToolConstants.java
 Tue Oct 16 14:54:37 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/trunk/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/JAXRSContainer.java
URL: 
http://svn.apache.org/viewvc/cxf/trunk/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/JAXRSContainer.java?rev=1398831&r1=1398830&r2=1398831&view=diff
==============================================================================
--- 
cxf/trunk/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/JAXRSContainer.java
 (original)
+++ 
cxf/trunk/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/JAXRSContainer.java
 Tue Oct 16 14:54:37 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/trunk/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/SourceGenerator.java
URL: 
http://svn.apache.org/viewvc/cxf/trunk/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/SourceGenerator.java?rev=1398831&r1=1398830&r2=1398831&view=diff
==============================================================================
--- 
cxf/trunk/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/SourceGenerator.java
 (original)
+++ 
cxf/trunk/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/SourceGenerator.java
 Tue Oct 16 14:54:37 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; 
     
@@ -191,7 +192,7 @@ public class SourceGenerator {
     private Map<String, String> mediaTypesMap = Collections.emptyMap();
     private Bus bus;
     private boolean supportMultipleXmlReps;
-    
+        
     private SchemaCollection schemaCollection = new SchemaCollection();
     
     public SourceGenerator() {
@@ -210,6 +211,9 @@ public class SourceGenerator {
         this.wadlNamespace = ns;
     }
     
+    public void setUseVoidForEmptyResponses(boolean use) {
+        this.useVoidForEmptyResponses = use;
+    }
     public String getWadlNamespace() {
         return wadlNamespace;
     }
@@ -381,8 +385,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, 
@@ -826,8 +829,13 @@ public class SourceGenerator {
             repElements = CastUtils.cast(Collections.emptyList(), 
Element.class);
         }
         
-        if (repElements.size() == 0) {    
-            sbCode.append("void ");
+        if (repElements.size() == 0) {
+            if (useVoidForEmptyResponses) {
+                sbCode.append("void ");
+            } else {
+                addImport(imports, Response.class.getName());
+                sbCode.append("Response ");
+            }
             return false;
         }
         String elementName = getElementRefName(
@@ -1150,10 +1158,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/trunk/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/jaxrs-toolspec.xml
URL: 
http://svn.apache.org/viewvc/cxf/trunk/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/jaxrs-toolspec.xml?rev=1398831&r1=1398830&r2=1398831&view=diff
==============================================================================
--- 
cxf/trunk/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/jaxrs-toolspec.xml
 (original)
+++ 
cxf/trunk/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/jaxrs-toolspec.xml
 Tue Oct 16 14:54:37 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/trunk/tools/wadlto/jaxrs/src/test/java/org/apache/cxf/tools/wadlto/jaxrs/JAXRSContainerTest.java
URL: 
http://svn.apache.org/viewvc/cxf/trunk/tools/wadlto/jaxrs/src/test/java/org/apache/cxf/tools/wadlto/jaxrs/JAXRSContainerTest.java?rev=1398831&r1=1398830&r2=1398831&view=diff
==============================================================================
--- 
cxf/trunk/tools/wadlto/jaxrs/src/test/java/org/apache/cxf/tools/wadlto/jaxrs/JAXRSContainerTest.java
 (original)
+++ 
cxf/trunk/tools/wadlto/jaxrs/src/test/java/org/apache/cxf/tools/wadlto/jaxrs/JAXRSContainerTest.java
 Tue Oct 16 14:54:37 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/trunk/tools/wadlto/jaxrs/src/test/resources/wadl/bookstoreInlinedSchemaWithImport.xml
URL: 
http://svn.apache.org/viewvc/cxf/trunk/tools/wadlto/jaxrs/src/test/resources/wadl/bookstoreInlinedSchemaWithImport.xml?rev=1398831&r1=1398830&r2=1398831&view=diff
==============================================================================
--- 
cxf/trunk/tools/wadlto/jaxrs/src/test/resources/wadl/bookstoreInlinedSchemaWithImport.xml
 (original)
+++ 
cxf/trunk/tools/wadlto/jaxrs/src/test/resources/wadl/bookstoreInlinedSchemaWithImport.xml
 Tue Oct 16 14:54:37 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>


Reply via email to