src/share/jaxws_classes/com/sun/xml/internal/messaging/saaj/soap/EnvelopeFactory.java

changeset 515
6cd506508147
parent 368
0989ad8c0860
child 637
9c07ef4934dd
     1.1 --- a/src/share/jaxws_classes/com/sun/xml/internal/messaging/saaj/soap/EnvelopeFactory.java	Fri Feb 14 10:53:55 2014 +0100
     1.2 +++ b/src/share/jaxws_classes/com/sun/xml/internal/messaging/saaj/soap/EnvelopeFactory.java	Fri Feb 14 11:13:45 2014 +0100
     1.3 @@ -1,5 +1,5 @@
     1.4  /*
     1.5 - * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
     1.6 + * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
     1.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.8   *
     1.9   * This code is free software; you can redistribute it and/or modify it
    1.10 @@ -25,7 +25,14 @@
    1.11  
    1.12  package com.sun.xml.internal.messaging.saaj.soap;
    1.13  
    1.14 -import java.util.logging.Logger;
    1.15 +import com.sun.xml.internal.messaging.saaj.SOAPExceptionImpl;
    1.16 +import com.sun.xml.internal.messaging.saaj.util.JAXMStreamSource;
    1.17 +import com.sun.xml.internal.messaging.saaj.util.LogDomainConstants;
    1.18 +import com.sun.xml.internal.messaging.saaj.util.ParserPool;
    1.19 +import com.sun.xml.internal.messaging.saaj.util.RejectDoctypeSaxFilter;
    1.20 +import com.sun.xml.internal.messaging.saaj.util.transform.EfficientStreamingTransformer;
    1.21 +import org.xml.sax.InputSource;
    1.22 +import org.xml.sax.XMLReader;
    1.23  
    1.24  import javax.xml.parsers.SAXParser;
    1.25  import javax.xml.soap.SOAPException;
    1.26 @@ -34,14 +41,7 @@
    1.27  import javax.xml.transform.dom.DOMResult;
    1.28  import javax.xml.transform.sax.SAXSource;
    1.29  import javax.xml.transform.stream.StreamSource;
    1.30 -
    1.31 -import org.xml.sax.InputSource;
    1.32 -import org.xml.sax.XMLReader;
    1.33 -
    1.34 -import com.sun.xml.internal.messaging.saaj.SOAPExceptionImpl;
    1.35 -import com.sun.xml.internal.messaging.saaj.util.*;
    1.36 -
    1.37 -import com.sun.xml.internal.messaging.saaj.util.transform.EfficientStreamingTransformer;
    1.38 +import java.util.logging.Logger;
    1.39  
    1.40  /**
    1.41   * EnvelopeFactory creates SOAP Envelope objects using different
    1.42 @@ -50,14 +50,19 @@
    1.43  public class EnvelopeFactory {
    1.44  
    1.45      protected static final Logger
    1.46 -        log = Logger.getLogger(LogDomainConstants.SOAP_DOMAIN,
    1.47 -        "com.sun.xml.internal.messaging.saaj.soap.LocalStrings");
    1.48 +            log = Logger.getLogger(LogDomainConstants.SOAP_DOMAIN,
    1.49 +            "com.sun.xml.internal.messaging.saaj.soap.LocalStrings");
    1.50  
    1.51 -    private static ParserPool parserPool = new ParserPool(5);
    1.52 +    private static ContextClassloaderLocal<ParserPool> parserPool =
    1.53 +            new ContextClassloaderLocal<ParserPool>() {
    1.54 +                @Override
    1.55 +                protected ParserPool initialValue() throws Exception {
    1.56 +                    return new ParserPool(5);
    1.57 +                }
    1.58 +            };
    1.59  
    1.60      public static Envelope createEnvelope(Source src, SOAPPartImpl soapPart)
    1.61 -        throws SOAPException
    1.62 -    {
    1.63 +            throws SOAPException {
    1.64          // Insert SAX filter to disallow Document Type Declarations since
    1.65          // they are not legal in SOAP
    1.66          SAXParser saxParser = null;
    1.67 @@ -73,15 +78,15 @@
    1.68                  }
    1.69              }
    1.70              try {
    1.71 -                saxParser = parserPool.get();
    1.72 +                saxParser = parserPool.get().get();
    1.73              } catch (Exception e) {
    1.74                  log.severe("SAAJ0601.util.newSAXParser.exception");
    1.75                  throw new SOAPExceptionImpl(
    1.76 -                    "Couldn't get a SAX parser while constructing a envelope",
    1.77 -                    e);
    1.78 +                        "Couldn't get a SAX parser while constructing a envelope",
    1.79 +                        e);
    1.80              }
    1.81              InputSource is = SAXSource.sourceToInputSource(src);
    1.82 -            if (is.getEncoding()== null && soapPart.getSourceCharsetEncoding() != null) {
    1.83 +            if (is.getEncoding() == null && soapPart.getSourceCharsetEncoding() != null) {
    1.84                  is.setEncoding(soapPart.getSourceCharsetEncoding());
    1.85              }
    1.86              XMLReader rejectFilter;
    1.87 @@ -90,15 +95,15 @@
    1.88              } catch (Exception ex) {
    1.89                  log.severe("SAAJ0510.soap.cannot.create.envelope");
    1.90                  throw new SOAPExceptionImpl(
    1.91 -                    "Unable to create envelope from given source: ",
    1.92 -                    ex);
    1.93 +                        "Unable to create envelope from given source: ",
    1.94 +                        ex);
    1.95              }
    1.96              src = new SAXSource(rejectFilter, is);
    1.97          }
    1.98  
    1.99          try {
   1.100              Transformer transformer =
   1.101 -                EfficientStreamingTransformer.newTransformer();
   1.102 +                    EfficientStreamingTransformer.newTransformer();
   1.103              DOMResult result = new DOMResult(soapPart);
   1.104              transformer.transform(src, result);
   1.105  
   1.106 @@ -110,11 +115,11 @@
   1.107              }
   1.108              log.severe("SAAJ0511.soap.cannot.create.envelope");
   1.109              throw new SOAPExceptionImpl(
   1.110 -                "Unable to create envelope from given source: ",
   1.111 -                ex);
   1.112 +                    "Unable to create envelope from given source: ",
   1.113 +                    ex);
   1.114          } finally {
   1.115              if (saxParser != null) {
   1.116 -                parserPool.returnParser(saxParser);
   1.117 +                parserPool.get().returnParser(saxParser);
   1.118              }
   1.119          }
   1.120      }

mercurial