cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject [05/21] git commit: Get the XLSTJaxbProvider to work with eclipse MOXy, sort of.
Date Wed, 02 Apr 2014 06:26:01 GMT
Get the XLSTJaxbProvider to work with eclipse MOXy, sort of.


Project: http://git-wip-us.apache.org/repos/asf/cxf/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/9ab6680a
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/9ab6680a
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/9ab6680a

Branch: refs/heads/2.7.x-fixes
Commit: 9ab6680aabecc499b87b153a1f27f47c5d966c0a
Parents: ccf144e
Author: Daniel Kulp <dkulp@apache.org>
Authored: Wed Mar 26 16:12:52 2014 -0400
Committer: Daniel Kulp <dkulp@apache.org>
Committed: Wed Apr 2 02:10:10 2014 -0400

----------------------------------------------------------------------
 .../cxf/jaxrs/provider/XSLTJaxbProvider.java    | 21 +++++++++++++++++---
 1 file changed, 18 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/9ab6680a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/XSLTJaxbProvider.java
----------------------------------------------------------------------
diff --git a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/XSLTJaxbProvider.java
b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/XSLTJaxbProvider.java
index 0a8fe45..7eec160 100644
--- a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/XSLTJaxbProvider.java
+++ b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/XSLTJaxbProvider.java
@@ -49,16 +49,19 @@ import javax.xml.transform.Source;
 import javax.xml.transform.Templates;
 import javax.xml.transform.Transformer;
 import javax.xml.transform.TransformerConfigurationException;
+import javax.xml.transform.TransformerException;
 import javax.xml.transform.TransformerFactory;
 import javax.xml.transform.URIResolver;
+import javax.xml.transform.dom.DOMResult;
 import javax.xml.transform.sax.SAXSource;
 import javax.xml.transform.sax.SAXTransformerFactory;
 import javax.xml.transform.sax.TransformerHandler;
 import javax.xml.transform.stream.StreamResult;
 import javax.xml.transform.stream.StreamSource;
 
-import org.xml.sax.InputSource;
+import org.xml.sax.ContentHandler;
 import org.xml.sax.XMLFilter;
+import org.xml.sax.XMLReader;
 
 import org.apache.cxf.common.logging.LogUtils;
 import org.apache.cxf.io.CachedOutputStream;
@@ -170,6 +173,15 @@ public class XSLTJaxbProvider<T> extends JAXBElementProvider<T>
{
             if (t == null && supportJaxbOnly) {
                 return super.unmarshalFromInputStream(unmarshaller, is, mt);
             }
+            
+            if (unmarshaller.getClass().getName().contains("eclipse")) {
+                //eclipse MOXy doesn't work properly with the XMLFilter/Reader thing
+                //so we need to bounce through a DOM
+                Source reader = new StaxSource(StaxUtils.createXMLStreamReader(is));
+                DOMResult dom = new DOMResult();
+                t.newTransformer().transform(reader, dom);
+                return unmarshaller.unmarshal(dom.getNode());
+            }
             XMLFilter filter = null;
             try {
                 filter = factory.newXMLFilter(t);
@@ -178,12 +190,15 @@ public class XSLTJaxbProvider<T> extends JAXBElementProvider<T>
{
                 filter = factory.newXMLFilter(ti.getTemplates());
                 trySettingProperties(filter, ti);
             }
-            SAXSource source = new SAXSource(filter, new InputSource(is));
+            XMLReader reader = new StaxSource(StaxUtils.createXMLStreamReader(is));
+            filter.setParent(reader);
+            SAXSource source = new SAXSource();
+            source.setXMLReader(filter);
             if (systemId != null) {
                 source.setSystemId(systemId);
             }
             return unmarshaller.unmarshal(source);
-        } catch (TransformerConfigurationException ex) {
+        } catch (TransformerException ex) {
             LOG.warning("Transformation exception : " + ex.getMessage());
             throw ExceptionUtils.toInternalServerErrorException(ex, null); 
         }


Mime
View raw message