Skip to content

Package: SOAPPartImpl

SOAPPartImpl

nameinstructionbranchcomplexitylinemethod
SOAPPartImpl()
M: 0 C: 4
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
SOAPPartImpl(MessageImpl)
M: 0 C: 32
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 9
100%
M: 0 C: 1
100%
addMimeHeader(String, String)
M: 0 C: 6
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
adoptNode(Node)
M: 7 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
appendChild(Node)
M: 0 C: 7
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
cloneNode(boolean)
M: 0 C: 5
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
compareDocumentPosition(Node)
M: 5 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
createAttribute(String)
M: 5 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
createAttributeNS(String, String)
M: 6 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
createCDATASection(String)
M: 5 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
createComment(String)
M: 0 C: 5
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
createDocumentFragment()
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
createElement(String)
M: 5 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
createElementNS(String, String)
M: 0 C: 6
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
createEntityReference(String)
M: 5 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
createProcessingInstruction(String, String)
M: 6 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
createTextNode(String)
M: 0 C: 5
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
detachNode()
M: 1 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
doCloneNode()
M: 0 C: 28
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 6
100%
M: 0 C: 1
100%
doGetDocumentElement()
M: 1 C: 6
86%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 1 C: 4
80%
M: 0 C: 1
100%
getAllMimeHeaders()
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getAttributes()
M: 5 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getBaseURI()
M: 5 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getChildNodes()
M: 0 C: 6
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
getContent()
M: 13 C: 30
70%
M: 4 C: 4
50%
M: 3 C: 2
40%
M: 3 C: 11
79%
M: 0 C: 1
100%
getContentAsStream()
M: 35 C: 51
59%
M: 6 C: 10
63%
M: 5 C: 4
44%
M: 11 C: 15
58%
M: 0 C: 1
100%
getContentTypeString()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getDataHandler()
M: 0 C: 10
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
getDoctype()
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getDocument()
M: 0 C: 5
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
getDocumentElement()
M: 1 C: 8
89%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 1 C: 3
75%
M: 0 C: 1
100%
getDocumentURI()
M: 5 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getDomConfig()
M: 5 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getElementById(String)
M: 7 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
getElementsByTagName(String)
M: 7 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
getElementsByTagNameNS(String, String)
M: 0 C: 8
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
getEnvelope()
M: 0 C: 50
100%
M: 0 C: 8
100%
M: 0 C: 5
100%
M: 0 C: 12
100%
M: 0 C: 1
100%
getFeature(String, String)
M: 6 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getFirstChild()
M: 0 C: 6
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
getImplementation()
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getInputEncoding()
M: 5 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getLastChild()
M: 6 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
getLocalName()
M: 5 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getMatchingMimeHeaders(String[])
M: 5 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getMimeHeader(String)
M: 0 C: 5
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
getMimeHeaders()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getMimePart()
M: 13 C: 14
52%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 5 C: 4
44%
M: 0 C: 1
100%
getNamespaceURI()
M: 5 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getNextSibling()
M: 6 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
getNodeName()
M: 5 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getNodeType()
M: 5 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getNodeValue()
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getNonMatchingMimeHeaders(String[])
M: 5 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getOwnerDocument()
M: 0 C: 3
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
getParentElement()
M: 2 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getParentNode()
M: 5 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getPrefix()
M: 5 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getPreviousSibling()
M: 5 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getSOAPPart()
M: 2 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getSourceCharsetEncoding()
M: 0 C: 3
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
getStrictErrorChecking()
M: 5 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getTextContent()
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getUserData(String)
M: 6 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getValue()
M: 2 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getXmlEncoding()
M: 5 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getXmlStandalone()
M: 5 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getXmlVersion()
M: 5 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
handleNewSource()
M: 1 C: 8
89%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 1 C: 4
80%
M: 0 C: 1
100%
hasAttributes()
M: 5 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
hasChildNodes()
M: 6 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
importNode(Node, boolean)
M: 0 C: 8
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
insertBefore(Node, Node)
M: 0 C: 8
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
isDefaultNamespace(String)
M: 5 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
isEqualNode(Node)
M: 6 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
isFastInfoset()
M: 0 C: 9
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
isSameNode(Node)
M: 5 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
isSupported(String, String)
M: 7 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
lookForEnvelope()
M: 20 C: 61
75%
M: 5 C: 9
64%
M: 5 C: 3
38%
M: 5 C: 13
72%
M: 0 C: 1
100%
lookForXmlDecl()
M: 32 C: 84
72%
M: 5 C: 15
75%
M: 5 C: 6
55%
M: 8 C: 23
74%
M: 0 C: 1
100%
lookupNamespaceURI(String)
M: 5 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
lookupPrefix(String)
M: 6 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
normalize()
M: 6 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
normalizeDocument()
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
recycleNode()
M: 1 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
removeAllMimeHeaders()
M: 0 C: 4
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
removeChild(Node)
M: 7 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
removeMimeHeader(String)
M: 5 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
renameNode(Node, String, String)
M: 9 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
replaceChild(Node, Node)
M: 8 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
setContent(Source)
M: 48 C: 41
46%
M: 6 C: 6
50%
M: 4 C: 3
43%
M: 18 C: 13
42%
M: 0 C: 1
100%
setDocumentURI(String)
M: 5 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
setMimeHeader(String, String)
M: 0 C: 6
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
setNodeValue(String)
M: 5 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
setParentElement(SOAPElement)
M: 8 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
setPrefix(String)
M: 5 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
setSourceCharsetEncoding(String)
M: 0 C: 4
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
setStrictErrorChecking(boolean)
M: 5 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
setTextContent(String)
M: 5 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
setUserData(String, Object, UserDataHandler)
M: 7 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
setValue(String)
M: 8 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
setXmlStandalone(boolean)
M: 5 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
setXmlVersion(String)
M: 0 C: 5
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
static {...}
M: 0 C: 8
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 4
100%
M: 0 C: 1
100%

Coverage

1: /*
2: * Copyright (c) 1997, 2021 Oracle and/or its affiliates. All rights reserved.
3: *
4: * This program and the accompanying materials are made available under the
5: * terms of the Eclipse Distribution License v. 1.0, which is available at
6: * http://www.eclipse.org/org/documents/edl-v10.php.
7: *
8: * SPDX-License-Identifier: BSD-3-Clause
9: */
10:
11: package com.sun.xml.messaging.saaj.soap;
12:
13: import com.sun.xml.messaging.saaj.SOAPExceptionImpl;
14: import com.sun.xml.messaging.saaj.packaging.mime.internet.MimeBodyPart;
15: import com.sun.xml.messaging.saaj.soap.impl.ElementImpl;
16: import com.sun.xml.messaging.saaj.soap.impl.EnvelopeImpl;
17: import com.sun.xml.messaging.saaj.soap.name.NameImpl;
18: import com.sun.xml.messaging.saaj.util.ByteInputStream;
19: import com.sun.xml.messaging.saaj.util.ByteOutputStream;
20: import com.sun.xml.messaging.saaj.util.FastInfosetReflection;
21: import com.sun.xml.messaging.saaj.util.JAXMStreamSource;
22: import com.sun.xml.messaging.saaj.util.LogDomainConstants;
23: import com.sun.xml.messaging.saaj.util.MimeHeadersUtil;
24: import com.sun.xml.messaging.saaj.util.SAAJUtil;
25: import com.sun.xml.messaging.saaj.util.XMLDeclarationParser;
26: import org.w3c.dom.Attr;
27: import org.w3c.dom.CDATASection;
28: import org.w3c.dom.Comment;
29: import org.w3c.dom.DOMConfiguration;
30: import org.w3c.dom.DOMException;
31: import org.w3c.dom.DOMImplementation;
32: import org.w3c.dom.Document;
33: import org.w3c.dom.DocumentFragment;
34: import org.w3c.dom.DocumentType;
35: import org.w3c.dom.Element;
36: import org.w3c.dom.EntityReference;
37: import org.w3c.dom.NamedNodeMap;
38: import org.w3c.dom.NodeList;
39: import org.w3c.dom.ProcessingInstruction;
40: import org.w3c.dom.UserDataHandler;
41:
42: import jakarta.activation.DataHandler;
43: import jakarta.activation.DataSource;
44: import jakarta.xml.soap.MimeHeaders;
45: import jakarta.xml.soap.SOAPElement;
46: import jakarta.xml.soap.SOAPEnvelope;
47: import jakarta.xml.soap.SOAPException;
48: import jakarta.xml.soap.SOAPPart;
49: import javax.xml.transform.Source;
50: import javax.xml.transform.dom.DOMSource;
51: import javax.xml.transform.sax.SAXSource;
52: import javax.xml.transform.stream.StreamSource;
53: import java.io.IOException;
54: import java.io.InputStream;
55: import java.io.InputStreamReader;
56: import java.io.OutputStream;
57: import java.io.PushbackReader;
58: import java.io.Reader;
59: import java.io.UnsupportedEncodingException;
60: import java.util.Iterator;
61: import java.util.logging.Level;
62: import java.util.logging.Logger;
63: import jakarta.xml.soap.MimeHeader;
64:
65: /**
66: * SOAPPartImpl is the first attachment. This contains the XML/SOAP document.
67: *
68: * @author Anil Vijendran (anil@sun.com)
69: */
70: public abstract class SOAPPartImpl extends SOAPPart implements SOAPDocument {
71: protected static final Logger log =
72: Logger.getLogger(LogDomainConstants.SOAP_DOMAIN,
73: "com.sun.xml.messaging.saaj.soap.LocalStrings");
74:
75: protected MimeHeaders headers;
76: protected Envelope envelope;
77: protected Source source;
78: protected SOAPDocumentImpl document;
79:
80: //flag to indicate if a setContent happened.
81: private boolean sourceWasSet = false;
82:
83: // Records whether the input source had an xml decl or not.
84: protected boolean omitXmlDecl = true;
85:
86: // Records the charset encoding of the input stream source if provided.
87: protected String sourceCharsetEncoding = null;
88:
89: /**
90: * Reference to containing message (may be null)
91: */
92: protected MessageImpl message;
93:
94: static final boolean lazyContentLength;
95: static {
96: lazyContentLength = SAAJUtil.getSystemBoolean("saaj.lazy.contentlength");
97: }
98:
99: protected SOAPPartImpl() {
100: this(null);
101: }
102:
103: protected SOAPPartImpl(MessageImpl message) {
104: document = new SOAPDocumentImpl(this);
105: headers = new MimeHeaders();
106: this.message = message;
107: headers.setHeader("Content-Type", getContentType());
108: }
109:
110: protected abstract String getContentType();
111: protected abstract Envelope createEnvelopeFromSource()
112: throws SOAPException;
113: protected abstract Envelope createEmptyEnvelope(String prefix)
114: throws SOAPException;
115: protected abstract SOAPPartImpl duplicateType();
116:
117: protected String getContentTypeString() {
118: return getContentType();
119: }
120:
121: public boolean isFastInfoset() {
122:• return (message != null) ? message.isFastInfoset() : false;
123: }
124:
125: @Override
126: public SOAPEnvelope getEnvelope() throws SOAPException {
127:
128: // If there is no SOAP envelope already created, then create
129: // one from a source if one exists. If there is a newer source
130: // then use that source.
131:
132:• if (sourceWasSet)
133: sourceWasSet = false;
134:
135: lookForEnvelope();
136:• if (envelope != null) {
137:• if (source != null) { // there's a newer source, use it
138: document.removeChild(envelope);
139: envelope = createEnvelopeFromSource();
140: }
141:• } else if (source != null) {
142: envelope = createEnvelopeFromSource();
143: } else {
144: envelope = createEmptyEnvelope(null);
145: document.insertBefore(((EnvelopeImpl) envelope).getDomElement(), null);
146: }
147: return envelope;
148: }
149:
150: protected void lookForEnvelope() throws SOAPException {
151: Element envelopeChildElement = document.doGetDocumentElement();
152: org.w3c.dom.Node soapEnvelope = document.findIfPresent(envelopeChildElement);
153:• if (soapEnvelope == null || soapEnvelope instanceof Envelope) {
154: envelope = (EnvelopeImpl) soapEnvelope;
155:• } else if (document.find(envelopeChildElement) == null) {
156: log.severe("SAAJ0512.soap.incorrect.factory.used");
157: throw new SOAPExceptionImpl("Unable to create envelope: incorrect factory used during tree construction");
158: } else {
159: ElementImpl soapElement = (ElementImpl) document.find(envelopeChildElement);
160:• if (soapElement.getLocalName().equalsIgnoreCase("Envelope")) {
161: String prefix = soapElement.getPrefix();
162:• String uri = (prefix == null) ? soapElement.getNamespaceURI() : soapElement.getNamespaceURI(prefix);
163:• if(!uri.equals(NameImpl.SOAP11_NAMESPACE) && !uri.equals(NameImpl.SOAP12_NAMESPACE)) {
164: log.severe("SAAJ0513.soap.unknown.ns");
165: throw new SOAPVersionMismatchException("Unable to create envelope from given source because the namespace was not recognized");
166: }
167: } else {
168: log.severe("SAAJ0514.soap.root.elem.not.named.envelope");
169: throw new SOAPExceptionImpl(
170: "Unable to create envelope from given source because the root element is not named \"Envelope\"");
171: }
172: }
173: }
174:
175: @Override
176: public void removeAllMimeHeaders() {
177: headers.removeAllHeaders();
178: }
179:
180: @Override
181: public void removeMimeHeader(String header) {
182: headers.removeHeader(header);
183: }
184:
185: @Override
186: public String[] getMimeHeader(String name) {
187: return headers.getHeader(name);
188: }
189:
190: @Override
191: public void setMimeHeader(String name, String value) {
192: headers.setHeader(name, value);
193: }
194:
195: @Override
196: public void addMimeHeader(String name, String value) {
197: headers.addHeader(name, value);
198: }
199:
200: @Override
201: public Iterator<MimeHeader> getAllMimeHeaders() {
202: return headers.getAllHeaders();
203: }
204:
205: @Override
206: public Iterator<MimeHeader> getMatchingMimeHeaders(String[] names) {
207: return headers.getMatchingHeaders(names);
208: }
209:
210: @Override
211: public Iterator<MimeHeader> getNonMatchingMimeHeaders(String[] names) {
212: return headers.getNonMatchingHeaders(names);
213: }
214:
215: @Override
216: public Source getContent() throws SOAPException {
217:• if (source != null) {
218: InputStream bis = null;
219:• if (source instanceof JAXMStreamSource) {
220: StreamSource streamSource = (StreamSource)source;
221: bis = streamSource.getInputStream();
222:• } else if (FastInfosetReflection.isFastInfosetSource(source)) {
223: // FastInfosetSource inherits from SAXSource
224: SAXSource saxSource = (SAXSource)source;
225: bis = saxSource.getInputSource().getByteStream();
226: }
227:
228:• if (bis != null) {
229: try {
230: bis.reset();
231: } catch (IOException e) {
232: /* This exception will never be thrown.
233: *
234: * The setContent method will modify the source
235: * if StreamSource to JAXMStreamSource, that uses
236: * a ByteInputStream, and for a FastInfosetSource will
237: * replace the InputStream with a ByteInputStream.
238: */
239: }
240: }
241: return source;
242: }
243:
244: return ((Envelope) getEnvelope()).getContent();
245: }
246:
247: @Override
248: public void setContent(Source source) throws SOAPException {
249: try {
250:• if (source instanceof StreamSource) {
251: InputStream is = ((StreamSource) source).getInputStream();
252: Reader rdr = ((StreamSource) source).getReader();
253:
254:• if (is != null) {
255: this.source = new JAXMStreamSource(is);
256:• } else if (rdr != null) {
257: this.source = new JAXMStreamSource(rdr);
258: } else {
259: log.severe("SAAJ0544.soap.no.valid.reader.for.src");
260: throw new SOAPExceptionImpl("Source does not have a valid Reader or InputStream");
261: }
262: }
263:• else if (FastInfosetReflection.isFastInfosetSource(source)) {
264: // InputStream is = source.getInputStream()
265: InputStream is = FastInfosetReflection.FastInfosetSource_getInputStream(source);
266:
267: /*
268: * Underlying stream must be ByteInputStream for getContentAsStream(). We pay the
269: * cost of copying the underlying bytes here to avoid multiple copies every time
270: * getBytes() is called on a ByteInputStream.
271: */
272:• if (!(is instanceof ByteInputStream)) {
273: ByteOutputStream bout = null;
274: try {
275: bout = new ByteOutputStream();
276: bout.write(is);
277:
278: // source.setInputStream(new ByteInputStream(...))
279: FastInfosetReflection.FastInfosetSource_setInputStream(
280: source, bout.newInputStream());
281: } finally {
282:• if (bout != null)
283: bout.close();
284: }
285: }
286: this.source = source;
287: }
288: else {
289: this.source = source;
290: }
291: sourceWasSet = true;
292: }
293: catch (Exception ex) {
294: ex.printStackTrace();
295:
296: log.severe("SAAJ0545.soap.cannot.set.src.for.part");
297: throw new SOAPExceptionImpl(
298: "Error setting the source for SOAPPart: " + ex.getMessage());
299: }
300: }
301:
302: public InputStream getContentAsStream() throws IOException {
303:• if (source != null) {
304: InputStream is = null;
305:
306: // Allow message to be transcode if so requested
307:• if (source instanceof StreamSource && !isFastInfoset()) {
308: is = ((StreamSource) source).getInputStream();
309: }
310:• else if (FastInfosetReflection.isFastInfosetSource(source) &&
311:• isFastInfoset())
312: {
313: try {
314: // InputStream is = source.getInputStream()
315: is = FastInfosetReflection.FastInfosetSource_getInputStream(source);
316: }
317: catch (Exception e) {
318: throw new IOException(e.toString());
319: }
320: }
321:
322:• if (is != null) {
323:• if (lazyContentLength) {
324: return is;
325: }
326:• if (!(is instanceof ByteInputStream)) {
327: log.severe("SAAJ0546.soap.stream.incorrect.type");
328: throw new IOException("Internal error: stream not of the right type");
329: }
330: return (ByteInputStream) is;
331: }
332: // need to do something here for reader...
333: // for now we'll see if we can fallback...
334: }
335:
336: ByteOutputStream b = new ByteOutputStream();
337:
338: Envelope env = null;
339:
340: try {
341: env = (Envelope) getEnvelope();
342: env.output(b, isFastInfoset());
343: }
344: catch (SOAPException soapException) {
345: log.severe("SAAJ0547.soap.cannot.externalize");
346: throw new SOAPIOException(
347: "SOAP exception while trying to externalize: ",
348: soapException);
349: }
350:
351: return b.newInputStream();
352: }
353:
354: MimeBodyPart getMimePart() throws SOAPException {
355: try {
356: MimeBodyPart headerEnvelope = new MimeBodyPart();
357:
358: headerEnvelope.setDataHandler(getDataHandler());
359: AttachmentPartImpl.copyMimeHeaders(headers, headerEnvelope);
360:
361: return headerEnvelope;
362: } catch (SOAPException ex) {
363: throw ex;
364: } catch (Exception ex) {
365: log.severe("SAAJ0548.soap.cannot.externalize.hdr");
366: throw new SOAPExceptionImpl("Unable to externalize header", ex);
367: }
368: }
369:
370: MimeHeaders getMimeHeaders() {
371: return headers;
372: }
373:
374: DataHandler getDataHandler() {
375: DataSource ds = new DataSource() {
376: @Override
377: public OutputStream getOutputStream() throws IOException {
378: throw new IOException("Illegal Operation");
379: }
380:
381: @Override
382: public String getContentType() {
383: return getContentTypeString();
384: }
385:
386: @Override
387: public String getName() {
388: return getContentId();
389: }
390:
391: @Override
392: public InputStream getInputStream() throws IOException {
393: return getContentAsStream();
394: }
395: };
396: return new DataHandler(ds);
397: }
398:
399: @Override
400: public SOAPDocumentImpl getDocument() {
401: handleNewSource();
402: return document;
403: }
404:
405: @Override
406: public SOAPPartImpl getSOAPPart() {
407: return this;
408: }
409:
410: @Override
411: public DocumentType getDoctype() {
412: return document.getDoctype();
413: }
414:
415: // Forward all of these calls to the document to ensure that they work the
416: // same way whether they are called from here or directly from the document.
417: // If the document needs any help from this SOAPPart then
418: // Make it use a call-back as in doGetDocumentElement() below
419: @Override
420: public DOMImplementation getImplementation() {
421: return document.getImplementation();
422: }
423:
424: @Override
425: public Element getDocumentElement() {
426: // If there is no SOAP envelope already created, then create
427: // one from a source if one exists. If there is a newer source
428: // then use that source.
429: try {
430: getEnvelope();
431: } catch (SOAPException e) {
432: }
433: return document.getDocumentElement();
434: }
435:
436: protected void doGetDocumentElement() {
437: handleNewSource();
438: try {
439: lookForEnvelope();
440: } catch (SOAPException e) {
441: }
442: }
443:
444: @Override
445: public Element createElement(String tagName) throws DOMException {
446: return document.createElement(tagName);
447: }
448:
449: @Override
450: public DocumentFragment createDocumentFragment() {
451: return document.createDocumentFragment();
452: }
453:
454: @Override
455: public org.w3c.dom.Text createTextNode(String data) {
456: return document.createTextNode(data);
457: }
458:
459: @Override
460: public Comment createComment(String data) {
461: return document.createComment(data);
462: }
463:
464: @Override
465: public CDATASection createCDATASection(String data) throws DOMException {
466: return document.createCDATASection(data);
467: }
468:
469: @Override
470: public ProcessingInstruction createProcessingInstruction(
471: String target,
472: String data)
473: throws DOMException {
474: return document.createProcessingInstruction(target, data);
475: }
476:
477: @Override
478: public Attr createAttribute(String name) throws DOMException {
479: return document.createAttribute(name);
480: }
481:
482: @Override
483: public EntityReference createEntityReference(String name)
484: throws DOMException {
485: return document.createEntityReference(name);
486: }
487:
488: @Override
489: public NodeList getElementsByTagName(String tagname) {
490: handleNewSource();
491: return document.getElementsByTagName(tagname);
492: }
493:
494: @Override
495: public org.w3c.dom.Node importNode(
496: org.w3c.dom.Node importedNode,
497: boolean deep)
498: throws DOMException {
499: handleNewSource();
500: return document.importNode(importedNode, deep);
501: }
502:
503: @Override
504: public Element createElementNS(String namespaceURI, String qualifiedName)
505: throws DOMException {
506: return document.createElementNS(namespaceURI, qualifiedName);
507: }
508:
509: @Override
510: public Attr createAttributeNS(String namespaceURI, String qualifiedName)
511: throws DOMException {
512: return document.createAttributeNS(namespaceURI, qualifiedName);
513: }
514:
515: @Override
516: public NodeList getElementsByTagNameNS(
517: String namespaceURI,
518: String localName) {
519: handleNewSource();
520: return document.getElementsByTagNameNS(namespaceURI, localName);
521: }
522:
523: @Override
524: public Element getElementById(String elementId) {
525: handleNewSource();
526: return document.getElementById(elementId);
527: }
528: @Override
529: public org.w3c.dom.Node appendChild(org.w3c.dom.Node newChild)
530: throws DOMException {
531: handleNewSource();
532: return document.appendChild(newChild);
533: }
534:
535: @Override
536: public org.w3c.dom.Node cloneNode(boolean deep) {
537: handleNewSource();
538: return doCloneNode();
539: }
540:
541: protected SOAPPartImpl doCloneNode() {
542: handleNewSource();
543: SOAPPartImpl newSoapPart = duplicateType();
544:
545: newSoapPart.headers = MimeHeadersUtil.copy(this.headers);
546: newSoapPart.source = this.source;
547: newSoapPart.document = new SOAPDocumentImpl(newSoapPart, (Document) this.document.getDomDocument().cloneNode(true));
548: return newSoapPart;
549: }
550:
551: @Override
552: public NamedNodeMap getAttributes() {
553: return document.getDomDocument().getAttributes();
554: }
555:
556: @Override
557: public NodeList getChildNodes() {
558: handleNewSource();
559: return document.getChildNodes();
560: }
561:
562: @Override
563: public org.w3c.dom.Node getFirstChild() {
564: handleNewSource();
565: return document.getFirstChild();
566: }
567:
568: @Override
569: public org.w3c.dom.Node getLastChild() {
570: handleNewSource();
571: return document.getLastChild();
572: }
573:
574: @Override
575: public String getLocalName() {
576: return document.getDomDocument().getLocalName();
577: }
578:
579: @Override
580: public String getNamespaceURI() {
581: return document.getDomDocument().getNamespaceURI();
582: }
583:
584: @Override
585: public org.w3c.dom.Node getNextSibling() {
586: handleNewSource();
587: return document.getNextSibling();
588: }
589:
590: @Override
591: public String getNodeName() {
592: return document.getDomDocument().getNodeName();
593: }
594:
595: @Override
596: public short getNodeType() {
597: return document.getDomDocument().getNodeType();
598: }
599:
600: @Override
601: public String getNodeValue() throws DOMException {
602: return document.getNodeValue();
603: }
604:
605: @Override
606: public Document getOwnerDocument() {
607: return document;
608: }
609:
610: @Override
611: public org.w3c.dom.Node getParentNode() {
612: return document.getDomDocument().getParentNode();
613: }
614:
615: @Override
616: public String getPrefix() {
617: return document.getDomDocument().getPrefix();
618: }
619:
620: @Override
621: public org.w3c.dom.Node getPreviousSibling() {
622: return document.getDomDocument().getPreviousSibling();
623: }
624:
625: @Override
626: public boolean hasAttributes() {
627: return document.getDomDocument().hasAttributes();
628: }
629:
630: @Override
631: public boolean hasChildNodes() {
632: handleNewSource();
633: return document.hasChildNodes();
634: }
635:
636: @Override
637: public org.w3c.dom.Node insertBefore(
638: org.w3c.dom.Node arg0,
639: org.w3c.dom.Node arg1)
640: throws DOMException {
641: handleNewSource();
642: return document.insertBefore(arg0, arg1);
643: }
644:
645: @Override
646: public boolean isSupported(String arg0, String arg1) {
647: return document.getDomDocument().isSupported(arg0, arg1);
648: }
649:
650: @Override
651: public void normalize() {
652: handleNewSource();
653: document.normalize();
654: }
655:
656: @Override
657: public org.w3c.dom.Node removeChild(org.w3c.dom.Node arg0)
658: throws DOMException {
659: handleNewSource();
660: return document.removeChild(arg0);
661: }
662:
663: @Override
664: public org.w3c.dom.Node replaceChild(
665: org.w3c.dom.Node arg0,
666: org.w3c.dom.Node arg1)
667: throws DOMException {
668: handleNewSource();
669: return document.replaceChild(arg0, arg1);
670: }
671:
672: @Override
673: public void setNodeValue(String arg0) throws DOMException {
674: document.setNodeValue(arg0);
675: }
676:
677: @Override
678: public void setPrefix(String arg0) throws DOMException {
679: document.setPrefix(arg0);
680: }
681:
682: private void handleNewSource() {
683:• if (sourceWasSet) {
684: // There is a newer source use that source.
685: try {
686: getEnvelope();
687: } catch (SOAPException e) {
688: }
689: }
690: }
691:
692: protected XMLDeclarationParser lookForXmlDecl() throws SOAPException {
693:• if ((source != null) && (source instanceof StreamSource)) {
694:
695: Reader reader = null;
696:
697: InputStream inputStream = ((StreamSource) source).getInputStream();
698:• if (inputStream != null) {
699:• if (getSourceCharsetEncoding() == null) {
700: reader = new InputStreamReader(inputStream);
701: } else {
702: try {
703: reader =
704: new InputStreamReader(
705: inputStream, getSourceCharsetEncoding());
706: } catch (UnsupportedEncodingException uee) {
707: log.log(
708: Level.SEVERE,
709: "SAAJ0551.soap.unsupported.encoding",
710: new Object[] {getSourceCharsetEncoding()});
711: throw new SOAPExceptionImpl(
712: "Unsupported encoding " + getSourceCharsetEncoding(),
713: uee);
714: }
715: }
716: } else {
717: reader = ((StreamSource) source).getReader();
718: }
719:• if (reader != null) {
720: PushbackReader pushbackReader =
721: new PushbackReader(reader, 4096); //some size to unread <?xml ....?>
722: XMLDeclarationParser ev =
723: new XMLDeclarationParser(pushbackReader);
724: try {
725: ev.parse();
726: } catch (Exception e) {
727: log.log(
728: Level.SEVERE,
729: "SAAJ0552.soap.xml.decl.parsing.failed");
730: throw new SOAPExceptionImpl(
731: "XML declaration parsing failed", e);
732: }
733: String xmlDecl = ev.getXmlDeclaration();
734:• if ((xmlDecl != null) && (xmlDecl.length() > 0)) {
735: this.omitXmlDecl = false;
736: }
737:• if (lazyContentLength) {
738: source = new StreamSource(pushbackReader);
739: }
740: return ev;
741: }
742:• } else if ((source != null) && (source instanceof DOMSource)) {
743: //TODO: A Domsource maynot contain XMLDecl ?.
744: }
745: return null;
746: }
747:
748: public void setSourceCharsetEncoding(String charset) {
749: this.sourceCharsetEncoding = charset;
750: }
751:
752: @Override
753: public org.w3c.dom.Node renameNode(org.w3c.dom.Node n, String namespaceURI, String qualifiedName)
754: throws DOMException {
755: handleNewSource();
756: return document.renameNode(n, namespaceURI, qualifiedName);
757: }
758:
759: @Override
760: public void normalizeDocument() {
761: document.normalizeDocument();
762: }
763:
764: @Override
765: public DOMConfiguration getDomConfig() {
766: return document.getDomDocument().getDomConfig();
767: }
768:
769: @Override
770: public org.w3c.dom.Node adoptNode(org.w3c.dom.Node source) throws DOMException {
771: handleNewSource();
772: return document.adoptNode(source);
773: }
774:
775: @Override
776: public void setDocumentURI(String documentURI) {
777: document.setDocumentURI(documentURI);
778: }
779:
780: @Override
781: public String getDocumentURI() {
782: return document.getDomDocument().getDocumentURI();
783: }
784:
785: @Override
786: public void setStrictErrorChecking(boolean strictErrorChecking) {
787: document.setStrictErrorChecking(strictErrorChecking);
788: }
789:
790: @Override
791: public String getInputEncoding() {
792: return document.getDomDocument().getInputEncoding();
793: }
794:
795: @Override
796: public String getXmlEncoding() {
797: return document.getDomDocument().getXmlEncoding();
798: }
799:
800: @Override
801: public boolean getXmlStandalone() {
802: return document.getDomDocument().getXmlStandalone();
803: }
804:
805: @Override
806: public void setXmlStandalone(boolean xmlStandalone) throws DOMException {
807: document.setXmlStandalone(xmlStandalone);
808: }
809:
810: @Override
811: public String getXmlVersion() {
812: return document.getDomDocument().getXmlVersion();
813: }
814:
815: @Override
816: public void setXmlVersion(String xmlVersion) throws DOMException {
817: document.setXmlVersion(xmlVersion);
818: }
819:
820: @Override
821: public boolean getStrictErrorChecking() {
822: return document.getDomDocument().getStrictErrorChecking();
823: }
824:
825: // DOM L3 methods from org.w3c.dom.Node
826: @Override
827: public String getBaseURI() {
828: return document.getDomDocument().getBaseURI();
829: }
830:
831: @Override
832: public short compareDocumentPosition(org.w3c.dom.Node other)
833: throws DOMException {
834: return document.compareDocumentPosition(other);
835: }
836:
837: @Override
838: public String getTextContent()
839: throws DOMException {
840: return document.getTextContent();
841: }
842:
843: @Override
844: public void setTextContent(String textContent) throws DOMException {
845: document.setTextContent(textContent);
846: }
847:
848: @Override
849: public boolean isSameNode(org.w3c.dom.Node other) {
850: return document.isSameNode(other);
851: }
852:
853: @Override
854: public String lookupPrefix(String namespaceURI) {
855: return document.getDomDocument().lookupPrefix(namespaceURI);
856: }
857:
858: @Override
859: public boolean isDefaultNamespace(String namespaceURI) {
860: return document.isDefaultNamespace(namespaceURI);
861: }
862:
863: @Override
864: public String lookupNamespaceURI(String prefix) {
865: return document.lookupNamespaceURI(prefix);
866: }
867:
868: @Override
869: public boolean isEqualNode(org.w3c.dom.Node arg) {
870: return document.getDomDocument().isEqualNode(arg);
871: }
872:
873: @Override
874: public Object getFeature(String feature,
875: String version) {
876: return document.getFeature(feature,version);
877: }
878:
879: @Override
880: public Object setUserData(String key,
881: Object data,
882: UserDataHandler handler) {
883: return document.setUserData(key, data, handler);
884: }
885:
886: @Override
887: public Object getUserData(String key) {
888: return document.getDomDocument().getUserData(key);
889: }
890:
891: @Override
892: public void recycleNode() {
893: // Nothing seems to be required to be done here
894: }
895:
896: @Override
897: public String getValue() {
898: return null;
899: }
900:
901: @Override
902: public void setValue(String value) {
903: log.severe("SAAJ0571.soappart.setValue.not.defined");
904: throw new IllegalStateException("Setting value of a soap part is not defined");
905: }
906:
907: @Override
908: public void setParentElement(SOAPElement parent) throws SOAPException {
909: log.severe("SAAJ0570.soappart.parent.element.not.defined");
910: throw new SOAPExceptionImpl("The parent element of a soap part is not defined");
911: }
912:
913: @Override
914: public SOAPElement getParentElement() {
915: return null;
916: }
917:
918: @Override
919: public void detachNode() {
920: // Nothing seems to be required to be done here
921: }
922:
923: public String getSourceCharsetEncoding() {
924: return sourceCharsetEncoding;
925: }
926:
927: public abstract String getSOAPNamespace();
928: }