cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1349725 - in /cxf/branches/2.6.x-fixes: ./ rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/fortest/jaxb/packageinfo/ rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/ rt/rs/extensions/providers/src/main/java/org/apache/...
Date Wed, 13 Jun 2012 10:19:55 GMT
Author: sergeyb
Date: Wed Jun 13 10:19:54 2012
New Revision: 1349725

URL: http://svn.apache.org/viewvc?rev=1349725&view=rev
Log:
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.6.x-fixes/   (props changed)
    cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/fortest/jaxb/packageinfo/package-info.java
    cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/WadlGeneratorTest.java
    cxf/branches/2.6.x-fixes/rt/rs/extensions/providers/src/main/java/org/apache/cxf/jaxrs/provider/json/JSONProvider.java
    cxf/branches/2.6.x-fixes/rt/rs/extensions/providers/src/test/java/org/apache/cxf/jaxrs/provider/json/JSONProviderTest.java
    cxf/branches/2.6.x-fixes/rt/rs/extensions/providers/src/test/java/org/apache/cxf/jaxrs/resources/jaxb/package-info.java

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

Propchange: cxf/branches/2.6.x-fixes/
------------------------------------------------------------------------------
--- svnmerge-integrated (original)
+++ svnmerge-integrated Wed Jun 13 10:19:54 2012
@@ -1 +1 @@
-/cxf/trunk:1-1348209,1348845,1348862,1348866,1349016,1349264,1349307,1349406,1349549
+/cxf/trunk:1-1348209,1348845,1348862,1348866,1349016,1349264,1349307,1349406,1349549,1349714-1349717

Modified: cxf/branches/2.6.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.6.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/fortest/jaxb/packageinfo/package-info.java?rev=1349725&r1=1349724&r2=1349725&view=diff
==============================================================================
--- cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/fortest/jaxb/packageinfo/package-info.java
(original)
+++ cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/fortest/jaxb/packageinfo/package-info.java
Wed Jun 13 10:19:54 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.6.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.6.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/WadlGeneratorTest.java?rev=1349725&r1=1349724&r2=1349725&view=diff
==============================================================================
--- cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/WadlGeneratorTest.java
(original)
+++ cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/WadlGeneratorTest.java
Wed Jun 13 10:19:54 2012
@@ -85,7 +85,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");
     }
@@ -193,7 +193,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");
     }
@@ -211,7 +211,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");
     }
@@ -267,7 +267,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 {
@@ -300,16 +300,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());
@@ -323,11 +323,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.6.x-fixes/rt/rs/extensions/providers/src/main/java/org/apache/cxf/jaxrs/provider/json/JSONProvider.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.6.x-fixes/rt/rs/extensions/providers/src/main/java/org/apache/cxf/jaxrs/provider/json/JSONProvider.java?rev=1349725&r1=1349724&r2=1349725&view=diff
==============================================================================
--- cxf/branches/2.6.x-fixes/rt/rs/extensions/providers/src/main/java/org/apache/cxf/jaxrs/provider/json/JSONProvider.java
(original)
+++ cxf/branches/2.6.x-fixes/rt/rs/extensions/providers/src/main/java/org/apache/cxf/jaxrs/provider/json/JSONProvider.java
Wed Jun 13 10:19:54 2012
@@ -302,7 +302,7 @@ public class JSONProvider<T> extends Abs
             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();
@@ -475,7 +475,7 @@ public class JSONProvider<T> extends Abs
     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());
         }
@@ -512,27 +512,19 @@ public class JSONProvider<T> extends Abs
         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.6.x-fixes/rt/rs/extensions/providers/src/test/java/org/apache/cxf/jaxrs/provider/json/JSONProviderTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.6.x-fixes/rt/rs/extensions/providers/src/test/java/org/apache/cxf/jaxrs/provider/json/JSONProviderTest.java?rev=1349725&r1=1349724&r2=1349725&view=diff
==============================================================================
--- cxf/branches/2.6.x-fixes/rt/rs/extensions/providers/src/test/java/org/apache/cxf/jaxrs/provider/json/JSONProviderTest.java
(original)
+++ cxf/branches/2.6.x-fixes/rt/rs/extensions/providers/src/test/java/org/apache/cxf/jaxrs/provider/json/JSONProviderTest.java
Wed Jun 13 10:19:54 2012
@@ -590,6 +590,7 @@ public class JSONProviderTest extends As
     @Test
     public void testWriteToSingleQualifiedTag2() throws Exception {
         JSONProvider<TagVO2> p = new JSONProvider<TagVO2>();
+        p.setNamespaceMap(Collections.singletonMap("http://tags", "ns1"));
         TagVO2 tag = createTag2("a", "b");
         
         ByteArrayOutputStream os = new ByteArrayOutputStream();
@@ -598,7 +599,6 @@ 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);
         
     }
@@ -997,6 +997,20 @@ public class JSONProviderTest extends As
     
     
     @Test
+    public void testWriteWithXmlRootElementAndPackageInfo() throws Exception {
+        JSONProvider<org.apache.cxf.jaxrs.resources.jaxb.Book2> provider = 
+            new JSONProvider<org.apache.cxf.jaxrs.resources.jaxb.Book2>();
+        org.apache.cxf.jaxrs.resources.jaxb.Book2 book = 
+            new org.apache.cxf.jaxrs.resources.jaxb.Book2(333);
+        ByteArrayOutputStream bos = new ByteArrayOutputStream();
+        provider.writeTo(book, org.apache.cxf.jaxrs.resources.jaxb.Book2.class, 
+                         org.apache.cxf.jaxrs.resources.jaxb.Book2.class,
+                         new Annotation[0], MediaType.APPLICATION_JSON_TYPE, 
+                         new MetadataMap<String, Object>(), bos);
+        assertEquals("{\"os.thebook2\":{\"id\":333}}", bos.toString());
+    }
+    
+    @Test
     public void testDropQualifiedElements() throws Exception {
         JSONProvider<TagVO2> provider = new JSONProvider<TagVO2>();
         List<String> list = new ArrayList<String>();
@@ -1051,7 +1065,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());
     }
     
@@ -1065,7 +1079,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());
     }
     

Modified: cxf/branches/2.6.x-fixes/rt/rs/extensions/providers/src/test/java/org/apache/cxf/jaxrs/resources/jaxb/package-info.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.6.x-fixes/rt/rs/extensions/providers/src/test/java/org/apache/cxf/jaxrs/resources/jaxb/package-info.java?rev=1349725&r1=1349724&r2=1349725&view=diff
==============================================================================
--- cxf/branches/2.6.x-fixes/rt/rs/extensions/providers/src/test/java/org/apache/cxf/jaxrs/resources/jaxb/package-info.java
(original)
+++ cxf/branches/2.6.x-fixes/rt/rs/extensions/providers/src/test/java/org/apache/cxf/jaxrs/resources/jaxb/package-info.java
Wed Jun 13 10:19:54 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.resources.jaxb;
 
+import javax.xml.bind.annotation.XmlNs;
+



Mime
View raw message