01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one
03: * or more contributor license agreements. See the NOTICE file
04: * distributed with this work for additional information
05: * regarding copyright ownership. The ASF licenses this file
06: * to you under the Apache License, Version 2.0 (the
07: * "License"); you may not use this file except in compliance
08: * with the License. You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing,
13: * software distributed under the License is distributed on an
14: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15: * KIND, either express or implied. See the License for the
16: * specific language governing permissions and limitations
17: * under the License.
18: */
19:
20: package org.apache.axis2.builder;
21:
22: import org.apache.axiom.om.OMElement;
23: import org.apache.axiom.om.impl.builder.StAXBuilder;
24: import org.apache.axiom.om.util.StAXUtils;
25: import org.apache.axiom.soap.SOAPEnvelope;
26: import org.apache.axiom.soap.impl.builder.StAXSOAPModelBuilder;
27: import org.apache.axis2.AxisFault;
28: import org.apache.axis2.Constants;
29: import org.apache.axis2.context.MessageContext;
30:
31: import javax.xml.stream.XMLStreamException;
32: import javax.xml.stream.XMLStreamReader;
33: import java.io.IOException;
34: import java.io.InputStream;
35: import java.io.PushbackInputStream;
36:
37: public class SOAPBuilder implements Builder {
38:
39: public OMElement processDocument(InputStream inputStream,
40: String contentType, MessageContext messageContext)
41: throws AxisFault {
42: XMLStreamReader streamReader;
43: try {
44: String charSetEncoding = (String) messageContext
45: .getProperty(Constants.Configuration.CHARACTER_SET_ENCODING);
46:
47: // Get the actual encoding by looking at the BOM of the InputStream
48: PushbackInputStream pis = BuilderUtil
49: .getPushbackInputStream(inputStream);
50: String actualCharSetEncoding = BuilderUtil
51: .getCharSetEncoding(pis, charSetEncoding);
52:
53: // Get the XMLStreamReader for this input stream
54: streamReader = StAXUtils.createXMLStreamReader(pis,
55: actualCharSetEncoding);
56:
57: StAXBuilder builder = new StAXSOAPModelBuilder(streamReader);
58: SOAPEnvelope envelope = (SOAPEnvelope) builder
59: .getDocumentElement();
60: BuilderUtil.validateSOAPVersion(BuilderUtil
61: .getEnvelopeNamespace(contentType), envelope);
62: BuilderUtil.validateCharSetEncoding(charSetEncoding,
63: builder.getDocument().getCharsetEncoding(),
64: envelope.getNamespace().getNamespaceURI());
65: return envelope;
66: } catch (IOException e) {
67: throw AxisFault.makeFault(e);
68: } catch (XMLStreamException e) {
69: throw AxisFault.makeFault(e);
70: }
71: }
72: }
|