Author: dkulp Date: Tue Jan 5 03:31:38 2010 New Revision: 895876 URL: http://svn.apache.org/viewvc?rev=895876&view=rev Log: Merged revisions 893390 via svnmerge from https://svn.apache.org/repos/asf/cxf/branches/2.2.x-fixes
................ r893390 | dkulp | 2009-12-22 22:33:57 -0500 (Tue, 22 Dec 2009) | 10 lines Merged revisions 893388 via svnmerge from https://svn.apache.org/repos/asf/cxf/trunk ........ r893388 | dkulp | 2009-12-22 22:20:06 -0500 (Tue, 22 Dec 2009) | 2 lines [CXF-2286, CXF-1816] Use weak references for ASMHelper stuff to make sure classes are not held onto strongly. ........ ................ Modified: cxf/branches/2.1.x-fixes/ (props changed) cxf/branches/2.1.x-fixes/common/common/src/main/java/org/apache/cxf/common/util/ASMHelper.java cxf/branches/2.1.x-fixes/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBDataBinding.java cxf/branches/2.1.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/ServletContextResourceResolver.java Propchange: cxf/branches/2.1.x-fixes/ ------------------------------------------------------------------------------ Binary property 'svnmerge-integrated' - no diff available. Modified: cxf/branches/2.1.x-fixes/common/common/src/main/java/org/apache/cxf/common/util/ASMHelper.java URL: http://svn.apache.org/viewvc/cxf/branches/2.1.x-fixes/common/common/src/main/java/org/apache/cxf/common/util/ASMHelper.java?rev=895876&r1=895875&r2=895876&view=diff ============================================================================== --- cxf/branches/2.1.x-fixes/common/common/src/main/java/org/apache/cxf/common/util/ASMHelper.java (original) +++ cxf/branches/2.1.x-fixes/common/common/src/main/java/org/apache/cxf/common/util/ASMHelper.java Tue Jan 5 03:31:38 2010 @@ -19,6 +19,7 @@ package org.apache.cxf.common.util; +import java.lang.ref.WeakReference; import java.lang.reflect.Constructor; import java.lang.reflect.GenericArrayType; import java.lang.reflect.Method; @@ -34,8 +35,8 @@ protected static final Map<Class<?>, String> PRIMITIVE_MAP = new HashMap<Class<?>, String>(); protected static final Map<Class<?>, String> NONPRIMITIVE_MAP = new HashMap<Class<?>, String>(); - protected static final Map<Class<?>, TypeHelperClassLoader> LOADER_MAP - = new WeakIdentityHashMap<Class<?>, TypeHelperClassLoader>(); + protected static final Map<Class<?>, WeakReference<TypeHelperClassLoader>> LOADER_MAP + = new WeakIdentityHashMap<Class<?>, WeakReference<TypeHelperClassLoader>>(); protected static boolean oldASM; @@ -167,10 +168,13 @@ } private static synchronized TypeHelperClassLoader getTypeHelperClassLoader(Class<?> l) { - TypeHelperClassLoader ret = LOADER_MAP.get(l); - if (ret == null) { + WeakReference<TypeHelperClassLoader> ref = LOADER_MAP.get(l); + TypeHelperClassLoader ret; + if (ref == null || ref.get() == null) { ret = new TypeHelperClassLoader(l.getClassLoader()); - LOADER_MAP.put(l, ret); + LOADER_MAP.put(l, new WeakReference<TypeHelperClassLoader>(ret)); + } else { + ret = ref.get(); } return ret; } Modified: cxf/branches/2.1.x-fixes/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBDataBinding.java URL: http://svn.apache.org/viewvc/cxf/branches/2.1.x-fixes/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBDataBinding.java?rev=895876&r1=895875&r2=895876&view=diff ============================================================================== --- cxf/branches/2.1.x-fixes/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBDataBinding.java (original) +++ cxf/branches/2.1.x-fixes/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBDataBinding.java Tue Jan 5 03:31:38 2010 @@ -52,7 +52,6 @@ import javax.xml.bind.ValidationEventHandler; import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlElementDecl; -import javax.xml.parsers.ParserConfigurationException; import javax.xml.stream.XMLEventReader; import javax.xml.stream.XMLEventWriter; import javax.xml.stream.XMLStreamReader; @@ -64,8 +63,6 @@ import org.w3c.dom.Document; import org.w3c.dom.Node; -import org.xml.sax.SAXException; - import org.apache.cxf.common.classloader.ClassLoaderUtils; import org.apache.cxf.common.i18n.Message; import org.apache.cxf.common.logging.LogUtils; @@ -113,15 +110,15 @@ XMLStreamWriter.class}; private static final class CachedContextAndSchemas { - private JAXBContext context; + private WeakReference<JAXBContext> context; private Collection<DOMSource> schemas; CachedContextAndSchemas(JAXBContext context) { - this.context = context; + this.context = new WeakReference<JAXBContext>(context); } public JAXBContext getContext() { - return context; + return context.get(); } public Collection<DOMSource> getSchemas() { @@ -169,11 +166,7 @@ BUILT_IN_SCHEMAS.put("http://www.w3.org/2005/02/addressing/wsdl", dr); resolver.unresolve(); } - } catch (IOException e) { - //IGNORE - } catch (ParserConfigurationException e) { - //IGNORE - } catch (SAXException e) { + } catch (Exception e) { //IGNORE } try { @@ -186,11 +179,7 @@ BUILT_IN_SCHEMAS.put("http://www.w3.org/2005/08/addressing", dr); resolver.unresolve(); } - } catch (IOException e) { - //IGNORE - } catch (ParserConfigurationException e) { - //IGNORE - } catch (SAXException e) { + } catch (Exception e) { //IGNORE } try { @@ -203,11 +192,7 @@ BUILT_IN_SCHEMAS.put("http://schemas.xmlsoap.org/ws/2005/02/rm", dr); resolver.unresolve(); } - } catch (IOException e) { - //IGNORE - } catch (ParserConfigurationException e) { - //IGNORE - } catch (SAXException e) { + } catch (Exception e) { //IGNORE } try { @@ -220,15 +205,10 @@ BUILT_IN_SCHEMAS.put("http://schemas.xmlsoap.org/ws/2005/02/rm", dr); resolver.unresolve(); } - } catch (IOException e) { - //IGNORE - } catch (ParserConfigurationException e) { - //IGNORE - } catch (SAXException e) { + } catch (Exception e) { //IGNORE } } - Class[] extraClass; @@ -380,7 +360,7 @@ } else { synchronized (JAXBCONTEXT_CACHE) { JAXBCONTEXT_CACHE.put(contextClasses, cachedContextAndSchemas); - } + } } } ctx = cachedContextAndSchemas.getContext(); @@ -514,6 +494,7 @@ } scanPackages(classes); + //JAXBUtils.scanPackages(classes, new HashMap<Package, CachedClass>()); addWsAddressingTypes(classes); for (Class<?> clz : classes) { @@ -541,9 +522,12 @@ cachedContextAndSchemas = JAXBCONTEXT_CACHE.get(classes); } } - if (cachedContextAndSchemas == null) { - JAXBContext ctx = createContext(classes, map); - cachedContextAndSchemas = new CachedContextAndSchemas(ctx); + if (cachedContextAndSchemas != null) { + context = cachedContextAndSchemas.getContext(); + } + if (context == null) { + context = createContext(classes, map); + cachedContextAndSchemas = new CachedContextAndSchemas(context); synchronized (JAXBCONTEXT_CACHE) { if (typeRefs.isEmpty()) { JAXBCONTEXT_CACHE.put(classes, cachedContextAndSchemas); Modified: cxf/branches/2.1.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/ServletContextResourceResolver.java URL: http://svn.apache.org/viewvc/cxf/branches/2.1.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/ServletContextResourceResolver.java?rev=895876&r1=895875&r2=895876&view=diff ============================================================================== --- cxf/branches/2.1.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/ServletContextResourceResolver.java (original) +++ cxf/branches/2.1.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/ServletContextResourceResolver.java Tue Jan 5 03:31:38 2010 @@ -60,7 +60,11 @@ try { if (entryName != null) { InitialContext ic = new InitialContext(); - obj = ic.lookup(entryName); + try { + obj = ic.lookup(entryName); + } finally { + ic.close(); + } } } catch (NamingException e) { //do nothing
