< prev index next >
src/java.xml.ws/share/classes/com/sun/xml/internal/messaging/saaj/soap/EnvelopeFactory.java
Print this page
*** 30,39 ****
--- 30,40 ----
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;
*** 44,70 ****
import javax.xml.transform.Transformer;
import javax.xml.transform.dom.DOMResult;
import javax.xml.transform.sax.SAXSource;
import javax.xml.transform.stax.StAXSource;
import javax.xml.transform.stream.StreamSource;
import java.util.logging.Logger;
/**
* EnvelopeFactory creates SOAP Envelope objects using different
* underlying implementations.
*/
public class EnvelopeFactory {
protected static final Logger
log = Logger.getLogger(LogDomainConstants.SOAP_DOMAIN,
"com.sun.xml.internal.messaging.saaj.soap.LocalStrings");
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
--- 45,89 ----
import javax.xml.transform.Transformer;
import javax.xml.transform.dom.DOMResult;
import javax.xml.transform.sax.SAXSource;
import javax.xml.transform.stax.StAXSource;
import javax.xml.transform.stream.StreamSource;
+
+ import java.security.AccessController;
+ import java.security.PrivilegedAction;
import java.util.logging.Logger;
/**
* EnvelopeFactory creates SOAP Envelope objects using different
* underlying implementations.
*/
public class EnvelopeFactory {
+ private static final String SAX_PARSER_POOL_SIZE_PROP_NAME = "com.sun.xml.internal.messaging.saaj.soap.saxParserPoolSize";
+ private static final int DEFAULT_SAX_PARSER_POOL_SIZE = 5;
protected static final Logger
log = Logger.getLogger(LogDomainConstants.SOAP_DOMAIN,
"com.sun.xml.internal.messaging.saaj.soap.LocalStrings");
private static ContextClassloaderLocal<ParserPool> parserPool =
new ContextClassloaderLocal<ParserPool>() {
@Override
protected ParserPool initialValue() throws Exception {
! Integer poolSize = AccessController.doPrivileged(
! new PrivilegedAction<Integer>() {
! @Override
! public Integer run() {
! try {
! return Integer.getInteger(
! SAX_PARSER_POOL_SIZE_PROP_NAME,
! DEFAULT_SAX_PARSER_POOL_SIZE);
! } catch (SecurityException se) {
! return DEFAULT_SAX_PARSER_POOL_SIZE;
! }
! }
! });
! return new ParserPool(poolSize);
}
};
public static Envelope createEnvelope(Source src, SOAPPartImpl soapPart)
throws SOAPException
*** 130,142 ****
throw new SOAPException(e);
}
}
private static Envelope parseEnvelopeSax(Source src, SOAPPartImpl soapPart)
throws SOAPException {
// Insert SAX filter to disallow Document Type Declarations since
// they are not legal in SOAP
! SAXParser saxParser = null;
if (src instanceof StreamSource) {
try {
saxParser = parserPool.get().get();
} catch (Exception e) {
log.severe("SAAJ0601.util.newSAXParser.exception");
--- 149,163 ----
throw new SOAPException(e);
}
}
private static Envelope parseEnvelopeSax(Source src, SOAPPartImpl soapPart)
throws SOAPException {
+ SAXParser saxParser = null;
+ try {
// Insert SAX filter to disallow Document Type Declarations since
// they are not legal in SOAP
!
if (src instanceof StreamSource) {
try {
saxParser = parserPool.get().get();
} catch (Exception e) {
log.severe("SAAJ0601.util.newSAXParser.exception");
*** 174,184 ****
--- 195,207 ----
}
log.severe("SAAJ0511.soap.cannot.create.envelope");
throw new SOAPExceptionImpl(
"Unable to create envelope from given source: ",
ex);
+ }
} finally {
+ //no matter what condition occurs, always return the parser to the pool
if (saxParser != null) {
parserPool.get().returnParser(saxParser);
}
}
}
< prev index next >