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 java.util.Locale;
20  import javax.xml.namespace.QName;
21  import javax.xml.soap.SOAPBody;
22  import javax.xml.soap.SOAPException;
23  import javax.xml.soap.SOAPFault;
24  
25  import org.springframework.util.Assert;
26  import org.springframework.ws.soap.SoapVersion;
27  import org.springframework.ws.soap.soap11.Soap11Body;
28  import org.springframework.ws.soap.soap11.Soap11Fault;
29  
30  /**
31   * SAAJ-specific implementation of the <code>Soap11Body</code> interface. Wraps a {@link javax.xml.soap.SOAPBody}.
32   *
33   * @author Arjen Poutsma
34   * @since 1.0.0
35   */
36  class SaajSoap11Body extends SaajSoapBody implements Soap11Body {
37  
38      private final boolean langAttributeOnSoap11FaultString;
39  
40      SaajSoap11Body(SOAPBody body, boolean langAttributeOnSoap11FaultString) {
41          super(body);
42          this.langAttributeOnSoap11FaultString = langAttributeOnSoap11FaultString;
43      }
44  
45      public Soap11Fault getFault() {
46          SOAPFault fault = getImplementation().getFault(getSaajBody());
47          return fault != null ? new SaajSoap11Fault(fault) : null;
48      }
49  
50      public Soap11Fault addFault(QName faultCode, String faultString, Locale faultStringLocale) {
51          Assert.notNull(faultCode, "No faultCode given");
52          Assert.hasLength(faultString, "faultString cannot be empty");
53          Assert.hasLength(faultCode.getLocalPart(), "faultCode's localPart cannot be empty");
54          Assert.hasLength(faultCode.getNamespaceURI(), "faultCode's namespaceUri cannot be empty");
55          if (!langAttributeOnSoap11FaultString) {
56              faultStringLocale = null;
57          }
58          try {
59              getImplementation().removeContents(getSaajBody());
60              SOAPFault saajFault =
61                      getImplementation().addFault(getSaajBody(), faultCode, faultString, faultStringLocale);
62              return new SaajSoap11Fault(saajFault);
63          }
64          catch (SOAPException ex) {
65              throw new SaajSoapFaultException(ex);
66          }
67      }
68  
69      public Soap11Fault addClientOrSenderFault(String faultString, Locale locale) {
70          return addFault(SoapVersion.SOAP_11.getClientOrSenderFaultName(), faultString, locale);
71      }
72  
73      public Soap11Fault addMustUnderstandFault(String faultString, Locale locale) {
74          return addFault(SoapVersion.SOAP_11.getMustUnderstandFaultName(), faultString, locale);
75      }
76  
77      public Soap11Fault addServerOrReceiverFault(String faultString, Locale locale) {
78          return addFault(SoapVersion.SOAP_11.getServerOrReceiverFaultName(), faultString, locale);
79      }
80  
81      public Soap11Fault addVersionMismatchFault(String faultString, Locale locale) {
82          return addFault(SoapVersion.SOAP_11.getVersionMismatchFaultName(), faultString, locale);
83      }
84  
85  }