jaxws/src/share/jaxws_classes/com/sun/xml/internal/messaging/saaj/soap/MessageImpl.java
changeset 23782 953bfc3fbe31
parent 22679 d785acd84a14
equal deleted inserted replaced
23403:85dbdc227c5e 23782:953bfc3fbe31
     1 /*
     1 /*
     2  * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.  Oracle designates this
     7  * published by the Free Software Foundation.  Oracle designates this
    31 import java.util.logging.Logger;
    31 import java.util.logging.Logger;
    32 
    32 
    33 import javax.activation.DataHandler;
    33 import javax.activation.DataHandler;
    34 import javax.activation.DataSource;
    34 import javax.activation.DataSource;
    35 import javax.xml.soap.*;
    35 import javax.xml.soap.*;
       
    36 import javax.xml.stream.XMLStreamReader;
    36 import javax.xml.transform.Source;
    37 import javax.xml.transform.Source;
       
    38 import javax.xml.transform.stax.StAXSource;
    37 import javax.xml.transform.stream.StreamSource;
    39 import javax.xml.transform.stream.StreamSource;
    38 
    40 
    39 import com.sun.xml.internal.messaging.saaj.packaging.mime.Header;
    41 import com.sun.xml.internal.messaging.saaj.packaging.mime.Header;
    40 import com.sun.xml.internal.messaging.saaj.packaging.mime.internet.*;
    42 import com.sun.xml.internal.messaging.saaj.packaging.mime.internet.*;
    41 import com.sun.xml.internal.messaging.saaj.packaging.mime.util.*;
    43 import com.sun.xml.internal.messaging.saaj.packaging.mime.util.*;
   107 
   109 
   108     // if attachments are present, don't read the entire message in byte stream in saveTo()
   110     // if attachments are present, don't read the entire message in byte stream in saveTo()
   109     private boolean optimizeAttachmentProcessing = true;
   111     private boolean optimizeAttachmentProcessing = true;
   110 
   112 
   111     private InputStream inputStreamAfterSaveChanges = null;
   113     private InputStream inputStreamAfterSaveChanges = null;
       
   114 
       
   115     public static final String LAZY_SOAP_BODY_PARSING = "saaj.lazy.soap.body";
   112 
   116 
   113     // switch back to old MimeMultipart incase of problem
   117     // switch back to old MimeMultipart incase of problem
   114     private static boolean switchOffBM = false;
   118     private static boolean switchOffBM = false;
   115     private static boolean switchOffLazyAttachment = false;
   119     private static boolean switchOffLazyAttachment = false;
   116     private static boolean useMimePull = false;
   120     private static boolean useMimePull = false;
   339     protected MessageImpl(MimeHeaders headers, final ContentType contentType, int stat, final InputStream in) throws SOAPExceptionImpl {
   343     protected MessageImpl(MimeHeaders headers, final ContentType contentType, int stat, final InputStream in) throws SOAPExceptionImpl {
   340         init(headers, stat, contentType, in);
   344         init(headers, stat, contentType, in);
   341 
   345 
   342     }
   346     }
   343 
   347 
   344     private void init(MimeHeaders headers, int stat, final ContentType contentType, final InputStream in) throws SOAPExceptionImpl {
   348     public MessageImpl(MimeHeaders headers, ContentType ct, int stat,
       
   349             XMLStreamReader reader) throws SOAPExceptionImpl {
       
   350         init(headers, stat, ct, reader);
       
   351     }
       
   352 
       
   353     private void init(MimeHeaders headers, int stat, final ContentType contentType, final Object input) throws SOAPExceptionImpl {
   345         this.headers = headers;
   354         this.headers = headers;
   346 
   355 
   347         try {
   356         try {
   348 
   357 
   349             // Set isFastInfoset/acceptFastInfoset flag based on MIME type
   358             // Set isFastInfoset/acceptFastInfoset flag based on MIME type
   380                     "Cannot create message: incorrect content-type for SOAP version. Got: "
   389                     "Cannot create message: incorrect content-type for SOAP version. Got: "
   381                         + contentType
   390                         + contentType
   382                         + " Expected: "
   391                         + " Expected: "
   383                         + getExpectedContentType());
   392                         + getExpectedContentType());
   384             }
   393             }
   385 
   394             InputStream in = null;
       
   395             XMLStreamReader rdr = null;
       
   396             if (input instanceof InputStream) {
       
   397                in = (InputStream) input;
       
   398             } else {
       
   399               //is a StAX reader
       
   400                 rdr = (XMLStreamReader) input;
       
   401             }
   386             if ((stat & PLAIN_XML_FLAG) != 0) {
   402             if ((stat & PLAIN_XML_FLAG) != 0) {
   387                 if (isFastInfoset) {
   403                 if (in != null) {
   388                     getSOAPPart().setContent(
   404                     if (isFastInfoset) {
   389                         FastInfosetReflection.FastInfosetSource_new(in));
   405                         getSOAPPart().setContent(
       
   406                                 FastInfosetReflection.FastInfosetSource_new(in));
       
   407                     } else {
       
   408                         initCharsetProperty(contentType);
       
   409                         getSOAPPart().setContent(new StreamSource(in));
       
   410                     }
   390                 } else {
   411                 } else {
   391                     initCharsetProperty(contentType);
   412                     //is a StAX reader
   392                     getSOAPPart().setContent(new StreamSource(in));
   413                     if (isFastInfoset) {
   393                 }
   414                         //need to get FI stax reader
   394             }
   415                     } else {
   395             else if ((stat & MIME_MULTIPART_FLAG) != 0) {
   416                         initCharsetProperty(contentType);
       
   417                         getSOAPPart().setContent(new StAXSource(rdr));
       
   418                     }
       
   419                 }
       
   420             }
       
   421             else if ((stat & MIME_MULTIPART_FLAG) != 0 && in == null) {
       
   422                 //only parse multipart in the inputstream case
       
   423                 //in stax reader case, we would be given the attachments separately
       
   424                 getSOAPPart().setContent(new StAXSource(rdr));
       
   425             } else if ((stat & MIME_MULTIPART_FLAG) != 0) {
       
   426                 final InputStream finalIn = in;
   396                 DataSource ds = new DataSource() {
   427                 DataSource ds = new DataSource() {
   397                     public InputStream getInputStream() {
   428                     public InputStream getInputStream() {
   398                         return in;
   429                         return finalIn;
   399                     }
   430                     }
   400 
   431 
   401                     public OutputStream getOutputStream() {
   432                     public OutputStream getOutputStream() {
   402                         return null;
   433                         return null;
   403                     }
   434                     }
   485                             }
   516                             }
   486                         }
   517                         }
   487                     }
   518                     }
   488                 }
   519                 }
   489 
   520 
   490                 if (soapPartInputStream == null && soapMessagePart != null) {
   521                 // findbugs correctly points out that we'd NPE instantiating
       
   522                 // the ContentType (just below here) if soapMessagePart were
       
   523                 // null.  Hence are better off throwing a controlled exception
       
   524                 // at this point if it is null.
       
   525                 if (soapMessagePart == null) {
       
   526                     log.severe("SAAJ0510.soap.cannot.create.envelope");
       
   527                     throw new SOAPExceptionImpl(
       
   528                         "Unable to create envelope from given source: SOAP part not found");
       
   529                 }
       
   530 
       
   531                 if (soapPartInputStream == null) {
   491                     soapPartInputStream = soapMessagePart.getInputStream();
   532                     soapPartInputStream = soapMessagePart.getInputStream();
   492                 }
   533                 }
   493 
   534 
   494                 ContentType soapPartCType = new ContentType(
   535                 ContentType soapPartCType = new ContentType(
   495                                             soapMessagePart.getContentType());
   536                                             soapMessagePart.getContentType());
   539             }
   580             }
   540             saved = false;      // ensure transcoding if necessary
   581             saved = false;      // ensure transcoding if necessary
   541         }
   582         }
   542     }
   583     }
   543 
   584 
       
   585     public boolean isLazySoapBodyParsing() {
       
   586         Object lazyParsingProp = getProperty(LAZY_SOAP_BODY_PARSING);
       
   587         if (lazyParsingProp == null) return false;
       
   588         if (lazyParsingProp instanceof Boolean) {
       
   589             return ((Boolean) lazyParsingProp).booleanValue();
       
   590         } else {
       
   591             return Boolean.valueOf(lazyParsingProp.toString());
       
   592         }
       
   593     }
   544     public Object getProperty(String property) {
   594     public Object getProperty(String property) {
   545         return (String) properties.get(property);
   595         return (String) properties.get(property);
   546     }
   596     }
   547 
   597 
   548     public void setProperty(String property, Object value) {
   598     public void setProperty(String property, Object value) {