jaxws/src/share/jaxws_classes/com/sun/xml/internal/messaging/saaj/soap/MessageImpl.java
author mkos
Mon, 31 Mar 2014 10:43:20 +0200
changeset 23782 953bfc3fbe31
parent 22679 d785acd84a14
permissions -rw-r--r--
8036030: Update JAX-WS RI integration to latest version Summary: JAX-WS RI upgrade from 2.2.9-b130926.1035 to 2.2.10-b140228.1436; Reviewed-by: chegar
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
12009
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
     1
/*
23782
953bfc3fbe31 8036030: Update JAX-WS RI integration to latest version
mkos
parents: 22679
diff changeset
     2
 * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
12009
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
     4
 *
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    10
 *
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    15
 * accompanied this code).
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    16
 *
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    20
 *
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    23
 * questions.
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    24
 */
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    25
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    26
package com.sun.xml.internal.messaging.saaj.soap;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    27
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    28
import java.io.*;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    29
import java.util.*;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    30
import java.util.logging.Level;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    31
import java.util.logging.Logger;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    32
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    33
import javax.activation.DataHandler;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    34
import javax.activation.DataSource;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    35
import javax.xml.soap.*;
23782
953bfc3fbe31 8036030: Update JAX-WS RI integration to latest version
mkos
parents: 22679
diff changeset
    36
import javax.xml.stream.XMLStreamReader;
12009
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    37
import javax.xml.transform.Source;
23782
953bfc3fbe31 8036030: Update JAX-WS RI integration to latest version
mkos
parents: 22679
diff changeset
    38
import javax.xml.transform.stax.StAXSource;
12009
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    39
import javax.xml.transform.stream.StreamSource;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    40
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    41
import com.sun.xml.internal.messaging.saaj.packaging.mime.Header;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    42
import com.sun.xml.internal.messaging.saaj.packaging.mime.internet.*;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    43
import com.sun.xml.internal.messaging.saaj.packaging.mime.util.*;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    44
import com.sun.xml.internal.messaging.saaj.packaging.mime.MessagingException;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    45
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    46
import com.sun.xml.internal.messaging.saaj.SOAPExceptionImpl;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    47
import com.sun.xml.internal.messaging.saaj.soap.impl.EnvelopeImpl;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    48
import com.sun.xml.internal.messaging.saaj.util.*;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    49
import com.sun.xml.internal.org.jvnet.mimepull.MIMEPart;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    50
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    51
/**
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    52
 * The message implementation for SOAP messages with
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    53
 * attachments. Messages for specific profiles will likely extend this
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    54
 * MessageImpl class and add more value for that particular profile.
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    55
 *
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    56
 * @author Anil Vijendran (akv@eng.sun.com)
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    57
 * @author Rajiv Mordani (rajiv.mordani@sun.com)
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    58
 * @author Manveen Kaur (manveen.kaur@sun.com)
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    59
 */
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    60
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    61
public abstract class MessageImpl
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    62
    extends SOAPMessage
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    63
    implements SOAPConstants {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    64
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    65
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    66
    public static final String CONTENT_ID             = "Content-ID";
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    67
    public static final String CONTENT_LOCATION       = "Content-Location";
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    68
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    69
    protected static final Logger log =
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    70
        Logger.getLogger(LogDomainConstants.SOAP_DOMAIN,
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    71
                         "com.sun.xml.internal.messaging.saaj.soap.LocalStrings");
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    72
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    73
    protected static final int PLAIN_XML_FLAG      = 1;      // 00001
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    74
    protected static final int MIME_MULTIPART_FLAG = 2;      // 00010
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    75
    protected static final int SOAP1_1_FLAG = 4;             // 00100
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    76
    protected static final int SOAP1_2_FLAG = 8;             // 01000
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    77
    //protected static final int MIME_MULTIPART_XOP_FLAG = 14; // 01110
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    78
    protected static final int MIME_MULTIPART_XOP_SOAP1_1_FLAG = 6;  // 00110
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    79
    protected static final int MIME_MULTIPART_XOP_SOAP1_2_FLAG = 10; // 01010
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    80
    protected static final int XOP_FLAG = 13;                // 01101
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    81
    protected static final int FI_ENCODED_FLAG     = 16;     // 10000
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    82
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    83
    protected MimeHeaders headers;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    84
    protected ContentType contentType;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    85
    protected SOAPPartImpl soapPartImpl;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    86
    protected FinalArrayList attachments;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    87
    protected boolean saved = false;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    88
    protected byte[] messageBytes;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    89
    protected int messageByteCount;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    90
    protected HashMap properties = new HashMap();
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    91
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    92
    // used for lazy attachment initialization
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    93
    protected MimeMultipart multiPart = null;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    94
    protected boolean attachmentsInitialized = false;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    95
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    96
    /**
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    97
     * True if this part is encoded using Fast Infoset.
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    98
     * MIME -> application/fastinfoset
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    99
     */
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   100
    protected boolean isFastInfoset = false;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   101
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   102
    /**
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   103
     * True if the Accept header of this message includes
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   104
     * application/fastinfoset
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   105
     */
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   106
    protected boolean acceptFastInfoset = false;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   107
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   108
    protected MimeMultipart mmp = null;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   109
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   110
    // if attachments are present, don't read the entire message in byte stream in saveTo()
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   111
    private boolean optimizeAttachmentProcessing = true;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   112
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   113
    private InputStream inputStreamAfterSaveChanges = null;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   114
23782
953bfc3fbe31 8036030: Update JAX-WS RI integration to latest version
mkos
parents: 22679
diff changeset
   115
    public static final String LAZY_SOAP_BODY_PARSING = "saaj.lazy.soap.body";
953bfc3fbe31 8036030: Update JAX-WS RI integration to latest version
mkos
parents: 22679
diff changeset
   116
12009
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   117
    // switch back to old MimeMultipart incase of problem
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   118
    private static boolean switchOffBM = false;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   119
    private static boolean switchOffLazyAttachment = false;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   120
    private static boolean useMimePull = false;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   121
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   122
    static {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   123
            String s = SAAJUtil.getSystemProperty("saaj.mime.optimization");
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   124
            if ((s != null) && s.equals("false")) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   125
                switchOffBM = true;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   126
            }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   127
            s = SAAJUtil.getSystemProperty("saaj.lazy.mime.optimization");
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   128
            if ((s != null) && s.equals("false")) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   129
                switchOffLazyAttachment = true;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   130
            }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   131
            useMimePull = SAAJUtil.getSystemBoolean("saaj.use.mimepull");
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   132
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   133
    }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   134
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   135
    //property to indicate optimized serialization for lazy attachments
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   136
    private boolean lazyAttachments = false;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   137
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   138
    // most of the times, Content-Types are already all lower cased.
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   139
    // String.toLowerCase() works faster in this case, so even if you
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   140
    // are only doing one comparison, it pays off to use String.toLowerCase()
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   141
    // than String.equalsIgnoreCase(). When you do more than one comparison,
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   142
    // the benefits of String.toLowerCase() dominates.
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   143
    //
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   144
    //
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   145
    // for FI,
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   146
    //   use application/fastinfoset for SOAP 1.1
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   147
    //   use application/soap+fastinfoset for SOAP 1.2
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   148
    // to speed up comparisons, test methods always use lower cases.
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   149
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   150
    /**
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   151
     * @param primary
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   152
     *      must be all lower case
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   153
     * @param sub
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   154
     *      must be all lower case
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   155
     */
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   156
    private static boolean isSoap1_1Type(String primary, String sub) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   157
        return primary.equalsIgnoreCase("text") && sub.equalsIgnoreCase("xml")
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   158
            || primary.equalsIgnoreCase("text") && sub.equalsIgnoreCase("xml-soap")
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   159
            || primary.equals("application")
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   160
               && sub.equals("fastinfoset");
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   161
    }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   162
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   163
    /**
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   164
     * @param type
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   165
     *      must be all lower case
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   166
     */
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   167
    private static boolean isEqualToSoap1_1Type(String type) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   168
        return type.startsWith("text/xml") ||
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   169
               type.startsWith("application/fastinfoset");
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   170
    }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   171
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   172
    /**
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   173
     * @param primary
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   174
     *      must be all lower case
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   175
     * @param sub
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   176
     *      must be all lower case
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   177
     */
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   178
    private static boolean isSoap1_2Type(String primary, String sub) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   179
        return primary.equals("application")
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   180
               && (sub.equals("soap+xml")
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   181
                   || sub.equals("soap+fastinfoset"));
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   182
    }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   183
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   184
    /**
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   185
     * @param type
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   186
     *      must be all lower case
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   187
     */
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   188
    private static boolean isEqualToSoap1_2Type(String type) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   189
        return type.startsWith("application/soap+xml") ||
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   190
               type.startsWith("application/soap+fastinfoset");
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   191
    }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   192
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   193
    /**
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   194
      * Construct a new message. This will be invoked before message
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   195
      * sends.
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   196
      */
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   197
    protected MessageImpl() {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   198
        this(false, false);
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   199
        attachmentsInitialized = true;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   200
    }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   201
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   202
    /**
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   203
      * Construct a new message. This will be invoked before message
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   204
      * sends.
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   205
      */
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   206
    protected MessageImpl(boolean isFastInfoset, boolean acceptFastInfoset) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   207
        this.isFastInfoset = isFastInfoset;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   208
        this.acceptFastInfoset = acceptFastInfoset;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   209
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   210
        headers = new MimeHeaders();
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   211
        headers.setHeader("Accept", getExpectedAcceptHeader());
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   212
        contentType = new ContentType();
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   213
    }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   214
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   215
    /**
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   216
     * Shallow copy.
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   217
     */
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   218
    protected MessageImpl(SOAPMessage msg) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   219
        if (!(msg instanceof MessageImpl)) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   220
            // don't know how to handle this.
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   221
        }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   222
        MessageImpl src = (MessageImpl) msg;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   223
        this.headers = src.headers;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   224
        this.soapPartImpl = src.soapPartImpl;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   225
        this.attachments = src.attachments;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   226
        this.saved = src.saved;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   227
        this.messageBytes = src.messageBytes;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   228
        this.messageByteCount = src.messageByteCount;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   229
        this.properties = src.properties;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   230
        this.contentType = src.contentType;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   231
    }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   232
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   233
    /**
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   234
     * @param stat
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   235
     *      the mask value obtained from {@link #identifyContentType(ContentType)}
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   236
     */
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   237
    protected static boolean isSoap1_1Content(int stat) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   238
        return (stat & SOAP1_1_FLAG) != 0;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   239
    }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   240
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   241
    /**
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   242
     * @param stat
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   243
     *      the mask value obtained from {@link #identifyContentType(ContentType)}
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   244
     */
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   245
    protected static boolean isSoap1_2Content(int stat) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   246
        return (stat & SOAP1_2_FLAG) != 0;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   247
    }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   248
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   249
     private static boolean isMimeMultipartXOPSoap1_2Package(ContentType contentType) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   250
        String type = contentType.getParameter("type");
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   251
        if (type == null) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   252
            return false;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   253
        }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   254
        type = type.toLowerCase();
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   255
        if (!type.startsWith("application/xop+xml")) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   256
            return false;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   257
        }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   258
        String startinfo = contentType.getParameter("start-info");
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   259
        if (startinfo == null) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   260
            return false;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   261
        }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   262
        startinfo = startinfo.toLowerCase();
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   263
        return isEqualToSoap1_2Type(startinfo);
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   264
    }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   265
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   266
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   267
     //private static boolean isMimeMultipartXOPPackage(ContentType contentType) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   268
     private static boolean isMimeMultipartXOPSoap1_1Package(ContentType contentType) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   269
        String type = contentType.getParameter("type");
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   270
        if(type==null)
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   271
            return false;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   272
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   273
        type = type.toLowerCase();
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   274
        if(!type.startsWith("application/xop+xml"))
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   275
            return false;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   276
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   277
        String startinfo = contentType.getParameter("start-info");
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   278
        if(startinfo == null)
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   279
            return false;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   280
        startinfo = startinfo.toLowerCase();
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   281
        return isEqualToSoap1_1Type(startinfo);
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   282
    }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   283
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   284
    private static boolean isSOAPBodyXOPPackage(ContentType contentType){
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   285
        String primary = contentType.getPrimaryType();
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   286
        String sub = contentType.getSubType();
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   287
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   288
        if (primary.equalsIgnoreCase("application")) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   289
            if (sub.equalsIgnoreCase("xop+xml")) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   290
                String type = getTypeParameter(contentType);
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   291
                return isEqualToSoap1_2Type(type) || isEqualToSoap1_1Type(type);
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   292
            }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   293
        }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   294
        return false;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   295
    }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   296
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   297
    /**
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   298
     * Construct a message from an input stream. When messages are
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   299
     * received, there's two parts -- the transport headers and the
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   300
     * message content in a transport specific stream.
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   301
     */
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   302
    protected MessageImpl(MimeHeaders headers, final InputStream in)
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   303
        throws SOAPExceptionImpl {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   304
        contentType = parseContentType(headers);
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   305
        init(headers,identifyContentType(contentType),contentType,in);
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   306
    }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   307
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   308
    private static ContentType parseContentType(MimeHeaders headers) throws SOAPExceptionImpl {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   309
        final String ct;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   310
        if (headers != null)
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   311
            ct = getContentType(headers);
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   312
        else {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   313
            log.severe("SAAJ0550.soap.null.headers");
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   314
            throw new SOAPExceptionImpl("Cannot create message: " +
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   315
                                        "Headers can't be null");
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   316
        }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   317
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   318
        if (ct == null) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   319
            log.severe("SAAJ0532.soap.no.Content-Type");
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   320
            throw new SOAPExceptionImpl("Absent Content-Type");
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   321
        }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   322
        try {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   323
            return new ContentType(ct);
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   324
        } catch (Throwable ex) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   325
            log.severe("SAAJ0535.soap.cannot.internalize.message");
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   326
            throw new SOAPExceptionImpl("Unable to internalize message", ex);
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   327
        }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   328
    }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   329
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   330
    /**
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   331
     * Construct a message from an input stream. When messages are
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   332
     * received, there's two parts -- the transport headers and the
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   333
     * message content in a transport specific stream.
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   334
     *
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   335
     * @param contentType
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   336
     *      The parsed content type header from the headers variable.
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   337
     *      This is redundant parameter, but it avoids reparsing this header again.
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   338
     * @param stat
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   339
     *      The result of {@link #identifyContentType(ContentType)} over
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   340
     *      the contentType parameter. This redundant parameter, but it avoids
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   341
     *      recomputing this information again.
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   342
     */
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   343
    protected MessageImpl(MimeHeaders headers, final ContentType contentType, int stat, final InputStream in) throws SOAPExceptionImpl {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   344
        init(headers, stat, contentType, in);
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   345
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   346
    }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   347
23782
953bfc3fbe31 8036030: Update JAX-WS RI integration to latest version
mkos
parents: 22679
diff changeset
   348
    public MessageImpl(MimeHeaders headers, ContentType ct, int stat,
953bfc3fbe31 8036030: Update JAX-WS RI integration to latest version
mkos
parents: 22679
diff changeset
   349
            XMLStreamReader reader) throws SOAPExceptionImpl {
953bfc3fbe31 8036030: Update JAX-WS RI integration to latest version
mkos
parents: 22679
diff changeset
   350
        init(headers, stat, ct, reader);
953bfc3fbe31 8036030: Update JAX-WS RI integration to latest version
mkos
parents: 22679
diff changeset
   351
    }
953bfc3fbe31 8036030: Update JAX-WS RI integration to latest version
mkos
parents: 22679
diff changeset
   352
953bfc3fbe31 8036030: Update JAX-WS RI integration to latest version
mkos
parents: 22679
diff changeset
   353
    private void init(MimeHeaders headers, int stat, final ContentType contentType, final Object input) throws SOAPExceptionImpl {
12009
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   354
        this.headers = headers;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   355
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   356
        try {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   357
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   358
            // Set isFastInfoset/acceptFastInfoset flag based on MIME type
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   359
            if ((stat & FI_ENCODED_FLAG) > 0) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   360
                isFastInfoset = acceptFastInfoset = true;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   361
            }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   362
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   363
            // If necessary, inspect Accept header to set acceptFastInfoset
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   364
            if (!isFastInfoset) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   365
                String[] values = headers.getHeader("Accept");
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   366
                if (values != null) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   367
                    for (int i = 0; i < values.length; i++) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   368
                        StringTokenizer st = new StringTokenizer(values[i], ",");
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   369
                        while (st.hasMoreTokens()) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   370
                            final String token = st.nextToken().trim();
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   371
                            if (token.equalsIgnoreCase("application/fastinfoset") ||
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   372
                                token.equalsIgnoreCase("application/soap+fastinfoset")) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   373
                                acceptFastInfoset = true;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   374
                                break;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   375
                            }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   376
                        }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   377
                    }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   378
                }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   379
            }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   380
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   381
            if (!isCorrectSoapVersion(stat)) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   382
                log.log(
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   383
                    Level.SEVERE,
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   384
                    "SAAJ0533.soap.incorrect.Content-Type",
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   385
                    new String[] {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   386
                        contentType.toString(),
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   387
                        getExpectedContentType()});
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   388
                throw new SOAPVersionMismatchException(
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   389
                    "Cannot create message: incorrect content-type for SOAP version. Got: "
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   390
                        + contentType
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   391
                        + " Expected: "
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   392
                        + getExpectedContentType());
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   393
            }
23782
953bfc3fbe31 8036030: Update JAX-WS RI integration to latest version
mkos
parents: 22679
diff changeset
   394
            InputStream in = null;
953bfc3fbe31 8036030: Update JAX-WS RI integration to latest version
mkos
parents: 22679
diff changeset
   395
            XMLStreamReader rdr = null;
953bfc3fbe31 8036030: Update JAX-WS RI integration to latest version
mkos
parents: 22679
diff changeset
   396
            if (input instanceof InputStream) {
953bfc3fbe31 8036030: Update JAX-WS RI integration to latest version
mkos
parents: 22679
diff changeset
   397
               in = (InputStream) input;
953bfc3fbe31 8036030: Update JAX-WS RI integration to latest version
mkos
parents: 22679
diff changeset
   398
            } else {
953bfc3fbe31 8036030: Update JAX-WS RI integration to latest version
mkos
parents: 22679
diff changeset
   399
              //is a StAX reader
953bfc3fbe31 8036030: Update JAX-WS RI integration to latest version
mkos
parents: 22679
diff changeset
   400
                rdr = (XMLStreamReader) input;
953bfc3fbe31 8036030: Update JAX-WS RI integration to latest version
mkos
parents: 22679
diff changeset
   401
            }
12009
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   402
            if ((stat & PLAIN_XML_FLAG) != 0) {
23782
953bfc3fbe31 8036030: Update JAX-WS RI integration to latest version
mkos
parents: 22679
diff changeset
   403
                if (in != null) {
953bfc3fbe31 8036030: Update JAX-WS RI integration to latest version
mkos
parents: 22679
diff changeset
   404
                    if (isFastInfoset) {
953bfc3fbe31 8036030: Update JAX-WS RI integration to latest version
mkos
parents: 22679
diff changeset
   405
                        getSOAPPart().setContent(
953bfc3fbe31 8036030: Update JAX-WS RI integration to latest version
mkos
parents: 22679
diff changeset
   406
                                FastInfosetReflection.FastInfosetSource_new(in));
953bfc3fbe31 8036030: Update JAX-WS RI integration to latest version
mkos
parents: 22679
diff changeset
   407
                    } else {
953bfc3fbe31 8036030: Update JAX-WS RI integration to latest version
mkos
parents: 22679
diff changeset
   408
                        initCharsetProperty(contentType);
953bfc3fbe31 8036030: Update JAX-WS RI integration to latest version
mkos
parents: 22679
diff changeset
   409
                        getSOAPPart().setContent(new StreamSource(in));
953bfc3fbe31 8036030: Update JAX-WS RI integration to latest version
mkos
parents: 22679
diff changeset
   410
                    }
12009
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   411
                } else {
23782
953bfc3fbe31 8036030: Update JAX-WS RI integration to latest version
mkos
parents: 22679
diff changeset
   412
                    //is a StAX reader
953bfc3fbe31 8036030: Update JAX-WS RI integration to latest version
mkos
parents: 22679
diff changeset
   413
                    if (isFastInfoset) {
953bfc3fbe31 8036030: Update JAX-WS RI integration to latest version
mkos
parents: 22679
diff changeset
   414
                        //need to get FI stax reader
953bfc3fbe31 8036030: Update JAX-WS RI integration to latest version
mkos
parents: 22679
diff changeset
   415
                    } else {
953bfc3fbe31 8036030: Update JAX-WS RI integration to latest version
mkos
parents: 22679
diff changeset
   416
                        initCharsetProperty(contentType);
953bfc3fbe31 8036030: Update JAX-WS RI integration to latest version
mkos
parents: 22679
diff changeset
   417
                        getSOAPPart().setContent(new StAXSource(rdr));
953bfc3fbe31 8036030: Update JAX-WS RI integration to latest version
mkos
parents: 22679
diff changeset
   418
                    }
12009
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   419
                }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   420
            }
23782
953bfc3fbe31 8036030: Update JAX-WS RI integration to latest version
mkos
parents: 22679
diff changeset
   421
            else if ((stat & MIME_MULTIPART_FLAG) != 0 && in == null) {
953bfc3fbe31 8036030: Update JAX-WS RI integration to latest version
mkos
parents: 22679
diff changeset
   422
                //only parse multipart in the inputstream case
953bfc3fbe31 8036030: Update JAX-WS RI integration to latest version
mkos
parents: 22679
diff changeset
   423
                //in stax reader case, we would be given the attachments separately
953bfc3fbe31 8036030: Update JAX-WS RI integration to latest version
mkos
parents: 22679
diff changeset
   424
                getSOAPPart().setContent(new StAXSource(rdr));
953bfc3fbe31 8036030: Update JAX-WS RI integration to latest version
mkos
parents: 22679
diff changeset
   425
            } else if ((stat & MIME_MULTIPART_FLAG) != 0) {
953bfc3fbe31 8036030: Update JAX-WS RI integration to latest version
mkos
parents: 22679
diff changeset
   426
                final InputStream finalIn = in;
12009
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   427
                DataSource ds = new DataSource() {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   428
                    public InputStream getInputStream() {
23782
953bfc3fbe31 8036030: Update JAX-WS RI integration to latest version
mkos
parents: 22679
diff changeset
   429
                        return finalIn;
12009
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   430
                    }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   431
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   432
                    public OutputStream getOutputStream() {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   433
                        return null;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   434
                    }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   435
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   436
                    public String getContentType() {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   437
                        return contentType.toString();
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   438
                    }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   439
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   440
                    public String getName() {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   441
                        return "";
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   442
                    }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   443
                };
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   444
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   445
                multiPart = null;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   446
                if (useMimePull) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   447
                    multiPart = new MimePullMultipart(ds,contentType);
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   448
                } else if (switchOffBM) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   449
                    multiPart = new MimeMultipart(ds,contentType);
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   450
                } else {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   451
                    multiPart = new BMMimeMultipart(ds,contentType);
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   452
                }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   453
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   454
                String startParam = contentType.getParameter("start");
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   455
                MimeBodyPart soapMessagePart = null;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   456
                InputStream soapPartInputStream = null;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   457
                String contentID = null;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   458
                String contentIDNoAngle = null;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   459
                if (switchOffBM || switchOffLazyAttachment) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   460
                    if(startParam == null) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   461
                        soapMessagePart = multiPart.getBodyPart(0);
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   462
                        for (int i = 1; i < multiPart.getCount(); i++) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   463
                            initializeAttachment(multiPart, i);
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   464
                        }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   465
                    } else {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   466
                        soapMessagePart = multiPart.getBodyPart(startParam);
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   467
                        for (int i = 0; i < multiPart.getCount(); i++) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   468
                            contentID = multiPart.getBodyPart(i).getContentID();
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   469
                            // Old versions of AXIS2 put angle brackets around the content
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   470
                            // id but not the start param
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   471
                            contentIDNoAngle = (contentID != null) ?
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   472
                                contentID.replaceFirst("^<", "").replaceFirst(">$", "") : null;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   473
                            if(!startParam.equals(contentID) && !startParam.equals(contentIDNoAngle))
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   474
                                initializeAttachment(multiPart, i);
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   475
                        }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   476
                    }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   477
                } else {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   478
                    if (useMimePull) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   479
                        MimePullMultipart mpMultipart = (MimePullMultipart)multiPart;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   480
                        MIMEPart sp = mpMultipart.readAndReturnSOAPPart();
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   481
                        soapMessagePart = new MimeBodyPart(sp);
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   482
                        soapPartInputStream = sp.readOnce();
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   483
                    } else {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   484
                        BMMimeMultipart bmMultipart =
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   485
                                (BMMimeMultipart) multiPart;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   486
                        InputStream stream = bmMultipart.initStream();
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   487
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   488
                        SharedInputStream sin = null;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   489
                        if (stream instanceof SharedInputStream) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   490
                            sin = (SharedInputStream) stream;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   491
                        }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   492
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   493
                        String boundary = "--" +
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   494
                                contentType.getParameter("boundary");
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   495
                        byte[] bndbytes = ASCIIUtility.getBytes(boundary);
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   496
                        if (startParam == null) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   497
                            soapMessagePart =
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   498
                                    bmMultipart.getNextPart(stream, bndbytes, sin);
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   499
                            bmMultipart.removeBodyPart(soapMessagePart);
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   500
                        } else {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   501
                            MimeBodyPart bp = null;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   502
                            try {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   503
                               while (!startParam.equals(contentID) && !startParam.equals(contentIDNoAngle)) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   504
                                    bp = bmMultipart.getNextPart(
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   505
                                            stream, bndbytes, sin);
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   506
                                    contentID = bp.getContentID();
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   507
                                    // Old versions of AXIS2 put angle brackets around the content
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   508
                                    // id but not the start param
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   509
                                    contentIDNoAngle = (contentID != null) ?
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   510
                                        contentID.replaceFirst("^<", "").replaceFirst(">$", "") : null;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   511
                                }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   512
                                soapMessagePart = bp;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   513
                                bmMultipart.removeBodyPart(bp);
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   514
                            } catch (Exception e) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   515
                                throw new SOAPExceptionImpl(e);
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   516
                            }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   517
                        }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   518
                    }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   519
                }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   520
23782
953bfc3fbe31 8036030: Update JAX-WS RI integration to latest version
mkos
parents: 22679
diff changeset
   521
                // findbugs correctly points out that we'd NPE instantiating
953bfc3fbe31 8036030: Update JAX-WS RI integration to latest version
mkos
parents: 22679
diff changeset
   522
                // the ContentType (just below here) if soapMessagePart were
953bfc3fbe31 8036030: Update JAX-WS RI integration to latest version
mkos
parents: 22679
diff changeset
   523
                // null.  Hence are better off throwing a controlled exception
953bfc3fbe31 8036030: Update JAX-WS RI integration to latest version
mkos
parents: 22679
diff changeset
   524
                // at this point if it is null.
953bfc3fbe31 8036030: Update JAX-WS RI integration to latest version
mkos
parents: 22679
diff changeset
   525
                if (soapMessagePart == null) {
953bfc3fbe31 8036030: Update JAX-WS RI integration to latest version
mkos
parents: 22679
diff changeset
   526
                    log.severe("SAAJ0510.soap.cannot.create.envelope");
953bfc3fbe31 8036030: Update JAX-WS RI integration to latest version
mkos
parents: 22679
diff changeset
   527
                    throw new SOAPExceptionImpl(
953bfc3fbe31 8036030: Update JAX-WS RI integration to latest version
mkos
parents: 22679
diff changeset
   528
                        "Unable to create envelope from given source: SOAP part not found");
953bfc3fbe31 8036030: Update JAX-WS RI integration to latest version
mkos
parents: 22679
diff changeset
   529
                }
953bfc3fbe31 8036030: Update JAX-WS RI integration to latest version
mkos
parents: 22679
diff changeset
   530
953bfc3fbe31 8036030: Update JAX-WS RI integration to latest version
mkos
parents: 22679
diff changeset
   531
                if (soapPartInputStream == null) {
12009
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   532
                    soapPartInputStream = soapMessagePart.getInputStream();
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   533
                }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   534
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   535
                ContentType soapPartCType = new ContentType(
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   536
                                            soapMessagePart.getContentType());
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   537
                initCharsetProperty(soapPartCType);
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   538
                String baseType = soapPartCType.getBaseType().toLowerCase();
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   539
                if(!(isEqualToSoap1_1Type(baseType)
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   540
                  || isEqualToSoap1_2Type(baseType)
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   541
                  || isSOAPBodyXOPPackage(soapPartCType))) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   542
                    log.log(Level.SEVERE,
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   543
                            "SAAJ0549.soap.part.invalid.Content-Type",
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   544
                            new Object[] {baseType});
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   545
                    throw new SOAPExceptionImpl(
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   546
                            "Bad Content-Type for SOAP Part : " +
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   547
                            baseType);
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   548
                }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   549
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   550
                SOAPPart soapPart = getSOAPPart();
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   551
                setMimeHeaders(soapPart, soapMessagePart);
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   552
                soapPart.setContent(isFastInfoset ?
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   553
                     (Source) FastInfosetReflection.FastInfosetSource_new(
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   554
                         soapPartInputStream) :
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   555
                     (Source) new StreamSource(soapPartInputStream));
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   556
            } else {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   557
                log.severe("SAAJ0534.soap.unknown.Content-Type");
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   558
                throw new SOAPExceptionImpl("Unrecognized Content-Type");
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   559
            }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   560
        } catch (Throwable ex) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   561
            log.severe("SAAJ0535.soap.cannot.internalize.message");
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   562
            throw new SOAPExceptionImpl("Unable to internalize message", ex);
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   563
        }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   564
        needsSave();
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   565
    }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   566
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   567
    public boolean isFastInfoset() {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   568
        return isFastInfoset;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   569
    }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   570
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   571
    public boolean acceptFastInfoset() {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   572
        return acceptFastInfoset;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   573
    }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   574
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   575
    public void setIsFastInfoset(boolean value) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   576
        if (value != isFastInfoset) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   577
            isFastInfoset = value;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   578
            if (isFastInfoset) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   579
                acceptFastInfoset = true;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   580
            }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   581
            saved = false;      // ensure transcoding if necessary
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   582
        }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   583
    }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   584
23782
953bfc3fbe31 8036030: Update JAX-WS RI integration to latest version
mkos
parents: 22679
diff changeset
   585
    public boolean isLazySoapBodyParsing() {
953bfc3fbe31 8036030: Update JAX-WS RI integration to latest version
mkos
parents: 22679
diff changeset
   586
        Object lazyParsingProp = getProperty(LAZY_SOAP_BODY_PARSING);
953bfc3fbe31 8036030: Update JAX-WS RI integration to latest version
mkos
parents: 22679
diff changeset
   587
        if (lazyParsingProp == null) return false;
953bfc3fbe31 8036030: Update JAX-WS RI integration to latest version
mkos
parents: 22679
diff changeset
   588
        if (lazyParsingProp instanceof Boolean) {
953bfc3fbe31 8036030: Update JAX-WS RI integration to latest version
mkos
parents: 22679
diff changeset
   589
            return ((Boolean) lazyParsingProp).booleanValue();
953bfc3fbe31 8036030: Update JAX-WS RI integration to latest version
mkos
parents: 22679
diff changeset
   590
        } else {
953bfc3fbe31 8036030: Update JAX-WS RI integration to latest version
mkos
parents: 22679
diff changeset
   591
            return Boolean.valueOf(lazyParsingProp.toString());
953bfc3fbe31 8036030: Update JAX-WS RI integration to latest version
mkos
parents: 22679
diff changeset
   592
        }
953bfc3fbe31 8036030: Update JAX-WS RI integration to latest version
mkos
parents: 22679
diff changeset
   593
    }
12009
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   594
    public Object getProperty(String property) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   595
        return (String) properties.get(property);
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   596
    }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   597
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   598
    public void setProperty(String property, Object value) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   599
        verify(property, value);
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   600
        properties.put(property, value);
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   601
    }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   602
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   603
    private void verify(String property, Object value) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   604
        if (property.equalsIgnoreCase(SOAPMessage.WRITE_XML_DECLARATION)) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   605
            if (!("true".equals(value) || "false".equals(value)))
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   606
                throw new RuntimeException(
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   607
                    property + " must have value false or true");
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   608
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   609
            try {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   610
                EnvelopeImpl env = (EnvelopeImpl) getSOAPPart().getEnvelope();
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   611
                if ("true".equalsIgnoreCase((String)value)) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   612
                    env.setOmitXmlDecl("no");
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   613
                } else if ("false".equalsIgnoreCase((String)value)) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   614
                    env.setOmitXmlDecl("yes");
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   615
                }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   616
            } catch (Exception e) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   617
                log.log(Level.SEVERE, "SAAJ0591.soap.exception.in.set.property",
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   618
                    new Object[] {e.getMessage(), "javax.xml.soap.write-xml-declaration"});
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   619
                throw new RuntimeException(e);
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   620
            }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   621
            return;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   622
        }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   623
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   624
        if (property.equalsIgnoreCase(SOAPMessage.CHARACTER_SET_ENCODING)) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   625
            try {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   626
                ((EnvelopeImpl) getSOAPPart().getEnvelope()).setCharsetEncoding((String)value);
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   627
            } catch (Exception e) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   628
                log.log(Level.SEVERE, "SAAJ0591.soap.exception.in.set.property",
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   629
                    new Object[] {e.getMessage(), "javax.xml.soap.character-set-encoding"});
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   630
                throw new RuntimeException(e);
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   631
            }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   632
        }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   633
    }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   634
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   635
    protected abstract boolean isCorrectSoapVersion(int contentTypeId);
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   636
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   637
    protected abstract String getExpectedContentType();
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   638
    protected abstract String getExpectedAcceptHeader();
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   639
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   640
    /**
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   641
     * Sniffs the Content-Type header so that we can determine how to process.
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   642
     *
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   643
     * <p>
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   644
     * In the absence of type attribute we assume it to be text/xml.
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   645
     * That would mean we're easy on accepting the message and
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   646
     * generate the correct thing (as the SWA spec also specifies
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   647
     * that the type parameter should always be text/xml)
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   648
     *
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   649
     * @return
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   650
     *      combination of flags, such as PLAIN_XML_CODE and MIME_MULTIPART_CODE.
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   651
     */
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   652
    // SOAP1.2 allow SOAP1.2 content type
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   653
    static int identifyContentType(ContentType ct)
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   654
        throws SOAPExceptionImpl {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   655
        // TBD
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   656
        //    Is there anything else we need to verify here?
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   657
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   658
        String primary = ct.getPrimaryType().toLowerCase();
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   659
        String sub = ct.getSubType().toLowerCase();
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   660
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   661
        if (primary.equals("multipart")) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   662
            if (sub.equals("related")) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   663
                String type = getTypeParameter(ct);
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   664
                if (isEqualToSoap1_1Type(type)) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   665
                    return (type.equals("application/fastinfoset") ?
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   666
                           FI_ENCODED_FLAG : 0) | MIME_MULTIPART_FLAG | SOAP1_1_FLAG;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   667
                }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   668
                else if (isEqualToSoap1_2Type(type)) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   669
                    return (type.equals("application/soap+fastinfoset") ?
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   670
                           FI_ENCODED_FLAG : 0) | MIME_MULTIPART_FLAG | SOAP1_2_FLAG;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   671
                /*} else if (isMimeMultipartXOPPackage(ct)) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   672
                    return MIME_MULTIPART_XOP_FLAG;*/
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   673
                } else if (isMimeMultipartXOPSoap1_1Package(ct)) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   674
                    return MIME_MULTIPART_XOP_SOAP1_1_FLAG;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   675
                } else if (isMimeMultipartXOPSoap1_2Package(ct)) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   676
                    return MIME_MULTIPART_XOP_SOAP1_2_FLAG;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   677
                } else {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   678
                    log.severe("SAAJ0536.soap.content-type.mustbe.multipart");
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   679
                    throw new SOAPExceptionImpl(
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   680
                        "Content-Type needs to be Multipart/Related "
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   681
                            + "and with \"type=text/xml\" "
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   682
                            + "or \"type=application/soap+xml\"");
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   683
                }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   684
            } else {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   685
                log.severe("SAAJ0537.soap.invalid.content-type");
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   686
                throw new SOAPExceptionImpl(
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   687
                    "Invalid Content-Type: " + primary + '/' + sub);
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   688
            }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   689
        }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   690
        else if (isSoap1_1Type(primary, sub)) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   691
            return (primary.equalsIgnoreCase("application")
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   692
                    && sub.equalsIgnoreCase("fastinfoset") ?
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   693
                        FI_ENCODED_FLAG : 0)
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   694
                   | PLAIN_XML_FLAG | SOAP1_1_FLAG;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   695
        }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   696
        else if (isSoap1_2Type(primary, sub)) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   697
            return (primary.equalsIgnoreCase("application")
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   698
                    && sub.equalsIgnoreCase("soap+fastinfoset") ?
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   699
                        FI_ENCODED_FLAG : 0)
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   700
                   | PLAIN_XML_FLAG | SOAP1_2_FLAG;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   701
        } else if(isSOAPBodyXOPPackage(ct)){
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   702
            return XOP_FLAG;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   703
        } else {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   704
            log.severe("SAAJ0537.soap.invalid.content-type");
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   705
            throw new SOAPExceptionImpl(
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   706
                "Invalid Content-Type:"
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   707
                    + primary
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   708
                    + '/'
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   709
                    + sub
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   710
                    + ". Is this an error message instead of a SOAP response?");
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   711
        }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   712
    }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   713
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   714
    /**
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   715
     * Obtains the type parameter of the Content-Type header. Defaults to "text/xml".
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   716
     */
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   717
    private static String getTypeParameter(ContentType contentType) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   718
        String p = contentType.getParameter("type");
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   719
        if(p!=null)
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   720
            return p.toLowerCase();
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   721
        else
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   722
            return "text/xml";
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   723
    }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   724
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   725
    public MimeHeaders getMimeHeaders() {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   726
        return this.headers;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   727
    }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   728
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   729
    final static String getContentType(MimeHeaders headers) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   730
        String[] values = headers.getHeader("Content-Type");
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   731
        if (values == null)
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   732
            return null;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   733
        else
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   734
            return values[0];
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   735
    }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   736
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   737
    /*
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   738
     * Get the complete ContentType value along with optional parameters.
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   739
     */
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   740
    public String getContentType() {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   741
        return getContentType(this.headers);
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   742
    }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   743
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   744
    public void setContentType(String type) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   745
        headers.setHeader("Content-Type", type);
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   746
        needsSave();
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   747
    }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   748
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   749
    private ContentType contentType() {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   750
        ContentType ct = null;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   751
        try {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   752
            String currentContent = getContentType();
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   753
            if (currentContent == null) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   754
                return this.contentType;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   755
            }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   756
            ct = new ContentType(currentContent);
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   757
        } catch (Exception e) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   758
            // what to do here?
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   759
        }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   760
        return ct;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   761
    }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   762
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   763
    /*
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   764
     * Return the MIME type string, without the parameters.
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   765
     */
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   766
    public String getBaseType() {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   767
        return contentType().getBaseType();
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   768
    }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   769
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   770
    public void setBaseType(String type) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   771
        ContentType ct = contentType();
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   772
        ct.setParameter("type", type);
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   773
        headers.setHeader("Content-Type", ct.toString());
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   774
        needsSave();
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   775
    }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   776
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   777
    public String getAction() {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   778
        return contentType().getParameter("action");
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   779
    }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   780
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   781
    public void setAction(String action) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   782
        ContentType ct = contentType();
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   783
        ct.setParameter("action", action);
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   784
        headers.setHeader("Content-Type", ct.toString());
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   785
        needsSave();
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   786
    }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   787
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   788
    public String getCharset() {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   789
        return contentType().getParameter("charset");
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   790
    }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   791
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   792
    public void setCharset(String charset) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   793
        ContentType ct = contentType();
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   794
        ct.setParameter("charset", charset);
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   795
        headers.setHeader("Content-Type", ct.toString());
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   796
        needsSave();
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   797
    }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   798
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   799
    /**
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   800
     * All write methods (i.e setters) should call this method in
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   801
     * order to make sure that a save is necessary since the state
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   802
     * has been modified.
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   803
     */
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   804
    private final void needsSave() {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   805
        saved = false;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   806
    }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   807
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   808
    public  boolean saveRequired() {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   809
        return saved != true;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   810
    }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   811
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   812
    public String getContentDescription() {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   813
        String[] values = headers.getHeader("Content-Description");
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   814
        if (values != null && values.length > 0)
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   815
            return values[0];
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   816
        return null;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   817
    }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   818
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   819
    public void setContentDescription(String description) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   820
        headers.setHeader("Content-Description", description);
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   821
        needsSave();
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   822
    }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   823
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   824
    public abstract SOAPPart getSOAPPart();
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   825
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   826
    public void removeAllAttachments() {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   827
        try {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   828
            initializeAllAttachments();
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   829
        } catch (Exception e) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   830
            throw new RuntimeException(e);
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   831
        }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   832
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   833
        if (attachments != null) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   834
            attachments.clear();
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   835
            needsSave();
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   836
        }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   837
    }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   838
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   839
    public int countAttachments() {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   840
        try {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   841
            initializeAllAttachments();
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   842
        } catch (Exception e) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   843
            throw new RuntimeException(e);
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   844
        }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   845
        if (attachments != null)
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   846
            return attachments.size();
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   847
        return 0;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   848
    }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   849
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   850
    public void addAttachmentPart(AttachmentPart attachment) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   851
        try {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   852
            initializeAllAttachments();
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   853
            this.optimizeAttachmentProcessing = true;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   854
        } catch (Exception e) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   855
            throw new RuntimeException(e);
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   856
        }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   857
        if (attachments == null)
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   858
            attachments = new FinalArrayList();
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   859
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   860
        attachments.add(attachment);
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   861
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   862
        needsSave();
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   863
    }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   864
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   865
    static private final Iterator nullIter = Collections.EMPTY_LIST.iterator();
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   866
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   867
    public Iterator getAttachments() {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   868
        try {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   869
            initializeAllAttachments();
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   870
        } catch (Exception e) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   871
            throw new RuntimeException(e);
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   872
        }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   873
        if (attachments == null)
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   874
            return nullIter;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   875
        return attachments.iterator();
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   876
    }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   877
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   878
    private void setFinalContentType(String charset) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   879
        ContentType ct = contentType();
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   880
        if (ct == null) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   881
            ct = new ContentType();
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   882
        }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   883
        String[] split = getExpectedContentType().split("/");
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   884
        ct.setPrimaryType(split[0]);
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   885
        ct.setSubType(split[1]);
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   886
        ct.setParameter("charset", charset);
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   887
        headers.setHeader("Content-Type", ct.toString());
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   888
    }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   889
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   890
    private class MimeMatchingIterator implements Iterator {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   891
        public MimeMatchingIterator(MimeHeaders headers) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   892
            this.headers = headers;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   893
            this.iter = attachments.iterator();
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   894
        }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   895
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   896
        private Iterator iter;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   897
        private MimeHeaders headers;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   898
        private Object nextAttachment;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   899
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   900
        public boolean hasNext() {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   901
            if (nextAttachment == null)
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   902
                nextAttachment = nextMatch();
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   903
            return nextAttachment != null;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   904
        }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   905
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   906
        public Object next() {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   907
            if (nextAttachment != null) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   908
                Object ret = nextAttachment;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   909
                nextAttachment = null;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   910
                return ret;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   911
            }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   912
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   913
            if (hasNext())
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   914
                return nextAttachment;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   915
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   916
            return null;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   917
        }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   918
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   919
        Object nextMatch() {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   920
            while (iter.hasNext()) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   921
                AttachmentPartImpl ap = (AttachmentPartImpl) iter.next();
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   922
                if (ap.hasAllHeaders(headers))
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   923
                    return ap;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   924
            }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   925
            return null;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   926
        }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   927
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   928
        public void remove() {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   929
            iter.remove();
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   930
        }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   931
    }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   932
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   933
    public Iterator getAttachments(MimeHeaders headers) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   934
        try {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   935
            initializeAllAttachments();
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   936
        } catch (Exception e) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   937
            throw new RuntimeException(e);
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   938
        }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   939
        if (attachments == null)
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   940
            return nullIter;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   941
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   942
        return new MimeMatchingIterator(headers);
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   943
    }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   944
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   945
    public void removeAttachments(MimeHeaders headers) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   946
        try {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   947
            initializeAllAttachments();
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   948
        } catch (Exception e) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   949
            throw new RuntimeException(e);
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   950
        }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   951
        if (attachments == null)
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   952
            return ;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   953
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   954
        Iterator it =  new MimeMatchingIterator(headers);
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   955
        while (it.hasNext()) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   956
            int index = attachments.indexOf(it.next());
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   957
            attachments.set(index, null);
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   958
        }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   959
        FinalArrayList f = new FinalArrayList();
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   960
        for (int i = 0; i < attachments.size(); i++) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   961
            if (attachments.get(i) != null) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   962
                f.add(attachments.get(i));
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   963
            }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   964
        }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   965
        attachments = f;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   966
       // needsSave();
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   967
    }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   968
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   969
    public AttachmentPart createAttachmentPart() {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   970
        return new AttachmentPartImpl();
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   971
    }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   972
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   973
    public  AttachmentPart getAttachment(SOAPElement element)
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   974
        throws SOAPException {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   975
        try {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   976
            initializeAllAttachments();
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   977
        } catch (Exception e) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   978
            throw new RuntimeException(e);
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   979
        }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   980
        String uri;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   981
        String hrefAttr = element.getAttribute("href");
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   982
        if ("".equals(hrefAttr)) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   983
            Node node = getValueNodeStrict(element);
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   984
            String swaRef = null;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   985
            if (node != null) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   986
                swaRef = node.getValue();
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   987
            }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   988
            if (swaRef == null || "".equals(swaRef)) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   989
                return null;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   990
            } else {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   991
                uri = swaRef;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   992
            }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   993
        } else {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   994
            uri = hrefAttr;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   995
        }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   996
        return getAttachmentPart(uri);
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   997
    }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   998
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   999
    private Node getValueNodeStrict(SOAPElement element) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1000
        Node node = (Node)element.getFirstChild();
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1001
        if (node != null) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1002
            if (node.getNextSibling() == null
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1003
                && node.getNodeType() == org.w3c.dom.Node.TEXT_NODE) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1004
                return node;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1005
            } else {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1006
                return null;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1007
            }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1008
        }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1009
        return null;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1010
    }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1011
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1012
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1013
    private AttachmentPart getAttachmentPart(String uri) throws SOAPException {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1014
        AttachmentPart _part;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1015
        try {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1016
            if (uri.startsWith("cid:")) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1017
                // rfc2392
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1018
                uri = '<'+uri.substring("cid:".length())+'>';
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1019
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1020
                MimeHeaders headersToMatch = new MimeHeaders();
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1021
                headersToMatch.addHeader(CONTENT_ID, uri);
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1022
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1023
                Iterator i = this.getAttachments(headersToMatch);
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1024
                _part = (i == null) ? null : (AttachmentPart)i.next();
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1025
            } else {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1026
                // try content-location
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1027
                MimeHeaders headersToMatch = new MimeHeaders();
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1028
                headersToMatch.addHeader(CONTENT_LOCATION, uri);
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1029
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1030
                Iterator i = this.getAttachments(headersToMatch);
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1031
                _part = (i == null) ? null : (AttachmentPart)i.next();
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1032
            }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1033
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1034
            // try  auto-generated JAXRPC CID
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1035
            if (_part == null) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1036
                Iterator j = this.getAttachments();
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1037
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1038
                while (j.hasNext()) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1039
                    AttachmentPart p = (AttachmentPart)j.next();
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1040
                    String cl = p.getContentId();
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1041
                    if (cl != null) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1042
                        // obtain the partname
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1043
                        int eqIndex = cl.indexOf("=");
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1044
                        if (eqIndex > -1) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1045
                            cl = cl.substring(1, eqIndex);
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1046
                            if (cl.equalsIgnoreCase(uri)) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1047
                                _part = p;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1048
                                 break;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1049
                            }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1050
                        }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1051
                    }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1052
                }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1053
            }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1054
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1055
        } catch (Exception se) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1056
            log.log(Level.SEVERE, "SAAJ0590.soap.unable.to.locate.attachment", new Object[] {uri});
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1057
            throw new SOAPExceptionImpl(se);
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1058
        }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1059
        return _part;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1060
    }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1061
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1062
    private final InputStream getHeaderBytes()
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1063
        throws IOException {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1064
        SOAPPartImpl sp = (SOAPPartImpl) getSOAPPart();
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1065
        return sp.getContentAsStream();
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1066
    }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1067
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1068
    private String convertToSingleLine(String contentType) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1069
        StringBuffer buffer = new StringBuffer();
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1070
        for (int i = 0; i < contentType.length(); i ++) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1071
            char c = contentType.charAt(i);
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1072
            if (c != '\r' && c != '\n' && c != '\t')
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1073
                buffer.append(c);
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1074
        }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1075
        return buffer.toString();
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1076
    }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1077
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1078
    private MimeMultipart getMimeMessage() throws SOAPException {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1079
        try {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1080
            SOAPPartImpl soapPart = (SOAPPartImpl) getSOAPPart();
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1081
            MimeBodyPart mimeSoapPart = soapPart.getMimePart();
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1082
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1083
            /*
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1084
             * Get content type from this message instead of soapPart
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1085
             * to ensure agreement if soapPart is transcoded (XML <-> FI)
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1086
             */
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1087
            ContentType soapPartCtype = new ContentType(getExpectedContentType());
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1088
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1089
            if (!isFastInfoset) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1090
                soapPartCtype.setParameter("charset", initCharset());
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1091
            }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1092
            mimeSoapPart.setHeader("Content-Type", soapPartCtype.toString());
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1093
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1094
            MimeMultipart headerAndBody = null;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1095
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1096
            if (!switchOffBM && !switchOffLazyAttachment &&
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1097
                   (multiPart != null) && !attachmentsInitialized) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1098
                headerAndBody = new BMMimeMultipart();
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1099
                headerAndBody.addBodyPart(mimeSoapPart);
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1100
                if (attachments != null) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1101
                    for (Iterator eachAttachment = attachments.iterator();
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1102
                         eachAttachment.hasNext();) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1103
                        headerAndBody.addBodyPart(
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1104
                            ((AttachmentPartImpl) eachAttachment.next())
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1105
                                .getMimePart());
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1106
                    }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1107
                }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1108
                InputStream in = ((BMMimeMultipart)multiPart).getInputStream();
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1109
                if (!((BMMimeMultipart)multiPart).lastBodyPartFound() &&
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1110
                    !((BMMimeMultipart)multiPart).isEndOfStream()) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1111
                    ((BMMimeMultipart)headerAndBody).setInputStream(in);
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1112
                    ((BMMimeMultipart)headerAndBody).setBoundary(
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1113
                        ((BMMimeMultipart)multiPart).getBoundary());
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1114
                    ((BMMimeMultipart)headerAndBody).
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1115
                        setLazyAttachments(lazyAttachments);
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1116
                }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1117
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1118
            } else {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1119
                headerAndBody = new MimeMultipart();
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1120
                headerAndBody.addBodyPart(mimeSoapPart);
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1121
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1122
                for (Iterator eachAttachement = getAttachments();
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1123
                    eachAttachement.hasNext();
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1124
                    ) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1125
                    headerAndBody.addBodyPart(
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1126
                        ((AttachmentPartImpl) eachAttachement.next())
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1127
                            .getMimePart());
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1128
                }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1129
            }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1130
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1131
            ContentType contentType = headerAndBody.getContentType();
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1132
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1133
            ParameterList l = contentType.getParameterList();
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1134
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1135
            // set content type depending on SOAP version
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1136
            l.set("type", getExpectedContentType());
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1137
            l.set("boundary", contentType.getParameter("boundary"));
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1138
            ContentType nct = new ContentType("multipart", "related", l);
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1139
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1140
            headers.setHeader(
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1141
                "Content-Type",
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1142
                convertToSingleLine(nct.toString()));
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1143
          // TBD
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1144
          //    Set content length MIME header here.
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1145
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1146
            return headerAndBody;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1147
        } catch (SOAPException ex) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1148
            throw ex;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1149
        } catch (Throwable ex) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1150
            log.severe("SAAJ0538.soap.cannot.convert.msg.to.multipart.obj");
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1151
            throw new SOAPExceptionImpl(
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1152
                "Unable to convert SOAP message into "
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1153
                    + "a MimeMultipart object",
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1154
                ex);
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1155
        }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1156
    }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1157
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1158
    private String initCharset() {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1159
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1160
        String charset = null;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1161
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1162
        String[] cts = getMimeHeaders().getHeader("Content-Type");
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1163
        if ((cts != null) && (cts[0] != null)) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1164
            charset = getCharsetString(cts[0]);
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1165
        }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1166
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1167
        if (charset == null) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1168
            charset = (String) getProperty(CHARACTER_SET_ENCODING);
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1169
        }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1170
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1171
        if (charset != null) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1172
            return charset;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1173
        }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1174
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1175
        return "utf-8";
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1176
    }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1177
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1178
    private String getCharsetString(String s) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1179
        try {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1180
            int index = s.indexOf(";");
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1181
            if(index < 0)
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1182
                return null;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1183
            ParameterList pl = new ParameterList(s.substring(index));
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1184
            return pl.get("charset");
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1185
        } catch(Exception e) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1186
            return null;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1187
        }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1188
    }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1189
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1190
    public void saveChanges() throws SOAPException {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1191
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1192
        // suck in all the data from the attachments and have it
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1193
        // ready for writing/sending etc.
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1194
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1195
        String charset = initCharset();
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1196
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1197
        /*if (countAttachments() == 0) {*/
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1198
        int attachmentCount = (attachments == null) ? 0 : attachments.size();
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1199
        if (attachmentCount == 0) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1200
            if (!switchOffBM && !switchOffLazyAttachment &&
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1201
                !attachmentsInitialized && (multiPart != null)) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1202
                // so there might be attachments
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1203
                attachmentCount = 1;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1204
            }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1205
        }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1206
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1207
        try {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1208
            if ((attachmentCount == 0) && !hasXOPContent()) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1209
                InputStream in;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1210
                try{
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1211
                /*
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1212
                 * Not sure why this is called getHeaderBytes(), but it actually
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1213
                 * returns the whole message as a byte stream. This stream could
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1214
                 * be either XML of Fast depending on the mode.
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1215
                 */
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1216
                    in = getHeaderBytes();
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1217
                    // no attachments, hence this property can be false
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1218
                    this.optimizeAttachmentProcessing = false;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1219
                    if (SOAPPartImpl.lazyContentLength) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1220
                        inputStreamAfterSaveChanges = in;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1221
                    }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1222
                } catch (IOException ex) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1223
                    log.severe("SAAJ0539.soap.cannot.get.header.stream");
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1224
                    throw new SOAPExceptionImpl(
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1225
                            "Unable to get header stream in saveChanges: ",
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1226
                            ex);
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1227
                }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1228
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1229
                if (in instanceof ByteInputStream) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1230
                    ByteInputStream bIn = (ByteInputStream)in;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1231
                    messageBytes = bIn.getBytes();
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1232
                    messageByteCount = bIn.getCount();
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1233
                }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1234
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1235
                setFinalContentType(charset);
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1236
                /*
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1237
                headers.setHeader(
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1238
                        "Content-Type",
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1239
                        getExpectedContentType() +
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1240
                        (isFastInfoset ? "" : "; charset=" + charset));*/
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1241
                if (messageByteCount > 0) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1242
                    headers.setHeader(
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1243
                            "Content-Length",
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1244
                            Integer.toString(messageByteCount));
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1245
                }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1246
            } else {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1247
                if(hasXOPContent())
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1248
                    mmp = getXOPMessage();
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1249
                else
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1250
                    mmp = getMimeMessage();
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1251
            }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1252
        } catch (Throwable ex) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1253
            log.severe("SAAJ0540.soap.err.saving.multipart.msg");
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1254
            throw new SOAPExceptionImpl(
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1255
                    "Error during saving a multipart message",
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1256
                    ex);
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1257
        }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1258
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1259
        // FIX ME -- SOAP Action replaced by Content-Type optional parameter action
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1260
        /*
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1261
        if(isCorrectSoapVersion(SOAP1_1_FLAG)) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1262
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1263
            String[] soapAction = headers.getHeader("SOAPAction");
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1264
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1265
            if (soapAction == null || soapAction.length == 0)
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1266
                headers.setHeader("SOAPAction", "\"\"");
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1267
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1268
        }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1269
        */
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1270
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1271
        saved = true;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1272
    }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1273
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1274
    private MimeMultipart getXOPMessage() throws SOAPException {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1275
        try {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1276
            MimeMultipart headerAndBody = new MimeMultipart();
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1277
            SOAPPartImpl soapPart =  (SOAPPartImpl)getSOAPPart();
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1278
            MimeBodyPart mimeSoapPart = soapPart.getMimePart();
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1279
            ContentType soapPartCtype =
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1280
                new ContentType("application/xop+xml");
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1281
            soapPartCtype.setParameter("type", getExpectedContentType());
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1282
            String charset = initCharset();
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1283
            soapPartCtype.setParameter("charset", charset);
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1284
            mimeSoapPart.setHeader("Content-Type", soapPartCtype.toString());
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1285
            headerAndBody.addBodyPart(mimeSoapPart);
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1286
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1287
            for (Iterator eachAttachement = getAttachments();
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1288
                eachAttachement.hasNext();
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1289
                ) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1290
                headerAndBody.addBodyPart(
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1291
                    ((AttachmentPartImpl) eachAttachement.next())
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1292
                        .getMimePart());
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1293
            }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1294
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1295
            ContentType contentType = headerAndBody.getContentType();
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1296
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1297
            ParameterList l = contentType.getParameterList();
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1298
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1299
            //lets not write start-info for now till we get servlet fix done
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1300
            l.set("start-info", getExpectedContentType());//+";charset="+initCharset());
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1301
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1302
            // set content type depending on SOAP version
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1303
            l.set("type", "application/xop+xml");
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1304
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1305
            if (isCorrectSoapVersion(SOAP1_2_FLAG)) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1306
                 String action = getAction();
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1307
                 if(action != null)
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1308
                     l.set("action", action);
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1309
            }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1310
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1311
            l.set("boundary", contentType.getParameter("boundary"));
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1312
            ContentType nct = new ContentType("Multipart", "Related", l);
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1313
            headers.setHeader(
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1314
                "Content-Type",
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1315
                convertToSingleLine(nct.toString()));
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1316
            // TBD
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1317
            //    Set content length MIME header here.
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1318
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1319
            return headerAndBody;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1320
        } catch (SOAPException ex) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1321
            throw ex;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1322
        } catch (Throwable ex) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1323
            log.severe("SAAJ0538.soap.cannot.convert.msg.to.multipart.obj");
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1324
            throw new SOAPExceptionImpl(
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1325
                "Unable to convert SOAP message into "
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1326
                    + "a MimeMultipart object",
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1327
                ex);
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1328
        }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1329
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1330
    }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1331
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1332
    private boolean hasXOPContent() throws ParseException {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1333
        String type = getContentType();
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1334
        if(type == null)
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1335
            return false;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1336
        ContentType ct = new ContentType(type);
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1337
        //return isMimeMultipartXOPPackage(ct) || isSOAPBodyXOPPackage(ct);
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1338
        return isMimeMultipartXOPSoap1_1Package(ct) ||
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1339
            isMimeMultipartXOPSoap1_2Package(ct) || isSOAPBodyXOPPackage(ct);
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1340
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1341
    }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1342
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1343
    public void writeTo(OutputStream out) throws SOAPException, IOException {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1344
        if (saveRequired()){
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1345
            this.optimizeAttachmentProcessing = true;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1346
            saveChanges();
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1347
        }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1348
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1349
        if(!optimizeAttachmentProcessing){
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1350
            if (SOAPPartImpl.lazyContentLength && messageByteCount <= 0) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1351
                byte[] buf = new byte[1024];
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1352
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1353
                int length = 0;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1354
                while( (length = inputStreamAfterSaveChanges.read(buf)) != -1) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1355
                    out.write(buf,0, length);
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1356
                    messageByteCount += length;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1357
                }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1358
                if (messageByteCount > 0) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1359
                    headers.setHeader(
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1360
                            "Content-Length",
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1361
                            Integer.toString(messageByteCount));
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1362
                }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1363
            } else {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1364
                out.write(messageBytes, 0, messageByteCount);
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1365
            }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1366
        }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1367
        else{
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1368
            try{
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1369
                if(hasXOPContent()){
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1370
                    mmp.writeTo(out);
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1371
                }else{
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1372
                    mmp.writeTo(out);
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1373
                    if (!switchOffBM && !switchOffLazyAttachment &&
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1374
                            (multiPart != null) && !attachmentsInitialized) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1375
                        ((BMMimeMultipart)multiPart).setInputStream(
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1376
                                ((BMMimeMultipart)mmp).getInputStream());
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1377
                    }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1378
                }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1379
            } catch(Exception ex){
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1380
                log.severe("SAAJ0540.soap.err.saving.multipart.msg");
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1381
                throw new SOAPExceptionImpl(
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1382
                        "Error during saving a multipart message",
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1383
                        ex);
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1384
            }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1385
        }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1386
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1387
        if(isCorrectSoapVersion(SOAP1_1_FLAG)) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1388
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1389
            String[] soapAction = headers.getHeader("SOAPAction");
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1390
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1391
            if (soapAction == null || soapAction.length == 0)
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1392
                headers.setHeader("SOAPAction", "\"\"");
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1393
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1394
        }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1395
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1396
        messageBytes = null;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1397
        needsSave();
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1398
    }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1399
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1400
    public SOAPBody getSOAPBody() throws SOAPException {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1401
        SOAPBody body = getSOAPPart().getEnvelope().getBody();
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1402
        /*if (body == null) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1403
             throw new SOAPException("No SOAP Body was found in the SOAP Message");
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1404
        }*/
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1405
        return body;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1406
    }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1407
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1408
    public SOAPHeader getSOAPHeader() throws SOAPException {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1409
        SOAPHeader hdr = getSOAPPart().getEnvelope().getHeader();
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1410
        /*if (hdr == null) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1411
            throw new SOAPException("No SOAP Header was found in the SOAP Message");
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1412
        }*/
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1413
        return hdr;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1414
    }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1415
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1416
    private void initializeAllAttachments ()
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1417
        throws MessagingException, SOAPException {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1418
        if (switchOffBM || switchOffLazyAttachment) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1419
            return;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1420
        }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1421
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1422
        if (attachmentsInitialized || (multiPart == null)) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1423
            return;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1424
        }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1425
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1426
        if (attachments == null)
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1427
            attachments = new FinalArrayList();
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1428
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1429
        int count = multiPart.getCount();
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1430
        for (int i=0; i < count; i++ ) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1431
            initializeAttachment(multiPart.getBodyPart(i));
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1432
        }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1433
        attachmentsInitialized = true;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1434
        //multiPart = null;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1435
        needsSave();
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1436
     }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1437
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1438
    private void initializeAttachment(MimeBodyPart mbp) throws SOAPException {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1439
        AttachmentPartImpl attachmentPart = new AttachmentPartImpl();
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1440
        DataHandler attachmentHandler = mbp.getDataHandler();
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1441
        attachmentPart.setDataHandler(attachmentHandler);
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1442
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1443
        AttachmentPartImpl.copyMimeHeaders(mbp, attachmentPart);
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1444
        attachments.add(attachmentPart);
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1445
    }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1446
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1447
    private void initializeAttachment(MimeMultipart multiPart, int i)
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1448
        throws Exception {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1449
        MimeBodyPart currentBodyPart = multiPart.getBodyPart(i);
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1450
        AttachmentPartImpl attachmentPart = new AttachmentPartImpl();
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1451
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1452
        DataHandler attachmentHandler = currentBodyPart.getDataHandler();
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1453
        attachmentPart.setDataHandler(attachmentHandler);
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1454
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1455
        AttachmentPartImpl.copyMimeHeaders(currentBodyPart, attachmentPart);
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1456
        addAttachmentPart(attachmentPart);
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1457
    }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1458
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1459
    private void setMimeHeaders(SOAPPart soapPart,
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1460
            MimeBodyPart soapMessagePart) throws Exception {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1461
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1462
        // first remove the existing content-type
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1463
        soapPart.removeAllMimeHeaders();
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1464
        // add everything present in soapMessagePart
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1465
        List headers = soapMessagePart.getAllHeaders();
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1466
        int sz = headers.size();
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1467
        for( int i=0; i<sz; i++ ) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1468
            Header h = (Header) headers.get(i);
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1469
            soapPart.addMimeHeader(h.getName(), h.getValue());
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1470
        }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1471
    }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1472
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1473
    private void initCharsetProperty(ContentType contentType) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1474
        String charset = contentType.getParameter("charset");
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1475
        if (charset != null) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1476
            ((SOAPPartImpl) getSOAPPart()).setSourceCharsetEncoding(charset);
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1477
            if(!charset.equalsIgnoreCase("utf-8"))
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1478
                setProperty(CHARACTER_SET_ENCODING, charset);
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1479
        }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1480
    }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1481
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1482
    public void setLazyAttachments(boolean flag) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1483
        lazyAttachments = flag;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1484
    }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1485
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
  1486
}