You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by ch...@apache.org on 2011/01/30 05:06:37 UTC

svn commit: r1065178 - /activemq/activemq-apollo/trunk/apollo-dto/src/main/java/org/apache/activemq/apollo/dto/XmlCodec.java

Author: chirino
Date: Sun Jan 30 04:06:37 2011
New Revision: 1065178

URL: http://svn.apache.org/viewvc?rev=1065178&view=rev
Log:
Make sure the context class loader is always set before demarshalling.

Modified:
    activemq/activemq-apollo/trunk/apollo-dto/src/main/java/org/apache/activemq/apollo/dto/XmlCodec.java

Modified: activemq/activemq-apollo/trunk/apollo-dto/src/main/java/org/apache/activemq/apollo/dto/XmlCodec.java
URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-dto/src/main/java/org/apache/activemq/apollo/dto/XmlCodec.java?rev=1065178&r1=1065177&r2=1065178&view=diff
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-dto/src/main/java/org/apache/activemq/apollo/dto/XmlCodec.java (original)
+++ activemq/activemq-apollo/trunk/apollo-dto/src/main/java/org/apache/activemq/apollo/dto/XmlCodec.java Sun Jan 30 04:06:37 2011
@@ -77,28 +77,27 @@ public class XmlCodec {
     private static final XMLInputFactory factory = XMLInputFactory.newInstance();
     private static final JAXBContext context;
 
+    public static ClassLoader loader = Thread.currentThread().getContextClassLoader();
+
     static {
         try {
             String path = "META-INF/services/org.apache.activemq.apollo/xml-packages.index";
-            ClassLoader[] loaders = new ClassLoader[]{Thread.currentThread().getContextClassLoader()};
 
             HashSet<String> names = new HashSet<String>();
-            for (ClassLoader loader : loaders) {
-                try {
-                    Enumeration<URL> resources = loader.getResources(path);
-
-                    while (resources.hasMoreElements()) {
-                        URL url = resources.nextElement();
-                        Properties p = loadProperties(url.openStream());
-                        Enumeration<Object> keys = p.keys();
-                        while (keys.hasMoreElements()) {
-                            names.add((String) keys.nextElement());
-                        }
-                    }
+            try {
+                Enumeration<URL> resources = loader.getResources(path);
 
-                } catch (IOException e) {
-                    e.printStackTrace();
+                while (resources.hasMoreElements()) {
+                    URL url = resources.nextElement();
+                    Properties p = loadProperties(url.openStream());
+                    Enumeration<Object> keys = p.keys();
+                    while (keys.hasMoreElements()) {
+                        names.add((String) keys.nextElement());
+                    }
                 }
+
+            } catch (IOException e) {
+                e.printStackTrace();
             }
 
             String packages = "";
@@ -147,18 +146,25 @@ public class XmlCodec {
     }
 
     static public BrokerDTO unmarshalBrokerDTO(InputStream is, Properties props) throws IOException, XMLStreamException, JAXBException {
-        if (is == null) {
-            throw new IllegalArgumentException("input stream was null");
-        }
+        ClassLoader original = Thread.currentThread().getContextClassLoader();
         try {
-            XMLStreamReader reader = factory.createXMLStreamReader(is);
-            if (props != null) {
-                reader = new PropertiesFilter(reader, props);
+            Thread.currentThread().setContextClassLoader(loader);
+            if (is == null) {
+                throw new IllegalArgumentException("input stream was null");
+            }
+            try {
+                XMLStreamReader reader = factory.createXMLStreamReader(is);
+                if (props != null) {
+                    reader = new PropertiesFilter(reader, props);
+                }
+                Unmarshaller unmarshaller = context.createUnmarshaller();
+                return (BrokerDTO) unmarshaller.unmarshal(reader);
+            } finally {
+                is.close();
             }
-            Unmarshaller unmarshaller = context.createUnmarshaller();
-            return (BrokerDTO) unmarshaller.unmarshal(reader);
+
         } finally {
-            is.close();
+            Thread.currentThread().setContextClassLoader(original);
         }
     }