1 /*
2 * Copyright 2006 the original author or authors.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 package org.springframework.ws.soap;
18
19 import javax.xml.transform.Result;
20 import javax.xml.transform.Source;
21
22 import org.springframework.ws.mime.AbstractMimeMessage;
23
24 /**
25 * Abstract implementation of the {@link SoapMessage} interface. Contains convenient default implementations.
26 *
27 * @author Arjen Poutsma
28 * @since 1.0.0
29 */
30 public abstract class AbstractSoapMessage extends AbstractMimeMessage implements SoapMessage {
31
32 private SoapVersion version;
33
34 /** Returns <code>getEnvelope().getBody()</code>. */
35 public final SoapBody getSoapBody() {
36 return getEnvelope().getBody();
37 }
38
39 /** Returns <code>getEnvelope().getHeader()</code>. */
40 public final SoapHeader getSoapHeader() {
41 return getEnvelope().getHeader();
42 }
43
44 /** Returns <code>getSoapBody().getPayloadSource()</code>. */
45 public final Source getPayloadSource() {
46 return getSoapBody().getPayloadSource();
47 }
48
49 /** Returns <code>getSoapBody().getPayloadResult()</code>. */
50 public final Result getPayloadResult() {
51 return getSoapBody().getPayloadResult();
52 }
53
54 /** Returns <code>getSoapBody().hasFault()</code>. */
55 public final boolean hasFault() {
56 return getSoapBody().hasFault();
57 }
58
59 /** Returns <code>getSoapBody().getFault().getFaultStringOrReason()</code>. */
60 public final String getFaultReason() {
61 if (hasFault()) {
62 return getSoapBody().getFault().getFaultStringOrReason();
63 }
64 else {
65 return null;
66 }
67 }
68
69 public SoapVersion getVersion() {
70 if (version == null) {
71 String envelopeNamespace = getEnvelope().getName().getNamespaceURI();
72 if (SoapVersion.SOAP_11.getEnvelopeNamespaceUri().equals(envelopeNamespace)) {
73 version = SoapVersion.SOAP_11;
74 }
75 else if (SoapVersion.SOAP_12.getEnvelopeNamespaceUri().equals(envelopeNamespace)) {
76 version = SoapVersion.SOAP_12;
77 }
78 else {
79 throw new IllegalStateException(
80 "Unknown Envelope namespace uri '" + envelopeNamespace + "'. " + "Cannot deduce SoapVersion.");
81 }
82 }
83 return version;
84 }
85 }