Author: dkulp Date: Wed Jul 15 20:48:49 2009 New Revision: 794411 URL: http://svn.apache.org/viewvc?rev=794411&view=rev Log: Merged revisions 794404 via svnmerge from https://svn.apache.org/repos/asf/cxf/branches/2.2.x-fixes
................ r794404 | dkulp | 2009-07-15 16:26:33 -0400 (Wed, 15 Jul 2009) | 11 lines Merged revisions 794396 via svnmerge from https://svn.apache.org/repos/asf/cxf/trunk ........ r794396 | dkulp | 2009-07-15 16:17:11 -0400 (Wed, 15 Jul 2009) | 3 lines [CXF-2342] Update to use pools of XMLInputFactory/XMLOutputFactory objects Modified patch from Kevin Conaway applied ........ ................ Modified: cxf/branches/2.1.x-fixes/ (props changed) cxf/branches/2.1.x-fixes/common/common/src/main/java/org/apache/cxf/staxutils/StaxUtils.java cxf/branches/2.1.x-fixes/common/common/src/test/java/org/apache/cxf/staxutils/DepthXMLStreamReaderTest.java cxf/branches/2.1.x-fixes/common/common/src/test/java/org/apache/cxf/staxutils/FragmentStreamReaderTest.java cxf/branches/2.1.x-fixes/rt/bindings/http/src/main/java/org/apache/cxf/binding/http/interceptor/URIParameterInInterceptor.java cxf/branches/2.1.x-fixes/rt/core/src/main/java/org/apache/cxf/interceptor/StaxInInterceptor.java cxf/branches/2.1.x-fixes/rt/core/src/main/java/org/apache/cxf/interceptor/StaxOutInterceptor.java cxf/branches/2.1.x-fixes/systests/src/test/java/org/apache/cxf/systest/versioning/MediatorInInterceptor.java Propchange: cxf/branches/2.1.x-fixes/ ------------------------------------------------------------------------------ --- svn:mergeinfo (original) +++ svn:mergeinfo Wed Jul 15 20:48:49 2009 @@ -1,2 +1,2 @@ -/cxf/branches/2.2.x-fixes:743446,753380,753397,753421,754585,755365,757499,757859,757899,757935,757951,758195,758303,758308,758378,758690,758910,759890,759961,759963-759964,759966,760029,760073,760150,760171,760178,760198,760212,760456,760468,760582,760938,761094,761113,761120,761317,761759,761789,762393,762518,762567,763200,763272,763495,763854,763931,763942,763953,764033-764034,764581,764599-764606,764887,765357,766013,766058,766100-766101,766763,766770,766860,766962-766963,767159,767191,767927,771416,772143,772402,772658,772714,773009-773010,773027,773049,773146,773581,773691,773693,774446-774496,774558,774760,774851,774979,775423,776024-776025,776218,776429,776459,777189,777224,777243,777481,777505,777572,777580,780033,780184,780213,780421,780664,780800,780902,780911,781497,781841,782733,782735-782736,783099,783407,784064,784197,785293,785296,785298-785299,785301,785656,786158,786587,786589,786591-786592,786640,787272,787276,787282-787283,787285,787295,787307,787324,7873 67,788824-788825,788827-788828,788830,789423,789429,789707,789709-789710,789712,789721,789905,789908,789910,789912,790295,790646-790647,790651,790654-790655,790659,791948,791950,791952,791955,792276,792288,792291,792992,792995,792998,794402 -/cxf/trunk:782181,782728-782730,783097,783396,784059,784181,784895,785279-785282,785468,786142,786271,786395,786582-786583,786638,786647,787269,787277-787279,787290,787305,787323,787366,788060,788187,788703,788774,788820,789371,789420,789527-789529,789704-789705,789896,789898-789900,790294,790637-790644,791354,791538,791753,791947,792261-792263,792684,792975,792985,794297 +/cxf/branches/2.2.x-fixes:743446,753380,753397,753421,754585,755365,757499,757859,757899,757935,757951,758195,758303,758308,758378,758690,758910,759890,759961,759963-759964,759966,760029,760073,760150,760171,760178,760198,760212,760456,760468,760582,760938,761094,761113,761120,761317,761759,761789,762393,762518,762567,763200,763272,763495,763854,763931,763942,763953,764033-764034,764581,764599-764606,764887,765357,766013,766058,766100-766101,766763,766770,766860,766962-766963,767159,767191,767927,771416,772143,772402,772658,772714,773009-773010,773027,773049,773146,773581,773691,773693,774446-774496,774558,774760,774851,774979,775423,776024-776025,776218,776429,776459,777189,777224,777243,777481,777505,777572,777580,780033,780184,780213,780421,780664,780800,780902,780911,781497,781841,782733,782735-782736,783099,783407,784064,784197,785293,785296,785298-785299,785301,785656,786158,786587,786589,786591-786592,786640,787272,787276,787282-787283,787285,787295,787307,787324,7873 67,788824-788825,788827-788828,788830,789423,789429,789707,789709-789710,789712,789721,789905,789908,789910,789912,790295,790646-790647,790651,790654-790655,790659,791948,791950,791952,791955,792276,792288,792291,792992,792995,792998,794402,794404 +/cxf/trunk:782181,782728-782730,783097,783396,784059,784181,784895,785279-785282,785468,786142,786271,786395,786582-786583,786638,786647,787269,787277-787279,787290,787305,787323,787366,788060,788187,788703,788774,788820,789371,789420,789527-789529,789704-789705,789896,789898-789900,790294,790637-790644,791354,791538,791753,791947,792261-792263,792684,792975,792985,794297,794396 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/staxutils/StaxUtils.java URL: http://svn.apache.org/viewvc/cxf/branches/2.1.x-fixes/common/common/src/main/java/org/apache/cxf/staxutils/StaxUtils.java?rev=794411&r1=794410&r2=794411&view=diff ============================================================================== --- cxf/branches/2.1.x-fixes/common/common/src/main/java/org/apache/cxf/staxutils/StaxUtils.java (original) +++ cxf/branches/2.1.x-fixes/common/common/src/main/java/org/apache/cxf/staxutils/StaxUtils.java Wed Jul 15 20:48:49 2009 @@ -23,9 +23,9 @@ import java.io.OutputStream; import java.io.Reader; import java.io.Writer; -//import java.util.HashMap; -//import java.util.Map; import java.util.Iterator; +import java.util.concurrent.BlockingQueue; +import java.util.concurrent.LinkedBlockingQueue; import java.util.logging.Logger; import javax.xml.namespace.NamespaceContext; @@ -74,23 +74,27 @@ private static final Logger LOG = LogUtils.getL7dLogger(StaxUtils.class); - private static final XMLInputFactory XML_NS_AWARE_INPUT_FACTORY = XMLInputFactory.newInstance(); - private static final XMLInputFactory XML_INPUT_FACTORY = XMLInputFactory.newInstance(); - private static final XMLOutputFactory XML_OUTPUT_FACTORY = XMLOutputFactory.newInstance(); + private static final BlockingQueue<XMLInputFactory> NS_AWARE_INPUT_FACTORY_POOL; + private static final BlockingQueue<XMLOutputFactory> OUTPUT_FACTORY_POOL; private static final String XML_NS = "http://www.w3.org/2000/xmlns/"; static { + int i = 20; + try { - XML_INPUT_FACTORY.setProperty(XMLInputFactory.IS_NAMESPACE_AWARE, false); - } catch (Exception e) { - //ignore + String s = System.getProperty("org.apache.cxf.staxutils.pool-size", + "-1"); + i = Integer.parseInt(s); + } catch (Throwable t) { + //ignore + i = 20; } - try { - XML_NS_AWARE_INPUT_FACTORY.setProperty(XMLInputFactory.IS_NAMESPACE_AWARE, true); - } catch (Exception ex) { - //ignore + if (i <= 0) { + i = 20; } + NS_AWARE_INPUT_FACTORY_POOL = new LinkedBlockingQueue<XMLInputFactory>(i); + OUTPUT_FACTORY_POOL = new LinkedBlockingQueue<XMLOutputFactory>(i); } private StaxUtils() { @@ -109,17 +113,29 @@ * Return a cached, namespace-aware, factory. * @return */ - public static XMLInputFactory getXMLInputFactory() { - return getXMLInputFactory(true); + private static XMLInputFactory getXMLInputFactory() { + XMLInputFactory f = NS_AWARE_INPUT_FACTORY_POOL.poll(); + if (f == null) { + f = XMLInputFactory.newInstance(); + f.setProperty(XMLInputFactory.IS_NAMESPACE_AWARE, true); + } + return f; } - /** - * Return a cached factory. - * @param nsAware - * @return - */ - public static XMLInputFactory getXMLInputFactory(boolean nsAware) { - return nsAware ? XML_NS_AWARE_INPUT_FACTORY : XML_INPUT_FACTORY; + private static void returnXMLInputFactory(XMLInputFactory factory) { + NS_AWARE_INPUT_FACTORY_POOL.offer(factory); + } + + private static XMLOutputFactory getXMLOutputFactory() { + XMLOutputFactory f = OUTPUT_FACTORY_POOL.poll(); + if (f == null) { + f = XMLOutputFactory.newInstance(); + } + return f; + } + + private static void returnXMLOutputFactory(XMLOutputFactory factory) { + OUTPUT_FACTORY_POOL.offer(factory); } /** @@ -133,18 +149,16 @@ return factory; } - public static XMLOutputFactory getXMLOutputFactory() { - return XML_OUTPUT_FACTORY; - } + public static XMLStreamWriter createXMLStreamWriter(Writer out) { + XMLOutputFactory factory = getXMLOutputFactory(); try { - XMLOutputFactory factory = getXMLOutputFactory(); - synchronized (factory) { - return factory.createXMLStreamWriter(out); - } + return factory.createXMLStreamWriter(out); } catch (XMLStreamException e) { throw new RuntimeException("Cant' create XMLStreamWriter", e); + } finally { + returnXMLOutputFactory(factory); } } @@ -156,36 +170,35 @@ if (encoding == null) { encoding = "UTF-8"; } - + XMLOutputFactory factory = getXMLOutputFactory(); try { - XMLOutputFactory factory = getXMLOutputFactory(); - synchronized (factory) { - return factory.createXMLStreamWriter(out, encoding); - } + return factory.createXMLStreamWriter(out, encoding); } catch (XMLStreamException e) { throw new RuntimeException("Cant' create XMLStreamWriter", e); + } finally { + returnXMLOutputFactory(factory); } } public static XMLStreamWriter createXMLStreamWriter(Result r) { + XMLOutputFactory factory = getXMLOutputFactory(); try { - XMLOutputFactory factory = getXMLOutputFactory(); - synchronized (factory) { - return factory.createXMLStreamWriter(r); - } + return factory.createXMLStreamWriter(r); } catch (XMLStreamException e) { throw new RuntimeException("Cant' create XMLStreamWriter", e); + } finally { + returnXMLOutputFactory(factory); } } public static XMLStreamReader createFilteredReader(XMLStreamReader reader, StreamFilter filter) { + XMLInputFactory factory = getXMLInputFactory(); try { - XMLInputFactory factory = getXMLInputFactory(); - synchronized (factory) { - return factory.createFilteredReader(reader, filter); - } + return factory.createFilteredReader(reader, filter); } catch (XMLStreamException e) { throw new RuntimeException("Cant' create XMLStreamReader", e); + } finally { + returnXMLInputFactory(factory); } } @@ -840,13 +853,13 @@ encoding = "UTF-8"; } + XMLInputFactory factory = getXMLInputFactory(); try { - XMLInputFactory factory = getXMLInputFactory(); - synchronized (factory) { - return factory.createXMLStreamReader(in, encoding); - } + return factory.createXMLStreamReader(in, encoding); } catch (XMLStreamException e) { throw new RuntimeException("Couldn't parse stream.", e); + } finally { + returnXMLInputFactory(factory); } } @@ -855,24 +868,24 @@ * @return */ public static XMLStreamReader createXMLStreamReader(InputStream in) { + XMLInputFactory factory = getXMLInputFactory(); try { - XMLInputFactory factory = getXMLInputFactory(); - synchronized (factory) { - return factory.createXMLStreamReader(in); - } + return factory.createXMLStreamReader(in); } catch (XMLStreamException e) { throw new RuntimeException("Couldn't parse stream.", e); + } finally { + returnXMLInputFactory(factory); } } public static XMLStreamReader createXMLStreamReader(String systemId, InputStream in) { + XMLInputFactory factory = getXMLInputFactory(); try { - XMLInputFactory factory = getXMLInputFactory(); - synchronized (factory) { - return factory.createXMLStreamReader(systemId, in); - } + return factory.createXMLStreamReader(systemId, in); } catch (XMLStreamException e) { throw new RuntimeException("Couldn't parse stream.", e); + } finally { + returnXMLInputFactory(factory); } } @@ -899,9 +912,12 @@ return new W3CDOMStreamReader(el); } } + XMLInputFactory factory = getXMLInputFactory(); - synchronized (factory) { + try { return factory.createXMLStreamReader(source); + } finally { + returnXMLInputFactory(factory); } } catch (XMLStreamException e) { throw new RuntimeException("Couldn't parse stream.", e); @@ -913,14 +929,13 @@ * @return */ public static XMLStreamReader createXMLStreamReader(Reader reader) { - + XMLInputFactory factory = getXMLInputFactory(); try { - XMLInputFactory factory = getXMLInputFactory(); - synchronized (factory) { - return factory.createXMLStreamReader(reader); - } + return factory.createXMLStreamReader(reader); } catch (XMLStreamException e) { throw new RuntimeException("Couldn't parse stream.", e); + } finally { + returnXMLInputFactory(factory); } } Modified: cxf/branches/2.1.x-fixes/common/common/src/test/java/org/apache/cxf/staxutils/DepthXMLStreamReaderTest.java URL: http://svn.apache.org/viewvc/cxf/branches/2.1.x-fixes/common/common/src/test/java/org/apache/cxf/staxutils/DepthXMLStreamReaderTest.java?rev=794411&r1=794410&r2=794411&view=diff ============================================================================== --- cxf/branches/2.1.x-fixes/common/common/src/test/java/org/apache/cxf/staxutils/DepthXMLStreamReaderTest.java (original) +++ cxf/branches/2.1.x-fixes/common/common/src/test/java/org/apache/cxf/staxutils/DepthXMLStreamReaderTest.java Wed Jul 15 20:48:49 2009 @@ -19,7 +19,6 @@ package org.apache.cxf.staxutils; -import javax.xml.stream.XMLInputFactory; import javax.xml.stream.XMLStreamReader; import org.junit.Assert; @@ -29,9 +28,8 @@ @Test public void testReader() throws Exception { - XMLInputFactory ifactory = StaxUtils.getXMLInputFactory(); XMLStreamReader reader = - ifactory.createXMLStreamReader(getClass().getResourceAsStream("./resources/amazon.xml")); + StaxUtils.createXMLStreamReader(getClass().getResourceAsStream("./resources/amazon.xml")); DepthXMLStreamReader dr = new DepthXMLStreamReader(reader); Modified: cxf/branches/2.1.x-fixes/common/common/src/test/java/org/apache/cxf/staxutils/FragmentStreamReaderTest.java URL: http://svn.apache.org/viewvc/cxf/branches/2.1.x-fixes/common/common/src/test/java/org/apache/cxf/staxutils/FragmentStreamReaderTest.java?rev=794411&r1=794410&r2=794411&view=diff ============================================================================== --- cxf/branches/2.1.x-fixes/common/common/src/test/java/org/apache/cxf/staxutils/FragmentStreamReaderTest.java (original) +++ cxf/branches/2.1.x-fixes/common/common/src/test/java/org/apache/cxf/staxutils/FragmentStreamReaderTest.java Wed Jul 15 20:48:49 2009 @@ -19,7 +19,6 @@ package org.apache.cxf.staxutils; -import javax.xml.stream.XMLInputFactory; import javax.xml.stream.XMLStreamReader; import org.junit.Assert; @@ -29,9 +28,8 @@ @Test public void testReader() throws Exception { - XMLInputFactory ifactory = StaxUtils.getXMLInputFactory(); XMLStreamReader reader = - ifactory.createXMLStreamReader(getClass().getResourceAsStream("./resources/amazon.xml")); + StaxUtils.createXMLStreamReader(getClass().getResourceAsStream("./resources/amazon.xml")); DepthXMLStreamReader dr = new DepthXMLStreamReader(reader); Modified: cxf/branches/2.1.x-fixes/rt/bindings/http/src/main/java/org/apache/cxf/binding/http/interceptor/URIParameterInInterceptor.java URL: http://svn.apache.org/viewvc/cxf/branches/2.1.x-fixes/rt/bindings/http/src/main/java/org/apache/cxf/binding/http/interceptor/URIParameterInInterceptor.java?rev=794411&r1=794410&r2=794411&view=diff ============================================================================== --- cxf/branches/2.1.x-fixes/rt/bindings/http/src/main/java/org/apache/cxf/binding/http/interceptor/URIParameterInInterceptor.java (original) +++ cxf/branches/2.1.x-fixes/rt/bindings/http/src/main/java/org/apache/cxf/binding/http/interceptor/URIParameterInInterceptor.java Wed Jul 15 20:48:49 2009 @@ -114,8 +114,12 @@ XMLInputFactory inputFactory = StaxInInterceptor.getXMLInputFactory(message); try { XMLStreamReader reader; - synchronized (inputFactory) { - reader = inputFactory.createXMLStreamReader(message.getContent(InputStream.class)); + if (inputFactory == null) { + reader = StaxUtils.createXMLStreamReader(message.getContent(InputStream.class)); + } else { + synchronized (inputFactory) { + reader = inputFactory.createXMLStreamReader(message.getContent(InputStream.class)); + } } doc = StaxUtils.read(reader); } catch (XMLStreamException e) { Modified: cxf/branches/2.1.x-fixes/rt/core/src/main/java/org/apache/cxf/interceptor/StaxInInterceptor.java URL: http://svn.apache.org/viewvc/cxf/branches/2.1.x-fixes/rt/core/src/main/java/org/apache/cxf/interceptor/StaxInInterceptor.java?rev=794411&r1=794410&r2=794411&view=diff ============================================================================== --- cxf/branches/2.1.x-fixes/rt/core/src/main/java/org/apache/cxf/interceptor/StaxInInterceptor.java (original) +++ cxf/branches/2.1.x-fixes/rt/core/src/main/java/org/apache/cxf/interceptor/StaxInInterceptor.java Wed Jul 15 20:48:49 2009 @@ -79,8 +79,12 @@ XMLStreamReader reader; try { XMLInputFactory factory = getXMLInputFactory(message); - synchronized (factory) { - reader = factory.createXMLStreamReader(is, encoding); + if (factory == null) { + reader = StaxUtils.createXMLStreamReader(is, encoding); + } else { + synchronized (factory) { + reader = factory.createXMLStreamReader(is, encoding); + } } } catch (XMLStreamException e) { throw new Fault(new org.apache.cxf.common.i18n.Message("STREAM_CREATE_EXC", @@ -123,8 +127,7 @@ } } return xif; - } else { - return StaxUtils.getXMLInputFactory(); - } + } + return null; } } Modified: cxf/branches/2.1.x-fixes/rt/core/src/main/java/org/apache/cxf/interceptor/StaxOutInterceptor.java URL: http://svn.apache.org/viewvc/cxf/branches/2.1.x-fixes/rt/core/src/main/java/org/apache/cxf/interceptor/StaxOutInterceptor.java?rev=794411&r1=794410&r2=794411&view=diff ============================================================================== --- cxf/branches/2.1.x-fixes/rt/core/src/main/java/org/apache/cxf/interceptor/StaxOutInterceptor.java (original) +++ cxf/branches/2.1.x-fixes/rt/core/src/main/java/org/apache/cxf/interceptor/StaxOutInterceptor.java Wed Jul 15 20:48:49 2009 @@ -65,8 +65,12 @@ try { XMLOutputFactory factory = getXMLOutputFactory(message); - synchronized (factory) { - writer = factory.createXMLStreamWriter(os, encoding); + if (factory == null) { + writer = StaxUtils.createXMLStreamWriter(os, encoding); + } else { + synchronized (factory) { + writer = factory.createXMLStreamWriter(os, encoding); + } } if (Boolean.TRUE.equals(message.getContextualProperty(FORCE_START_DOCUMENT))) { writer.writeStartDocument(encoding, "1.0"); @@ -142,9 +146,8 @@ Boolean.TRUE); m.put(FORCE_START_DOCUMENT, Boolean.TRUE); return xif; - } else { - return StaxUtils.getXMLOutputFactory(); } + return null; } public class StaxOutEndingInterceptor extends AbstractPhaseInterceptor<Message> { Modified: cxf/branches/2.1.x-fixes/systests/src/test/java/org/apache/cxf/systest/versioning/MediatorInInterceptor.java URL: http://svn.apache.org/viewvc/cxf/branches/2.1.x-fixes/systests/src/test/java/org/apache/cxf/systest/versioning/MediatorInInterceptor.java?rev=794411&r1=794410&r2=794411&view=diff ============================================================================== --- cxf/branches/2.1.x-fixes/systests/src/test/java/org/apache/cxf/systest/versioning/MediatorInInterceptor.java (original) +++ cxf/branches/2.1.x-fixes/systests/src/test/java/org/apache/cxf/systest/versioning/MediatorInInterceptor.java Wed Jul 15 20:48:49 2009 @@ -36,6 +36,7 @@ import org.apache.cxf.io.CachedOutputStream; import org.apache.cxf.message.Message; import org.apache.cxf.phase.Phase; +import org.apache.cxf.staxutils.StaxUtils; public class MediatorInInterceptor extends AbstractEndpointSelectionInterceptor { @@ -64,8 +65,12 @@ XMLStreamReader xsr; XMLInputFactory factory = StaxInInterceptor.getXMLInputFactory(message); - synchronized (factory) { - xsr = factory.createXMLStreamReader(bos.getInputStream(), encoding); + if (factory == null) { + xsr = StaxUtils.createXMLStreamReader(bos.getInputStream(), encoding); + } else { + synchronized (factory) { + xsr = factory.createXMLStreamReader(bos.getInputStream(), encoding); + } } // move to the soap body
