wink-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From r...@apache.org
Subject svn commit: r1023921 - in /incubator/wink/trunk: ./ wink-client/src/test/java/org/apache/wink/client/ wink-common/src/main/java/org/apache/wink/common/internal/model/ wink-common/src/main/java/org/apache/wink/common/internal/providers/entity/json/ wink...
Date Mon, 18 Oct 2010 17:42:47 GMT
Author: rott
Date: Mon Oct 18 17:42:46 2010
New Revision: 1023921

URL: http://svn.apache.org/viewvc?rev=1023921&view=rev
Log:
WINK-321: update dependency to JAXB 2.2 and add support for @XmlJavaTypeAdapter and @XmlElement on JAX-RS resource method params and return types

Modified:
    incubator/wink/trunk/pom.xml
    incubator/wink/trunk/wink-client/src/test/java/org/apache/wink/client/ProvidersTest.java
    incubator/wink/trunk/wink-common/src/main/java/org/apache/wink/common/internal/model/AtomXhtml.java
    incubator/wink/trunk/wink-common/src/main/java/org/apache/wink/common/internal/model/ModelUtils.java
    incubator/wink/trunk/wink-common/src/main/java/org/apache/wink/common/internal/providers/entity/json/JAXBArrayJSONProvider.java
    incubator/wink/trunk/wink-common/src/main/java/org/apache/wink/common/internal/providers/entity/xml/AbstractJAXBCollectionProvider.java
    incubator/wink/trunk/wink-common/src/main/java/org/apache/wink/common/internal/providers/entity/xml/AbstractJAXBProvider.java
    incubator/wink/trunk/wink-common/src/main/java/org/apache/wink/common/internal/providers/entity/xml/JAXBArrayXmlProvider.java
    incubator/wink/trunk/wink-common/src/main/java/org/apache/wink/common/internal/providers/entity/xml/JAXBCollectionXmlProvider.java
    incubator/wink/trunk/wink-common/src/main/java/org/apache/wink/common/internal/providers/entity/xml/JAXBElementXmlProvider.java
    incubator/wink/trunk/wink-common/src/main/java/org/apache/wink/common/internal/providers/entity/xml/JAXBXmlProvider.java
    incubator/wink/trunk/wink-common/src/test/java/org/apache/wink/common/model/rss/RssTest.java

Modified: incubator/wink/trunk/pom.xml
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/pom.xml?rev=1023921&r1=1023920&r2=1023921&view=diff
==============================================================================
--- incubator/wink/trunk/pom.xml (original)
+++ incubator/wink/trunk/pom.xml Mon Oct 18 17:42:46 2010
@@ -234,6 +234,7 @@
                         <encoding>UTF-8</encoding>
                         <showDeprecation>true</showDeprecation>
                         <showWarnings>true</showWarnings>
+                        <compilerArgument>-Xbootclasspath/p:${settings.localRepository}/javax/xml/bind/jaxb-api/2.2/jaxb-api-2.2.jar${path.separator}${settings.localRepository}/com/sun/xml/bind/jaxb-impl/2.2.1.1/jaxb-impl-2.2.1.1.jar</compilerArgument>
                     </configuration>
                 </plugin>
                 <plugin>
@@ -241,6 +242,7 @@
                     <artifactId>maven-surefire-plugin</artifactId>
                     <configuration>
                         <redirectTestOutputToFile>true</redirectTestOutputToFile>
+                        <argline>-Xbootclasspath/p:${settings.localRepository}/javax/xml/bind/jaxb-api/2.2/jaxb-api-2.2.jar${path.separator}${settings.localRepository}/com/sun/xml/bind/jaxb-impl/2.2.1.1/jaxb-impl-2.2.1.1.jar</argline>
                     </configuration>
                 </plugin>
                 <plugin>
@@ -522,12 +524,12 @@
             <dependency>
                 <groupId>javax.xml.bind</groupId>
                 <artifactId>jaxb-api</artifactId>
-                <version>2.1</version>
+                <version>2.2</version>
             </dependency>
             <dependency>
                 <groupId>com.sun.xml.bind</groupId>
                 <artifactId>jaxb-impl</artifactId>
-                <version>2.1.4</version>
+                <version>2.2.1.1</version>
             </dependency>
             <dependency>
                 <groupId>javax.activation</groupId>

Modified: incubator/wink/trunk/wink-client/src/test/java/org/apache/wink/client/ProvidersTest.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-client/src/test/java/org/apache/wink/client/ProvidersTest.java?rev=1023921&r1=1023920&r2=1023921&view=diff
==============================================================================
--- incubator/wink/trunk/wink-client/src/test/java/org/apache/wink/client/ProvidersTest.java (original)
+++ incubator/wink/trunk/wink-client/src/test/java/org/apache/wink/client/ProvidersTest.java Mon Oct 18 17:42:46 2010
@@ -92,6 +92,48 @@ public class ProvidersTest extends TestC
                                                     + "</entry>"
                                                     + "</feed>";
 
+    // apparently JAXB 2.2 reads JAXB bean fields in a different order, and replaces namespace prefixes.  This XML is equivalent to above.
+    private static final String FEED_JAXB_22 = "<feed xmlns=\"http://www.w3.org/2005/Atom\" xmlns:ns2=\"http://a9.com/-/spec/opensearch/1.1/\" xmlns:ns3=\"http://www.w3.org/1999/xhtml\">"
+        + "<id>urn:feed:1</id>"
+        + "<updated>1970-01-02T11:20:00+02:00</updated>"
+        + "<title type=\"text\" xml:lang=\"en\">Title</title>"
+        + "<subtitle type=\"text\" xml:lang=\"en\">Subtitle</subtitle>"
+        + "<link rel=\"self\" href=\"http://localhost:8080/rest/service/feed\"/>"
+        + "<author>"
+        + "<name>John Smith</name>"
+        + "</author>"
+        + "<category term=\"1\" scheme=\"urn:entity:priority\" label=\"lable\"/>"
+        + "<entry>"
+        + "<id>urn:entry2</id>"
+        + "<updated>1970-01-02T11:20:00+02:00</updated>"
+        + "<title type=\"text\" xml:lang=\"en\">Title</title>"
+        + "<summary type=\"text\" xml:lang=\"en\">Title</summary>"
+        + "<published>1970-01-02T11:20:00+02:00</published>"
+        + "<link rel=\"self\" type=\"application/xml\" href=\"http://localhost:8080/rest/service/entry/2\"/>"
+        + "<author>"
+        + "<name>John Smith</name>"
+        + "</author>"
+        + "<category term=\"1\" scheme=\"urn:entity:priority\" label=\"lable\"/>"
+        + "<content type=\"text\">This is entity created by John Smith</content>"
+        + "</entry>"
+        + "<entry>"
+        + "<id>urn:entry3</id>"
+        + "<updated>1970-01-02T11:20:00+02:00</updated>"
+        + "<title type=\"text\" xml:lang=\"en\">Title</title>"
+        + "<summary type=\"text\" xml:lang=\"en\">Title</summary>"
+        + "<published>1970-01-02T11:20:00+02:00</published>"
+        + "<link rel=\"self\" type=\"application/xml\" href=\"http://localhost:8080/rest/service/entry/3\"/>"
+        + "<author>"
+        + "<name>John Smith</name>"
+        + "</author>"
+        + "<category term=\"1\" scheme=\"urn:entity:priority\" label=\"lable\"/>"
+        + "<content type=\"text\">This is entity created by John Smith</content>"
+        + "</entry>"
+        + "<ns2:totalResults>100</ns2:totalResults>"
+        + "<ns2:itemsPerPage>10</ns2:itemsPerPage>"
+        + "<ns2:startIndex>0</ns2:startIndex>"
+        + "</feed>";
+    
     @Override
     protected void setUp() throws Exception {
         super.setUp();
@@ -169,6 +211,9 @@ public class ProvidersTest extends TestC
             String actual = os.toString();
 
             String msg = TestUtils.diffIgnoreUpdateWithAttributeQualifier(FEED, actual);
+            if (msg != null) {
+                msg = TestUtils.diffIgnoreUpdateWithAttributeQualifier(FEED_JAXB_22, actual);
+            }
             assertNull(msg, msg);
         } finally {
             server.stopServer();

Modified: incubator/wink/trunk/wink-common/src/main/java/org/apache/wink/common/internal/model/AtomXhtml.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-common/src/main/java/org/apache/wink/common/internal/model/AtomXhtml.java?rev=1023921&r1=1023920&r2=1023921&view=diff
==============================================================================
--- incubator/wink/trunk/wink-common/src/main/java/org/apache/wink/common/internal/model/AtomXhtml.java (original)
+++ incubator/wink/trunk/wink-common/src/main/java/org/apache/wink/common/internal/model/AtomXhtml.java Mon Oct 18 17:42:46 2010
@@ -28,6 +28,8 @@ import javax.xml.bind.annotation.XmlAnyE
 import javax.xml.bind.annotation.XmlMixed;
 import javax.xml.bind.annotation.XmlType;
 
+import org.apache.wink.common.model.atom.AtomTextType;
+
 /**
  * Used to de-serialize XHTML content.
  */
@@ -47,6 +49,7 @@ public class AtomXhtml {
     }
 
     public List<Object> getAny() {
+        ModelUtils.fixAnyContent(any, AtomTextType.xhtml.name());
         return any;
     }
 

Modified: incubator/wink/trunk/wink-common/src/main/java/org/apache/wink/common/internal/model/ModelUtils.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-common/src/main/java/org/apache/wink/common/internal/model/ModelUtils.java?rev=1023921&r1=1023920&r2=1023921&view=diff
==============================================================================
--- incubator/wink/trunk/wink-common/src/main/java/org/apache/wink/common/internal/model/ModelUtils.java (original)
+++ incubator/wink/trunk/wink-common/src/main/java/org/apache/wink/common/internal/model/ModelUtils.java Mon Oct 18 17:42:46 2010
@@ -384,8 +384,8 @@ public class ModelUtils {
             XmlWrapper xmlWrapper = (XmlWrapper)value;
             if (xmlWrapper.getType() == null) {
                 // fixes type on the XmlWrapper in the case it was not set, it
-                // happens if the same object was unmarsheled, and now is going
-                // to be marsheled back to xml
+                // happens if the same object was unmarshaled, and now is going
+                // to be marshaled back to xml
                 xmlWrapper.setType(type);
             }
         } else if (value.getClass() == String.class && !isTypeXml(type)) {
@@ -394,6 +394,28 @@ public class ModelUtils {
         } else {
             // wrapping with XmlWrapper will cause the Providers code to run
             // xml content won't be escaped
+            
+            // because the list comes from an unmarshal through JAXB, we may have white space nodes
+            // see sample XHTML data in AtomTest.  We need the JAXBElement, not the surrounding white space.
+            for (Object anyValue: any) {
+                if (anyValue instanceof JAXBElement) {
+                    value = anyValue;
+                    break;
+                } else if (anyValue instanceof XmlWrapper) {
+                    XmlWrapper xmlWrapper = (XmlWrapper)anyValue;
+                    if (xmlWrapper.getType() == null) {
+                        // fixes type on the XmlWrapper in the case it was not set, it
+                        // happens if the same object was unmarshaled, and now is going
+                        // to be marshaled back to xml
+                        xmlWrapper.setType(type);
+                    }
+                    // only one child of AtomContent is permitted per Atom spec for XHTML content,
+                    // so let's clear the list, and reset the first item to be the content we care about
+                    any.clear();
+                    any.add(0, xmlWrapper);
+                    return;
+                }
+            }
             any.set(0, new XmlWrapper(value, type));
         }
     }

Modified: incubator/wink/trunk/wink-common/src/main/java/org/apache/wink/common/internal/providers/entity/json/JAXBArrayJSONProvider.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-common/src/main/java/org/apache/wink/common/internal/providers/entity/json/JAXBArrayJSONProvider.java?rev=1023921&r1=1023920&r2=1023921&view=diff
==============================================================================
--- incubator/wink/trunk/wink-common/src/main/java/org/apache/wink/common/internal/providers/entity/json/JAXBArrayJSONProvider.java (original)
+++ incubator/wink/trunk/wink-common/src/main/java/org/apache/wink/common/internal/providers/entity/json/JAXBArrayJSONProvider.java Mon Oct 18 17:42:46 2010
@@ -67,7 +67,7 @@ public class JAXBArrayJSONProvider exten
                               Type genericType,
                               Annotation[] annotations,
                               MediaType mediaType) {
-        Class<?> theType = getParameterizedTypeClass(type, genericType, false);
+        Class<?> theType = getParameterizedTypeClassForRead(type, genericType, false);
         if (theType != null)
             return (type.isArray() && isJAXBObject(theType, genericType) && !isJAXBElement(theType,
                                                                                            genericType));
@@ -89,7 +89,7 @@ public class JAXBArrayJSONProvider exten
                              MediaType mediaType,
                              MultivaluedMap<String, String> httpHeaders,
                              InputStream entityStream) throws IOException, WebApplicationException {
-        Class<?> theType = getParameterizedTypeClass(type, genericType, false);
+        Class<?> theType = getParameterizedTypeClassForRead(type, genericType, false);
         if (this.readerProvider == null) {
             this.readerProvider =
                 injectedProviders.getMessageBodyReader((Class<Object>)theType,
@@ -160,7 +160,7 @@ public class JAXBArrayJSONProvider exten
                         MediaType mediaType,
                         MultivaluedMap<String, Object> httpHeaders,
                         OutputStream entityStream) throws IOException, WebApplicationException {
-        Class<?> theType = getParameterizedTypeClass(type, genericType, false);
+        Class<?> theType = getParameterizedTypeClassForWrite(type, genericType, false);
         if (this.writerProvider == null) {
             this.writerProvider =
                 injectedProviders.getMessageBodyWriter((Class<Object>)theType,
@@ -189,7 +189,7 @@ public class JAXBArrayJSONProvider exten
                                Type genericType,
                                Annotation[] annotations,
                                MediaType mediaType) {
-        Class<?> theType = getParameterizedTypeClass(type, genericType, false);
+        Class<?> theType = getParameterizedTypeClassForWrite(type, genericType, false);
 
         if (theType != null)
             return (isJAXBObject(theType, genericType) && !isJAXBElement(theType, genericType));

Modified: incubator/wink/trunk/wink-common/src/main/java/org/apache/wink/common/internal/providers/entity/xml/AbstractJAXBCollectionProvider.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-common/src/main/java/org/apache/wink/common/internal/providers/entity/xml/AbstractJAXBCollectionProvider.java?rev=1023921&r1=1023920&r2=1023921&view=diff
==============================================================================
--- incubator/wink/trunk/wink-common/src/main/java/org/apache/wink/common/internal/providers/entity/xml/AbstractJAXBCollectionProvider.java (original)
+++ incubator/wink/trunk/wink-common/src/main/java/org/apache/wink/common/internal/providers/entity/xml/AbstractJAXBCollectionProvider.java Mon Oct 18 17:42:46 2010
@@ -70,7 +70,8 @@ public abstract class AbstractJAXBCollec
         XMLStreamReader xsr = null;
         try {
             xsr = getXMLStreamReader(entityStream);
-            Class<?> theType = getParameterizedTypeClass(type, genericType, true);
+            Class<?> theType = getParameterizedTypeClassForRead(type, genericType, true);
+            theType = getConcreteTypeFromTypeMap(theType, annotations);
             JAXBContext context = getContext(theType, mediaType);
             Unmarshaller unmarshaller = getJAXBUnmarshaller(type, context, mediaType);
 
@@ -84,10 +85,12 @@ public abstract class AbstractJAXBCollec
             while (nextEvent != XMLStreamReader.END_DOCUMENT) {
                 switch (nextEvent) {
                     case XMLStreamReader.START_ELEMENT:
-                        if (getParameterizedTypeClass(type, genericType, false) == JAXBElement.class) {
+                        Class<?> parameterizedTypeClass = getParameterizedTypeClassForRead(type, genericType, false);
+                        if (parameterizedTypeClass == JAXBElement.class) {
                             elementList.add(unmarshaller.unmarshal(xsr, theType));
                         } else if (theType.isAnnotationPresent(XmlRootElement.class)) {
                             Object o = unmarshaller.unmarshal(xsr);
+                            o = unmarshalWithXmlAdapter(o, getParameterizedTypeClassForRead(type, genericType, false), annotations);
                             if (o instanceof JAXBElement) {
                                 o = ((JAXBElement)o).getValue();
                             }
@@ -140,7 +143,8 @@ public abstract class AbstractJAXBCollec
         mediaType = MediaTypeUtils.setDefaultCharsetOnMediaTypeHeader(httpHeaders, mediaType);
 
         try {
-            Class<?> theType = getParameterizedTypeClass(type, genericType, false);
+            Class<?> adapterClass = getParameterizedTypeClassForWrite(type, genericType, true);
+            Class<?> theType = getConcreteTypeFromTypeMap(adapterClass, annotations);
             Object[] elementArray = type.isArray() ? (Object[])t : ((Collection<?>)t).toArray();
             QName qname = null;
             boolean isJAXBElement = false;
@@ -159,6 +163,7 @@ public abstract class AbstractJAXBCollec
             Marshaller marshaller = null;
             JAXBContext context = null;
             for (Object o : elementArray) {
+                o = marshalWithXmlAdapter(o, getParameterizedTypeClassForWrite(type, genericType, false), annotations);
                 if(marshaller == null) {
                     Class<?> oType =
                         isJAXBElement ? ((JAXBElement<?>)o).getDeclaredType() : o.getClass();
@@ -168,7 +173,7 @@ public abstract class AbstractJAXBCollec
                         Charset charSet = getCharSet(mediaType);
                         marshaller.setProperty(Marshaller.JAXB_ENCODING, charSet.name());
                 }
-                Object entityToMarshal = getEntityToMarshal(o, theType);
+                Object entityToMarshal = getEntityToMarshal(o, getParameterizedTypeClassForWrite(type, genericType, false));
                 if (qname == null) {
                     if (entityToMarshal instanceof JAXBElement<?>)
                         qname = ((JAXBElement<?>)entityToMarshal).getName();
@@ -227,7 +232,7 @@ public abstract class AbstractJAXBCollec
         entityStream.write(endTag.getBytes());
     }
 
-    public static Class<?> getParameterizedTypeClass(Class<?> type,
+    public static Class<?> getParameterizedTypeClassForRead(Class<?> type,
                                                         Type genericType,
                                                         boolean recurse) {
         if (Collection.class.isAssignableFrom(type)) {
@@ -239,7 +244,7 @@ public abstract class AbstractJAXBCollec
                 } else {
                     parameterizedType = (ParameterizedType)actualTypeArguments[0];
                     if (recurse)
-                        return getParameterizedTypeClass(type, parameterizedType, recurse);
+                        return getParameterizedTypeClassForRead(type, parameterizedType, recurse);
                     else
                         return (Class<?>)parameterizedType.getRawType();
                 }
@@ -251,6 +256,42 @@ public abstract class AbstractJAXBCollec
         }
         return null;
     }
+    
+    public static Class<?> getParameterizedTypeClassForWrite(Class<?> type,
+            Type genericType,
+            boolean recurse) {
+        if (Collection.class.isAssignableFrom(type)) {
+            if (genericType instanceof ParameterizedType) {
+                ParameterizedType parameterizedType = (ParameterizedType)genericType;
+                Type[] actualTypeArguments = parameterizedType.getActualTypeArguments();
+                if (!(actualTypeArguments[0] instanceof ParameterizedType)) {
+                    return (Class<?>)actualTypeArguments[0];
+                } else {
+                    parameterizedType = (ParameterizedType)actualTypeArguments[0];
+                    if (recurse)
+                        return getParameterizedTypeClassForRead(type, parameterizedType, recurse);
+                    else
+                        return (Class<?>)parameterizedType.getRawType();
+                }
+            } else {
+                return GenericsUtils.getGenericParamType(genericType);
+            }
+        } else if (genericType != null) {
+            Class genericTypeClass = null;
+            try {
+                genericTypeClass = (Class<?>)genericType;
+            } catch (ClassCastException cce) {
+                genericTypeClass = genericType.getClass();
+            }
+            if (genericTypeClass.isArray()) {
+                return genericTypeClass.getComponentType();
+            }
+        }
+        if (type.isArray()) {
+            return type.getComponentType();
+        }
+        return null;
+    }
 
     protected static QName getJaxbQName(Class<?> cls) {
         XmlRootElement root = cls.getAnnotation(XmlRootElement.class);

Modified: incubator/wink/trunk/wink-common/src/main/java/org/apache/wink/common/internal/providers/entity/xml/AbstractJAXBProvider.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-common/src/main/java/org/apache/wink/common/internal/providers/entity/xml/AbstractJAXBProvider.java?rev=1023921&r1=1023920&r2=1023921&view=diff
==============================================================================
--- incubator/wink/trunk/wink-common/src/main/java/org/apache/wink/common/internal/providers/entity/xml/AbstractJAXBProvider.java (original)
+++ incubator/wink/trunk/wink-common/src/main/java/org/apache/wink/common/internal/providers/entity/xml/AbstractJAXBProvider.java Mon Oct 18 17:42:46 2010
@@ -21,6 +21,7 @@ package org.apache.wink.common.internal.
 
 import java.io.InputStream;
 import java.io.InputStreamReader;
+import java.lang.annotation.Annotation;
 import java.lang.ref.SoftReference;
 import java.lang.reflect.Method;
 import java.lang.reflect.Type;
@@ -43,9 +44,12 @@ import javax.xml.bind.JAXBElement;
 import javax.xml.bind.JAXBException;
 import javax.xml.bind.Marshaller;
 import javax.xml.bind.Unmarshaller;
+import javax.xml.bind.annotation.XmlElement;
 import javax.xml.bind.annotation.XmlRegistry;
 import javax.xml.bind.annotation.XmlRootElement;
 import javax.xml.bind.annotation.XmlType;
+import javax.xml.bind.annotation.adapters.XmlAdapter;
+import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
 import javax.xml.namespace.QName;
 import javax.xml.stream.XMLInputFactory;
 import javax.xml.stream.XMLStreamException;
@@ -66,20 +70,36 @@ import org.slf4j.LoggerFactory;
 
 public abstract class AbstractJAXBProvider {
 
-    private static final Logger                                   logger                    =
-                                                                                                LoggerFactory
-                                                                                                    .getLogger(AbstractJAXBProvider.class);
-    private static final SoftConcurrentMap<Class<?>, JAXBContext> jaxbDefaultContexts       =
-                                                                                                new SoftConcurrentMap<Class<?>, JAXBContext>();
+    private static final Logger                                      logger                         =
+                                                                                                        LoggerFactory
+                                                                                                            .getLogger(AbstractJAXBProvider.class);
+    private static final SoftConcurrentMap<Class<?>, JAXBContext>    jaxbDefaultContexts            =
+                                                                                                        new SoftConcurrentMap<Class<?>, JAXBContext>();
 
     @Context
-    protected Providers                                           providers;
+    protected Providers                                              providers;
 
-    private static final SoftConcurrentMap<Class<?>, Boolean>     jaxbIsXMLRootElementCache =
-                                                                                                new SoftConcurrentMap<Class<?>, Boolean>();
+    private static final SoftConcurrentMap<Class<?>, Boolean>        jaxbIsXMLRootElementCache      =
+                                                                                                        new SoftConcurrentMap<Class<?>, Boolean>();
 
-    private static final SoftConcurrentMap<Class<?>, Boolean>     jaxbIsXMLTypeCache        =
-                                                                                                new SoftConcurrentMap<Class<?>, Boolean>();
+    private static final SoftConcurrentMap<Class<?>, Boolean>        jaxbIsXMLTypeCache             =
+                                                                                                        new SoftConcurrentMap<Class<?>, Boolean>();
+
+    private static final SoftConcurrentMap<Class<?>, Class<?>>       xmlElementConcreteClassCache   =
+                                                                                                        new SoftConcurrentMap<Class<?>, Class<?>>();
+
+    // if JAXB objects implement an interface where that interface has
+    // @XmlJavaTypeAdapter annotation, or
+    // in JAXB 2.2 if the @XMLElement annotation is on the 'type' of the
+    // resource method parameter
+    protected static final SoftConcurrentMap<Class<?>, Class<?>>     jaxbTypeMapCache               =
+                                                                                                        new SoftConcurrentMap<Class<?>, Class<?>>();
+
+    private static final SoftConcurrentMap<Type, XmlJavaTypeAdapter> xmlJavaTypeAdapterCache        =
+                                                                                                        new SoftConcurrentMap<Type, XmlJavaTypeAdapter>();
+
+    private static final SoftConcurrentMap<Type, Boolean>            xmlJavaTypeAdapterPresentCache =
+                                                                                                        new SoftConcurrentMap<Type, Boolean>();
 
     // the Pool code for the pooling of unmarshallers is from Axis2 Java
     // http://svn.apache.org/repos/asf/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/databinding/JAXBUtils.java
@@ -265,7 +285,7 @@ public abstract class AbstractJAXBProvid
                     }
                 }
                 if (!supportDTD) {
-                    throw new XMLStreamException(Messages.getMessage("entityRefsNotSupported")); //$NON-NLS-1$
+                    throw new EntityReferenceXMLStreamException(Messages.getMessage("entityRefsNotSupported")); //$NON-NLS-1$
                 } else {
                     logger.trace("DTD entity reference expansion is enabled.  This may present a security risk."); //$NON-NLS-1$
                 }
@@ -438,7 +458,154 @@ public abstract class AbstractJAXBProvid
         }
         return false;
     }
+    
+    /**
+     * Checks to see if type is marshallable.  One of two annotations must be present with the following conditions:
+     * 1)  @XmlJavaTypeAdapter(type, SomeotherType), or
+     * 2)  @XmlElement(type=SomeotherType.class) where SomeotherType is a JAXB object.
+     * @param type
+     * @param annotations
+     * @return
+     */
+    public boolean isCompatible(Class<?> type, Annotation[] annotations) {
+        return isJAXBObject(getConcreteTypeFromTypeMap(type, annotations));
+    }
 
+    private Class<?> getConcreteTypeFromAdapter(Class<?> type, Annotation[] annotations) {
+        XmlJavaTypeAdapter adapter = getXmlJavaTypeAdapter(type, annotations);
+        if (adapter != null) {
+            Class<?> adapterClass = adapter.value();
+            try {
+                return (Class<?>) adapterClass.getMethod("marshal", type).getReturnType();
+            } catch (NoSuchMethodException e) {
+                // not possible to get here;
+                // compiler would have prevented compilation of an application with an XmlJavaTypeAdapter that lacked a "marshal" method
+            }
+        }
+        return type;
+    }
+    
+    private Class<?> getConcreteTypeFromXmlElementAnno(Class<?> type, Annotation[] annotations) {
+        Class<?> ret = xmlElementConcreteClassCache.get(type);
+        if (ret == null) {
+            XmlElement xmlElement = getXmlElementAnno(type, annotations);
+            if (xmlElement != null) {
+                Type xmlElementType = xmlElement.type();
+                if (xmlElementType != null) {
+                    ret = (Class<?>)xmlElementType;
+                }
+            }
+            if (ret == null)
+                ret = type;
+            xmlElementConcreteClassCache.put(type, ret);
+        }
+        return ret;
+    }
+
+    public Class<?> getConcreteTypeFromTypeMap(Class<?> type, Annotation[] annotations) {
+        Class<?> concreteType = jaxbTypeMapCache.get(type);
+        if (concreteType == null) {
+            concreteType = getConcreteTypeFromAdapter(type, annotations);
+            // @XmlJavaTypeAdapter takes priority over XmlElement
+            if (concreteType == type) {
+                concreteType = getConcreteTypeFromXmlElementAnno(type, annotations);
+            }
+            jaxbTypeMapCache.put(type, concreteType);
+        }
+        return concreteType;
+    }
+    
+    @SuppressWarnings("unchecked")
+    protected Object marshalWithXmlAdapter(Object obj, Type type, Annotation[] annotations) {
+        if ((type == null) || (annotations == null)) {
+            return obj;
+        }
+        XmlJavaTypeAdapter xmlJavaTypeAdapter = getXmlJavaTypeAdapter(type,
+                annotations);
+        if (xmlJavaTypeAdapter != null) {
+            try {
+                XmlAdapter xmlAdapter = xmlJavaTypeAdapter.value().newInstance();
+                return xmlAdapter.marshal(obj);
+            } catch (Exception e) {
+                if (logger.isDebugEnabled()) {
+                    logger.debug("Could not marshal {} using {} due to exception:", new Object[]{obj, xmlJavaTypeAdapter.value().getName(), e});
+                }
+            }
+        }
+        return obj;
+    }
+
+    /**
+     * @param type
+     * @param annotations
+     * @return
+     */
+    private XmlJavaTypeAdapter getXmlJavaTypeAdapter(Type type, Annotation[] annotations) {
+        Boolean present = xmlJavaTypeAdapterPresentCache.get(type);
+        if (Boolean.FALSE.equals(present)) {
+            return null;
+        }
+        XmlJavaTypeAdapter xmlJavaTypeAdapter = xmlJavaTypeAdapterCache.get(type);
+        if(xmlJavaTypeAdapter == null) {
+            xmlJavaTypeAdapter = findXmlJavaTypeAdapter(type, annotations);
+            xmlJavaTypeAdapterCache.put(type, xmlJavaTypeAdapter);
+            xmlJavaTypeAdapterPresentCache.put(type, xmlJavaTypeAdapter != null);
+        }
+        return xmlJavaTypeAdapter;
+    }
+
+    private XmlJavaTypeAdapter findXmlJavaTypeAdapter(Type type, Annotation[] annotations) {
+        XmlJavaTypeAdapter xmlJavaTypeAdapter = null;
+        for (int i = 0; (annotations != null) && i < annotations.length; i++) {
+            if (annotations[i].annotationType() == XmlJavaTypeAdapter.class) {
+                xmlJavaTypeAdapter = (XmlJavaTypeAdapter)annotations[i];
+                break;
+            }
+        }
+        if ((xmlJavaTypeAdapter == null) && (type != null)) {
+            // check the type itself
+            xmlJavaTypeAdapter = ((Class<?>)type).getAnnotation(XmlJavaTypeAdapter.class);
+        }
+        return xmlJavaTypeAdapter;
+    }
+    
+    /**
+     * @param type
+     * @param annotations
+     * @return
+     */
+    private XmlElement getXmlElementAnno(Type type,
+            Annotation[] annotations) {
+        XmlElement xmlElement = null;
+        for (int i = 0; (annotations != null) && i < annotations.length; i++) {
+            if (annotations[i].annotationType() == XmlElement.class) {
+                xmlElement = (XmlElement)annotations[i];
+                break;
+            }
+        }
+        return xmlElement;
+    }
+    
+    @SuppressWarnings("unchecked")
+    protected Object unmarshalWithXmlAdapter(Object obj, Type type, Annotation[] annotations) {
+        if ((type == null) || (annotations == null)) {
+            return obj;
+        }
+        XmlJavaTypeAdapter xmlJavaTypeAdapter = getXmlJavaTypeAdapter(type,
+                annotations);
+        if (xmlJavaTypeAdapter != null) {
+            try {
+                XmlAdapter xmlAdapter = xmlJavaTypeAdapter.value().newInstance();
+                return xmlAdapter.unmarshal(obj);
+            } catch (Exception e) {
+                if (logger.isDebugEnabled()) {
+                    logger.debug("Could not unmarshal {} using {} due to exception:", new Object[]{obj, xmlJavaTypeAdapter.value().getName(), e});
+                }
+            }
+        }
+        return obj;
+    }
+    
     public static boolean isJAXBObject(Class<?> type) {
         return isXMLRootElement(type) || isXMLType(type);
     }
@@ -477,7 +644,10 @@ public abstract class AbstractJAXBProvid
 
     protected JAXBContext getContext(Class<?> type, Type genericType, MediaType mediaType)
         throws JAXBException {
-        logger.trace("getContext({}, {}, {}) entry", new Object[] { type, genericType, mediaType }); //$NON-NLS-1$
+        if (logger.isTraceEnabled()) {
+            logger
+                .trace("getContext({}, {}, {}) entry", new Object[] {type, genericType, mediaType}); //$NON-NLS-1$
+        }
         ContextResolver<JAXBContext> contextResolver =
             providers.getContextResolver(JAXBContext.class, mediaType);
 
@@ -489,12 +659,18 @@ public abstract class AbstractJAXBProvid
             // it's ok and safe for contextResolver to be null at this point.
             // JAXBContextResolverKey can handle it
             key = new JAXBContextResolverKey(contextResolver, type);
-            logger.trace("created JAXBContextResolverKey {} for ({}, {}, {})", new Object[] { key, type, genericType, mediaType }); //$NON-NLS-1$
+            if (logger.isTraceEnabled()) {
+                logger
+                    .trace("created JAXBContextResolverKey {} for ({}, {}, {})", new Object[] {key, type, genericType, mediaType}); //$NON-NLS-1$
+            }
             context = jaxbContextCache.get(key);
             logger.trace("retrieved context {}", context); //$NON-NLS-1$
             if (context != null) {
-                logger.trace("retrieved context {}@{}", context.getClass().getName(), System.identityHashCode(context)); //$NON-NLS-1$
-                logger.trace("returned context {}", context); //$NON-NLS-1$
+                if (logger.isTraceEnabled()) {
+                    logger
+                        .trace("retrieved context {}@{}", context.getClass().getName(), System.identityHashCode(context)); //$NON-NLS-1$
+                    logger.trace("returned context {}", context); //$NON-NLS-1$
+                }
                 return context;
             }
         }
@@ -512,8 +688,11 @@ public abstract class AbstractJAXBProvid
             jaxbContextCache.put(key, context);
         }
 
-        logger.trace("returned context {}", context); //$NON-NLS-1$
-        logger.trace("retrieved context {}@{}", context.getClass().getName(), System.identityHashCode(context)); //$NON-NLS-1$
+        if (logger.isTraceEnabled()) {
+            logger.trace("returned context {}", context); //$NON-NLS-1$
+            logger
+                .trace("retrieved context {}@{}", context.getClass().getName(), System.identityHashCode(context)); //$NON-NLS-1$
+        }
         return context;
     }
 
@@ -531,7 +710,7 @@ public abstract class AbstractJAXBProvid
                         // effect of putting a namespace prefix and the namespace decl on
                         // the subelements of the
                         // desired type, thus degrading performance.
-                        
+
                         if (!isXMLRootElement(type) && !isXMLType(type)) { // use
                             // genericType.
                             // If that fails,
@@ -546,8 +725,11 @@ public abstract class AbstractJAXBProvid
 
                         jaxbDefaultContexts.put(type, context);
                     }
-                    logger.trace("getDefaultContext() exit returning", context); //$NON-NLS-1$
-                    logger.trace("returning context {}@{}", context.getClass().getName(), System.identityHashCode(context)); //$NON-NLS-1$
+                    if (logger.isTraceEnabled()) {
+                        logger.trace("getDefaultContext() exit returning", context); //$NON-NLS-1$
+                        logger
+                            .trace("returning context {}@{}", context.getClass().getName(), System.identityHashCode(context)); //$NON-NLS-1$
+                    }
                     return context;
                 }
                 
@@ -611,7 +793,7 @@ public abstract class AbstractJAXBProvid
             return defaultWrapInJAXBElement(jaxbObject, type);
         } catch (Exception e) {
             if (logger.isErrorEnabled()) {
-                logger.error(Messages.getMessage("jaxbElementFailToBuild", type.getName())); //$NON-NLS-1$
+                logger.error(Messages.getMessage("jaxbElementFailToBuild", type.getName()), e); //$NON-NLS-1$
             }
             return null;
         }
@@ -636,8 +818,8 @@ public abstract class AbstractJAXBProvid
                 }
             });
         } catch(PrivilegedActionException e) {
-            if (logger.isErrorEnabled()) {
-                logger.error(Messages.getMessage("jaxbObjectFactoryNotFound", type.getName())); //$NON-NLS-1$
+            if (logger.isDebugEnabled()) {
+                logger.debug(Messages.getMessage("jaxbObjectFactoryNotFound", type.getName()), e); //$NON-NLS-1$
             }
             return null;
         }

Modified: incubator/wink/trunk/wink-common/src/main/java/org/apache/wink/common/internal/providers/entity/xml/JAXBArrayXmlProvider.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-common/src/main/java/org/apache/wink/common/internal/providers/entity/xml/JAXBArrayXmlProvider.java?rev=1023921&r1=1023920&r2=1023921&view=diff
==============================================================================
--- incubator/wink/trunk/wink-common/src/main/java/org/apache/wink/common/internal/providers/entity/xml/JAXBArrayXmlProvider.java (original)
+++ incubator/wink/trunk/wink-common/src/main/java/org/apache/wink/common/internal/providers/entity/xml/JAXBArrayXmlProvider.java Mon Oct 18 17:42:46 2010
@@ -45,10 +45,11 @@ public class JAXBArrayXmlProvider extend
                               Type genericType,
                               Annotation[] annotations,
                               MediaType mediaType) {
-        Class<?> theType = getParameterizedTypeClass(type, genericType, false);
+        Class<?> theType = getParameterizedTypeClassForRead(type, genericType, false);
         if (theType != null)
-            return (isSupportedMediaType(mediaType) && isJAXBObject(theType, genericType) && !isJAXBElement(theType,
-                                                                                                            genericType));
+            return (isSupportedMediaType(mediaType) && ((isJAXBObject(theType, genericType) && !isJAXBElement(theType,
+                                                                                                            genericType))
+                                                                                                            || isCompatible(theType, annotations)));
         return false;
     }
 
@@ -78,10 +79,10 @@ public class JAXBArrayXmlProvider extend
                                Type genericType,
                                Annotation[] annotations,
                                MediaType mediaType) {
-        Class<?> theType = getParameterizedTypeClass(type, genericType, false);
+        Class<?> theType = getParameterizedTypeClassForWrite(type, genericType, false);
         if (theType != null)
-            return (isSupportedMediaType(mediaType) && isJAXBObject(theType, genericType) && !isJAXBElement(theType,
-                                                                                                            genericType));
+            return (isSupportedMediaType(mediaType) && ((isJAXBObject(theType, genericType) && !isJAXBElement(theType,
+                                                                                                            genericType)) || isCompatible(theType, annotations)));
         return false;
     }
 

Modified: incubator/wink/trunk/wink-common/src/main/java/org/apache/wink/common/internal/providers/entity/xml/JAXBCollectionXmlProvider.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-common/src/main/java/org/apache/wink/common/internal/providers/entity/xml/JAXBCollectionXmlProvider.java?rev=1023921&r1=1023920&r2=1023921&view=diff
==============================================================================
--- incubator/wink/trunk/wink-common/src/main/java/org/apache/wink/common/internal/providers/entity/xml/JAXBCollectionXmlProvider.java (original)
+++ incubator/wink/trunk/wink-common/src/main/java/org/apache/wink/common/internal/providers/entity/xml/JAXBCollectionXmlProvider.java Mon Oct 18 17:42:46 2010
@@ -46,10 +46,10 @@ public class JAXBCollectionXmlProvider e
                               Type genericType,
                               Annotation[] annotations,
                               MediaType mediaType) {
-        Class<?> theType = getParameterizedTypeClass(type, genericType, false);
+        Class<?> theType = getParameterizedTypeClassForRead(type, genericType, false);
         if (theType != null)
-            return (Collection.class.isAssignableFrom(type) && isSupportedMediaType(mediaType) && (isJAXBObject(theType, genericType) || (isJAXBElement(theType,
-                                                                                                             genericType))));
+            return (Collection.class.isAssignableFrom(type) && isSupportedMediaType(mediaType) && ((isJAXBObject(theType, genericType) || (isJAXBElement(theType,
+                                                                                                             genericType))) || isCompatible(theType, annotations)));
         return false;
     }
 
@@ -74,10 +74,10 @@ public class JAXBCollectionXmlProvider e
                                Type genericType,
                                Annotation[] annotations,
                                MediaType mediaType) {
-        Class<?> theType = getParameterizedTypeClass(type, genericType, false);
+        Class<?> theType = getParameterizedTypeClassForWrite(type, genericType, false);
         if (theType != null)
-            return (Collection.class.isAssignableFrom(type) && isSupportedMediaType(mediaType) && (isJAXBObject(theType, genericType) || (isJAXBElement(theType,
-                                                                                                             genericType))));
+            return (Collection.class.isAssignableFrom(type) && isSupportedMediaType(mediaType) && ((isJAXBObject(theType, genericType) || (isJAXBElement(theType,
+                                                                                                             genericType))) || isCompatible(theType, annotations)));
         return false;
     }
 

Modified: incubator/wink/trunk/wink-common/src/main/java/org/apache/wink/common/internal/providers/entity/xml/JAXBElementXmlProvider.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-common/src/main/java/org/apache/wink/common/internal/providers/entity/xml/JAXBElementXmlProvider.java?rev=1023921&r1=1023920&r2=1023921&view=diff
==============================================================================
--- incubator/wink/trunk/wink-common/src/main/java/org/apache/wink/common/internal/providers/entity/xml/JAXBElementXmlProvider.java (original)
+++ incubator/wink/trunk/wink-common/src/main/java/org/apache/wink/common/internal/providers/entity/xml/JAXBElementXmlProvider.java Mon Oct 18 17:42:46 2010
@@ -102,12 +102,15 @@ public class JAXBElementXmlProvider exte
                 logger.error(Messages.getMessage("jaxbFailToUnmarshal", type.getName()), e); //$NON-NLS-1$
             }
             throw new WebApplicationException(e, Response.Status.BAD_REQUEST);
-        } catch (XMLStreamException e) {
+        } catch (EntityReferenceXMLStreamException e) {
             closeXMLStreamReader(xmlStreamReader);
             if (logger.isErrorEnabled()) {
                 logger.error(Messages.getMessage("entityRefsNotSupported")); //$NON-NLS-1$
             }
             throw new WebApplicationException(e, Response.Status.BAD_REQUEST);
+        } catch (XMLStreamException e) {
+            closeXMLStreamReader(xmlStreamReader);
+            throw new WebApplicationException(e, Response.Status.BAD_REQUEST);
         } catch (RuntimeException e) {
             closeXMLStreamReader(xmlStreamReader);
             throw new WebApplicationException(e, Response.Status.BAD_REQUEST);

Modified: incubator/wink/trunk/wink-common/src/main/java/org/apache/wink/common/internal/providers/entity/xml/JAXBXmlProvider.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-common/src/main/java/org/apache/wink/common/internal/providers/entity/xml/JAXBXmlProvider.java?rev=1023921&r1=1023920&r2=1023921&view=diff
==============================================================================
--- incubator/wink/trunk/wink-common/src/main/java/org/apache/wink/common/internal/providers/entity/xml/JAXBXmlProvider.java (original)
+++ incubator/wink/trunk/wink-common/src/main/java/org/apache/wink/common/internal/providers/entity/xml/JAXBXmlProvider.java Mon Oct 18 17:42:46 2010
@@ -63,7 +63,7 @@ public class JAXBXmlProvider extends Abs
                               Type genericType,
                               Annotation[] annotations,
                               MediaType mediaType) {
-        return isJAXBObject(type, genericType) && isSupportedMediaType(mediaType);
+        return (isJAXBObject(type, genericType) || isCompatible(type, annotations)) && isSupportedMediaType(mediaType);
     }
 
     public Object readFrom(final Class<Object> type,
@@ -73,14 +73,17 @@ public class JAXBXmlProvider extends Abs
                            MultivaluedMap<String, String> httpHeaders,
                            final InputStream entityStream) throws IOException,
         WebApplicationException {
+
+        Class<?> concreteType = getConcreteTypeFromTypeMap(type, annotations);
+        
         Unmarshaller unmarshaller = null;
         Object unmarshaledResource = null;
         XMLStreamReader xmlStreamReader = null;
         try {
-            JAXBContext context = getContext(type, mediaType);
-            unmarshaller = getJAXBUnmarshaller(type, context, mediaType);
+            JAXBContext context = getContext(concreteType, mediaType);
+            unmarshaller = getJAXBUnmarshaller(concreteType, context, mediaType);
             xmlStreamReader = getXMLStreamReader(entityStream);
-            if (type.isAnnotationPresent(XmlRootElement.class)) {
+            if (concreteType.isAnnotationPresent(XmlRootElement.class)) {
                 unmarshaledResource = unmarshaller.unmarshal(xmlStreamReader);
                 closeXMLStreamReader(xmlStreamReader);
                 if (unmarshaledResource instanceof JAXBElement) {
@@ -101,11 +104,12 @@ public class JAXBXmlProvider extends Abs
                 try {
                     final Unmarshaller _unmarshaller = unmarshaller;
                     final XMLStreamReader _xmlStreamReader = xmlStreamReader;
+                    final Class<?> _concreteType = concreteType;
                     unmarshaledResource =
                         AccessController.doPrivileged(new PrivilegedExceptionAction<Object>() {
                             public Object run() throws PrivilegedActionException {
                                 try {
-                                    Object obj = _unmarshaller.unmarshal(_xmlStreamReader, type).getValue();
+                                    Object obj = _unmarshaller.unmarshal(_xmlStreamReader, _concreteType).getValue();
                                     closeXMLStreamReader(_xmlStreamReader);
                                     return obj;
                                 } catch (JAXBException e) {
@@ -117,7 +121,7 @@ public class JAXBXmlProvider extends Abs
                     closeXMLStreamReader(xmlStreamReader);
                     if (logger.isErrorEnabled()) {
                         logger
-                            .error(Messages.getMessage("jaxbFailToUnmarshal", type.getName()), e.getException()); //$NON-NLS-1$
+                            .error(Messages.getMessage("jaxbFailToUnmarshal", concreteType.getName()), e.getException()); //$NON-NLS-1$
                     }
                     throw new WebApplicationException(e.getException(), Response.Status.BAD_REQUEST);
                 }
@@ -127,20 +131,23 @@ public class JAXBXmlProvider extends Abs
         } catch (JAXBException e) {
             closeXMLStreamReader(xmlStreamReader);
             if (logger.isErrorEnabled()) {
-                logger.error(Messages.getMessage("jaxbFailToUnmarshal", type.getName()), e); //$NON-NLS-1$
+                logger.error(Messages.getMessage("jaxbFailToUnmarshal", concreteType.getName()), e); //$NON-NLS-1$
             }
             throw new WebApplicationException(e, Response.Status.BAD_REQUEST);
-        } catch (XMLStreamException e) {
+        } catch (EntityReferenceXMLStreamException e) {
             closeXMLStreamReader(xmlStreamReader);
             if (logger.isErrorEnabled()) {
                 logger.error(Messages.getMessage("entityRefsNotSupported")); //$NON-NLS-1$
             }
             throw new WebApplicationException(e, Response.Status.BAD_REQUEST);
+        } catch (XMLStreamException e) {
+            closeXMLStreamReader(xmlStreamReader);
+            throw new WebApplicationException(e, Response.Status.BAD_REQUEST);
         } catch (RuntimeException e) {
             closeXMLStreamReader(xmlStreamReader);
             throw e;
         }
-        return unmarshaledResource;
+        return unmarshalWithXmlAdapter(unmarshaledResource, type, annotations);
     }
 
     public long getSize(Object t,
@@ -155,7 +162,7 @@ public class JAXBXmlProvider extends Abs
                                Type genericType,
                                Annotation[] annotations,
                                MediaType mediaType) {
-        return isJAXBObject(type, genericType) && isSupportedMediaType(mediaType);
+        return (isJAXBObject(type, genericType) || isCompatible(type, annotations)) && isSupportedMediaType(mediaType);
     }
 
     public void writeTo(Object t,
@@ -166,14 +173,16 @@ public class JAXBXmlProvider extends Abs
                         MultivaluedMap<String, Object> httpHeaders,
                         OutputStream entityStream) throws IOException, WebApplicationException {
 
+        t = marshalWithXmlAdapter(t, genericType, annotations);
+        Class<?> concreteType = getConcreteTypeFromTypeMap(type, annotations);
         mediaType = MediaTypeUtils.setDefaultCharsetOnMediaTypeHeader(httpHeaders, mediaType);
 
         try {
-            if (isJAXBObject(type)) {
-                JAXBContext context = getContext(type, genericType, mediaType);
+            if (isJAXBObject(concreteType)) {
+                JAXBContext context = getContext(concreteType, genericType, mediaType);
                 logger.trace("using context {}@{} to get marshaller", context.getClass().getName(), System.identityHashCode(context)); //$NON-NLS-1$
-                Marshaller marshaller = getJAXBMarshaller(type, context, mediaType);
-                Object entityToMarshal = getEntityToMarshal(t, type);
+                Marshaller marshaller = getJAXBMarshaller(concreteType, context, mediaType);
+                Object entityToMarshal = getEntityToMarshal(t, concreteType);
 
                 // Use an OutputStream directly instead of a Writer for
                 // performance.
@@ -194,7 +203,7 @@ public class JAXBXmlProvider extends Abs
             }
         } catch (JAXBException e) {
             if (logger.isErrorEnabled()) {
-                logger.error(Messages.getMessage("jaxbFailToMarshal", type.getName()), e); //$NON-NLS-1$
+                logger.error(Messages.getMessage("jaxbFailToMarshal", concreteType.getName()), e); //$NON-NLS-1$
             }
             throw new WebApplicationException(e);
         }

Modified: incubator/wink/trunk/wink-common/src/test/java/org/apache/wink/common/model/rss/RssTest.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-common/src/test/java/org/apache/wink/common/model/rss/RssTest.java?rev=1023921&r1=1023920&r2=1023921&view=diff
==============================================================================
--- incubator/wink/trunk/wink-common/src/test/java/org/apache/wink/common/model/rss/RssTest.java (original)
+++ incubator/wink/trunk/wink-common/src/test/java/org/apache/wink/common/model/rss/RssTest.java Mon Oct 18 17:42:46 2010
@@ -41,6 +41,9 @@ public class RssTest extends TestCase {
                                                   "\n<category domain=\"Newspapers/Regional/United_States\">Texas</category>\n";
     private static final String RSS_CLOUD     =
                                                   "\n<cloud protocol=\"xml-rpc\" registerProcedure=\"cloud.notify\" path=\"/rpc\" port=\"80\" domain=\"server.example.com\"/>\n";
+    // apparently JAXB 2.2 reads the fields in a different order, so:
+    private static final String RSS_CLOUD_JAXB_22 =
+                                                  "\n<cloud domain=\"server.example.com\" port=\"80\" path=\"/rpc\" registerProcedure=\"cloud.notify\" protocol=\"xml-rpc\"/>\n";
     private static final String RSS_IMAGE     =
                                                   "\n<image>\n" + "    <url>http://dallas.example.com/masthead.gif</url>\n"
                                                       + "    <title>Dallas Times-Herald</title>\n"
@@ -72,6 +75,9 @@ public class RssTest extends TestCase {
                                                   "\n<source url=\"http://la.example.com/rss.xml\">Los Angeles Herald-Examiner</source>\n";
     private static final String RSS_ENCLOSURE =
                                                   "\n<enclosure type=\"audio/mpeg\" length=\"24986239\" url=\"http://dallas.example.com/joebob_050689.mp3\"/>\n";
+    // apparently JAXB 2.2 reads the fields in a different order, so:
+    private static final String RSS_ENCLOSURE_JAXB_22 =
+                                                  "\n<enclosure url=\"http://dallas.example.com/joebob_050689.mp3\" length=\"24986239\" type=\"audio/mpeg\"/>\n";
     private static final String RSS_ITEM      =
                                                   "\n<item>\n" + "    <title>Joe Bob Goes to the Drive-In</title>\n"
                                                       + "    <link>http://dallas.example.com/1983/05/06/joebob.htm</link>\n"
@@ -79,7 +85,20 @@ public class RssTest extends TestCase {
                                                       + "    <author>jbb@dallas.example.com (Joe Bob Briggs)</author>\n"
                                                       + "    <category>rec.arts.movies.reviews</category>\n"
                                                       + "    <comments>http://dallas.example.com/feedback/1983/06/joebob.htm</comments>\n"
-                                                      + "    <enclosure type=\"audio/mpeg\" length=\"24986239\" url=\"http://dallas.example.com/joebob_050689.mp3\"/>\n"
+                                                      + "    " + RSS_ENCLOSURE.replaceFirst("\n", "")
+                                                      + "    <guid>http://dallas.example.com/1983/05/06/joebob.htm</guid>\n"
+                                                      + "    <pubDate>Fri, 06 May 1983 09:00:00 CST</pubDate>\n"
+                                                      + "    <source url=\"http://la.example.com/rss.xml\">Los Angeles Herald-Examiner</source>\n"
+                                                      + "</item>\n";
+    // apparently JAXB 2.2 reads the fields in a different order, so:
+    private static final String RSS_ITEM_JAXB_22      =
+                                                  "\n<item>\n" + "    <title>Joe Bob Goes to the Drive-In</title>\n"
+                                                      + "    <link>http://dallas.example.com/1983/05/06/joebob.htm</link>\n"
+                                                      + "    <description>I'm headed for France. I wasn't gonna go this year, but then last week &quot;Valley Girl&quot; came out and I said to myself, Joe Bob, you gotta get out of the country for a while.</description>\n"
+                                                      + "    <author>jbb@dallas.example.com (Joe Bob Briggs)</author>\n"
+                                                      + "    <category>rec.arts.movies.reviews</category>\n"
+                                                      + "    <comments>http://dallas.example.com/feedback/1983/06/joebob.htm</comments>\n"
+                                                      + "    " + RSS_ENCLOSURE_JAXB_22.replaceFirst("\n", "")
                                                       + "    <guid>http://dallas.example.com/1983/05/06/joebob.htm</guid>\n"
                                                       + "    <pubDate>Fri, 06 May 1983 09:00:00 CST</pubDate>\n"
                                                       + "    <source url=\"http://la.example.com/rss.xml\">Los Angeles Herald-Examiner</source>\n"
@@ -171,7 +190,8 @@ public class RssTest extends TestCase {
         Marshaller m = JAXBUtils.createMarshaller(ctx);
         ByteArrayOutputStream os = new ByteArrayOutputStream();
         m.marshal(new ObjectFactory().createRssCloud(cloud), os);
-        assertEquals(RSS_CLOUD, os.toString());
+        String actual = os.toString();
+        assertTrue(actual.equals(RSS_CLOUD) || actual.equals(RSS_CLOUD_JAXB_22));
     }
 
     public void testRssCloudUnmarshal() throws JAXBException {
@@ -369,7 +389,8 @@ public class RssTest extends TestCase {
         Marshaller m = JAXBUtils.createMarshaller(ctx);
         ByteArrayOutputStream os = new ByteArrayOutputStream();
         m.marshal(new ObjectFactory().createRssEnclosure(enclosure), os);
-        assertEquals(RSS_ENCLOSURE, os.toString());
+        String actual = os.toString();
+        assertTrue(actual.equals(RSS_ENCLOSURE) || actual.equals(RSS_ENCLOSURE_JAXB_22));
     }
 
     public void testRssEnclosureUnmarshal() throws JAXBException {
@@ -425,7 +446,8 @@ public class RssTest extends TestCase {
         Marshaller m = JAXBUtils.createMarshaller(ctx);
         ByteArrayOutputStream os = new ByteArrayOutputStream();
         m.marshal(new ObjectFactory().createRssItem(item), os);
-        assertEquals(RSS_ITEM, os.toString());
+        String actual = os.toString();
+        assertTrue(actual.equals(RSS_ITEM) || actual.equals(RSS_ITEM_JAXB_22));
     }
 
     public void testRssItemUnmarshal() throws JAXBException {



Mime
View raw message