cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1072739 - in /cxf/branches/2.3.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/p...
Date Sun, 20 Feb 2011 21:33:18 GMT
Author: sergeyb
Date: Sun Feb 20 21:33:17 2011
New Revision: 1072739

URL: http://svn.apache.org/viewvc?rev=1072739&view=rev
Log:
Merged revisions 1072736 via svnmerge from 
https://svn.apache.org/repos/asf/cxf/trunk

........
  r1072736 | sergeyb | 2011-02-20 21:30:36 +0000 (Sun, 20 Feb 2011) | 1 line
  
  [CXF-3351] Getting the readers from the message and checking the package namespace
........

Added:
    cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/fortest/jaxb/packageinfo/Book2NoRootElement.java
      - copied unchanged from r1072736, cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/fortest/jaxb/packageinfo/Book2NoRootElement.java
    cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/resources/BookNoRootElement.java
      - copied unchanged from r1072736, cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/resources/BookNoRootElement.java
Modified:
    cxf/branches/2.3.x-fixes/   (props changed)
    cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AbstractJAXBProvider.java
    cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JAXBElementProvider.java
    cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/JAXBElementProviderTest.java

Propchange: cxf/branches/2.3.x-fixes/
------------------------------------------------------------------------------
    svn:mergeinfo = /cxf/trunk:1072736

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

Modified: cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AbstractJAXBProvider.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AbstractJAXBProvider.java?rev=1072739&r1=1072738&r2=1072739&view=diff
==============================================================================
--- cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AbstractJAXBProvider.java
(original)
+++ cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AbstractJAXBProvider.java
Sun Feb 20 21:33:17 2011
@@ -207,7 +207,8 @@ public abstract class AbstractJAXBProvid
             }
         }
         if (name == null && marshalAsJaxbElement) {
-            name = JAXRSUtils.convertStringToQName(cls.getSimpleName());
+            name = new QName(getPackageNamespace(cls),
+                             cls.getSimpleName());
         }
         if (name != null) {
             return new JAXBElement(name, cls, null, obj);
@@ -284,10 +285,7 @@ public abstract class AbstractJAXBProvid
         if (root != null) {
             String namespace = getNamespace(root.namespace());
             if ("".equals(namespace)) {
-                String packageNs = JAXBUtils.getPackageNamespace(cls);
-                if (packageNs != null) {
-                    namespace = getNamespace(packageNs);
-                }
+                namespace = getPackageNamespace(cls);
             }
             String name = getLocalName(root.name(), cls.getSimpleName(), pluralName);
             return new QName(namespace, name);
@@ -326,6 +324,11 @@ public abstract class AbstractJAXBProvid
         return name;
     }
     
+    private String getPackageNamespace(Class<?> cls) {
+        String packageNs = JAXBUtils.getPackageNamespace(cls);
+        return packageNs != null ? getNamespace(packageNs) : "";
+    }
+    
     private String getNamespace(String namespace) {
         if (JAXB_DEFAULT_NAMESPACE.equals(namespace)) {
             return "";

Modified: cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JAXBElementProvider.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JAXBElementProvider.java?rev=1072739&r1=1072738&r2=1072739&view=diff
==============================================================================
--- cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JAXBElementProvider.java
(original)
+++ cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JAXBElementProvider.java
Sun Feb 20 21:33:17 2011
@@ -152,7 +152,10 @@ public class JAXBElementProvider extends
             if (JAXBElement.class.isAssignableFrom(type) 
                 || unmarshalAsJaxbElement 
                 || jaxbElementClassMap != null && jaxbElementClassMap.containsKey(theType.getName()))
{
-                response = unmarshaller.unmarshal(StaxUtils.createXMLStreamReader(is), theType);
+                XMLStreamReader reader = getStreamReader(is, type, mt);
+                response = unmarshaller.unmarshal(
+                     TransformUtils.createNewReaderIfNeeded(reader, is), 
+                     theType);
             } else {
                 response = doUnmarshal(unmarshaller, type, is, mt);
             }

Modified: cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/JAXBElementProviderTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/JAXBElementProviderTest.java?rev=1072739&r1=1072738&r2=1072739&view=diff
==============================================================================
--- cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/JAXBElementProviderTest.java
(original)
+++ cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/JAXBElementProviderTest.java
Sun Feb 20 21:33:17 2011
@@ -62,10 +62,12 @@ import org.w3c.dom.Node;
 
 import org.xml.sax.ContentHandler;
 
+import org.apache.cxf.jaxrs.fortest.jaxb.packageinfo.Book2NoRootElement;
 import org.apache.cxf.jaxrs.impl.MetadataMap;
 import org.apache.cxf.jaxrs.model.ClassResourceInfo;
 import org.apache.cxf.jaxrs.provider.index.TestBean;
 import org.apache.cxf.jaxrs.resources.Book;
+import org.apache.cxf.jaxrs.resources.BookNoRootElement;
 import org.apache.cxf.jaxrs.resources.BookStore;
 import org.apache.cxf.jaxrs.resources.CollectionsResource;
 import org.apache.cxf.jaxrs.resources.ManyTags;
@@ -303,6 +305,28 @@ public class JAXBElementProviderTest ext
         readSuperBook2(bos.toString(), false);
     }
     
+    @SuppressWarnings("unchecked")
+    @Test
+    public void testWriteWithoutXmlRootElementWithPackageInfo() throws Exception {
+        JAXBElementProvider provider = new JAXBElementProvider();
+        provider.setMarshallAsJaxbElement(true);
+        Book2NoRootElement book = new Book2NoRootElement(333);
+        ByteArrayOutputStream bos = new ByteArrayOutputStream();
+        provider.writeTo(book, Book2NoRootElement.class, 
+                         Book2NoRootElement.class,
+                         new Annotation[0], MediaType.TEXT_XML_TYPE, 
+                         new MetadataMap<String, Object>(), bos);
+        provider.setUnmarshallAsJaxbElement(true);
+        
+        ByteArrayInputStream is = new ByteArrayInputStream(bos.toByteArray());
+        Book2NoRootElement book2 = 
+            (Book2NoRootElement)provider.readFrom(
+                       (Class)Book2NoRootElement.class, 
+                       Book2NoRootElement.class,
+                       new Annotation[0], MediaType.TEXT_XML_TYPE, new MetadataMap<String,
String>(), is);
+        assertEquals(book2.getId(), book.getId());
+    }
+    
     @Test
     @SuppressWarnings("unchecked")
     public void testWriteWithoutXmlRootElementObjectFactory() throws Exception {
@@ -342,6 +366,40 @@ public class JAXBElementProviderTest ext
     }
     
     @SuppressWarnings("unchecked")
+    @Test
+    public void testReadSuperBookWithJaxbElement() throws Exception {
+        final String data = "<BookNoRootElement>"
+            + "<name>superbook</name><id>111</id>" 
+            + "</BookNoRootElement>";
+        JAXBElementProvider provider = new JAXBElementProvider();
+        provider.setUnmarshallAsJaxbElement(true);
+        ByteArrayInputStream is = new ByteArrayInputStream(data.getBytes());
+        BookNoRootElement book = (BookNoRootElement)provider.readFrom(
+                       (Class)BookNoRootElement.class, BookNoRootElement.class,
+                       new Annotation[0], MediaType.TEXT_XML_TYPE, new MetadataMap<String,
String>(), is);
+        assertEquals(111L, book.getId());
+        assertEquals("superbook", book.getName());
+    }
+    
+    @SuppressWarnings("unchecked")
+    @Test
+    public void testReadSuperBookWithJaxbElementAndTransform() throws Exception {
+        final String data = "<BookNoRootElement xmlns=\"http://books\">"
+            + "<name>superbook</name><id>111</id>" 
+            + "</BookNoRootElement>";
+        JAXBElementProvider provider = new JAXBElementProvider();
+        provider.setUnmarshallAsJaxbElement(true);
+        provider.setInTransformElements(Collections.singletonMap(
+             "{http://books}*", ""));
+        ByteArrayInputStream is = new ByteArrayInputStream(data.getBytes());
+        BookNoRootElement book = (BookNoRootElement)provider.readFrom(
+                       (Class)BookNoRootElement.class, BookNoRootElement.class,
+                       new Annotation[0], MediaType.TEXT_XML_TYPE, new MetadataMap<String,
String>(), is);
+        assertEquals(111L, book.getId());
+        assertEquals("superbook", book.getName());
+    }
+    
+    @SuppressWarnings("unchecked")
     private void readSuperBook2(String data, boolean unmarshalAsJaxbElement) throws Exception
{
         JAXBElementProvider provider = new JAXBElementProvider();
         if (!unmarshalAsJaxbElement) {



Mime
View raw message