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 com.sun.xml.internal.messaging.saaj.SOAPExceptionImpl;
29 import com.sun.xml.internal.messaging.saaj.util.JAXMStreamSource;
30 import com.sun.xml.internal.messaging.saaj.util.LogDomainConstants;
31 import com.sun.xml.internal.messaging.saaj.util.ParserPool;
32 import com.sun.xml.internal.messaging.saaj.util.RejectDoctypeSaxFilter;
33 import com.sun.xml.internal.messaging.saaj.util.transform.EfficientStreamingTransformer;
34 import org.xml.sax.InputSource;
35 import org.xml.sax.XMLReader;
36
37 import javax.xml.parsers.SAXParser;
38 import javax.xml.soap.SOAPException;
39 import javax.xml.stream.XMLInputFactory;
40 import javax.xml.stream.XMLStreamException;
41 import javax.xml.stream.XMLStreamReader;
42 import javax.xml.transform.Source;
43 import javax.xml.transform.Transformer;
44 import javax.xml.transform.dom.DOMResult;
45 import javax.xml.transform.sax.SAXSource;
46 import javax.xml.transform.stax.StAXSource;
47 import javax.xml.transform.stream.StreamSource;
48
49 import com.sun.xml.internal.messaging.saaj.LazyEnvelopeSource;
50 import com.sun.xml.internal.messaging.saaj.util.transform.EfficientStreamingTransformer;
51
52 import java.util.logging.Logger;
53
54 /**
55 * EnvelopeFactory creates SOAP Envelope objects using different
56 * underlying implementations.
57 */
58 public class EnvelopeFactory {
59
60 protected static final Logger
61 log = Logger.getLogger(LogDomainConstants.SOAP_DOMAIN,
62 "com.sun.xml.internal.messaging.saaj.soap.LocalStrings");
63
64 private static ContextClassloaderLocal<ParserPool> parserPool =
65 new ContextClassloaderLocal<ParserPool>() {
66 @Override
67 protected ParserPool initialValue() throws Exception {
68 return new ParserPool(5);
69 }
70 };
71
131 return env;
132 } catch (Exception e) {
133 throw new SOAPException(e);
134 }
135 }
136 private static Envelope parseEnvelopeSax(Source src, SOAPPartImpl soapPart)
137 throws SOAPException {
138 // Insert SAX filter to disallow Document Type Declarations since
139 // they are not legal in SOAP
140 SAXParser saxParser = null;
141 if (src instanceof StreamSource) {
142 try {
143 saxParser = parserPool.get().get();
144 } catch (Exception e) {
145 log.severe("SAAJ0601.util.newSAXParser.exception");
146 throw new SOAPExceptionImpl(
147 "Couldn't get a SAX parser while constructing a envelope",
148 e);
149 }
150 InputSource is = SAXSource.sourceToInputSource(src);
151 if (is.getEncoding() == null && soapPart.getSourceCharsetEncoding() != null) {
152 is.setEncoding(soapPart.getSourceCharsetEncoding());
153 }
154 XMLReader rejectFilter;
155 try {
156 rejectFilter = new RejectDoctypeSaxFilter(saxParser);
157 } catch (Exception ex) {
158 log.severe("SAAJ0510.soap.cannot.create.envelope");
159 throw new SOAPExceptionImpl(
160 "Unable to create envelope from given source: ",
161 ex);
162 }
163 src = new SAXSource(rejectFilter, is);
164 }
165
166 try {
167 Transformer transformer =
168 EfficientStreamingTransformer.newTransformer();
169 DOMResult result = new DOMResult(soapPart);
170 transformer.transform(src, result);
171
|
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 com.sun.xml.internal.messaging.saaj.LazyEnvelopeSource;
29 import com.sun.xml.internal.messaging.saaj.SOAPExceptionImpl;
30 import com.sun.xml.internal.messaging.saaj.util.JAXMStreamSource;
31 import com.sun.xml.internal.messaging.saaj.util.LogDomainConstants;
32 import com.sun.xml.internal.messaging.saaj.util.ParserPool;
33 import com.sun.xml.internal.messaging.saaj.util.RejectDoctypeSaxFilter;
34 import com.sun.xml.internal.messaging.saaj.util.transform.EfficientStreamingTransformer;
35 import org.xml.sax.InputSource;
36 import org.xml.sax.XMLReader;
37
38 import javax.xml.parsers.SAXParser;
39 import javax.xml.soap.SOAPException;
40 import javax.xml.stream.XMLInputFactory;
41 import javax.xml.stream.XMLStreamException;
42 import javax.xml.stream.XMLStreamReader;
43 import javax.xml.transform.Source;
44 import javax.xml.transform.Transformer;
45 import javax.xml.transform.dom.DOMResult;
46 import javax.xml.transform.sax.SAXSource;
47 import javax.xml.transform.stax.StAXSource;
48 import javax.xml.transform.stream.StreamSource;
49 import java.util.logging.Logger;
50
51 /**
52 * EnvelopeFactory creates SOAP Envelope objects using different
53 * underlying implementations.
54 */
55 public class EnvelopeFactory {
56
57 protected static final Logger
58 log = Logger.getLogger(LogDomainConstants.SOAP_DOMAIN,
59 "com.sun.xml.internal.messaging.saaj.soap.LocalStrings");
60
61 private static ContextClassloaderLocal<ParserPool> parserPool =
62 new ContextClassloaderLocal<ParserPool>() {
63 @Override
64 protected ParserPool initialValue() throws Exception {
65 return new ParserPool(5);
66 }
67 };
68
128 return env;
129 } catch (Exception e) {
130 throw new SOAPException(e);
131 }
132 }
133 private static Envelope parseEnvelopeSax(Source src, SOAPPartImpl soapPart)
134 throws SOAPException {
135 // Insert SAX filter to disallow Document Type Declarations since
136 // they are not legal in SOAP
137 SAXParser saxParser = null;
138 if (src instanceof StreamSource) {
139 try {
140 saxParser = parserPool.get().get();
141 } catch (Exception e) {
142 log.severe("SAAJ0601.util.newSAXParser.exception");
143 throw new SOAPExceptionImpl(
144 "Couldn't get a SAX parser while constructing a envelope",
145 e);
146 }
147 InputSource is = SAXSource.sourceToInputSource(src);
148 if (is.getEncoding()== null && soapPart.getSourceCharsetEncoding() != null) {
149 is.setEncoding(soapPart.getSourceCharsetEncoding());
150 }
151 XMLReader rejectFilter;
152 try {
153 rejectFilter = new RejectDoctypeSaxFilter(saxParser);
154 } catch (Exception ex) {
155 log.severe("SAAJ0510.soap.cannot.create.envelope");
156 throw new SOAPExceptionImpl(
157 "Unable to create envelope from given source: ",
158 ex);
159 }
160 src = new SAXSource(rejectFilter, is);
161 }
162
163 try {
164 Transformer transformer =
165 EfficientStreamingTransformer.newTransformer();
166 DOMResult result = new DOMResult(soapPart);
167 transformer.transform(src, result);
168
|