author | mkos |
Mon, 31 Mar 2014 10:43:20 +0200 | |
changeset 23782 | 953bfc3fbe31 |
parent 22679 | d785acd84a14 |
child 23961 | 439846965790 |
permissions | -rw-r--r-- |
12009 | 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 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. Oracle designates this |
|
8 |
* particular file as subject to the "Classpath" exception as provided |
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
|
10 |
* |
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
24 |
*/ |
|
25 |
||
26 |
package com.sun.xml.internal.messaging.saaj.soap; |
|
27 |
||
28 |
import java.util.logging.Logger; |
|
29 |
||
30 |
import javax.xml.parsers.SAXParser; |
|
31 |
import javax.xml.soap.SOAPException; |
|
23782
953bfc3fbe31
8036030: Update JAX-WS RI integration to latest version
mkos
parents:
22679
diff
changeset
|
32 |
import javax.xml.stream.XMLInputFactory; |
953bfc3fbe31
8036030: Update JAX-WS RI integration to latest version
mkos
parents:
22679
diff
changeset
|
33 |
import javax.xml.stream.XMLStreamException; |
953bfc3fbe31
8036030: Update JAX-WS RI integration to latest version
mkos
parents:
22679
diff
changeset
|
34 |
import javax.xml.stream.XMLStreamReader; |
12009 | 35 |
import javax.xml.transform.Source; |
36 |
import javax.xml.transform.Transformer; |
|
37 |
import javax.xml.transform.dom.DOMResult; |
|
38 |
import javax.xml.transform.sax.SAXSource; |
|
23782
953bfc3fbe31
8036030: Update JAX-WS RI integration to latest version
mkos
parents:
22679
diff
changeset
|
39 |
import javax.xml.transform.stax.StAXSource; |
12009 | 40 |
import javax.xml.transform.stream.StreamSource; |
41 |
||
42 |
import org.xml.sax.InputSource; |
|
43 |
import org.xml.sax.XMLReader; |
|
44 |
||
23782
953bfc3fbe31
8036030: Update JAX-WS RI integration to latest version
mkos
parents:
22679
diff
changeset
|
45 |
import com.sun.xml.internal.messaging.saaj.LazyEnvelopeSource; |
12009 | 46 |
import com.sun.xml.internal.messaging.saaj.SOAPExceptionImpl; |
47 |
import com.sun.xml.internal.messaging.saaj.util.*; |
|
48 |
import com.sun.xml.internal.messaging.saaj.util.transform.EfficientStreamingTransformer; |
|
49 |
||
50 |
/** |
|
51 |
* EnvelopeFactory creates SOAP Envelope objects using different |
|
52 |
* underlying implementations. |
|
53 |
*/ |
|
54 |
public class EnvelopeFactory { |
|
55 |
||
56 |
protected static final Logger |
|
57 |
log = Logger.getLogger(LogDomainConstants.SOAP_DOMAIN, |
|
58 |
"com.sun.xml.internal.messaging.saaj.soap.LocalStrings"); |
|
59 |
||
60 |
private static ParserPool parserPool = new ParserPool(5); |
|
61 |
||
62 |
public static Envelope createEnvelope(Source src, SOAPPartImpl soapPart) |
|
63 |
throws SOAPException |
|
64 |
{ |
|
23782
953bfc3fbe31
8036030: Update JAX-WS RI integration to latest version
mkos
parents:
22679
diff
changeset
|
65 |
if (src instanceof JAXMStreamSource) { |
953bfc3fbe31
8036030: Update JAX-WS RI integration to latest version
mkos
parents:
22679
diff
changeset
|
66 |
try { |
953bfc3fbe31
8036030: Update JAX-WS RI integration to latest version
mkos
parents:
22679
diff
changeset
|
67 |
if (!SOAPPartImpl.lazyContentLength) { |
953bfc3fbe31
8036030: Update JAX-WS RI integration to latest version
mkos
parents:
22679
diff
changeset
|
68 |
((JAXMStreamSource) src).reset(); |
953bfc3fbe31
8036030: Update JAX-WS RI integration to latest version
mkos
parents:
22679
diff
changeset
|
69 |
} |
953bfc3fbe31
8036030: Update JAX-WS RI integration to latest version
mkos
parents:
22679
diff
changeset
|
70 |
} catch (java.io.IOException ioe) { |
953bfc3fbe31
8036030: Update JAX-WS RI integration to latest version
mkos
parents:
22679
diff
changeset
|
71 |
log.severe("SAAJ0515.source.reset.exception"); |
953bfc3fbe31
8036030: Update JAX-WS RI integration to latest version
mkos
parents:
22679
diff
changeset
|
72 |
throw new SOAPExceptionImpl(ioe); |
953bfc3fbe31
8036030: Update JAX-WS RI integration to latest version
mkos
parents:
22679
diff
changeset
|
73 |
} |
953bfc3fbe31
8036030: Update JAX-WS RI integration to latest version
mkos
parents:
22679
diff
changeset
|
74 |
} |
953bfc3fbe31
8036030: Update JAX-WS RI integration to latest version
mkos
parents:
22679
diff
changeset
|
75 |
if (src instanceof LazyEnvelopeSource) { |
953bfc3fbe31
8036030: Update JAX-WS RI integration to latest version
mkos
parents:
22679
diff
changeset
|
76 |
return lazy((LazyEnvelopeSource)src, soapPart); |
953bfc3fbe31
8036030: Update JAX-WS RI integration to latest version
mkos
parents:
22679
diff
changeset
|
77 |
} |
953bfc3fbe31
8036030: Update JAX-WS RI integration to latest version
mkos
parents:
22679
diff
changeset
|
78 |
if (soapPart.message.isLazySoapBodyParsing()) { |
953bfc3fbe31
8036030: Update JAX-WS RI integration to latest version
mkos
parents:
22679
diff
changeset
|
79 |
return parseEnvelopeStax(src, soapPart); |
953bfc3fbe31
8036030: Update JAX-WS RI integration to latest version
mkos
parents:
22679
diff
changeset
|
80 |
} else { |
953bfc3fbe31
8036030: Update JAX-WS RI integration to latest version
mkos
parents:
22679
diff
changeset
|
81 |
return parseEnvelopeSax(src, soapPart); |
953bfc3fbe31
8036030: Update JAX-WS RI integration to latest version
mkos
parents:
22679
diff
changeset
|
82 |
} |
953bfc3fbe31
8036030: Update JAX-WS RI integration to latest version
mkos
parents:
22679
diff
changeset
|
83 |
} |
953bfc3fbe31
8036030: Update JAX-WS RI integration to latest version
mkos
parents:
22679
diff
changeset
|
84 |
|
953bfc3fbe31
8036030: Update JAX-WS RI integration to latest version
mkos
parents:
22679
diff
changeset
|
85 |
private static Envelope lazy(LazyEnvelopeSource src, SOAPPartImpl soapPart) throws SOAPException { |
953bfc3fbe31
8036030: Update JAX-WS RI integration to latest version
mkos
parents:
22679
diff
changeset
|
86 |
try { |
953bfc3fbe31
8036030: Update JAX-WS RI integration to latest version
mkos
parents:
22679
diff
changeset
|
87 |
StaxBridge staxBridge = new StaxLazySourceBridge(src, soapPart); |
953bfc3fbe31
8036030: Update JAX-WS RI integration to latest version
mkos
parents:
22679
diff
changeset
|
88 |
staxBridge.bridgeEnvelopeAndHeaders(); |
953bfc3fbe31
8036030: Update JAX-WS RI integration to latest version
mkos
parents:
22679
diff
changeset
|
89 |
Envelope env = (Envelope) soapPart.getEnvelope(); |
953bfc3fbe31
8036030: Update JAX-WS RI integration to latest version
mkos
parents:
22679
diff
changeset
|
90 |
env.setStaxBridge(staxBridge); |
953bfc3fbe31
8036030: Update JAX-WS RI integration to latest version
mkos
parents:
22679
diff
changeset
|
91 |
return env; |
953bfc3fbe31
8036030: Update JAX-WS RI integration to latest version
mkos
parents:
22679
diff
changeset
|
92 |
} catch (XMLStreamException e) { |
953bfc3fbe31
8036030: Update JAX-WS RI integration to latest version
mkos
parents:
22679
diff
changeset
|
93 |
throw new SOAPException(e); |
953bfc3fbe31
8036030: Update JAX-WS RI integration to latest version
mkos
parents:
22679
diff
changeset
|
94 |
} |
953bfc3fbe31
8036030: Update JAX-WS RI integration to latest version
mkos
parents:
22679
diff
changeset
|
95 |
} |
953bfc3fbe31
8036030: Update JAX-WS RI integration to latest version
mkos
parents:
22679
diff
changeset
|
96 |
|
953bfc3fbe31
8036030: Update JAX-WS RI integration to latest version
mkos
parents:
22679
diff
changeset
|
97 |
static private XMLInputFactory xmlInputFactory = null; |
953bfc3fbe31
8036030: Update JAX-WS RI integration to latest version
mkos
parents:
22679
diff
changeset
|
98 |
|
953bfc3fbe31
8036030: Update JAX-WS RI integration to latest version
mkos
parents:
22679
diff
changeset
|
99 |
private static Envelope parseEnvelopeStax(Source src, SOAPPartImpl soapPart) |
953bfc3fbe31
8036030: Update JAX-WS RI integration to latest version
mkos
parents:
22679
diff
changeset
|
100 |
throws SOAPException { |
953bfc3fbe31
8036030: Update JAX-WS RI integration to latest version
mkos
parents:
22679
diff
changeset
|
101 |
XMLStreamReader streamReader = null; |
953bfc3fbe31
8036030: Update JAX-WS RI integration to latest version
mkos
parents:
22679
diff
changeset
|
102 |
if (src instanceof StAXSource) { |
953bfc3fbe31
8036030: Update JAX-WS RI integration to latest version
mkos
parents:
22679
diff
changeset
|
103 |
streamReader = ((StAXSource) src).getXMLStreamReader(); |
953bfc3fbe31
8036030: Update JAX-WS RI integration to latest version
mkos
parents:
22679
diff
changeset
|
104 |
} |
953bfc3fbe31
8036030: Update JAX-WS RI integration to latest version
mkos
parents:
22679
diff
changeset
|
105 |
try { |
953bfc3fbe31
8036030: Update JAX-WS RI integration to latest version
mkos
parents:
22679
diff
changeset
|
106 |
if (streamReader == null) { |
953bfc3fbe31
8036030: Update JAX-WS RI integration to latest version
mkos
parents:
22679
diff
changeset
|
107 |
if (xmlInputFactory == null) xmlInputFactory = XMLInputFactory.newInstance(); |
953bfc3fbe31
8036030: Update JAX-WS RI integration to latest version
mkos
parents:
22679
diff
changeset
|
108 |
streamReader = xmlInputFactory.createXMLStreamReader(src); |
953bfc3fbe31
8036030: Update JAX-WS RI integration to latest version
mkos
parents:
22679
diff
changeset
|
109 |
} |
953bfc3fbe31
8036030: Update JAX-WS RI integration to latest version
mkos
parents:
22679
diff
changeset
|
110 |
// SaajStaxWriter saajWriter = new SaajStaxWriter(soapPart.message, soapPart.document); |
953bfc3fbe31
8036030: Update JAX-WS RI integration to latest version
mkos
parents:
22679
diff
changeset
|
111 |
// XMLStreamReaderToXMLStreamWriter readerWriterBridge = new XMLStreamReaderToXMLStreamWriter( |
953bfc3fbe31
8036030: Update JAX-WS RI integration to latest version
mkos
parents:
22679
diff
changeset
|
112 |
// streamReader, saajWriter, soapPart.getSOAPNamespace()); |
953bfc3fbe31
8036030: Update JAX-WS RI integration to latest version
mkos
parents:
22679
diff
changeset
|
113 |
|
953bfc3fbe31
8036030: Update JAX-WS RI integration to latest version
mkos
parents:
22679
diff
changeset
|
114 |
StaxBridge readerWriterBridge = new StaxReaderBridge(streamReader, soapPart); |
953bfc3fbe31
8036030: Update JAX-WS RI integration to latest version
mkos
parents:
22679
diff
changeset
|
115 |
//bridge will stop reading at body element, and parse upon request, so save it |
953bfc3fbe31
8036030: Update JAX-WS RI integration to latest version
mkos
parents:
22679
diff
changeset
|
116 |
//on the envelope |
953bfc3fbe31
8036030: Update JAX-WS RI integration to latest version
mkos
parents:
22679
diff
changeset
|
117 |
readerWriterBridge.bridgeEnvelopeAndHeaders(); |
953bfc3fbe31
8036030: Update JAX-WS RI integration to latest version
mkos
parents:
22679
diff
changeset
|
118 |
|
953bfc3fbe31
8036030: Update JAX-WS RI integration to latest version
mkos
parents:
22679
diff
changeset
|
119 |
Envelope env = (Envelope) soapPart.getEnvelope(); |
953bfc3fbe31
8036030: Update JAX-WS RI integration to latest version
mkos
parents:
22679
diff
changeset
|
120 |
env.setStaxBridge(readerWriterBridge); |
953bfc3fbe31
8036030: Update JAX-WS RI integration to latest version
mkos
parents:
22679
diff
changeset
|
121 |
return env; |
953bfc3fbe31
8036030: Update JAX-WS RI integration to latest version
mkos
parents:
22679
diff
changeset
|
122 |
} catch (Exception e) { |
953bfc3fbe31
8036030: Update JAX-WS RI integration to latest version
mkos
parents:
22679
diff
changeset
|
123 |
throw new SOAPException(e); |
953bfc3fbe31
8036030: Update JAX-WS RI integration to latest version
mkos
parents:
22679
diff
changeset
|
124 |
} |
953bfc3fbe31
8036030: Update JAX-WS RI integration to latest version
mkos
parents:
22679
diff
changeset
|
125 |
} |
953bfc3fbe31
8036030: Update JAX-WS RI integration to latest version
mkos
parents:
22679
diff
changeset
|
126 |
private static Envelope parseEnvelopeSax(Source src, SOAPPartImpl soapPart) |
953bfc3fbe31
8036030: Update JAX-WS RI integration to latest version
mkos
parents:
22679
diff
changeset
|
127 |
throws SOAPException { |
12009 | 128 |
// Insert SAX filter to disallow Document Type Declarations since |
129 |
// they are not legal in SOAP |
|
130 |
SAXParser saxParser = null; |
|
131 |
if (src instanceof StreamSource) { |
|
132 |
try { |
|
133 |
saxParser = parserPool.get(); |
|
134 |
} catch (Exception e) { |
|
135 |
log.severe("SAAJ0601.util.newSAXParser.exception"); |
|
136 |
throw new SOAPExceptionImpl( |
|
137 |
"Couldn't get a SAX parser while constructing a envelope", |
|
138 |
e); |
|
139 |
} |
|
140 |
InputSource is = SAXSource.sourceToInputSource(src); |
|
141 |
if (is.getEncoding()== null && soapPart.getSourceCharsetEncoding() != null) { |
|
142 |
is.setEncoding(soapPart.getSourceCharsetEncoding()); |
|
143 |
} |
|
144 |
XMLReader rejectFilter; |
|
145 |
try { |
|
146 |
rejectFilter = new RejectDoctypeSaxFilter(saxParser); |
|
147 |
} catch (Exception ex) { |
|
148 |
log.severe("SAAJ0510.soap.cannot.create.envelope"); |
|
149 |
throw new SOAPExceptionImpl( |
|
150 |
"Unable to create envelope from given source: ", |
|
151 |
ex); |
|
152 |
} |
|
153 |
src = new SAXSource(rejectFilter, is); |
|
154 |
} |
|
155 |
||
156 |
try { |
|
157 |
Transformer transformer = |
|
158 |
EfficientStreamingTransformer.newTransformer(); |
|
159 |
DOMResult result = new DOMResult(soapPart); |
|
160 |
transformer.transform(src, result); |
|
161 |
||
162 |
Envelope env = (Envelope) soapPart.getEnvelope(); |
|
163 |
return env; |
|
164 |
} catch (Exception ex) { |
|
165 |
if (ex instanceof SOAPVersionMismatchException) { |
|
166 |
throw (SOAPVersionMismatchException) ex; |
|
167 |
} |
|
168 |
log.severe("SAAJ0511.soap.cannot.create.envelope"); |
|
169 |
throw new SOAPExceptionImpl( |
|
170 |
"Unable to create envelope from given source: ", |
|
171 |
ex); |
|
172 |
} finally { |
|
173 |
if (saxParser != null) { |
|
174 |
parserPool.returnParser(saxParser); |
|
175 |
} |
|
176 |
} |
|
177 |
} |
|
178 |
} |