cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r796355 - in /cxf/branches/2.2.x-fixes: ./ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ rt/frontend/ja...
Date Tue, 21 Jul 2009 16:10:00 GMT
Author: sergeyb
Date: Tue Jul 21 16:09:59 2009
New Revision: 796355

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

........
  r796352 | sergeyb | 2009-07-21 16:51:43 +0100 (Tue, 21 Jul 2009) | 1 line
  
  JAXRS : wrapping JAXB objects into JAXBElement, dropping root JSON elements, disabling exception
propogation if needed
........

Added:
    cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/resources/SuperBook.java
      - copied unchanged from r796352, cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/resources/SuperBook.java
Modified:
    cxf/branches/2.2.x-fixes/   (props changed)
    cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSInvoker.java
    cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSInInterceptor.java
    cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JAXBElementProvider.java
    cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JSONProvider.java
    cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java
    cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java
    cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/JAXBElementProviderTest.java
    cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/JSONProviderTest.java
    cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/resources/Book.java
    cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/resources/CollectionsResource.java
    cxf/branches/2.2.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java
    cxf/branches/2.2.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java

Propchange: cxf/branches/2.2.x-fixes/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Tue Jul 21 16:09:59 2009
@@ -1 +1 @@
-/cxf/trunk:782728-782730,783097,783294,783396,784059,784181-784184,784893,784895,785279-785282,785468,785621,785624,785651,785734,785866,786142,786271-786272,786395,786512,786514,786582-786583,786638,786647,786850,787200,787269,787277-787279,787290-787291,787305,787323,787366,787849,788030,788060,788187,788444,788451,788703,788752,788774,788819-788820,789013,789371,789387,789420,789527-789530,789704-789705,789788,789811,789896-789901,790074,790094,790134,790188,790294,790553,790637-790644,790868,791301,791354,791538,791753,791947,792007,792096,792183,792261-792265,792271,792604,792683-792685,792975,792985,793059,793570,794297,794396,794680,794728,794771,794778-794780,794892,795044,795104,795160,795583,795907,796022-796023
+/cxf/trunk:782728-782730,783097,783294,783396,784059,784181-784184,784893,784895,785279-785282,785468,785621,785624,785651,785734,785866,786142,786271-786272,786395,786512,786514,786582-786583,786638,786647,786850,787200,787269,787277-787279,787290-787291,787305,787323,787366,787849,788030,788060,788187,788444,788451,788703,788752,788774,788819-788820,789013,789371,789387,789420,789527-789530,789704-789705,789788,789811,789896-789901,790074,790094,790134,790188,790294,790553,790637-790644,790868,791301,791354,791538,791753,791947,792007,792096,792183,792261-792265,792271,792604,792683-792685,792975,792985,793059,793570,794297,794396,794680,794728,794771,794778-794780,794892,795044,795104,795160,795583,795907,796022-796023,796352

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

Modified: cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSInvoker.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSInvoker.java?rev=796355&r1=796354&r2=796355&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSInvoker.java
(original)
+++ cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSInvoker.java
Tue Jul 21 16:09:59 2009
@@ -126,7 +126,8 @@
                 if (criRoot != null) {
                     criRoot.clearThreadLocalProxies();
                 }
-                exchange.put(Message.PROPOGATE_EXCEPTION, Boolean.TRUE);
+                exchange.put(Message.PROPOGATE_EXCEPTION, 
+                             JAXRSUtils.propogateException(exchange.getInMessage()));
                 throw ex;
             }
             return new MessageContentsList(excResponse);

Modified: cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSInInterceptor.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSInInterceptor.java?rev=796355&r1=796354&r2=796355&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSInInterceptor.java
(original)
+++ cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSInInterceptor.java
Tue Jul 21 16:09:59 2009
@@ -54,7 +54,7 @@
 
     private static final Logger LOG = LogUtils.getL7dLogger(JAXRSInInterceptor.class);
     private static final ResourceBundle BUNDLE = BundleUtils.getBundle(JAXRSInInterceptor.class);
-
+    
     public JAXRSInInterceptor() {
         super(Phase.UNMARSHAL);
     }
@@ -67,7 +67,8 @@
             Response excResponse = JAXRSUtils.convertFaultToResponse(ex, message);
             if (excResponse == null) {
                 ProviderFactory.getInstance(message).clearThreadLocalProxies();
-                message.getExchange().put(Message.PROPOGATE_EXCEPTION, Boolean.TRUE);
+                message.getExchange().put(Message.PROPOGATE_EXCEPTION, 
+                                          JAXRSUtils.propogateException(message));
                 throw ex;
             }
             message.getExchange().put(Response.class, excResponse);

Modified: cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JAXBElementProvider.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JAXBElementProvider.java?rev=796355&r1=796354&r2=796355&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JAXBElementProvider.java
(original)
+++ cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JAXBElementProvider.java
Tue Jul 21 16:09:59 2009
@@ -72,6 +72,7 @@
     private Map<String, Object> mProperties = new HashMap<String, Object>();
     private boolean enableStreaming;
     private ValidationEventHandler eventHandler;
+    private List<String> jaxbElementClassNames;
     
     @Override
     public boolean isReadable(Class<?> type, Type genericType, Annotation[] anns, MediaType
mt) {
@@ -91,6 +92,10 @@
         super.setContext(mc);
     }
     
+    public void setJaxbElementClassNames(List<String> names) {
+        jaxbElementClassNames = names;
+    }
+    
     public void setValidationHandler(ValidationEventHandler handler) {
         eventHandler = handler;
     }
@@ -224,7 +229,16 @@
                                      Type genericType, String encoding, OutputStream os,
MediaType m) 
         throws Exception {
         
-        QName qname = getCollectionWrapperQName(actualClass, genericType, actualObject, true);
+        Object[] arr = originalCls.isArray() ? (Object[])actualObject : ((Collection)actualObject).toArray();
+        
+        QName qname = null;
+        if (arr.length > 0 && arr[0] instanceof JAXBElement) {
+            JAXBElement el = (JAXBElement)arr[0];
+            qname = el.getName();
+            actualClass = el.getDeclaredType();
+        } else {
+            qname = getCollectionWrapperQName(actualClass, genericType, actualObject, true);
+        }
         if (qname == null) {
             String message = new org.apache.cxf.common.i18n.Message("NO_COLLECTION_ROOT",

                                                                     BUNDLE).toString();
@@ -243,10 +257,9 @@
             endTag = "</" + qname.getLocalPart() + ">";
         }
         os.write(startTag.getBytes());
-        Object[] arr = originalCls.isArray() ? (Object[])actualObject : ((Collection)actualObject).toArray();
         for (Object o : arr) {
-            marshalCollectionMember(o, actualClass, genericType, encoding, os, m, 
-                                    qname.getNamespaceURI());    
+            marshalCollectionMember(o instanceof JAXBElement ? ((JAXBElement)o).getValue()
: o, 
+                                    actualClass, genericType, encoding, os, m, qname.getNamespaceURI());
   
         }
         os.write(endTag.getBytes());
     }
@@ -269,6 +282,17 @@
     
     protected void marshal(Object obj, Class<?> cls, Type genericType, 
                            String enc, OutputStream os, MediaType mt) throws Exception {
+        
+        if (jaxbElementClassNames != null && jaxbElementClassNames.contains(cls.getName()))
{
+            QName name = getJaxbQName(cls, genericType, obj, false);
+            if (name != null) {
+                @SuppressWarnings("unchecked")
+                JAXBElement el = new JAXBElement(name, cls, null, obj);
+                obj = el;
+                cls = JAXBElement.class;
+            }
+        }
+        
         Marshaller ms = createMarshaller(obj, cls, genericType, enc);
         marshal(obj, cls, genericType, enc, os, mt, ms);
     }

Modified: cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JSONProvider.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JSONProvider.java?rev=796355&r1=796354&r2=796355&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JSONProvider.java
(original)
+++ cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JSONProvider.java
Tue Jul 21 16:09:59 2009
@@ -72,12 +72,22 @@
     private boolean unwrapped;
     private String wrapperName;
     private Map<String, String> wrapperMap;
+    private boolean dropRootElement;
+    private boolean dropCollectionWrapperElement;
     
     @Context
     public void setMessageContext(MessageContext mc) {
         super.setContext(mc);
     }
     
+    public void setDropRootElement(boolean drop) {
+        this.dropRootElement = drop;
+    }
+    
+    public void setDropCollectionWrapperElement(boolean drop) {
+        this.dropCollectionWrapperElement = drop;
+    }
+    
     public void setSupportUnwrapped(boolean unwrap) {
         this.unwrapped = unwrap;
     }
@@ -131,7 +141,7 @@
             Unmarshaller unmarshaller = createUnmarshaller(theType, genericType);
             
             InputStream realStream = getInputStream(type, genericType, is);
-            XMLStreamReader xsw = getStreamReader(type, realStream);
+            XMLStreamReader xsw = createReader(type, realStream);
             
             Object response = null;
             if (JAXBElement.class.isAssignableFrom(type)) {
@@ -155,7 +165,7 @@
         return null;
     }
 
-    protected XMLStreamReader getStreamReader(Class<?> type, InputStream is) 
+    protected XMLStreamReader createReader(Class<?> type, InputStream is) 
         throws Exception {
         MappedXMLInputFactory factory = new MappedXMLInputFactory(namespaceMap);
         return factory.createXMLStreamReader(is);
@@ -246,21 +256,26 @@
                                      Type genericType, String encoding, OutputStream os,
MediaType m) 
         throws Exception {
         
-        QName qname = getCollectionWrapperQName(actualClass, genericType, actualObject, false);
-        if (qname == null) {
-            String message = new org.apache.cxf.common.i18n.Message("NO_COLLECTION_ROOT",

-                                                                    BUNDLE).toString();
-            throw new WebApplicationException(Response.serverError()
-                                              .entity(message).build());
-        }
         String startTag = null;
         String endTag = null;
-        if (qname.getNamespaceURI().length() > 0) {
-            startTag = "{\"ns1." + qname.getLocalPart() + "\":[";
+        if (!dropCollectionWrapperElement) {
+            QName qname = getCollectionWrapperQName(actualClass, genericType, actualObject,
false);
+            if (qname == null) {
+                String message = new org.apache.cxf.common.i18n.Message("NO_COLLECTION_ROOT",

+                                                                        BUNDLE).toString();
+                throw new WebApplicationException(Response.serverError()
+                                                  .entity(message).build());
+            }
+            if (qname.getNamespaceURI().length() > 0) {
+                startTag = "{\"ns1." + qname.getLocalPart() + "\":[";
+            } else {
+                startTag = "{\"" + qname.getLocalPart() + "\":[";
+            }
+            endTag = "]}";
         } else {
-            startTag = "{\"" + qname.getLocalPart() + "\":[";
+            startTag = "{";
+            endTag = "}";
         }
-        endTag = "]}";
         os.write(startTag.getBytes());
         Object[] arr = originalCls.isArray() ? (Object[])actualObject : ((Collection)actualObject).toArray();
         for (int i = 0; i < arr.length; i++) {
@@ -275,12 +290,21 @@
     
     protected void marshal(Marshaller ms, Object actualObject, Class<?> actualClass,

                   Type genericType, String enc, OutputStream os, boolean isCollection) throws
Exception {
+        
+        XMLStreamWriter writer = createWriter(actualObject, actualClass, genericType, enc,

+                                              os, isCollection);
+        ms.marshal(actualObject, writer);
+        writer.close();
+    }
+    
+    protected XMLStreamWriter createWriter(Object actualObject, Class<?> actualClass,

+        Type genericType, String enc, OutputStream os, boolean isCollection) throws Exception
{
         QName qname = getQName(actualClass, genericType, actualObject, true);
         Configuration c = new Configuration(namespaceMap);
         MappedNamespaceConvention convention = new MappedNamespaceConvention(c);
         AbstractXMLStreamWriter xsw = new MappedXMLStreamWriter(
-                                           convention, 
-                                           new OutputStreamWriter(os, enc));
+                                            convention, 
+                                            new OutputStreamWriter(os, enc));
         if (serializeAsArray) {
             if (arrayKeys != null) {
                 for (String key : arrayKeys) {
@@ -292,13 +316,9 @@
             }
         }
 
-        XMLStreamWriter writer = isCollection ? new JSONCollectionWriter(xsw, qname) : xsw;

-        ms.marshal(actualObject, writer);
-        xsw.close();
+        return isCollection || dropRootElement ? new JSONCollectionWriter(xsw, qname) : xsw;

     }
     
-    
-    
     protected void marshal(Object actualObject, Class<?> actualClass, 
                            Type genericType, String enc, OutputStream os) throws Exception
{
         Marshaller ms = createMarshaller(actualObject, actualClass, genericType, enc);

Modified: cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java?rev=796355&r1=796354&r2=796355&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java
(original)
+++ cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java
Tue Jul 21 16:09:59 2009
@@ -206,8 +206,7 @@
             throw new RuntimeException("No type can be found at position " + pos);
         }
         Type t = types[pos];
-        // we don't recurse at this stage, otherwise GenericEntity won't be handled properly
-        return t instanceof Class ? (Class<?>)t : null;
+        return t instanceof Class ? (Class<?>)t : getActualType(t, pos);
     }
     
     public static Type[] getActualTypes(Type genericType) {

Modified: cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java?rev=796355&r1=796354&r2=796355&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java
(original)
+++ cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java
Tue Jul 21 16:09:59 2009
@@ -97,6 +97,7 @@
     public static final MediaType ALL_TYPES = new MediaType();
     private static final Logger LOG = LogUtils.getL7dLogger(JAXRSUtils.class);
     private static final ResourceBundle BUNDLE = BundleUtils.getBundle(JAXRSUtils.class);
+    private static final String PROPOGATE_EXCEPTION = "org.apache.cxf.propogate.exception";
 
     private JAXRSUtils() {        
     }
@@ -1025,4 +1026,19 @@
         return sb.toString();
     }
         
+    public static boolean propogateException(Message m) {
+        
+        Object value = m.getContextualProperty(PROPOGATE_EXCEPTION);
+        
+        if (value == null) {
+            return true;
+        }
+
+        if (Boolean.TRUE.equals(value) || "true".equalsIgnoreCase(value.toString())) {
+            return true;
+        }
+        
+        return false;
+    }
+    
 }

Modified: cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/JAXBElementProviderTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/JAXBElementProviderTest.java?rev=796355&r1=796354&r2=796355&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/JAXBElementProviderTest.java
(original)
+++ cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/JAXBElementProviderTest.java
Tue Jul 21 16:09:59 2009
@@ -29,6 +29,7 @@
 import java.lang.reflect.Type;
 import java.util.ArrayList;
 import java.util.Collection;
+import java.util.Collections;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.List;
@@ -38,12 +39,14 @@
 
 import javax.ws.rs.core.MediaType;
 import javax.xml.bind.JAXBContext;
+import javax.xml.bind.JAXBElement;
 import javax.xml.bind.JAXBException;
 import javax.xml.bind.Marshaller;
 import javax.xml.bind.PropertyException;
 import javax.xml.bind.ValidationEventHandler;
 import javax.xml.bind.annotation.adapters.XmlAdapter;
 import javax.xml.bind.attachment.AttachmentMarshaller;
+import javax.xml.namespace.QName;
 import javax.xml.stream.XMLEventWriter;
 import javax.xml.stream.XMLStreamWriter;
 import javax.xml.transform.Result;
@@ -56,6 +59,7 @@
 import org.apache.cxf.jaxrs.impl.MetadataMap;
 import org.apache.cxf.jaxrs.resources.Book;
 import org.apache.cxf.jaxrs.resources.CollectionsResource;
+import org.apache.cxf.jaxrs.resources.SuperBook;
 import org.apache.cxf.jaxrs.resources.TagVO2;
 
 import org.junit.Assert;
@@ -78,10 +82,15 @@
         testIsWriteableCollection("getBookSet");
     }
     
+    @Test
+    public void testIsWriteableJAXBElements() throws Exception {
+        testIsWriteableCollection("getBookElements");
+    }
+    
     private void testIsWriteableCollection(String mName) throws Exception {
         JAXBElementProvider provider = new JAXBElementProvider();
         provider.setCollectionWrapperName("foo");
-        Method m = CollectionsResource.class.getMethod("getBooks", new Class[0]);
+        Method m = CollectionsResource.class.getMethod(mName, new Class[0]);
         assertTrue(provider.isWriteable(m.getReturnType(), m.getGenericReturnType(),
                              new Annotation[0], MediaType.TEXT_XML_TYPE));
     }
@@ -132,6 +141,65 @@
     }
     
     @Test
+    public void testWriteJAXBElementCollection() throws Exception {
+        doTestWriteJAXBCollection("getBookElements");
+    }
+    
+    @Test
+    public void testWriteJAXBElementCollection2() throws Exception {
+        doTestWriteJAXBCollection("getBookElements2");
+    }
+    
+    @Test
+    public void testWriteDerivedType() throws Exception {
+        JAXBElementProvider provider = new JAXBElementProvider();
+        provider.setJaxbElementClassNames(Collections.singletonList(Book.class.getName()));
+        Book b = new SuperBook("CXF in Action", 123L, 124L);
+        
+        ByteArrayOutputStream bos = new ByteArrayOutputStream();
+        provider.writeTo(b, Book.class, Book.class,
+                       new Annotation[0], MediaType.TEXT_XML_TYPE, new MetadataMap<String,
Object>(), bos);
+        readSuperBook(bos.toString());
+    }
+    
+    @Test
+    public void testWriteDerivedType2() throws Exception {
+        JAXBElementProvider provider = new JAXBElementProvider();
+        Book b = new SuperBook("CXF in Action", 123L, 124L);
+        
+        ByteArrayOutputStream bos = new ByteArrayOutputStream();
+        provider.writeTo(b, Book.class, Book.class,
+                       new Annotation[0], MediaType.TEXT_XML_TYPE, new MetadataMap<String,
Object>(), bos);
+        
+        readSuperBook(bos.toString());
+    }
+    
+    @SuppressWarnings("unchecked")
+    private void readSuperBook(String data) throws Exception {
+        JAXBElementProvider provider = new JAXBElementProvider();
+        ByteArrayInputStream is = new ByteArrayInputStream(data.getBytes());
+        SuperBook book = (SuperBook)provider.readFrom(
+                       (Class)SuperBook.class, SuperBook.class,
+                       new Annotation[0], MediaType.TEXT_XML_TYPE, new MetadataMap<String,
String>(), is);
+        assertEquals(124L, book.getSuperId());
+    }
+    
+    private void doTestWriteJAXBCollection(String mName) throws Exception {
+        JAXBElementProvider provider = new JAXBElementProvider();
+        List<JAXBElement<Book>> books = new ArrayList<JAXBElement<Book>>();
+        books.add(new JAXBElement<Book>(new QName("Books"), Book.class, null, 
+            new Book("CXF in Action", 123L)));
+        books.add(new JAXBElement<Book>(new QName("Books"), Book.class, null, 
+            new Book("CXF Rocks", 124L)));
+        
+        Method m = CollectionsResource.class.getMethod(mName, new Class[0]);
+        ByteArrayOutputStream bos = new ByteArrayOutputStream();
+        provider.writeTo(books, m.getReturnType(), m.getGenericReturnType(),
+                       new Annotation[0], MediaType.TEXT_XML_TYPE, new MetadataMap<String,
Object>(), bos);
+        doReadUnqualifiedCollection(bos.toString(), "setBooks", List.class);
+    }
+    
+    @Test
     public void testWriteQualifiedCollection() throws Exception {
         JAXBElementProvider provider = new JAXBElementProvider();
         provider.setCollectionWrapperName("{http://tags}tags");
@@ -168,8 +236,13 @@
             assertEquals(2, ((Book[])o).length);
             b1 = ((Book[])o)[0];
             b2 = ((Book[])o)[1];
+        } else if (type == Set.class) {
+            Set<Book> set = (Set)o;
+            List<Book> books = new ArrayList<Book>(new TreeSet<Book>(set));
+            b1 = books.get(0);
+            b2 = books.get(1);
         } else {
-            List<Book> books = type == Set.class ? new ArrayList<Book>(new TreeSet((Set)o))
: (List<Book>)o;
+            List<Book> books = (List<Book>)o;
             b1 = books.get(0);
             b2 = books.get(1);
         }

Modified: cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/JSONProviderTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/JSONProviderTest.java?rev=796355&r1=796354&r2=796355&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/JSONProviderTest.java
(original)
+++ cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/JSONProviderTest.java
Tue Jul 21 16:09:59 2009
@@ -162,13 +162,45 @@
         
         String s = os.toString();
         assertEquals("{\"ns1.thetag\":{\"group\":\"b\",\"name\":\"a\"}}", s);
+    }
+    
+    @Test
+    public void testDropRootElement() throws Exception {
+        JSONProvider p = new JSONProvider();
+        p.setDropRootElement(true);
+        Map<String, String> namespaceMap = new HashMap<String, String>();
+        namespaceMap.put("http://tags", "ns1");
+        p.setNamespaceMap(namespaceMap);
+        TagVO2 tag = createTag2("a", "b");
+        
+        ByteArrayOutputStream os = new ByteArrayOutputStream();
+        
+        p.writeTo(tag, (Class)TagVO2.class, TagVO2.class, TagVO2.class.getAnnotations(),

+                  MediaType.APPLICATION_JSON_TYPE, new MetadataMap<String, Object>(),
os);
+        
+        String s = os.toString();
+        assertEquals("{\"group\":\"b\",\"name\":\"a\"}", s);
         
     }
     
     @Test
     public void testWriteQualifiedCollection() throws Exception {
+        String data = "{\"ns1.tag\":[{\"group\":\"b\",\"name\":\"a\"}"
+            + ",{\"group\":\"d\",\"name\":\"c\"}]}";
+        doWriteQualifiedCollection(false, data);
+    }
+    
+    @Test
+    public void testWriteQualifiedCollection2() throws Exception {
+        String data = "{{\"group\":\"b\",\"name\":\"a\"}"
+            + ",{\"group\":\"d\",\"name\":\"c\"}}";
+        doWriteQualifiedCollection(true, data);
+    }
+    
+    public void doWriteQualifiedCollection(boolean drop, String data) throws Exception {
         JSONProvider p = new JSONProvider();
         p.setCollectionWrapperName("{http://tags}tag");
+        p.setDropCollectionWrapperElement(drop);
         Map<String, String> namespaceMap = new HashMap<String, String>();
         namespaceMap.put("http://tags", "ns1");
         p.setNamespaceMap(namespaceMap);
@@ -181,8 +213,6 @@
                   MediaType.APPLICATION_JSON_TYPE, new MetadataMap<String, Object>(),
os);
         
         String s = os.toString();
-        String data = "{\"ns1.tag\":[{\"group\":\"b\",\"name\":\"a\"}"
-            + ",{\"group\":\"d\",\"name\":\"c\"}]}";
         assertEquals(s, data);
     }
     

Modified: cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/resources/Book.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/resources/Book.java?rev=796355&r1=796354&r2=796355&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/resources/Book.java
(original)
+++ cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/resources/Book.java
Tue Jul 21 16:09:59 2009
@@ -26,9 +26,11 @@
 import javax.ws.rs.Path;
 import javax.ws.rs.PathParam;
 import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.XmlSeeAlso;
 
 
 @XmlRootElement(name = "Book")
+@XmlSeeAlso({SuperBook.class })
 public class Book implements Comparable<Book> {
     private String name;
     private long id;

Modified: cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/resources/CollectionsResource.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/resources/CollectionsResource.java?rev=796355&r1=796354&r2=796355&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/resources/CollectionsResource.java
(original)
+++ cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/resources/CollectionsResource.java
Tue Jul 21 16:09:59 2009
@@ -24,6 +24,7 @@
 
 import javax.ws.rs.GET;
 import javax.ws.rs.POST;
+import javax.xml.bind.JAXBElement;
 
 public class CollectionsResource {
     @GET
@@ -37,6 +38,16 @@
     }
     
     @GET
+    public List<JAXBElement<Book>> getBookElements() {
+        return null;
+    }
+    
+    @GET
+    public List<JAXBElement> getBookElements2() {
+        return null;
+    }
+    
+    @GET
     public Set<Book> getBookSet() {
         return null;
     }

Modified: cxf/branches/2.2.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java?rev=796355&r1=796354&r2=796355&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java
(original)
+++ cxf/branches/2.2.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java
Tue Jul 21 16:09:59 2009
@@ -60,6 +60,7 @@
 import javax.xml.transform.dom.DOMSource;
 
 import org.apache.cxf.helpers.XMLUtils;
+import org.apache.cxf.phase.PhaseInterceptorChain;
 
 @Path("/bookstore")
 public class BookStore {
@@ -95,6 +96,12 @@
         throw new BookNotFoundFault("Book Exception");
     }
     
+    @GET
+    @Path("propogateexception2")
+    public Book propogateException2() throws BookNotFoundFault {
+        PhaseInterceptorChain.getCurrentMessage().put("org.apache.cxf.propogate.exception",
Boolean.FALSE);
+        throw new BookNotFoundFault("Book Exception");
+    }
     
     @GET
     @Path("books/check/{id}")

Modified: cxf/branches/2.2.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java?rev=796355&r1=796354&r2=796355&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
(original)
+++ cxf/branches/2.2.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
Tue Jul 21 16:09:59 2009
@@ -66,6 +66,16 @@
     }
     
     @Test
+    public void testPropogateException2() throws Exception {
+        String data = "<ns1:XMLFault xmlns:ns1=\"http://cxf.apache.org/bindings/xformat\">"
+            + "<ns1:faultstring xmlns:ns1=\"http://cxf.apache.org/bindings/xformat\">"
+            + "org.apache.cxf.systest.jaxrs.BookNotFoundFault: Book Exception</ns1:faultstring>"
+            + "</ns1:XMLFault>";
+        getAndCompare("http://localhost:9080/bookstore/propogateexception2",
+                      data, "application/xml", 500);
+    }
+    
+    @Test
     public void testWebApplicationException() throws Exception {
         getAndCompare("http://localhost:9080/bookstore/webappexception",
                       "This is a WebApplicationException",



Mime
View raw message