cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject [4/7] git commit: Get the XLSTJaxbProvider to work with eclipse MOXy, sort of.
Date Wed, 26 Mar 2014 21:12:50 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/8ce34ce6
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/8ce34ce6
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/8ce34ce6

Branch: refs/heads/master
Commit: 8ce34ce6d7fa13d3fee58b4d7dcc5241a1742ff9
Parents: ee79134
Author: Daniel Kulp <dkulp@apache.org>
Authored: Wed Mar 26 16:12:52 2014 -0400
Committer: Daniel Kulp <dkulp@apache.org>
Committed: Wed Mar 26 16:12:52 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/8ce34ce6/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 993c251..5d96c2c 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
@@ -50,16 +50,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.classloader.ClassLoaderUtils;
 import org.apache.cxf.common.logging.LogUtils;
@@ -238,6 +241,15 @@ public class XSLTJaxbProvider<T> extends JAXBElementProvider<T>
{
             if (t == null && supportJaxbOnly) {
                 return super.unmarshalFromInputStream(unmarshaller, is, anns, 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);
@@ -246,12 +258,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