cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1349738 - in /cxf/branches/2.5.x-fixes: ./ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/fortest/jaxb/packageinfo/ rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/m...
Date Wed, 13 Jun 2012 10:36:05 GMT
Author: sergeyb
Date: Wed Jun 13 10:36:04 2012
New Revision: 1349738

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

................
  r1349725 | sergeyb | 2012-06-13 11:19:54 +0100 (Wed, 13 Jun 2012) | 13 lines
  
  Merged revisions 1349714,1349717 via svnmerge from 
  https://svn.apache.org/repos/asf/cxf/trunk
  
  ........
    r1349714 | sergeyb | 2012-06-13 10:58:26 +0100 (Wed, 13 Jun 2012) | 1 line
    
    [CXF-4374] JSONProvider should not auto-allocate prefixes, let JAXB or users do it
  ........
    r1349717 | sergeyb | 2012-06-13 11:05:39 +0100 (Wed, 13 Jun 2012) | 1 line
    
    [CXF-4374] The actual updates to JSONProvider
  ........
................

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/provider/JSONProvider.java
    cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/fortest/jaxb/packageinfo/package-info.java
    cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/WadlGeneratorTest.java
    cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/JAXBElementProviderTest.java
    cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/JSONProviderTest.java

Propchange: cxf/branches/2.5.x-fixes/
------------------------------------------------------------------------------
  Merged /cxf/trunk:r1349714-1349717
  Merged /cxf/branches/2.6.x-fixes:r1349725

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/provider/JSONProvider.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JSONProvider.java?rev=1349738&r1=1349737&r2=1349738&view=diff
==============================================================================
--- cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JSONProvider.java
(original)
+++ cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JSONProvider.java
Wed Jun 13 10:36:04 2012
@@ -300,7 +300,7 @@ public class JSONProvider extends Abstra
             name = wrapperMap.get(cls.getName());
         }
         if (name == null) {
-            QName qname = getQName(cls, type, null, false);
+            QName qname = getQName(cls, type, null);
             if (qname != null) {
                 name = qname.getLocalPart();
                 String prefix = qname.getPrefix();
@@ -473,7 +473,7 @@ public class JSONProvider extends Abstra
     protected XMLStreamWriter createWriter(Object actualObject, Class<?> actualClass,

         Type genericType, String enc, OutputStream os, boolean isCollection) throws Exception
{
         
-        QName qname = getQName(actualClass, genericType, actualObject, true);
+        QName qname = getQName(actualClass, genericType, actualObject);
         if (ignoreNamespaces && (isCollection  || dropRootElement)) {        
             qname = new QName(qname.getLocalPart());
         }
@@ -510,27 +510,19 @@ public class JSONProvider extends Abstra
         marshal(ms, actualObject, actualClass, genericType, enc, os, false);
     }
     
-    private QName getQName(Class<?> cls, Type type, Object object, boolean allocatePrefix)

+    private QName getQName(Class<?> cls, Type type, Object object) 
         throws Exception {
         QName qname = getJaxbQName(cls, type, object, false);
         if (qname != null) {
-            String prefix = getPrefix(qname.getNamespaceURI(), allocatePrefix);
+            String prefix = getPrefix(qname.getNamespaceURI());
             return new QName(qname.getNamespaceURI(), qname.getLocalPart(), prefix);
         }
         return null;
     }
     
-    private String getPrefix(String namespace, boolean allocatePrefix) {
+    private String getPrefix(String namespace) {
         String prefix = namespaceMap.get(namespace);
-        if (prefix == null) {
-            if (allocatePrefix && namespace.length() > 0) {
-                prefix = "ns" + (namespaceMap.size() + 1);
-                namespaceMap.put(namespace, prefix);
-            } else {
-                prefix = "";
-            }
-        }
-        return prefix;
+        return prefix == null ? "" : prefix;
     }
     
     public void setWriteXsiType(boolean writeXsiType) {

Modified: cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/fortest/jaxb/packageinfo/package-info.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/fortest/jaxb/packageinfo/package-info.java?rev=1349738&r1=1349737&r2=1349738&view=diff
==============================================================================
--- cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/fortest/jaxb/packageinfo/package-info.java
(original)
+++ cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/fortest/jaxb/packageinfo/package-info.java
Wed Jun 13 10:36:04 2012
@@ -16,6 +16,9 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-@javax.xml.bind.annotation.XmlSchema(namespace = "http://superbooks")
+@javax.xml.bind.annotation.XmlSchema(namespace = "http://superbooks",
+ xmlns = { @XmlNs(prefix = "os", namespaceURI = "http://superbooks") })
 package org.apache.cxf.jaxrs.fortest.jaxb.packageinfo;
 
+import javax.xml.bind.annotation.XmlNs;
+

Modified: cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/WadlGeneratorTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/WadlGeneratorTest.java?rev=1349738&r1=1349737&r2=1349738&view=diff
==============================================================================
--- cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/WadlGeneratorTest.java
(original)
+++ cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/WadlGeneratorTest.java
Wed Jun 13 10:36:04 2012
@@ -127,7 +127,7 @@ public class WadlGeneratorTest extends A
         Response r = wg.handleRequest(m, cri);
         checkResponse(r);
         Document doc = DOMUtils.readXml(new StringReader(r.getEntity().toString()));
-        checkGrammars(doc.getDocumentElement(), "thebook", "thebook2", "thechapter");
+        checkGrammars(doc.getDocumentElement(), "thebook", "thebook2", "thechapter", false);
         List<Element> els = getWadlResourcesInfo(doc, "http://localhost:8080/baz",
1);
         checkBookStoreInfo(els.get(0), "prefix1:thebook", "prefix1:thebook2", "prefix1:thechapter");
     }
@@ -235,7 +235,7 @@ public class WadlGeneratorTest extends A
         Response r = wg.handleRequest(m, cri);
         checkResponse(r);
         Document doc = DOMUtils.readXml(new StringReader(r.getEntity().toString()));
-        checkGrammars(doc.getDocumentElement(), "book", "book2", "chapter");
+        checkGrammars(doc.getDocumentElement(), "book", "book2", "chapter", false);
         List<Element> els = getWadlResourcesInfo(doc, "http://localhost:8080/baz",
1);
         checkBookStoreInfo(els.get(0), "prefix1:book", "prefix1:book2", "prefix1:chapter");
     }
@@ -253,7 +253,7 @@ public class WadlGeneratorTest extends A
         checkResponse(r);
         Document doc = DOMUtils.readXml(new StringReader(r.getEntity().toString()));
         checkDocs(doc.getDocumentElement(), "My Application", "", "");
-        checkGrammars(doc.getDocumentElement(), "thebook", "thebook2", "thechapter");
+        checkGrammars(doc.getDocumentElement(), "thebook", "thebook2", "thechapter", true);
         List<Element> els = getWadlResourcesInfo(doc, "http://localhost:8080/baz",
1);
         checkBookStoreInfo(els.get(0), "ns1:thebook", "ns1:thebook2", "ns1:thechapter");
     }
@@ -309,7 +309,7 @@ public class WadlGeneratorTest extends A
         
         verifyParameters(resourceEls.get(0), 1, new Param("id", "template", "xs:int"));
         
-        checkGrammars(doc.getDocumentElement(), "thebook", null, "thechapter");
+        checkGrammars(doc.getDocumentElement(), "thebook", null, "thechapter", false);
     }
     
     private void checkResponse(Response r) throws Exception {
@@ -342,16 +342,16 @@ public class WadlGeneratorTest extends A
         assertEquals(WadlGenerator.WADL_TYPE.toString(),
                      r.getMetadata().getFirst(HttpHeaders.CONTENT_TYPE));
         String wadl = r.getEntity().toString();
-        //System.out.println(wadl);
         Document doc = DOMUtils.readXml(new StringReader(wadl));
-        checkGrammars(doc.getDocumentElement(), "thebook", "thebook2", "thechapter");
+        checkGrammars(doc.getDocumentElement(), "thebook", "thebook2", "thechapter", true);
         List<Element> els = getWadlResourcesInfo(doc, "http://localhost:8080/baz",
2);
         checkBookStoreInfo(els.get(0), "prefix1:thebook", "prefix1:thebook2", "prefix1:thechapter");
         Element orderResource = els.get(1);
         assertEquals("/orders", orderResource.getAttribute("path"));
     }
 
-    private void checkGrammars(Element appElement, String bookEl, String book2El, String
chapterEl) {
+    private void checkGrammars(Element appElement, String bookEl, String book2El, String
chapterEl, 
+                               boolean customPrefix) {
         List<Element> grammarEls = DOMUtils.getChildrenWithName(appElement, WadlGenerator.WADL_NS,

                                                                 "grammars");
         assertEquals(1, grammarEls.size());
@@ -365,11 +365,12 @@ public class WadlGeneratorTest extends A
         int size = book2El == null ? 2 : 3;
         
         assertEquals(size, elementEls.size());
-        assertTrue(checkElement(elementEls, bookEl, "tns:book"));
+        String prefix = !customPrefix ? "tns" : "os";
+        assertTrue(checkElement(elementEls, bookEl, prefix + ":book"));
         if (book2El != null) {
-            assertTrue(checkElement(elementEls, book2El, "tns:book2"));
+            assertTrue(checkElement(elementEls, book2El, prefix + ":book2"));
         }
-        assertTrue(checkElement(elementEls, chapterEl, "tns:chapter"));
+        assertTrue(checkElement(elementEls, chapterEl, prefix + ":chapter"));
         
         List<Element> complexTypesEls = DOMUtils.getChildrenWithName(schemasEls.get(0),

                                         XmlSchemaConstants.XSD_NAMESPACE_URI, "complexType");

Modified: cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/JAXBElementProviderTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/JAXBElementProviderTest.java?rev=1349738&r1=1349737&r2=1349738&view=diff
==============================================================================
--- cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/JAXBElementProviderTest.java
(original)
+++ cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/JAXBElementProviderTest.java
Wed Jun 13 10:36:04 2012
@@ -68,7 +68,6 @@ import org.w3c.dom.Node;
 import org.xml.sax.ContentHandler;
 
 import org.apache.cxf.endpoint.Endpoint;
-import org.apache.cxf.helpers.CastUtils;
 import org.apache.cxf.jaxrs.ext.MessageContextImpl;
 import org.apache.cxf.jaxrs.ext.xml.XMLSource;
 import org.apache.cxf.jaxrs.fortest.jaxb.packageinfo.Book2;

Modified: cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/JSONProviderTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/JSONProviderTest.java?rev=1349738&r1=1349737&r2=1349738&view=diff
==============================================================================
--- cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/JSONProviderTest.java
(original)
+++ cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/JSONProviderTest.java
Wed Jun 13 10:36:04 2012
@@ -603,7 +603,7 @@ public class JSONProviderTest extends As
                   MediaType.APPLICATION_JSON_TYPE, new MetadataMap<String, Object>(),
os);
         
         String s = os.toString();
-        assertEquals("{\"ns1.thetag\":{\"group\":\"b\",\"name\":\"a\"}}", s);
+        assertEquals("{\"ns2.thetag\":{\"group\":\"b\",\"name\":\"a\"}}", s);
         
     }
     
@@ -987,6 +987,19 @@ public class JSONProviderTest extends As
     }
  
     @Test
+    public void testWriteWithXmlRootElementAndPackageInfo() throws Exception {
+        JSONProvider provider = new JSONProvider();
+        org.apache.cxf.jaxrs.fortest.jaxb.packageinfo.Book2 book = 
+            new org.apache.cxf.jaxrs.fortest.jaxb.packageinfo.Book2(333);
+        ByteArrayOutputStream bos = new ByteArrayOutputStream();
+        provider.writeTo(book, org.apache.cxf.jaxrs.fortest.jaxb.packageinfo.Book2.class,

+                         org.apache.cxf.jaxrs.fortest.jaxb.packageinfo.Book2.class,
+                         new Annotation[0], MediaType.APPLICATION_JSON_TYPE, 
+                         new MetadataMap<String, Object>(), bos);
+        assertEquals("{\"os.thebook2\":{\"id\":333}}", bos.toString());
+    }
+
+    @Test
     public void testDropElements() throws Exception {
         JSONProvider provider = new JSONProvider();
         List<String> list = new ArrayList<String>();
@@ -1062,7 +1075,7 @@ public class JSONProviderTest extends As
         ByteArrayOutputStream bos = new ByteArrayOutputStream();
         provider.writeTo(tag, TagVO2.class, TagVO2.class,
                        new Annotation[0], MediaType.TEXT_XML_TYPE, new MetadataMap<String,
Object>(), bos);
-        String expected = "{\"ns1.t\":{\"ns1.thetag\":{\"group\":\"B\",\"name\":\"A\"}}}";
+        String expected = "{\"ns2.t\":{\"ns2.thetag\":{\"group\":\"B\",\"name\":\"A\"}}}";
         assertEquals(expected, bos.toString());
     }
     
@@ -1076,7 +1089,7 @@ public class JSONProviderTest extends As
         ByteArrayOutputStream bos = new ByteArrayOutputStream();
         provider.writeTo(tag, TagVO2.class, TagVO2.class,
                        new Annotation[0], MediaType.TEXT_XML_TYPE, new MetadataMap<String,
Object>(), bos);
-        String expected = "{\"ps1.t\":{\"ns1.thetag\":{\"group\":\"B\",\"name\":\"A\"}}}";
+        String expected = "{\"ps1.t\":{\"ns2.thetag\":{\"group\":\"B\",\"name\":\"A\"}}}";
         assertEquals(expected, bos.toString());
     }
     



Mime
View raw message