cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1072736 - in /cxf/trunk/rt/frontend/jaxrs/src: main/java/org/apache/cxf/jaxrs/provider/ test/java/org/apache/cxf/jaxrs/fortest/jaxb/packageinfo/ test/java/org/apache/cxf/jaxrs/provider/ test/java/org/apache/cxf/jaxrs/resources/
Date Sun, 20 Feb 2011 21:30:37 GMT
Author: sergeyb
Date: Sun Feb 20 21:30:36 2011
New Revision: 1072736

URL: http://svn.apache.org/viewvc?rev=1072736&view=rev
Log:
[CXF-3351] Getting the readers from the message and checking the package namespace

Added:
    cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/fortest/jaxb/packageinfo/Book2NoRootElement.java
  (with props)
    cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/resources/BookNoRootElement.java
  (with props)
Modified:
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AbstractJAXBProvider.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JAXBElementProvider.java
    cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/JAXBElementProviderTest.java

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AbstractJAXBProvider.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AbstractJAXBProvider.java?rev=1072736&r1=1072735&r2=1072736&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AbstractJAXBProvider.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AbstractJAXBProvider.java
Sun Feb 20 21:30:36 2011
@@ -197,7 +197,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);
@@ -274,10 +275,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);
@@ -316,6 +314,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/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JAXBElementProvider.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JAXBElementProvider.java?rev=1072736&r1=1072735&r2=1072736&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JAXBElementProvider.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JAXBElementProvider.java
Sun Feb 20 21:30:36 2011
@@ -153,7 +153,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);
             }

Added: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/fortest/jaxb/packageinfo/Book2NoRootElement.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/fortest/jaxb/packageinfo/Book2NoRootElement.java?rev=1072736&view=auto
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/fortest/jaxb/packageinfo/Book2NoRootElement.java
(added)
+++ cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/fortest/jaxb/packageinfo/Book2NoRootElement.java
Sun Feb 20 21:30:36 2011
@@ -0,0 +1,40 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cxf.jaxrs.fortest.jaxb.packageinfo;
+
+
+public class Book2NoRootElement {
+
+    private int id;
+    
+    public Book2NoRootElement() {
+    }
+    
+    public Book2NoRootElement(int id) {
+        this.id = id;
+    }
+    
+    public int getId() {
+        return id;
+    }
+    
+    public void setId(int ident) {
+        id = ident;
+    }
+}

Propchange: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/fortest/jaxb/packageinfo/Book2NoRootElement.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/fortest/jaxb/packageinfo/Book2NoRootElement.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/JAXBElementProviderTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/JAXBElementProviderTest.java?rev=1072736&r1=1072735&r2=1072736&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/JAXBElementProviderTest.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/JAXBElementProviderTest.java
Sun Feb 20 21:30:36 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) {

Added: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/resources/BookNoRootElement.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/resources/BookNoRootElement.java?rev=1072736&view=auto
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/resources/BookNoRootElement.java
(added)
+++ cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/resources/BookNoRootElement.java
Sun Feb 20 21:30:36 2011
@@ -0,0 +1,51 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.cxf.jaxrs.resources;
+
+
+
+public class BookNoRootElement {
+    private String name;
+    private long id;
+    
+    public BookNoRootElement() {
+    }
+    
+    public BookNoRootElement(String name, long id) {
+        this.name = name;
+        this.id = id;
+    }
+    
+    public void setName(String n) {
+        name = n;
+    }
+
+    public String getName() {
+        return name;
+    }
+    
+    public void setId(long i) {
+        id = i;
+    }
+    public long getId() {
+        return id;
+    }
+    
+}

Propchange: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/resources/BookNoRootElement.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/resources/BookNoRootElement.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date



Mime
View raw message