jaxws/src/share/jaxws_classes/com/sun/xml/internal/messaging/saaj/soap/EnvelopeFactory.java
changeset 25429 1c4e76ec718a
parent 23961 439846965790
equal deleted inserted replaced
25031:28dd0c7beb3c 25429:1c4e76ec718a
    23  * questions.
    23  * questions.
    24  */
    24  */
    25 
    25 
    26 package com.sun.xml.internal.messaging.saaj.soap;
    26 package com.sun.xml.internal.messaging.saaj.soap;
    27 
    27 
       
    28 import com.sun.xml.internal.messaging.saaj.LazyEnvelopeSource;
    28 import com.sun.xml.internal.messaging.saaj.SOAPExceptionImpl;
    29 import com.sun.xml.internal.messaging.saaj.SOAPExceptionImpl;
    29 import com.sun.xml.internal.messaging.saaj.util.JAXMStreamSource;
    30 import com.sun.xml.internal.messaging.saaj.util.JAXMStreamSource;
    30 import com.sun.xml.internal.messaging.saaj.util.LogDomainConstants;
    31 import com.sun.xml.internal.messaging.saaj.util.LogDomainConstants;
    31 import com.sun.xml.internal.messaging.saaj.util.ParserPool;
    32 import com.sun.xml.internal.messaging.saaj.util.ParserPool;
    32 import com.sun.xml.internal.messaging.saaj.util.RejectDoctypeSaxFilter;
    33 import com.sun.xml.internal.messaging.saaj.util.RejectDoctypeSaxFilter;
    43 import javax.xml.transform.Transformer;
    44 import javax.xml.transform.Transformer;
    44 import javax.xml.transform.dom.DOMResult;
    45 import javax.xml.transform.dom.DOMResult;
    45 import javax.xml.transform.sax.SAXSource;
    46 import javax.xml.transform.sax.SAXSource;
    46 import javax.xml.transform.stax.StAXSource;
    47 import javax.xml.transform.stax.StAXSource;
    47 import javax.xml.transform.stream.StreamSource;
    48 import javax.xml.transform.stream.StreamSource;
    48 
       
    49 import com.sun.xml.internal.messaging.saaj.LazyEnvelopeSource;
       
    50 import com.sun.xml.internal.messaging.saaj.util.transform.EfficientStreamingTransformer;
       
    51 
       
    52 import java.util.logging.Logger;
    49 import java.util.logging.Logger;
    53 
    50 
    54 /**
    51 /**
    55  * EnvelopeFactory creates SOAP Envelope objects using different
    52  * EnvelopeFactory creates SOAP Envelope objects using different
    56  * underlying implementations.
    53  * underlying implementations.
    57  */
    54  */
    58 public class EnvelopeFactory {
    55 public class EnvelopeFactory {
    59 
    56 
    60     protected static final Logger
    57     protected static final Logger
    61             log = Logger.getLogger(LogDomainConstants.SOAP_DOMAIN,
    58         log = Logger.getLogger(LogDomainConstants.SOAP_DOMAIN,
    62             "com.sun.xml.internal.messaging.saaj.soap.LocalStrings");
    59         "com.sun.xml.internal.messaging.saaj.soap.LocalStrings");
    63 
    60 
    64     private static ContextClassloaderLocal<ParserPool> parserPool =
    61     private static ContextClassloaderLocal<ParserPool> parserPool =
    65             new ContextClassloaderLocal<ParserPool>() {
    62             new ContextClassloaderLocal<ParserPool>() {
    66                 @Override
    63                 @Override
    67                 protected ParserPool initialValue() throws Exception {
    64                 protected ParserPool initialValue() throws Exception {
    70             };
    67             };
    71 
    68 
    72     public static Envelope createEnvelope(Source src, SOAPPartImpl soapPart)
    69     public static Envelope createEnvelope(Source src, SOAPPartImpl soapPart)
    73         throws SOAPException
    70         throws SOAPException
    74     {
    71     {
    75         if (src instanceof JAXMStreamSource) {
    72             if (src instanceof JAXMStreamSource) {
    76             try {
    73                 try {
    77                 if (!SOAPPartImpl.lazyContentLength) {
    74                     if (!SOAPPartImpl.lazyContentLength) {
    78                     ((JAXMStreamSource) src).reset();
    75                         ((JAXMStreamSource) src).reset();
       
    76                     }
       
    77                 } catch (java.io.IOException ioe) {
       
    78                     log.severe("SAAJ0515.source.reset.exception");
       
    79                     throw new SOAPExceptionImpl(ioe);
    79                 }
    80                 }
    80             } catch (java.io.IOException ioe) {
       
    81                 log.severe("SAAJ0515.source.reset.exception");
       
    82                 throw new SOAPExceptionImpl(ioe);
       
    83             }
    81             }
    84         }
       
    85         if (src instanceof LazyEnvelopeSource) {
    82         if (src instanceof LazyEnvelopeSource) {
    86           return lazy((LazyEnvelopeSource)src, soapPart);
    83           return lazy((LazyEnvelopeSource)src, soapPart);
    87       }
    84       }
    88         if (soapPart.message.isLazySoapBodyParsing()) {
    85         if (soapPart.message.isLazySoapBodyParsing()) {
    89             return parseEnvelopeStax(src, soapPart);
    86             return parseEnvelopeStax(src, soapPart);
    91             return parseEnvelopeSax(src, soapPart);
    88             return parseEnvelopeSax(src, soapPart);
    92         }
    89         }
    93     }
    90     }
    94 
    91 
    95     private static Envelope lazy(LazyEnvelopeSource src, SOAPPartImpl soapPart) throws SOAPException {
    92     private static Envelope lazy(LazyEnvelopeSource src, SOAPPartImpl soapPart) throws SOAPException {
    96         try {
    93             try {
    97                 StaxBridge staxBridge = new StaxLazySourceBridge(src, soapPart);
    94                 StaxBridge staxBridge = new StaxLazySourceBridge(src, soapPart);
    98                 staxBridge.bridgeEnvelopeAndHeaders();
    95                 staxBridge.bridgeEnvelopeAndHeaders();
    99             Envelope env = (Envelope) soapPart.getEnvelope();
    96             Envelope env = (Envelope) soapPart.getEnvelope();
   100             env.setStaxBridge(staxBridge);
    97             env.setStaxBridge(staxBridge);
   101             return env;
    98             return env;
   142             try {
   139             try {
   143                 saxParser = parserPool.get().get();
   140                 saxParser = parserPool.get().get();
   144             } catch (Exception e) {
   141             } catch (Exception e) {
   145                 log.severe("SAAJ0601.util.newSAXParser.exception");
   142                 log.severe("SAAJ0601.util.newSAXParser.exception");
   146                 throw new SOAPExceptionImpl(
   143                 throw new SOAPExceptionImpl(
   147                         "Couldn't get a SAX parser while constructing a envelope",
   144                     "Couldn't get a SAX parser while constructing a envelope",
   148                         e);
   145                     e);
   149             }
   146             }
   150             InputSource is = SAXSource.sourceToInputSource(src);
   147             InputSource is = SAXSource.sourceToInputSource(src);
   151             if (is.getEncoding() == null && soapPart.getSourceCharsetEncoding() != null) {
   148             if (is.getEncoding()== null && soapPart.getSourceCharsetEncoding() != null) {
   152                 is.setEncoding(soapPart.getSourceCharsetEncoding());
   149                 is.setEncoding(soapPart.getSourceCharsetEncoding());
   153             }
   150             }
   154             XMLReader rejectFilter;
   151             XMLReader rejectFilter;
   155             try {
   152             try {
   156                 rejectFilter = new RejectDoctypeSaxFilter(saxParser);
   153                 rejectFilter = new RejectDoctypeSaxFilter(saxParser);
   157             } catch (Exception ex) {
   154             } catch (Exception ex) {
   158                 log.severe("SAAJ0510.soap.cannot.create.envelope");
   155                 log.severe("SAAJ0510.soap.cannot.create.envelope");
   159                 throw new SOAPExceptionImpl(
   156                 throw new SOAPExceptionImpl(
   160                         "Unable to create envelope from given source: ",
   157                     "Unable to create envelope from given source: ",
   161                         ex);
   158                     ex);
   162             }
   159             }
   163             src = new SAXSource(rejectFilter, is);
   160             src = new SAXSource(rejectFilter, is);
   164         }
   161         }
   165 
   162 
   166         try {
   163         try {
   167             Transformer transformer =
   164             Transformer transformer =
   168                     EfficientStreamingTransformer.newTransformer();
   165                 EfficientStreamingTransformer.newTransformer();
   169             DOMResult result = new DOMResult(soapPart);
   166             DOMResult result = new DOMResult(soapPart);
   170             transformer.transform(src, result);
   167             transformer.transform(src, result);
   171 
   168 
   172             Envelope env = (Envelope) soapPart.getEnvelope();
   169             Envelope env = (Envelope) soapPart.getEnvelope();
   173             return env;
   170             return env;
   175             if (ex instanceof SOAPVersionMismatchException) {
   172             if (ex instanceof SOAPVersionMismatchException) {
   176                 throw (SOAPVersionMismatchException) ex;
   173                 throw (SOAPVersionMismatchException) ex;
   177             }
   174             }
   178             log.severe("SAAJ0511.soap.cannot.create.envelope");
   175             log.severe("SAAJ0511.soap.cannot.create.envelope");
   179             throw new SOAPExceptionImpl(
   176             throw new SOAPExceptionImpl(
   180                     "Unable to create envelope from given source: ",
   177                 "Unable to create envelope from given source: ",
   181                     ex);
   178                 ex);
   182         } finally {
   179         } finally {
   183             if (saxParser != null) {
   180             if (saxParser != null) {
   184                 parserPool.get().returnParser(saxParser);
   181                 parserPool.get().returnParser(saxParser);
   185             }
   182             }
   186         }
   183         }