8026188: Enhance envelope factory
Avoiding caching data initialized via TCCL in static context; fix also reviewed by Alexander Fomin Reviewed-by: ahgross, mgrebac, skoivu
This commit is contained in:
parent
340602a342
commit
080a4bc77a
@ -0,0 +1,85 @@
|
||||
/*
|
||||
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.sun.tools.internal.ws.wsdl.parser;
|
||||
|
||||
import java.security.AccessController;
|
||||
import java.security.PrivilegedAction;
|
||||
import java.text.MessageFormat;
|
||||
import java.util.ResourceBundle;
|
||||
import java.util.WeakHashMap;
|
||||
|
||||
/**
|
||||
* Simple utility ensuring that the value is cached only in case it is non-internal implementation
|
||||
*/
|
||||
abstract class ContextClassloaderLocal<V> {
|
||||
|
||||
private static final String FAILED_TO_CREATE_NEW_INSTANCE = "FAILED_TO_CREATE_NEW_INSTANCE";
|
||||
|
||||
private WeakHashMap<ClassLoader, V> CACHE = new WeakHashMap<ClassLoader, V>();
|
||||
|
||||
public V get() throws Error {
|
||||
ClassLoader tccl = getContextClassLoader();
|
||||
V instance = CACHE.get(tccl);
|
||||
if (instance == null) {
|
||||
instance = createNewInstance();
|
||||
CACHE.put(tccl, instance);
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
public void set(V instance) {
|
||||
CACHE.put(getContextClassLoader(), instance);
|
||||
}
|
||||
|
||||
protected abstract V initialValue() throws Exception;
|
||||
|
||||
private V createNewInstance() {
|
||||
try {
|
||||
return initialValue();
|
||||
} catch (Exception e) {
|
||||
throw new Error(format(FAILED_TO_CREATE_NEW_INSTANCE, getClass().getName()), e);
|
||||
}
|
||||
}
|
||||
|
||||
private static String format(String property, Object... args) {
|
||||
String text = ResourceBundle.getBundle(ContextClassloaderLocal.class.getName()).getString(property);
|
||||
return MessageFormat.format(text, args);
|
||||
}
|
||||
|
||||
private static ClassLoader getContextClassLoader() {
|
||||
return (ClassLoader)
|
||||
AccessController.doPrivileged(new PrivilegedAction() {
|
||||
public Object run() {
|
||||
ClassLoader cl = null;
|
||||
try {
|
||||
cl = Thread.currentThread().getContextClassLoader();
|
||||
} catch (SecurityException ex) {
|
||||
}
|
||||
return cl;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
#
|
||||
# Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
#
|
||||
# This code is free software; you can redistribute it and/or modify it
|
||||
# under the terms of the GNU General Public License version 2 only, as
|
||||
# published by the Free Software Foundation. Oracle designates this
|
||||
# particular file as subject to the "Classpath" exception as provided
|
||||
# by Oracle in the LICENSE file that accompanied this code.
|
||||
#
|
||||
# This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
# version 2 for more details (a copy is included in the LICENSE file that
|
||||
# accompanied this code).
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License version
|
||||
# 2 along with this work; if not, write to the Free Software Foundation,
|
||||
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
#
|
||||
# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
# or visit www.oracle.com if you need additional information or have any
|
||||
# questions.
|
||||
#
|
||||
|
||||
FAILED_TO_CREATE_NEW_INSTANCE=Failed to create new instance of {0}
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -60,12 +60,10 @@ import java.util.Set;
|
||||
*/
|
||||
public class Internalizer {
|
||||
|
||||
private static final XPathFactory xpf = XmlUtil.newXPathFactory(true);
|
||||
private final XPath xpath = xpf.newXPath();
|
||||
private final XPath xpath = xpf.get().newXPath();
|
||||
private final DOMForest forest;
|
||||
private final ErrorReceiver errorReceiver;
|
||||
|
||||
|
||||
public Internalizer(DOMForest forest, WsimportOptions options, ErrorReceiver errorReceiver) {
|
||||
this.forest = forest;
|
||||
this.errorReceiver = errorReceiver;
|
||||
@ -77,6 +75,12 @@ public class Internalizer {
|
||||
}
|
||||
}
|
||||
|
||||
private static final ContextClassloaderLocal<XPathFactory> xpf = new ContextClassloaderLocal<XPathFactory>() {
|
||||
@Override
|
||||
protected XPathFactory initialValue() throws Exception {
|
||||
return XPathFactory.newInstance();
|
||||
}
|
||||
};
|
||||
/**
|
||||
* Validates attributes of a <JAXWS:bindings> element.
|
||||
*/
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -54,8 +54,14 @@ import java.util.Map;
|
||||
public class JAXWSBindingExtensionHandler extends AbstractExtensionHandler {
|
||||
|
||||
// xml security enabled always, xpath used for parsing "part" attribute
|
||||
private static final XPathFactory xpf = XmlUtil.newXPathFactory(true);
|
||||
private final XPath xpath = xpf.newXPath();
|
||||
private static final ContextClassloaderLocal<XPathFactory> xpf = new ContextClassloaderLocal<XPathFactory>() {
|
||||
@Override
|
||||
protected XPathFactory initialValue() throws Exception {
|
||||
return XPathFactory.newInstance();
|
||||
}
|
||||
};
|
||||
|
||||
private final XPath xpath = xpf.get().newXPath();
|
||||
|
||||
public JAXWSBindingExtensionHandler(Map<String, AbstractExtensionHandler> extensionHandlerMap) {
|
||||
super(extensionHandlerMap);
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -76,8 +76,6 @@ class Internalizer {
|
||||
|
||||
private static final String WSDL_NS = "http://schemas.xmlsoap.org/wsdl/";
|
||||
|
||||
private static XPathFactory xpf = null;
|
||||
|
||||
private final XPath xpath;
|
||||
|
||||
/**
|
||||
@ -99,12 +97,7 @@ class Internalizer {
|
||||
this.errorHandler = forest.getErrorHandler();
|
||||
this.forest = forest;
|
||||
this.enableSCD = enableSCD;
|
||||
synchronized (this) {
|
||||
if (xpf == null) {
|
||||
xpf = XmlFactory.createXPathFactory(disableSecureProcessing);
|
||||
}
|
||||
}
|
||||
xpath = xpf.newXPath();
|
||||
xpath = XmlFactory.createXPathFactory(disableSecureProcessing).newXPath();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -170,7 +163,6 @@ class Internalizer {
|
||||
if( a.getLocalName().equals("multiple") ) //
|
||||
continue;
|
||||
|
||||
|
||||
// TODO: flag error for this undefined attribute
|
||||
}
|
||||
}
|
||||
|
@ -128,14 +128,6 @@ public final class JAXBContextImpl extends JAXBRIContext {
|
||||
*/
|
||||
private final Map<TypeReference,Bridge> bridges = new LinkedHashMap<TypeReference,Bridge>();
|
||||
|
||||
/**
|
||||
* Shared instance of {@link TransformerFactory}.
|
||||
* Lock before use, because a {@link TransformerFactory} is not thread-safe
|
||||
* whereas {@link JAXBContextImpl} is.
|
||||
* Lazily created.
|
||||
*/
|
||||
private volatile static SAXTransformerFactory tf;
|
||||
|
||||
/**
|
||||
* Shared instance of {@link DocumentBuilder}.
|
||||
* Lock before use. Lazily created.
|
||||
@ -705,13 +697,7 @@ public final class JAXBContextImpl extends JAXBRIContext {
|
||||
*/
|
||||
static Transformer createTransformer(boolean disableSecureProcessing) {
|
||||
try {
|
||||
if (tf==null) {
|
||||
synchronized(JAXBContextImpl.class) {
|
||||
if (tf==null) {
|
||||
tf = (SAXTransformerFactory)XmlFactory.createTransformerFactory(disableSecureProcessing);
|
||||
}
|
||||
}
|
||||
}
|
||||
SAXTransformerFactory tf = (SAXTransformerFactory)XmlFactory.createTransformerFactory(disableSecureProcessing);
|
||||
return tf.newTransformer();
|
||||
} catch (TransformerConfigurationException e) {
|
||||
throw new Error(e); // impossible
|
||||
@ -723,13 +709,7 @@ public final class JAXBContextImpl extends JAXBRIContext {
|
||||
*/
|
||||
public static TransformerHandler createTransformerHandler(boolean disableSecureProcessing) {
|
||||
try {
|
||||
if (tf==null) {
|
||||
synchronized(JAXBContextImpl.class) {
|
||||
if (tf==null) {
|
||||
tf = (SAXTransformerFactory)XmlFactory.createTransformerFactory(disableSecureProcessing);
|
||||
}
|
||||
}
|
||||
}
|
||||
SAXTransformerFactory tf = (SAXTransformerFactory)XmlFactory.createTransformerFactory(disableSecureProcessing);
|
||||
return tf.newTransformerHandler();
|
||||
} catch (TransformerConfigurationException e) {
|
||||
throw new Error(e); // impossible
|
||||
|
@ -0,0 +1,85 @@
|
||||
/*
|
||||
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.sun.xml.internal.messaging.saaj.soap;
|
||||
|
||||
import java.security.AccessController;
|
||||
import java.security.PrivilegedAction;
|
||||
import java.text.MessageFormat;
|
||||
import java.util.ResourceBundle;
|
||||
import java.util.WeakHashMap;
|
||||
|
||||
/**
|
||||
* Simple utility ensuring that the value is cached only in case it is non-internal implementation
|
||||
*/
|
||||
abstract class ContextClassloaderLocal<V> {
|
||||
|
||||
private static final String FAILED_TO_CREATE_NEW_INSTANCE = "FAILED_TO_CREATE_NEW_INSTANCE";
|
||||
|
||||
private WeakHashMap<ClassLoader, V> CACHE = new WeakHashMap<ClassLoader, V>();
|
||||
|
||||
public V get() throws Error {
|
||||
ClassLoader tccl = getContextClassLoader();
|
||||
V instance = CACHE.get(tccl);
|
||||
if (instance == null) {
|
||||
instance = createNewInstance();
|
||||
CACHE.put(tccl, instance);
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
public void set(V instance) {
|
||||
CACHE.put(getContextClassLoader(), instance);
|
||||
}
|
||||
|
||||
protected abstract V initialValue() throws Exception;
|
||||
|
||||
private V createNewInstance() {
|
||||
try {
|
||||
return initialValue();
|
||||
} catch (Exception e) {
|
||||
throw new Error(format(FAILED_TO_CREATE_NEW_INSTANCE, getClass().getName()), e);
|
||||
}
|
||||
}
|
||||
|
||||
private static String format(String property, Object... args) {
|
||||
String text = ResourceBundle.getBundle(ContextClassloaderLocal.class.getName()).getString(property);
|
||||
return MessageFormat.format(text, args);
|
||||
}
|
||||
|
||||
private static ClassLoader getContextClassLoader() {
|
||||
return (ClassLoader)
|
||||
AccessController.doPrivileged(new PrivilegedAction() {
|
||||
public Object run() {
|
||||
ClassLoader cl = null;
|
||||
try {
|
||||
cl = Thread.currentThread().getContextClassLoader();
|
||||
} catch (SecurityException ex) {
|
||||
}
|
||||
return cl;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
#
|
||||
# Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
#
|
||||
# This code is free software; you can redistribute it and/or modify it
|
||||
# under the terms of the GNU General Public License version 2 only, as
|
||||
# published by the Free Software Foundation. Oracle designates this
|
||||
# particular file as subject to the "Classpath" exception as provided
|
||||
# by Oracle in the LICENSE file that accompanied this code.
|
||||
#
|
||||
# This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
# version 2 for more details (a copy is included in the LICENSE file that
|
||||
# accompanied this code).
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License version
|
||||
# 2 along with this work; if not, write to the Free Software Foundation,
|
||||
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
#
|
||||
# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
# or visit www.oracle.com if you need additional information or have any
|
||||
# questions.
|
||||
#
|
||||
|
||||
FAILED_TO_CREATE_NEW_INSTANCE=Failed to create new instance of {0}
|
@ -25,7 +25,14 @@
|
||||
|
||||
package com.sun.xml.internal.messaging.saaj.soap;
|
||||
|
||||
import java.util.logging.Logger;
|
||||
import com.sun.xml.internal.messaging.saaj.SOAPExceptionImpl;
|
||||
import com.sun.xml.internal.messaging.saaj.util.JAXMStreamSource;
|
||||
import com.sun.xml.internal.messaging.saaj.util.LogDomainConstants;
|
||||
import com.sun.xml.internal.messaging.saaj.util.ParserPool;
|
||||
import com.sun.xml.internal.messaging.saaj.util.RejectDoctypeSaxFilter;
|
||||
import com.sun.xml.internal.messaging.saaj.util.transform.EfficientStreamingTransformer;
|
||||
import org.xml.sax.InputSource;
|
||||
import org.xml.sax.XMLReader;
|
||||
|
||||
import javax.xml.parsers.SAXParser;
|
||||
import javax.xml.soap.SOAPException;
|
||||
@ -39,14 +46,11 @@ import javax.xml.transform.sax.SAXSource;
|
||||
import javax.xml.transform.stax.StAXSource;
|
||||
import javax.xml.transform.stream.StreamSource;
|
||||
|
||||
import org.xml.sax.InputSource;
|
||||
import org.xml.sax.XMLReader;
|
||||
|
||||
import com.sun.xml.internal.messaging.saaj.LazyEnvelopeSource;
|
||||
import com.sun.xml.internal.messaging.saaj.SOAPExceptionImpl;
|
||||
import com.sun.xml.internal.messaging.saaj.util.*;
|
||||
import com.sun.xml.internal.messaging.saaj.util.transform.EfficientStreamingTransformer;
|
||||
|
||||
import java.util.logging.Logger;
|
||||
|
||||
/**
|
||||
* EnvelopeFactory creates SOAP Envelope objects using different
|
||||
* underlying implementations.
|
||||
@ -54,10 +58,16 @@ import com.sun.xml.internal.messaging.saaj.util.transform.EfficientStreamingTran
|
||||
public class EnvelopeFactory {
|
||||
|
||||
protected static final Logger
|
||||
log = Logger.getLogger(LogDomainConstants.SOAP_DOMAIN,
|
||||
"com.sun.xml.internal.messaging.saaj.soap.LocalStrings");
|
||||
log = Logger.getLogger(LogDomainConstants.SOAP_DOMAIN,
|
||||
"com.sun.xml.internal.messaging.saaj.soap.LocalStrings");
|
||||
|
||||
private static ParserPool parserPool = new ParserPool(5);
|
||||
private static ContextClassloaderLocal<ParserPool> parserPool =
|
||||
new ContextClassloaderLocal<ParserPool>() {
|
||||
@Override
|
||||
protected ParserPool initialValue() throws Exception {
|
||||
return new ParserPool(5);
|
||||
}
|
||||
};
|
||||
|
||||
public static Envelope createEnvelope(Source src, SOAPPartImpl soapPart)
|
||||
throws SOAPException
|
||||
@ -130,15 +140,15 @@ public class EnvelopeFactory {
|
||||
SAXParser saxParser = null;
|
||||
if (src instanceof StreamSource) {
|
||||
try {
|
||||
saxParser = parserPool.get();
|
||||
saxParser = parserPool.get().get();
|
||||
} catch (Exception e) {
|
||||
log.severe("SAAJ0601.util.newSAXParser.exception");
|
||||
throw new SOAPExceptionImpl(
|
||||
"Couldn't get a SAX parser while constructing a envelope",
|
||||
e);
|
||||
"Couldn't get a SAX parser while constructing a envelope",
|
||||
e);
|
||||
}
|
||||
InputSource is = SAXSource.sourceToInputSource(src);
|
||||
if (is.getEncoding()== null && soapPart.getSourceCharsetEncoding() != null) {
|
||||
if (is.getEncoding() == null && soapPart.getSourceCharsetEncoding() != null) {
|
||||
is.setEncoding(soapPart.getSourceCharsetEncoding());
|
||||
}
|
||||
XMLReader rejectFilter;
|
||||
@ -147,15 +157,15 @@ public class EnvelopeFactory {
|
||||
} catch (Exception ex) {
|
||||
log.severe("SAAJ0510.soap.cannot.create.envelope");
|
||||
throw new SOAPExceptionImpl(
|
||||
"Unable to create envelope from given source: ",
|
||||
ex);
|
||||
"Unable to create envelope from given source: ",
|
||||
ex);
|
||||
}
|
||||
src = new SAXSource(rejectFilter, is);
|
||||
}
|
||||
|
||||
try {
|
||||
Transformer transformer =
|
||||
EfficientStreamingTransformer.newTransformer();
|
||||
EfficientStreamingTransformer.newTransformer();
|
||||
DOMResult result = new DOMResult(soapPart);
|
||||
transformer.transform(src, result);
|
||||
|
||||
@ -167,11 +177,11 @@ public class EnvelopeFactory {
|
||||
}
|
||||
log.severe("SAAJ0511.soap.cannot.create.envelope");
|
||||
throw new SOAPExceptionImpl(
|
||||
"Unable to create envelope from given source: ",
|
||||
ex);
|
||||
"Unable to create envelope from given source: ",
|
||||
ex);
|
||||
} finally {
|
||||
if (saxParser != null) {
|
||||
parserPool.returnParser(saxParser);
|
||||
parserPool.get().returnParser(saxParser);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,85 @@
|
||||
/*
|
||||
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.sun.xml.internal.stream.buffer;
|
||||
|
||||
import java.security.AccessController;
|
||||
import java.security.PrivilegedAction;
|
||||
import java.text.MessageFormat;
|
||||
import java.util.ResourceBundle;
|
||||
import java.util.WeakHashMap;
|
||||
|
||||
/**
|
||||
* Simple utility ensuring that the value is cached only in case it is non-internal implementation
|
||||
*/
|
||||
abstract class ContextClassloaderLocal<V> {
|
||||
|
||||
private static final String FAILED_TO_CREATE_NEW_INSTANCE = "FAILED_TO_CREATE_NEW_INSTANCE";
|
||||
|
||||
private WeakHashMap<ClassLoader, V> CACHE = new WeakHashMap<ClassLoader, V>();
|
||||
|
||||
public V get() throws Error {
|
||||
ClassLoader tccl = getContextClassLoader();
|
||||
V instance = CACHE.get(tccl);
|
||||
if (instance == null) {
|
||||
instance = createNewInstance();
|
||||
CACHE.put(tccl, instance);
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
public void set(V instance) {
|
||||
CACHE.put(getContextClassLoader(), instance);
|
||||
}
|
||||
|
||||
protected abstract V initialValue() throws Exception;
|
||||
|
||||
private V createNewInstance() {
|
||||
try {
|
||||
return initialValue();
|
||||
} catch (Exception e) {
|
||||
throw new Error(format(FAILED_TO_CREATE_NEW_INSTANCE, getClass().getName()), e);
|
||||
}
|
||||
}
|
||||
|
||||
private static String format(String property, Object... args) {
|
||||
String text = ResourceBundle.getBundle(ContextClassloaderLocal.class.getName()).getString(property);
|
||||
return MessageFormat.format(text, args);
|
||||
}
|
||||
|
||||
private static ClassLoader getContextClassLoader() {
|
||||
return (ClassLoader)
|
||||
AccessController.doPrivileged(new PrivilegedAction() {
|
||||
public Object run() {
|
||||
ClassLoader cl = null;
|
||||
try {
|
||||
cl = Thread.currentThread().getContextClassLoader();
|
||||
} catch (SecurityException ex) {
|
||||
}
|
||||
return cl;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
#
|
||||
# Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
#
|
||||
# This code is free software; you can redistribute it and/or modify it
|
||||
# under the terms of the GNU General Public License version 2 only, as
|
||||
# published by the Free Software Foundation. Oracle designates this
|
||||
# particular file as subject to the "Classpath" exception as provided
|
||||
# by Oracle in the LICENSE file that accompanied this code.
|
||||
#
|
||||
# This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
# version 2 for more details (a copy is included in the LICENSE file that
|
||||
# accompanied this code).
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License version
|
||||
# 2 along with this work; if not, write to the Free Software Foundation,
|
||||
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
#
|
||||
# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
# or visit www.oracle.com if you need additional information or have any
|
||||
# questions.
|
||||
#
|
||||
|
||||
FAILED_TO_CREATE_NEW_INSTANCE=Failed to create new instance of {0}
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2005, 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -370,7 +370,12 @@ public abstract class XMLStreamBuffer {
|
||||
writeTo(handler, errorHandler, isFragment());
|
||||
}
|
||||
|
||||
private static final TransformerFactory trnsformerFactory = TransformerFactory.newInstance();
|
||||
private static final ContextClassloaderLocal<TransformerFactory> trnsformerFactory = new ContextClassloaderLocal<TransformerFactory>() {
|
||||
@Override
|
||||
protected TransformerFactory initialValue() throws Exception {
|
||||
return TransformerFactory.newInstance();
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Writes out the contents of this buffer as DOM node and append that to the given node.
|
||||
@ -382,7 +387,7 @@ public abstract class XMLStreamBuffer {
|
||||
*/
|
||||
public final Node writeTo(Node n) throws XMLStreamBufferException {
|
||||
try {
|
||||
Transformer t = trnsformerFactory.newTransformer();
|
||||
Transformer t = trnsformerFactory.get().newTransformer();
|
||||
t.transform(new XMLStreamBufferSource(this), new DOMResult(n));
|
||||
return n.getLastChild();
|
||||
} catch (TransformerException e) {
|
||||
|
@ -0,0 +1,85 @@
|
||||
/*
|
||||
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.sun.xml.internal.ws.api.streaming;
|
||||
|
||||
import java.security.AccessController;
|
||||
import java.security.PrivilegedAction;
|
||||
import java.text.MessageFormat;
|
||||
import java.util.ResourceBundle;
|
||||
import java.util.WeakHashMap;
|
||||
|
||||
/**
|
||||
* Simple utility ensuring that the value is cached only in case it is non-internal implementation
|
||||
*/
|
||||
abstract class ContextClassloaderLocal<V> {
|
||||
|
||||
private static final String FAILED_TO_CREATE_NEW_INSTANCE = "FAILED_TO_CREATE_NEW_INSTANCE";
|
||||
|
||||
private WeakHashMap<ClassLoader, V> CACHE = new WeakHashMap<ClassLoader, V>();
|
||||
|
||||
public V get() throws Error {
|
||||
ClassLoader tccl = getContextClassLoader();
|
||||
V instance = CACHE.get(tccl);
|
||||
if (instance == null) {
|
||||
instance = createNewInstance();
|
||||
CACHE.put(tccl, instance);
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
public void set(V instance) {
|
||||
CACHE.put(getContextClassLoader(), instance);
|
||||
}
|
||||
|
||||
protected abstract V initialValue() throws Exception;
|
||||
|
||||
private V createNewInstance() {
|
||||
try {
|
||||
return initialValue();
|
||||
} catch (Exception e) {
|
||||
throw new Error(format(FAILED_TO_CREATE_NEW_INSTANCE, getClass().getName()), e);
|
||||
}
|
||||
}
|
||||
|
||||
private static String format(String property, Object... args) {
|
||||
String text = ResourceBundle.getBundle(ContextClassloaderLocal.class.getName()).getString(property);
|
||||
return MessageFormat.format(text, args);
|
||||
}
|
||||
|
||||
private static ClassLoader getContextClassLoader() {
|
||||
return (ClassLoader)
|
||||
AccessController.doPrivileged(new PrivilegedAction() {
|
||||
public Object run() {
|
||||
ClassLoader cl = null;
|
||||
try {
|
||||
cl = Thread.currentThread().getContextClassLoader();
|
||||
} catch (SecurityException ex) {
|
||||
}
|
||||
return cl;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
#
|
||||
# Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
#
|
||||
# This code is free software; you can redistribute it and/or modify it
|
||||
# under the terms of the GNU General Public License version 2 only, as
|
||||
# published by the Free Software Foundation. Oracle designates this
|
||||
# particular file as subject to the "Classpath" exception as provided
|
||||
# by Oracle in the LICENSE file that accompanied this code.
|
||||
#
|
||||
# This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
# version 2 for more details (a copy is included in the LICENSE file that
|
||||
# accompanied this code).
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License version
|
||||
# 2 along with this work; if not, write to the Free Software Foundation,
|
||||
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
#
|
||||
# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
# or visit www.oracle.com if you need additional information or have any
|
||||
# questions.
|
||||
#
|
||||
|
||||
FAILED_TO_CREATE_NEW_INSTANCE=Failed to create new instance of {0}
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -63,39 +63,43 @@ public abstract class XMLStreamReaderFactory {
|
||||
|
||||
private static final Logger LOGGER = Logger.getLogger(XMLStreamReaderFactory.class.getName());
|
||||
|
||||
private static final String CLASS_NAME_OF_WSTXINPUTFACTORY = "com.ctc.wstx.stax.WstxInputFactory";
|
||||
|
||||
/**
|
||||
* Singleton instance.
|
||||
*/
|
||||
private static volatile @NotNull XMLStreamReaderFactory theInstance;
|
||||
private static volatile ContextClassloaderLocal<XMLStreamReaderFactory> streamReader =
|
||||
new ContextClassloaderLocal<XMLStreamReaderFactory>() {
|
||||
|
||||
private static final String CLASS_NAME_OF_WSTXINPUTFACTORY = "com.ctc.wstx.stax.WstxInputFactory";
|
||||
@Override
|
||||
protected XMLStreamReaderFactory initialValue() {
|
||||
|
||||
static {
|
||||
XMLInputFactory xif = getXMLInputFactory();
|
||||
XMLStreamReaderFactory f=null;
|
||||
XMLInputFactory xif = getXMLInputFactory();
|
||||
XMLStreamReaderFactory f=null;
|
||||
|
||||
// this system property can be used to disable the pooling altogether,
|
||||
// in case someone hits an issue with pooling in the production system.
|
||||
if(!getProperty(XMLStreamReaderFactory.class.getName()+".noPool")) {
|
||||
f = Zephyr.newInstance(xif);
|
||||
}
|
||||
// this system property can be used to disable the pooling altogether,
|
||||
// in case someone hits an issue with pooling in the production system.
|
||||
if(!getProperty(XMLStreamReaderFactory.class.getName()+".noPool")) {
|
||||
f = Zephyr.newInstance(xif);
|
||||
}
|
||||
|
||||
if(f==null) {
|
||||
// is this Woodstox?
|
||||
if (xif.getClass().getName().equals(CLASS_NAME_OF_WSTXINPUTFACTORY)) {
|
||||
f = new Woodstox(xif);
|
||||
}
|
||||
}
|
||||
if(f==null) {
|
||||
// is this Woodstox?
|
||||
if (xif.getClass().getName().equals(CLASS_NAME_OF_WSTXINPUTFACTORY)) {
|
||||
f = new Woodstox(xif);
|
||||
}
|
||||
}
|
||||
|
||||
if (f==null) {
|
||||
f = new Default();
|
||||
}
|
||||
if (f==null) {
|
||||
f = new Default();
|
||||
}
|
||||
|
||||
theInstance = f;
|
||||
if (LOGGER.isLoggable(Level.FINE)) {
|
||||
LOGGER.log(Level.FINE, "XMLStreamReaderFactory instance is = {0}", theInstance);
|
||||
}
|
||||
}
|
||||
if (LOGGER.isLoggable(Level.FINE)) {
|
||||
LOGGER.log(Level.FINE, "XMLStreamReaderFactory instance is = {0}", f);
|
||||
}
|
||||
return f;
|
||||
}
|
||||
};
|
||||
|
||||
private static XMLInputFactory getXMLInputFactory() {
|
||||
XMLInputFactory xif = null;
|
||||
@ -126,11 +130,11 @@ public abstract class XMLStreamReaderFactory {
|
||||
if(f==null) {
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
theInstance = f;
|
||||
streamReader.set(f);
|
||||
}
|
||||
|
||||
public static XMLStreamReaderFactory get() {
|
||||
return theInstance;
|
||||
return streamReader.get();
|
||||
}
|
||||
|
||||
public static XMLStreamReader create(InputSource source, boolean rejectDTDs) {
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -62,52 +62,54 @@ public abstract class XMLStreamWriterFactory {
|
||||
/**
|
||||
* Singleton instance.
|
||||
*/
|
||||
private static volatile @NotNull XMLStreamWriterFactory theInstance;
|
||||
private static volatile ContextClassloaderLocal<XMLStreamWriterFactory> writerFactory =
|
||||
new ContextClassloaderLocal<XMLStreamWriterFactory>() {
|
||||
|
||||
|
||||
static {
|
||||
XMLOutputFactory xof = null;
|
||||
if (Boolean.getBoolean(XMLStreamWriterFactory.class.getName()+".woodstox")) {
|
||||
try {
|
||||
xof = (XMLOutputFactory)Class.forName("com.ctc.wstx.stax.WstxOutputFactory").newInstance();
|
||||
} catch (Exception e) {
|
||||
// Ignore and fallback to default XMLOutputFactory
|
||||
}
|
||||
}
|
||||
if (xof == null) {
|
||||
xof = XMLOutputFactory.newInstance();
|
||||
}
|
||||
|
||||
XMLStreamWriterFactory f=null;
|
||||
|
||||
// this system property can be used to disable the pooling altogether,
|
||||
// in case someone hits an issue with pooling in the production system.
|
||||
if (!Boolean.getBoolean(XMLStreamWriterFactory.class.getName()+".noPool")) {
|
||||
try {
|
||||
Class<?> clazz = xof.createXMLStreamWriter(new StringWriter()).getClass();
|
||||
if (clazz.getName().startsWith("com.sun.xml.internal.stream.")) {
|
||||
f = new Zephyr(xof,clazz);
|
||||
@Override
|
||||
protected XMLStreamWriterFactory initialValue() {
|
||||
XMLOutputFactory xof = null;
|
||||
if (Boolean.getBoolean(XMLStreamWriterFactory.class.getName()+".woodstox")) {
|
||||
try {
|
||||
xof = (XMLOutputFactory)Class.forName("com.ctc.wstx.stax.WstxOutputFactory").newInstance();
|
||||
} catch (Exception e) {
|
||||
// Ignore and fallback to default XMLOutputFactory
|
||||
}
|
||||
} catch (XMLStreamException ex) {
|
||||
Logger.getLogger(XMLStreamWriterFactory.class.getName()).log(Level.INFO, null, ex);
|
||||
} catch (NoSuchMethodException ex) {
|
||||
Logger.getLogger(XMLStreamWriterFactory.class.getName()).log(Level.INFO, null, ex);
|
||||
}
|
||||
}
|
||||
if (xof == null) {
|
||||
xof = XMLOutputFactory.newInstance();
|
||||
}
|
||||
|
||||
if(f==null) {
|
||||
// is this Woodstox?
|
||||
if(xof.getClass().getName().equals("com.ctc.wstx.stax.WstxOutputFactory"))
|
||||
f = new NoLock(xof);
|
||||
}
|
||||
if (f == null)
|
||||
f = new Default(xof);
|
||||
XMLStreamWriterFactory f=null;
|
||||
|
||||
theInstance = f;
|
||||
if (LOGGER.isLoggable(Level.FINE)) {
|
||||
LOGGER.log(Level.FINE, "XMLStreamWriterFactory instance is = {0}", f);
|
||||
// this system property can be used to disable the pooling altogether,
|
||||
// in case someone hits an issue with pooling in the production system.
|
||||
if (!Boolean.getBoolean(XMLStreamWriterFactory.class.getName()+".noPool")) {
|
||||
try {
|
||||
Class<?> clazz = xof.createXMLStreamWriter(new StringWriter()).getClass();
|
||||
if (clazz.getName().startsWith("com.sun.xml.internal.stream.")) {
|
||||
f = new Zephyr(xof,clazz);
|
||||
}
|
||||
} catch (XMLStreamException ex) {
|
||||
Logger.getLogger(XMLStreamWriterFactory.class.getName()).log(Level.INFO, null, ex);
|
||||
} catch (NoSuchMethodException ex) {
|
||||
Logger.getLogger(XMLStreamWriterFactory.class.getName()).log(Level.INFO, null, ex);
|
||||
}
|
||||
}
|
||||
|
||||
if(f==null) {
|
||||
// is this Woodstox?
|
||||
if(xof.getClass().getName().equals("com.ctc.wstx.stax.WstxOutputFactory"))
|
||||
f = new NoLock(xof);
|
||||
}
|
||||
if (f == null)
|
||||
f = new Default(xof);
|
||||
|
||||
if (LOGGER.isLoggable(Level.FINE)) {
|
||||
LOGGER.log(Level.FINE, "XMLStreamWriterFactory instance is = {0}", f);
|
||||
}
|
||||
return f;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* See {@link #create(OutputStream)} for the contract.
|
||||
@ -170,7 +172,7 @@ public abstract class XMLStreamWriterFactory {
|
||||
* Gets the singleton instance.
|
||||
*/
|
||||
public static @NotNull XMLStreamWriterFactory get() {
|
||||
return theInstance;
|
||||
return writerFactory.get();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -183,7 +185,7 @@ public abstract class XMLStreamWriterFactory {
|
||||
@SuppressWarnings({"null", "ConstantConditions"})
|
||||
public static void set(@NotNull XMLStreamWriterFactory f) {
|
||||
if(f==null) throw new IllegalArgumentException();
|
||||
theInstance = f;
|
||||
writerFactory.set(f);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -0,0 +1,85 @@
|
||||
/*
|
||||
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.sun.xml.internal.ws.commons.xmlutil;
|
||||
|
||||
import java.security.AccessController;
|
||||
import java.security.PrivilegedAction;
|
||||
import java.text.MessageFormat;
|
||||
import java.util.ResourceBundle;
|
||||
import java.util.WeakHashMap;
|
||||
|
||||
/**
|
||||
* Simple utility ensuring that the value is cached only in case it is non-internal implementation
|
||||
*/
|
||||
abstract class ContextClassloaderLocal<V> {
|
||||
|
||||
private static final String FAILED_TO_CREATE_NEW_INSTANCE = "FAILED_TO_CREATE_NEW_INSTANCE";
|
||||
|
||||
private WeakHashMap<ClassLoader, V> CACHE = new WeakHashMap<ClassLoader, V>();
|
||||
|
||||
public V get() throws Error {
|
||||
ClassLoader tccl = getContextClassLoader();
|
||||
V instance = CACHE.get(tccl);
|
||||
if (instance == null) {
|
||||
instance = createNewInstance();
|
||||
CACHE.put(tccl, instance);
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
public void set(V instance) {
|
||||
CACHE.put(getContextClassLoader(), instance);
|
||||
}
|
||||
|
||||
protected abstract V initialValue() throws Exception;
|
||||
|
||||
private V createNewInstance() {
|
||||
try {
|
||||
return initialValue();
|
||||
} catch (Exception e) {
|
||||
throw new Error(format(FAILED_TO_CREATE_NEW_INSTANCE, getClass().getName()), e);
|
||||
}
|
||||
}
|
||||
|
||||
private static String format(String property, Object... args) {
|
||||
String text = ResourceBundle.getBundle(ContextClassloaderLocal.class.getName()).getString(property);
|
||||
return MessageFormat.format(text, args);
|
||||
}
|
||||
|
||||
private static ClassLoader getContextClassLoader() {
|
||||
return (ClassLoader)
|
||||
AccessController.doPrivileged(new PrivilegedAction() {
|
||||
public Object run() {
|
||||
ClassLoader cl = null;
|
||||
try {
|
||||
cl = Thread.currentThread().getContextClassLoader();
|
||||
} catch (SecurityException ex) {
|
||||
}
|
||||
return cl;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
#
|
||||
# Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
#
|
||||
# This code is free software; you can redistribute it and/or modify it
|
||||
# under the terms of the GNU General Public License version 2 only, as
|
||||
# published by the Free Software Foundation. Oracle designates this
|
||||
# particular file as subject to the "Classpath" exception as provided
|
||||
# by Oracle in the LICENSE file that accompanied this code.
|
||||
#
|
||||
# This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
# version 2 for more details (a copy is included in the LICENSE file that
|
||||
# accompanied this code).
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License version
|
||||
# 2 along with this work; if not, write to the Free Software Foundation,
|
||||
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
#
|
||||
# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
# or visit www.oracle.com if you need additional information or have any
|
||||
# questions.
|
||||
#
|
||||
|
||||
FAILED_TO_CREATE_NEW_INSTANCE=Failed to create new instance of {0}
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -53,7 +53,12 @@ public final class Converter {
|
||||
// prevents instantiation
|
||||
}
|
||||
private static final Logger LOGGER = Logger.getLogger(Converter.class);
|
||||
private static final XMLOutputFactory xmlOutputFactory = XMLOutputFactory.newInstance();
|
||||
private static final ContextClassloaderLocal<XMLOutputFactory> xmlOutputFactory = new ContextClassloaderLocal<XMLOutputFactory>() {
|
||||
@Override
|
||||
protected XMLOutputFactory initialValue() throws Exception {
|
||||
return XMLOutputFactory.newInstance();
|
||||
}
|
||||
};
|
||||
private static final AtomicBoolean logMissingStaxUtilsWarning = new AtomicBoolean(false);
|
||||
|
||||
/**
|
||||
@ -110,7 +115,7 @@ public final class Converter {
|
||||
stringOut = new StringWriter();
|
||||
XMLStreamWriter writer = null;
|
||||
try {
|
||||
writer = xmlOutputFactory.createXMLStreamWriter(stringOut);
|
||||
writer = xmlOutputFactory.get().createXMLStreamWriter(stringOut);
|
||||
if (createIndenter) {
|
||||
writer = createIndenter(writer);
|
||||
}
|
||||
@ -143,7 +148,7 @@ public final class Converter {
|
||||
|
||||
try {
|
||||
if (message != null) {
|
||||
XMLStreamWriter xsw = xmlOutputFactory.createXMLStreamWriter(baos, encoding);
|
||||
XMLStreamWriter xsw = xmlOutputFactory.get().createXMLStreamWriter(baos, encoding);
|
||||
try {
|
||||
message.writeTo(xsw);
|
||||
} finally {
|
||||
|
@ -0,0 +1,85 @@
|
||||
/*
|
||||
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.sun.xml.internal.ws.developer;
|
||||
|
||||
import java.security.AccessController;
|
||||
import java.security.PrivilegedAction;
|
||||
import java.text.MessageFormat;
|
||||
import java.util.ResourceBundle;
|
||||
import java.util.WeakHashMap;
|
||||
|
||||
/**
|
||||
* Simple utility ensuring that the value is cached only in case it is non-internal implementation
|
||||
*/
|
||||
abstract class ContextClassloaderLocal<V> {
|
||||
|
||||
private static final String FAILED_TO_CREATE_NEW_INSTANCE = "FAILED_TO_CREATE_NEW_INSTANCE";
|
||||
|
||||
private WeakHashMap<ClassLoader, V> CACHE = new WeakHashMap<ClassLoader, V>();
|
||||
|
||||
public V get() throws Error {
|
||||
ClassLoader tccl = getContextClassLoader();
|
||||
V instance = CACHE.get(tccl);
|
||||
if (instance == null) {
|
||||
instance = createNewInstance();
|
||||
CACHE.put(tccl, instance);
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
public void set(V instance) {
|
||||
CACHE.put(getContextClassLoader(), instance);
|
||||
}
|
||||
|
||||
protected abstract V initialValue() throws Exception;
|
||||
|
||||
private V createNewInstance() {
|
||||
try {
|
||||
return initialValue();
|
||||
} catch (Exception e) {
|
||||
throw new Error(format(FAILED_TO_CREATE_NEW_INSTANCE, getClass().getName()), e);
|
||||
}
|
||||
}
|
||||
|
||||
private static String format(String property, Object... args) {
|
||||
String text = ResourceBundle.getBundle(ContextClassloaderLocal.class.getName()).getString(property);
|
||||
return MessageFormat.format(text, args);
|
||||
}
|
||||
|
||||
private static ClassLoader getContextClassLoader() {
|
||||
return (ClassLoader)
|
||||
AccessController.doPrivileged(new PrivilegedAction() {
|
||||
public Object run() {
|
||||
ClassLoader cl = null;
|
||||
try {
|
||||
cl = Thread.currentThread().getContextClassLoader();
|
||||
} catch (SecurityException ex) {
|
||||
}
|
||||
return cl;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -64,7 +64,12 @@ import java.util.Map;
|
||||
@XmlType(name = "EndpointReferenceType", namespace = MemberSubmissionEndpointReference.MSNS)
|
||||
public final class MemberSubmissionEndpointReference extends EndpointReference implements MemberSubmissionAddressingConstants {
|
||||
|
||||
private final static JAXBContext msjc = MemberSubmissionEndpointReference.getMSJaxbContext();
|
||||
private final static ContextClassloaderLocal<JAXBContext> msjc = new ContextClassloaderLocal<JAXBContext>() {
|
||||
@Override
|
||||
protected JAXBContext initialValue() throws Exception {
|
||||
return MemberSubmissionEndpointReference.getMSJaxbContext();
|
||||
}
|
||||
};
|
||||
|
||||
public MemberSubmissionEndpointReference() {
|
||||
}
|
||||
@ -86,7 +91,7 @@ public final class MemberSubmissionEndpointReference extends EndpointReference i
|
||||
}
|
||||
|
||||
try {
|
||||
Unmarshaller unmarshaller = MemberSubmissionEndpointReference.msjc.createUnmarshaller();
|
||||
Unmarshaller unmarshaller = MemberSubmissionEndpointReference.msjc.get().createUnmarshaller();
|
||||
MemberSubmissionEndpointReference epr = unmarshaller.unmarshal(source,MemberSubmissionEndpointReference.class).getValue();
|
||||
|
||||
this.addr = epr.addr;
|
||||
@ -106,7 +111,7 @@ public final class MemberSubmissionEndpointReference extends EndpointReference i
|
||||
@Override
|
||||
public void writeTo(Result result) {
|
||||
try {
|
||||
Marshaller marshaller = MemberSubmissionEndpointReference.msjc.createMarshaller();
|
||||
Marshaller marshaller = MemberSubmissionEndpointReference.msjc.get().createMarshaller();
|
||||
//marshaller.setProperty(Marshaller.JAXB_FRAGMENT, true);
|
||||
marshaller.marshal(this, result);
|
||||
} catch (JAXBException e) {
|
||||
|
@ -0,0 +1,84 @@
|
||||
/*
|
||||
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.sun.xml.internal.ws.policy.sourcemodel.attach;
|
||||
|
||||
import java.security.AccessController;
|
||||
import java.security.PrivilegedAction;
|
||||
import java.text.MessageFormat;
|
||||
import java.util.ResourceBundle;
|
||||
import java.util.WeakHashMap;
|
||||
|
||||
/**
|
||||
* Simple utility ensuring that the value is cached only in case it is non-internal implementation
|
||||
*/
|
||||
abstract class ContextClassloaderLocal<V> {
|
||||
|
||||
private static final String FAILED_TO_CREATE_NEW_INSTANCE = "FAILED_TO_CREATE_NEW_INSTANCE";
|
||||
|
||||
private WeakHashMap<ClassLoader, V> CACHE = new WeakHashMap<ClassLoader, V>();
|
||||
|
||||
public V get() throws Error {
|
||||
ClassLoader tccl = getContextClassLoader();
|
||||
V instance = CACHE.get(tccl);
|
||||
if (instance == null) {
|
||||
instance = createNewInstance();
|
||||
CACHE.put(tccl, instance);
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
public void set(V instance) {
|
||||
CACHE.put(getContextClassLoader(), instance);
|
||||
}
|
||||
|
||||
protected abstract V initialValue() throws Exception;
|
||||
|
||||
private V createNewInstance() {
|
||||
try {
|
||||
return initialValue();
|
||||
} catch (Exception e) {
|
||||
throw new Error(format(FAILED_TO_CREATE_NEW_INSTANCE, getClass().getName()), e);
|
||||
}
|
||||
}
|
||||
|
||||
private static String format(String property, Object... args) {
|
||||
String text = ResourceBundle.getBundle(ContextClassloaderLocal.class.getName()).getString(property);
|
||||
return MessageFormat.format(text, args);
|
||||
}
|
||||
|
||||
private static ClassLoader getContextClassLoader() {
|
||||
return AccessController.doPrivileged(new PrivilegedAction<ClassLoader>() {
|
||||
public ClassLoader run() {
|
||||
ClassLoader cl = null;
|
||||
try {
|
||||
cl = Thread.currentThread().getContextClassLoader();
|
||||
} catch (SecurityException ex) {
|
||||
}
|
||||
return cl;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
#
|
||||
# Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
#
|
||||
# This code is free software; you can redistribute it and/or modify it
|
||||
# under the terms of the GNU General Public License version 2 only, as
|
||||
# published by the Free Software Foundation. Oracle designates this
|
||||
# particular file as subject to the "Classpath" exception as provided
|
||||
# by Oracle in the LICENSE file that accompanied this code.
|
||||
#
|
||||
# This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
# version 2 for more details (a copy is included in the LICENSE file that
|
||||
# accompanied this code).
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License version
|
||||
# 2 along with this work; if not, write to the Free Software Foundation,
|
||||
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
#
|
||||
# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
# or visit www.oracle.com if you need additional information or have any
|
||||
# questions.
|
||||
#
|
||||
|
||||
# Error messages for ContextClassloaderLocal utility class
|
||||
FAILED_TO_CREATE_NEW_INSTANCE=Failed to create new instance of {0}
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -83,7 +83,13 @@ public class ExternalAttachmentsUnmarshaller {
|
||||
private static final QName POLICY = new QName("http://www.w3.org/ns/ws-policy", "Policy");
|
||||
private static final QName URI = new QName("http://www.w3.org/ns/ws-policy", "URI");
|
||||
private static final QName POLICIES = new QName(PolicyConstants.SUN_MANAGEMENT_NAMESPACE, "Policies");
|
||||
private static final XMLInputFactory XML_INPUT_FACTORY = XMLInputFactory.newInstance();
|
||||
private static final ContextClassloaderLocal<XMLInputFactory> XML_INPUT_FACTORY = new ContextClassloaderLocal<XMLInputFactory>() {
|
||||
@Override
|
||||
protected XMLInputFactory initialValue() throws Exception {
|
||||
return XMLInputFactory.newInstance();
|
||||
}
|
||||
};
|
||||
|
||||
private static final PolicyModelUnmarshaller POLICY_UNMARSHALLER = PolicyModelUnmarshaller.getXmlUnmarshaller();
|
||||
|
||||
private final Map<URI, Policy> map = new HashMap<URI, Policy>();
|
||||
@ -93,7 +99,7 @@ public class ExternalAttachmentsUnmarshaller {
|
||||
public static Map<URI, Policy> unmarshal(final Reader source) throws PolicyException {
|
||||
LOGGER.entering(source);
|
||||
try {
|
||||
XMLEventReader reader = XML_INPUT_FACTORY.createXMLEventReader(source);
|
||||
XMLEventReader reader = XML_INPUT_FACTORY.get().createXMLEventReader(source);
|
||||
ExternalAttachmentsUnmarshaller instance = new ExternalAttachmentsUnmarshaller();
|
||||
final Map<URI, Policy> map = instance.unmarshal(reader, null);
|
||||
LOGGER.exiting(map);
|
||||
|
@ -0,0 +1,85 @@
|
||||
/*
|
||||
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.sun.xml.internal.ws.spi;
|
||||
|
||||
import java.security.AccessController;
|
||||
import java.security.PrivilegedAction;
|
||||
import java.text.MessageFormat;
|
||||
import java.util.ResourceBundle;
|
||||
import java.util.WeakHashMap;
|
||||
|
||||
/**
|
||||
* Simple utility ensuring that the value is cached only in case it is non-internal implementation
|
||||
*/
|
||||
abstract class ContextClassloaderLocal<V> {
|
||||
|
||||
private static final String FAILED_TO_CREATE_NEW_INSTANCE = "FAILED_TO_CREATE_NEW_INSTANCE";
|
||||
|
||||
private WeakHashMap<ClassLoader, V> CACHE = new WeakHashMap<ClassLoader, V>();
|
||||
|
||||
public V get() throws Error {
|
||||
ClassLoader tccl = getContextClassLoader();
|
||||
V instance = CACHE.get(tccl);
|
||||
if (instance == null) {
|
||||
instance = createNewInstance();
|
||||
CACHE.put(tccl, instance);
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
public void set(V instance) {
|
||||
CACHE.put(getContextClassLoader(), instance);
|
||||
}
|
||||
|
||||
protected abstract V initialValue() throws Exception;
|
||||
|
||||
private V createNewInstance() {
|
||||
try {
|
||||
return initialValue();
|
||||
} catch (Exception e) {
|
||||
throw new Error(format(FAILED_TO_CREATE_NEW_INSTANCE, getClass().getName()), e);
|
||||
}
|
||||
}
|
||||
|
||||
private static String format(String property, Object... args) {
|
||||
String text = ResourceBundle.getBundle(ContextClassloaderLocal.class.getName()).getString(property);
|
||||
return MessageFormat.format(text, args);
|
||||
}
|
||||
|
||||
private static ClassLoader getContextClassLoader() {
|
||||
return (ClassLoader)
|
||||
AccessController.doPrivileged(new PrivilegedAction() {
|
||||
public Object run() {
|
||||
ClassLoader cl = null;
|
||||
try {
|
||||
cl = Thread.currentThread().getContextClassLoader();
|
||||
} catch (SecurityException ex) {
|
||||
}
|
||||
return cl;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
#
|
||||
# Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
#
|
||||
# This code is free software; you can redistribute it and/or modify it
|
||||
# under the terms of the GNU General Public License version 2 only, as
|
||||
# published by the Free Software Foundation. Oracle designates this
|
||||
# particular file as subject to the "Classpath" exception as provided
|
||||
# by Oracle in the LICENSE file that accompanied this code.
|
||||
#
|
||||
# This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
# version 2 for more details (a copy is included in the LICENSE file that
|
||||
# accompanied this code).
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License version
|
||||
# 2 along with this work; if not, write to the Free Software Foundation,
|
||||
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
#
|
||||
# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
# or visit www.oracle.com if you need additional information or have any
|
||||
# questions.
|
||||
#
|
||||
|
||||
FAILED_TO_CREATE_NEW_INSTANCE=Failed to create new instance of {0}
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -80,7 +80,12 @@ import java.util.Map;
|
||||
*/
|
||||
public class ProviderImpl extends Provider {
|
||||
|
||||
private final static JAXBContext eprjc = getEPRJaxbContext();
|
||||
private final static ContextClassloaderLocal<JAXBContext> eprjc = new ContextClassloaderLocal<JAXBContext>() {
|
||||
@Override
|
||||
protected JAXBContext initialValue() throws Exception {
|
||||
return getEPRJaxbContext();
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Convenient singleton instance.
|
||||
@ -148,7 +153,7 @@ public class ProviderImpl extends Provider {
|
||||
return AccessController.doPrivileged(new PrivilegedAction<EndpointReference>() {
|
||||
public EndpointReference run() {
|
||||
try {
|
||||
Unmarshaller unmarshaller = eprjc.createUnmarshaller();
|
||||
Unmarshaller unmarshaller = eprjc.get().createUnmarshaller();
|
||||
return (EndpointReference) unmarshaller.unmarshal(eprInfoset);
|
||||
} catch (JAXBException e) {
|
||||
throw new WebServiceException("Error creating Marshaller or marshalling.", e);
|
||||
|
@ -0,0 +1,85 @@
|
||||
/*
|
||||
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.sun.xml.internal.ws.util.xml;
|
||||
|
||||
import java.security.AccessController;
|
||||
import java.security.PrivilegedAction;
|
||||
import java.text.MessageFormat;
|
||||
import java.util.ResourceBundle;
|
||||
import java.util.WeakHashMap;
|
||||
|
||||
/**
|
||||
* Simple utility ensuring that the value is cached only in case it is non-internal implementation
|
||||
*/
|
||||
abstract class ContextClassloaderLocal<V> {
|
||||
|
||||
private static final String FAILED_TO_CREATE_NEW_INSTANCE = "FAILED_TO_CREATE_NEW_INSTANCE";
|
||||
|
||||
private WeakHashMap<ClassLoader, V> CACHE = new WeakHashMap<ClassLoader, V>();
|
||||
|
||||
public V get() throws Error {
|
||||
ClassLoader tccl = getContextClassLoader();
|
||||
V instance = CACHE.get(tccl);
|
||||
if (instance == null) {
|
||||
instance = createNewInstance();
|
||||
CACHE.put(tccl, instance);
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
public void set(V instance) {
|
||||
CACHE.put(getContextClassLoader(), instance);
|
||||
}
|
||||
|
||||
protected abstract V initialValue() throws Exception;
|
||||
|
||||
private V createNewInstance() {
|
||||
try {
|
||||
return initialValue();
|
||||
} catch (Exception e) {
|
||||
throw new Error(format(FAILED_TO_CREATE_NEW_INSTANCE, getClass().getName()), e);
|
||||
}
|
||||
}
|
||||
|
||||
private static String format(String property, Object... args) {
|
||||
String text = ResourceBundle.getBundle(ContextClassloaderLocal.class.getName()).getString(property);
|
||||
return MessageFormat.format(text, args);
|
||||
}
|
||||
|
||||
private static ClassLoader getContextClassLoader() {
|
||||
return (ClassLoader)
|
||||
AccessController.doPrivileged(new PrivilegedAction() {
|
||||
public Object run() {
|
||||
ClassLoader cl = null;
|
||||
try {
|
||||
cl = Thread.currentThread().getContextClassLoader();
|
||||
} catch (SecurityException ex) {
|
||||
}
|
||||
return cl;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
#
|
||||
# Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
#
|
||||
# This code is free software; you can redistribute it and/or modify it
|
||||
# under the terms of the GNU General Public License version 2 only, as
|
||||
# published by the Free Software Foundation. Oracle designates this
|
||||
# particular file as subject to the "Classpath" exception as provided
|
||||
# by Oracle in the LICENSE file that accompanied this code.
|
||||
#
|
||||
# This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
# version 2 for more details (a copy is included in the LICENSE file that
|
||||
# accompanied this code).
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License version
|
||||
# 2 along with this work; if not, write to the Free Software Foundation,
|
||||
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
#
|
||||
# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
# or visit www.oracle.com if you need additional information or have any
|
||||
# questions.
|
||||
#
|
||||
|
||||
FAILED_TO_CREATE_NEW_INSTANCE=Failed to create new instance of {0}
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -215,20 +215,28 @@ public class XmlUtil {
|
||||
}
|
||||
}
|
||||
|
||||
static final TransformerFactory transformerFactory = newTransformerFactory();
|
||||
static final ContextClassloaderLocal<TransformerFactory> transformerFactory = new ContextClassloaderLocal<TransformerFactory>() {
|
||||
@Override
|
||||
protected TransformerFactory initialValue() throws Exception {
|
||||
return TransformerFactory.newInstance();
|
||||
}
|
||||
};
|
||||
|
||||
static final SAXParserFactory saxParserFactory = newSAXParserFactory(true);
|
||||
|
||||
static {
|
||||
saxParserFactory.setNamespaceAware(true);
|
||||
}
|
||||
static final ContextClassloaderLocal<SAXParserFactory> saxParserFactory = new ContextClassloaderLocal<SAXParserFactory>() {
|
||||
@Override
|
||||
protected SAXParserFactory initialValue() throws Exception {
|
||||
SAXParserFactory factory = SAXParserFactory.newInstance();
|
||||
factory.setNamespaceAware(true);
|
||||
return factory;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Creates a new identity transformer.
|
||||
*/
|
||||
public static Transformer newTransformer() {
|
||||
try {
|
||||
return transformerFactory.newTransformer();
|
||||
return transformerFactory.get().newTransformer();
|
||||
} catch (TransformerConfigurationException tex) {
|
||||
throw new IllegalStateException("Unable to create a JAXP transformer");
|
||||
}
|
||||
@ -243,9 +251,9 @@ public class XmlUtil {
|
||||
// work around a bug in JAXP in JDK6u4 and earlier where the namespace processing
|
||||
// is not turned on by default
|
||||
StreamSource ssrc = (StreamSource) src;
|
||||
TransformerHandler th = ((SAXTransformerFactory) transformerFactory).newTransformerHandler();
|
||||
TransformerHandler th = ((SAXTransformerFactory) transformerFactory.get()).newTransformerHandler();
|
||||
th.setResult(result);
|
||||
XMLReader reader = saxParserFactory.newSAXParser().getXMLReader();
|
||||
XMLReader reader = saxParserFactory.get().newSAXParser().getXMLReader();
|
||||
reader.setContentHandler(th);
|
||||
reader.setProperty(LEXICAL_HANDLER_PROPERTY, th);
|
||||
reader.parse(toInputSource(ssrc));
|
||||
|
@ -0,0 +1,85 @@
|
||||
/*
|
||||
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.sun.xml.internal.xsom.util;
|
||||
|
||||
import java.security.AccessController;
|
||||
import java.security.PrivilegedAction;
|
||||
import java.text.MessageFormat;
|
||||
import java.util.ResourceBundle;
|
||||
import java.util.WeakHashMap;
|
||||
|
||||
/**
|
||||
* Simple utility ensuring that the value is cached only in case it is non-internal implementation
|
||||
*/
|
||||
abstract class ContextClassloaderLocal<V> {
|
||||
|
||||
private static final String FAILED_TO_CREATE_NEW_INSTANCE = "FAILED_TO_CREATE_NEW_INSTANCE";
|
||||
|
||||
private WeakHashMap<ClassLoader, V> CACHE = new WeakHashMap<ClassLoader, V>();
|
||||
|
||||
public V get() throws Error {
|
||||
ClassLoader tccl = getContextClassLoader();
|
||||
V instance = CACHE.get(tccl);
|
||||
if (instance == null) {
|
||||
instance = createNewInstance();
|
||||
CACHE.put(tccl, instance);
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
public void set(V instance) {
|
||||
CACHE.put(getContextClassLoader(), instance);
|
||||
}
|
||||
|
||||
protected abstract V initialValue() throws Exception;
|
||||
|
||||
private V createNewInstance() {
|
||||
try {
|
||||
return initialValue();
|
||||
} catch (Exception e) {
|
||||
throw new Error(format(FAILED_TO_CREATE_NEW_INSTANCE, getClass().getName()), e);
|
||||
}
|
||||
}
|
||||
|
||||
private static String format(String property, Object... args) {
|
||||
String text = ResourceBundle.getBundle(ContextClassloaderLocal.class.getName()).getString(property);
|
||||
return MessageFormat.format(text, args);
|
||||
}
|
||||
|
||||
private static ClassLoader getContextClassLoader() {
|
||||
return (ClassLoader)
|
||||
AccessController.doPrivileged(new PrivilegedAction() {
|
||||
public Object run() {
|
||||
ClassLoader cl = null;
|
||||
try {
|
||||
cl = Thread.currentThread().getContextClassLoader();
|
||||
} catch (SecurityException ex) {
|
||||
}
|
||||
return cl;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
#
|
||||
# Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
#
|
||||
# This code is free software; you can redistribute it and/or modify it
|
||||
# under the terms of the GNU General Public License version 2 only, as
|
||||
# published by the Free Software Foundation. Oracle designates this
|
||||
# particular file as subject to the "Classpath" exception as provided
|
||||
# by Oracle in the LICENSE file that accompanied this code.
|
||||
#
|
||||
# This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
# version 2 for more details (a copy is included in the LICENSE file that
|
||||
# accompanied this code).
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License version
|
||||
# 2 along with this work; if not, write to the Free Software Foundation,
|
||||
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
#
|
||||
# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
# or visit www.oracle.com if you need additional information or have any
|
||||
# questions.
|
||||
#
|
||||
|
||||
FAILED_TO_CREATE_NEW_INSTANCE=Failed to create new instance of {0}
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -63,10 +63,15 @@ public class DomAnnotationParserFactory implements AnnotationParserFactory {
|
||||
}
|
||||
|
||||
public AnnotationParser create(boolean disableSecureProcessing) {
|
||||
return new AnnotationParserImpl();
|
||||
return new AnnotationParserImpl(disableSecureProcessing);
|
||||
}
|
||||
|
||||
private static final SAXTransformerFactory stf = (SAXTransformerFactory) SAXTransformerFactory.newInstance();
|
||||
private static final ContextClassloaderLocal<SAXTransformerFactory> stf = new ContextClassloaderLocal<SAXTransformerFactory>() {
|
||||
@Override
|
||||
protected SAXTransformerFactory initialValue() throws Exception {
|
||||
return (SAXTransformerFactory) SAXTransformerFactory.newInstance();
|
||||
}
|
||||
};
|
||||
|
||||
private static class AnnotationParserImpl extends AnnotationParser {
|
||||
|
||||
@ -82,8 +87,9 @@ public class DomAnnotationParserFactory implements AnnotationParserFactory {
|
||||
|
||||
AnnotationParserImpl(boolean disableSecureProcessing) {
|
||||
try {
|
||||
transformer = stf.newTransformerHandler();
|
||||
stf.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, disableSecureProcessing);
|
||||
SAXTransformerFactory factory = stf.get();
|
||||
factory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, disableSecureProcessing);
|
||||
transformer = factory.newTransformerHandler();
|
||||
} catch (TransformerConfigurationException e) {
|
||||
throw new Error(e); // impossible
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user