1 /*
2 * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
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
103 EMPTY_ATTS = new AttributesImpl();
104 List<TagInfoset> tagList = new ArrayList<TagInfoset>();
105 create(SOAPVersion.SOAP_11, tagList);
106 create(SOAPVersion.SOAP_12, tagList);
107 DEFAULT_TAGS = Collections.unmodifiableList(tagList);
108 }
109
110 protected AbstractMessageImpl(SOAPVersion soapVersion) {
111 this.soapVersion = soapVersion;
112 }
113
114 @Override
115 public SOAPVersion getSOAPVersion() {
116 return soapVersion;
117 }
118 /**
119 * Copy constructor.
120 */
121 protected AbstractMessageImpl(AbstractMessageImpl that) {
122 this.soapVersion = that.soapVersion;
123 }
124
125 @Override
126 public Source readEnvelopeAsSource() {
127 return new SAXSource(new XMLReaderImpl(this), XMLReaderImpl.THE_SOURCE);
128 }
129
130 @Override
131 public <T> T readPayloadAsJAXB(Unmarshaller unmarshaller) throws JAXBException {
132 if(hasAttachments())
133 unmarshaller.setAttachmentUnmarshaller(new AttachmentUnmarshallerImpl(getAttachments()));
134 try {
135 return (T) unmarshaller.unmarshal(readPayloadAsSource());
136 } finally{
137 unmarshaller.setAttachmentUnmarshaller(null);
138 }
139 }
140 /** @deprecated */
141 @Override
142 public <T> T readPayloadAsJAXB(Bridge<T> bridge) throws JAXBException {
143 return bridge.unmarshal(readPayloadAsSource(),
144 hasAttachments()? new AttachmentUnmarshallerImpl(getAttachments()) : null );
145 }
146
147 @Override
148 public <T> T readPayloadAsJAXB(XMLBridge<T> bridge) throws JAXBException {
149 return bridge.unmarshal(readPayloadAsSource(),
150 hasAttachments()? new AttachmentUnmarshallerImpl(getAttachments()) : null );
151 }
152
153 /**
154 * Default implementation that relies on {@link #writePayloadTo(XMLStreamWriter)}
155 */
156 @Override
157 public void writeTo(XMLStreamWriter w) throws XMLStreamException {
158 String soapNsUri = soapVersion.nsUri;
159 w.writeStartDocument();
160 w.writeStartElement("S","Envelope",soapNsUri);
161 w.writeNamespace("S",soapNsUri);
162 if(hasHeaders()) {
163 w.writeStartElement("S","Header",soapNsUri);
164 MessageHeaders headers = getHeaders();
165 for (Header h : headers.asList()) {
166 h.writeTo(w);
167 }
168 w.writeEndElement();
169 }
170 // write the body
171 w.writeStartElement("S","Body",soapNsUri);
172
173 writePayloadTo(w);
174
175 w.writeEndElement();
176 w.writeEndElement();
177 w.writeEndDocument();
178 }
179
180 /**
181 * Writes the whole envelope as SAX events.
182 */
183 @Override
184 public void writeTo( ContentHandler contentHandler, ErrorHandler errorHandler ) throws SAXException {
185 String soapNsUri = soapVersion.nsUri;
186
187 contentHandler.setDocumentLocator(NULL_LOCATOR);
188 contentHandler.startDocument();
189 contentHandler.startPrefixMapping("S",soapNsUri);
190 contentHandler.startElement(soapNsUri,"Envelope","S:Envelope",EMPTY_ATTS);
191 if(hasHeaders()) {
192 contentHandler.startElement(soapNsUri,"Header","S:Header",EMPTY_ATTS);
|
1 /*
2 * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
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
103 EMPTY_ATTS = new AttributesImpl();
104 List<TagInfoset> tagList = new ArrayList<TagInfoset>();
105 create(SOAPVersion.SOAP_11, tagList);
106 create(SOAPVersion.SOAP_12, tagList);
107 DEFAULT_TAGS = Collections.unmodifiableList(tagList);
108 }
109
110 protected AbstractMessageImpl(SOAPVersion soapVersion) {
111 this.soapVersion = soapVersion;
112 }
113
114 @Override
115 public SOAPVersion getSOAPVersion() {
116 return soapVersion;
117 }
118 /**
119 * Copy constructor.
120 */
121 protected AbstractMessageImpl(AbstractMessageImpl that) {
122 this.soapVersion = that.soapVersion;
123 this.copyFrom(that);
124 }
125
126 @Override
127 public Source readEnvelopeAsSource() {
128 return new SAXSource(new XMLReaderImpl(this), XMLReaderImpl.THE_SOURCE);
129 }
130
131 @Override
132 public <T> T readPayloadAsJAXB(Unmarshaller unmarshaller) throws JAXBException {
133 if(hasAttachments())
134 unmarshaller.setAttachmentUnmarshaller(new AttachmentUnmarshallerImpl(getAttachments()));
135 try {
136 return (T) unmarshaller.unmarshal(readPayloadAsSource());
137 } finally{
138 unmarshaller.setAttachmentUnmarshaller(null);
139 }
140 }
141 /** @deprecated */
142 @Override
143 public <T> T readPayloadAsJAXB(Bridge<T> bridge) throws JAXBException {
144 return bridge.unmarshal(readPayloadAsSource(),
145 hasAttachments()? new AttachmentUnmarshallerImpl(getAttachments()) : null );
146 }
147
148 @Override
149 public <T> T readPayloadAsJAXB(XMLBridge<T> bridge) throws JAXBException {
150 return bridge.unmarshal(readPayloadAsSource(),
151 hasAttachments()? new AttachmentUnmarshallerImpl(getAttachments()) : null );
152 }
153
154 public void writeToBodyStart(XMLStreamWriter w) throws XMLStreamException {
155 String soapNsUri = soapVersion.nsUri;
156 w.writeStartDocument();
157 w.writeStartElement("S","Envelope",soapNsUri);
158 w.writeNamespace("S",soapNsUri);
159 if(hasHeaders()) {
160 w.writeStartElement("S","Header",soapNsUri);
161 MessageHeaders headers = getHeaders();
162 for (Header h : headers.asList()) {
163 h.writeTo(w);
164 }
165 w.writeEndElement();
166 }
167 // write the body
168 w.writeStartElement("S","Body",soapNsUri);
169 }
170
171 /**
172 * Default implementation that relies on {@link #writePayloadTo(XMLStreamWriter)}
173 */
174 @Override
175 public void writeTo(XMLStreamWriter w) throws XMLStreamException {
176 writeToBodyStart(w);
177 writePayloadTo(w);
178
179 w.writeEndElement();
180 w.writeEndElement();
181 w.writeEndDocument();
182 }
183
184 /**
185 * Writes the whole envelope as SAX events.
186 */
187 @Override
188 public void writeTo( ContentHandler contentHandler, ErrorHandler errorHandler ) throws SAXException {
189 String soapNsUri = soapVersion.nsUri;
190
191 contentHandler.setDocumentLocator(NULL_LOCATOR);
192 contentHandler.startDocument();
193 contentHandler.startPrefixMapping("S",soapNsUri);
194 contentHandler.startElement(soapNsUri,"Envelope","S:Envelope",EMPTY_ATTS);
195 if(hasHeaders()) {
196 contentHandler.startElement(soapNsUri,"Header","S:Header",EMPTY_ATTS);
|