1
2
3
4
5
6
7
8
9
10
11
12
13
14
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.SoapFault;
27 import org.springframework.ws.soap.SoapVersion;
28 import org.springframework.ws.soap.soap11.Soap11Body;
29 import org.springframework.ws.soap.soap11.Soap11Fault;
30
31
32
33
34
35
36
37 class SaajSoap11Body extends SaajSoapBody implements Soap11Body {
38
39 private final boolean langAttributeOnSoap11FaultString;
40
41 SaajSoap11Body(SOAPBody body, boolean langAttributeOnSoap11FaultString) {
42 super(body);
43 this.langAttributeOnSoap11FaultString = langAttributeOnSoap11FaultString;
44 }
45
46 public SoapFault getFault() {
47 SOAPFault fault = getImplementation().getFault(getSaajBody());
48 return fault != null ? new SaajSoap11Fault(fault) : null;
49 }
50
51 public Soap11Fault addFault(QName faultCode, String faultString, Locale faultStringLocale) {
52 Assert.notNull(faultCode, "No faultCode given");
53 Assert.hasLength(faultString, "faultString cannot be empty");
54 Assert.hasLength(faultCode.getLocalPart(), "faultCode's localPart cannot be empty");
55 Assert.hasLength(faultCode.getNamespaceURI(), "faultCode's namespaceUri cannot be empty");
56 if (!langAttributeOnSoap11FaultString) {
57 faultStringLocale = null;
58 }
59 try {
60 getImplementation().removeContents(getSaajBody());
61 SOAPFault saajFault =
62 getImplementation().addFault(getSaajBody(), faultCode, faultString, faultStringLocale);
63 return new SaajSoap11Fault(saajFault);
64 }
65 catch (SOAPException ex) {
66 throw new SaajSoapFaultException(ex);
67 }
68 }
69
70 public SoapFault addClientOrSenderFault(String faultString, Locale locale) {
71 return addFault(SoapVersion.SOAP_11.getClientOrSenderFaultName(), faultString, locale);
72 }
73
74 public SoapFault addMustUnderstandFault(String faultString, Locale locale) {
75 return addFault(SoapVersion.SOAP_11.getMustUnderstandFaultName(), faultString, locale);
76 }
77
78 public SoapFault addServerOrReceiverFault(String faultString, Locale locale) {
79 return addFault(SoapVersion.SOAP_11.getServerOrReceiverFaultName(), faultString, locale);
80 }
81
82 public SoapFault addVersionMismatchFault(String faultString, Locale locale) {
83 return addFault(SoapVersion.SOAP_11.getVersionMismatchFaultName(), faultString, locale);
84 }
85
86 }