Author: dblevins
Date: Tue Jan 15 03:53:46 2013
New Revision: 1433279

URL: http://svn.apache.org/viewvc?rev=1433279&view=rev
Log:
Ensure we use the stax impl installed in the server.  Without this 
implementations in the webapp would get used to parse descriptors and 
applications can break themselves.
TOMEE-727

Modified:
    
tomee/trunk/openejb/container/openejb-jee-accessors/src/main/java/org/apache/openejb/sxc/Sxc.java

Modified: 
tomee/trunk/openejb/container/openejb-jee-accessors/src/main/java/org/apache/openejb/sxc/Sxc.java
URL: 
http://svn.apache.org/viewvc/tomee/trunk/openejb/container/openejb-jee-accessors/src/main/java/org/apache/openejb/sxc/Sxc.java?rev=1433279&r1=1433278&r2=1433279&view=diff
==============================================================================
--- 
tomee/trunk/openejb/container/openejb-jee-accessors/src/main/java/org/apache/openejb/sxc/Sxc.java
 (original)
+++ 
tomee/trunk/openejb/container/openejb-jee-accessors/src/main/java/org/apache/openejb/sxc/Sxc.java
 Tue Jan 15 03:53:46 2013
@@ -31,6 +31,7 @@ import com.envoisolutions.sxc.util.XoXML
 import javax.xml.bind.JAXBException;
 import javax.xml.bind.MarshalException;
 import javax.xml.namespace.QName;
+import javax.xml.stream.XMLInputFactory;
 import javax.xml.stream.XMLOutputFactory;
 import javax.xml.stream.XMLStreamConstants;
 import javax.xml.stream.XMLStreamException;
@@ -65,7 +66,7 @@ public class Sxc {
 
         XMLStreamWriter writer = null;
         try {
-            final XMLOutputFactory xof = XmlFactories.getXof();
+            final XMLOutputFactory xof = getXmOutputFactory();
             writer = xof.createXMLStreamWriter(streamResult.getOutputStream(), 
"UTF-8");
             writer = new PrettyPrintXMLStreamWriter(writer);
             XoXMLStreamWriter w = new XoXMLStreamWriterImpl(writer);
@@ -146,7 +147,7 @@ public class Sxc {
     public static XMLStreamReader prepareReader(InputStream inputStream) 
throws XMLStreamException {
         final Source source = new StreamSource(inputStream);
 
-        final XMLStreamReader streamReader = 
XmlFactories.getXif().createXMLStreamReader(source);
+        final XMLStreamReader streamReader = 
getXmlInputFactory().createXMLStreamReader(source);
 
         return new JavaeeNamespaceFilter(streamReader);
     }
@@ -166,4 +167,27 @@ public class Sxc {
 
         return jaxbType.read(reader, new RuntimeContext((ExtendedUnmarshaller) 
null));
     }
+
+    private static XMLInputFactory getXmlInputFactory() {
+        final ClassLoader contextClassLoader = 
Thread.currentThread().getContextClassLoader();
+        try {
+            // We don't want to use whatever they have put in the their app as 
a STAX impl
+            
Thread.currentThread().setContextClassLoader(Sxc.class.getClassLoader());
+            return XMLInputFactory.newInstance();
+        } finally {
+            Thread.currentThread().setContextClassLoader(contextClassLoader);
+        }
+    }
+
+    private static XMLOutputFactory getXmOutputFactory() {
+        final ClassLoader contextClassLoader = 
Thread.currentThread().getContextClassLoader();
+        try {
+            // We don't want to use whatever they have put in the their app as 
a STAX impl
+            
Thread.currentThread().setContextClassLoader(Sxc.class.getClassLoader());
+            return XMLOutputFactory.newInstance();
+        } finally {
+            Thread.currentThread().setContextClassLoader(contextClassLoader);
+        }
+    }
+
 }


Reply via email to