Author: veithen Date: Sat Oct 10 22:53:54 2009 New Revision: 823973 URL: http://svn.apache.org/viewvc?rev=823973&view=rev Log: WSCOMMONS-489: Attempt to work around the thread safety issue in older SJSXP versions reported by Aaron McIver.
Added: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/dialect/SynchronizedOutputFactoryWrapper.java (with props) Modified: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/dialect/SJSXPDialect.java webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/dialect/StAXDialectDetector.java Modified: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/dialect/SJSXPDialect.java URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/dialect/SJSXPDialect.java?rev=823973&r1=823972&r2=823973&view=diff ============================================================================== --- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/dialect/SJSXPDialect.java (original) +++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/dialect/SJSXPDialect.java Sat Oct 10 22:53:54 2009 @@ -27,10 +27,14 @@ import javax.xml.stream.XMLStreamWriter; class SJSXPDialect extends AbstractStAXDialect { - public static final SJSXPDialect INSTANCE = new SJSXPDialect(); + private final boolean isUnsafeStreamResult; + + public SJSXPDialect(boolean isUnsafeStreamResult) { + this.isUnsafeStreamResult = isUnsafeStreamResult; + } public String getName() { - return "SJSXP"; + return isUnsafeStreamResult ? "SJSXP (with thread safety issue)" : "SJSXP"; } public XMLInputFactory enableCDataReporting(XMLInputFactory factory) { @@ -64,6 +68,9 @@ public XMLOutputFactory makeThreadSafe(XMLOutputFactory factory) { factory.setProperty("reuse-instance", Boolean.FALSE); + if (isUnsafeStreamResult) { + factory = new SynchronizedOutputFactoryWrapper(factory); + } return factory; } Modified: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/dialect/StAXDialectDetector.java URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/dialect/StAXDialectDetector.java?rev=823973&r1=823972&r2=823973&view=diff ============================================================================== --- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/dialect/StAXDialectDetector.java (original) +++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/dialect/StAXDialectDetector.java Sat Oct 10 22:53:54 2009 @@ -227,7 +227,7 @@ if (vendor != null && vendor.toLowerCase().indexOf("woodstox") != -1) { return WoodstoxDialect.INSTANCE; } else if (title != null && title.indexOf("SJSXP") != -1) { - return SJSXPDialect.INSTANCE; + return new SJSXPDialect(false); } else if ("BEA".equals(vendor)) { return BEADialect.INSTANCE; } else if ("com.ibm.ws.prereq.banshee".equals(symbolicName)) { @@ -251,14 +251,25 @@ } private static StAXDialect detectDialectFromClasses(ClassLoader classLoader, URL rootUrl) { + Class cls; + // Try Sun's implementation found in JREs - if (loadClass(classLoader, rootUrl, "com.sun.xml.internal.stream.XMLInputFactoryImpl") - != null) { - return SJSXPDialect.INSTANCE; + cls = loadClass(classLoader, rootUrl, "com.sun.xml.internal.stream.XMLOutputFactoryImpl"); + if (cls != null) { + // Check if the implementation has the bug fixed here: + // https://sjsxp.dev.java.net/source/browse/sjsxp/zephyr/src/com/sun/xml/stream/ZephyrWriterFactory.java?rev=1.8&r1=1.4&r2=1.5 + boolean isUnsafeStreamResult; + try { + cls.getField("fStreamResult"); + isUnsafeStreamResult = true; + } catch (NoSuchFieldException ex) { + isUnsafeStreamResult = false; + } + return new SJSXPDialect(isUnsafeStreamResult); } // Try IBM's XL XP-J - Class cls = loadClass(classLoader, rootUrl, "com.ibm.xml.xlxp.api.stax.StAXImplConstants"); + cls = loadClass(classLoader, rootUrl, "com.ibm.xml.xlxp.api.stax.StAXImplConstants"); if (cls != null) { boolean isSetPrefixBroken; try { Added: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/dialect/SynchronizedOutputFactoryWrapper.java URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/dialect/SynchronizedOutputFactoryWrapper.java?rev=823973&view=auto ============================================================================== --- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/dialect/SynchronizedOutputFactoryWrapper.java (added) +++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/dialect/SynchronizedOutputFactoryWrapper.java Sat Oct 10 22:53:54 2009 @@ -0,0 +1,76 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.axiom.util.stax.dialect; + +import java.io.OutputStream; +import java.io.Writer; + +import javax.xml.stream.XMLEventWriter; +import javax.xml.stream.XMLOutputFactory; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamWriter; +import javax.xml.transform.Result; + +import org.apache.axiom.util.stax.wrapper.XMLOutputFactoryWrapper; + +class SynchronizedOutputFactoryWrapper extends XMLOutputFactoryWrapper { + public SynchronizedOutputFactoryWrapper(XMLOutputFactory parent) { + super(parent); + } + + public synchronized XMLEventWriter createXMLEventWriter(OutputStream stream, String encoding) + throws XMLStreamException { + return super.createXMLEventWriter(stream, encoding); + } + + public synchronized XMLEventWriter createXMLEventWriter(OutputStream stream) + throws XMLStreamException { + return super.createXMLEventWriter(stream); + } + + public synchronized XMLEventWriter createXMLEventWriter(Result result) + throws XMLStreamException { + return super.createXMLEventWriter(result); + } + + public synchronized XMLEventWriter createXMLEventWriter(Writer stream) + throws XMLStreamException { + return super.createXMLEventWriter(stream); + } + + public synchronized XMLStreamWriter createXMLStreamWriter(OutputStream stream, String encoding) + throws XMLStreamException { + return super.createXMLStreamWriter(stream, encoding); + } + + public synchronized XMLStreamWriter createXMLStreamWriter(OutputStream stream) + throws XMLStreamException { + return super.createXMLStreamWriter(stream); + } + + public synchronized XMLStreamWriter createXMLStreamWriter(Result result) + throws XMLStreamException { + return super.createXMLStreamWriter(result); + } + + public synchronized XMLStreamWriter createXMLStreamWriter(Writer stream) + throws XMLStreamException { + return super.createXMLStreamWriter(stream); + } +} Propchange: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/dialect/SynchronizedOutputFactoryWrapper.java ------------------------------------------------------------------------------ svn:eol-style = native