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.OMAbstractFactory;
23: import org.apache.axiom.om.OMElement;
24: import org.apache.axiom.om.impl.OMNodeEx;
25: import org.apache.axiom.om.impl.builder.StAXBuilder;
26: import org.apache.axiom.soap.SOAPBody;
27: import org.apache.axiom.soap.SOAPEnvelope;
28: import org.apache.axiom.soap.SOAPFactory;
29: import org.apache.axis2.AxisFault;
30: import org.apache.axis2.Constants;
31: import org.apache.axis2.context.MessageContext;
32:
33: import javax.xml.stream.XMLStreamException;
34: import java.io.IOException;
35: import java.io.InputStream;
36: import java.io.PushbackInputStream;
37:
38: /**
39: * This builder is used when the serialization of the message is application/xml.
40: */
41: public class ApplicationXMLBuilder implements Builder {
42:
43: /**
44: * @return Returns the document element.
45: */
46: public OMElement processDocument(InputStream inputStream,
47: String contentType, MessageContext messageContext)
48: throws AxisFault {
49: SOAPFactory soapFactory = OMAbstractFactory.getSOAP11Factory();
50: SOAPEnvelope soapEnvelope = soapFactory.getDefaultEnvelope();
51: if (inputStream != null) {
52: try {
53: PushbackInputStream pushbackInputStream = new PushbackInputStream(
54: inputStream);
55: int b;
56: if ((b = pushbackInputStream.read()) > 0) {
57: pushbackInputStream.unread(b);
58: StAXBuilder builder = BuilderUtil
59: .getPOXBuilder(
60: pushbackInputStream,
61: (String) messageContext
62: .getProperty(Constants.Configuration.CHARACTER_SET_ENCODING));
63: OMNodeEx documentElement = (OMNodeEx) builder
64: .getDocumentElement();
65: documentElement.setParent(null);
66: SOAPBody body = soapEnvelope.getBody();
67: body.addChild(documentElement);
68: }
69:
70: } catch (XMLStreamException e) {
71: throw AxisFault.makeFault(e);
72: } catch (IOException e) {
73: throw AxisFault.makeFault(e);
74: }
75: }
76: return soapEnvelope;
77: }
78:
79: }
|