View Javadoc

1   /*
2    * Copyright 2005-2010 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.saaj;
18  
19  import javax.xml.soap.SOAPBody;
20  import javax.xml.soap.SOAPEnvelope;
21  import javax.xml.soap.SOAPException;
22  import javax.xml.soap.SOAPHeader;
23  
24  import org.springframework.ws.soap.SoapBody;
25  import org.springframework.ws.soap.SoapEnvelope;
26  import org.springframework.ws.soap.SoapHeader;
27  import org.springframework.ws.soap.SoapVersion;
28  
29  /**
30   * SAAJ-specific implementation of the <code>SoapEnvelope</code> interface. Wraps a {@link
31   * javax.xml.soap.SOAPEnvelope}.
32   *
33   * @author Arjen Poutsma
34   * @since 1.0.0
35   */
36  class SaajSoapEnvelope extends SaajSoapElement<SOAPEnvelope> implements SoapEnvelope {
37  
38      private SaajSoapBody body;
39  
40      private SaajSoapHeader header;
41  
42      private final boolean langAttributeOnSoap11FaultString;
43  
44      SaajSoapEnvelope(SOAPEnvelope element, boolean langAttributeOnSoap11FaultString) {
45          super(element);
46          this.langAttributeOnSoap11FaultString = langAttributeOnSoap11FaultString;
47      }
48  
49      public SoapBody getBody() {
50          if (body == null) {
51              try {
52                  SOAPBody saajBody = getImplementation().getBody(getSaajEnvelope());
53                  if (getImplementation().getName(saajBody).getNamespaceURI()
54                          .equals(SoapVersion.SOAP_11.getEnvelopeNamespaceUri())) {
55                      body = new SaajSoap11Body(saajBody, langAttributeOnSoap11FaultString);
56                  }
57                  else {
58                      body = new SaajSoap12Body(saajBody);
59                  }
60              }
61              catch (SOAPException ex) {
62                  throw new SaajSoapBodyException(ex);
63              }
64          }
65          return body;
66      }
67  
68      public SoapHeader getHeader() {
69          if (header == null) {
70              try {
71                  SOAPHeader saajHeader = getImplementation().getHeader(getSaajEnvelope());
72                  if (saajHeader != null) {
73                      if (getImplementation().getName(saajHeader).getNamespaceURI()
74                              .equals(SoapVersion.SOAP_11.getEnvelopeNamespaceUri())) {
75                          header = new SaajSoap11Header(saajHeader);
76                      }
77                      else {
78                          header = new SaajSoap12Header(saajHeader);
79                      }
80                  }
81                  else {
82                      header = null;
83                  }
84              }
85              catch (SOAPException ex) {
86                  throw new SaajSoapHeaderException(ex);
87              }
88          }
89          return header;
90      }
91  
92      protected SOAPEnvelope getSaajEnvelope() {
93          return getSaajElement();
94      }
95  
96  }