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.SoapVersion;
27 import org.springframework.ws.soap.soap12.Soap12Body;
28 import org.springframework.ws.soap.soap12.Soap12Fault;
29
30
31
32
33
34
35
36 class SaajSoap12Body extends SaajSoapBody implements Soap12Body {
37
38 SaajSoap12Body(SOAPBody body) {
39 super(body);
40 }
41
42 public Soap12Fault getFault() {
43 SOAPFault fault = getImplementation().getFault(getSaajBody());
44 return fault != null ? new SaajSoap12Fault(fault) : null;
45 }
46
47 public Soap12Fault addClientOrSenderFault(String faultString, Locale locale) {
48 return addFault(SoapVersion.SOAP_12.getClientOrSenderFaultName(), faultString, locale);
49 }
50
51 public Soap12Fault addMustUnderstandFault(String faultString, Locale locale) {
52 return addFault(SoapVersion.SOAP_12.getMustUnderstandFaultName(), faultString, locale);
53 }
54
55 public Soap12Fault addServerOrReceiverFault(String faultString, Locale locale) {
56 return addFault(SoapVersion.SOAP_12.getServerOrReceiverFaultName(), faultString, locale);
57 }
58
59 public Soap12Fault addVersionMismatchFault(String faultString, Locale locale) {
60 return addFault(SoapVersion.SOAP_12.getVersionMismatchFaultName(), faultString, locale);
61 }
62
63 public Soap12Fault addDataEncodingUnknownFault(QName[] subcodes, String reason, Locale locale) {
64 QName name = new QName(SoapVersion.SOAP_12.getEnvelopeNamespaceUri(), "DataEncodingUnknown");
65 Soap12Fault fault = addFault(name, reason, locale);
66 for (QName subcode : subcodes) {
67 fault.addFaultSubcode(subcode);
68 }
69 return fault;
70 }
71
72 protected Soap12Fault addFault(QName faultCode, String faultString, Locale faultStringLocale) {
73 Assert.notNull(faultCode, "No faultCode given");
74 Assert.hasLength(faultString, "faultString cannot be empty");
75 Assert.hasLength(faultCode.getLocalPart(), "faultCode's localPart cannot be empty");
76 Assert.hasLength(faultCode.getNamespaceURI(), "faultCode's namespaceUri cannot be empty");
77 try {
78 getImplementation().removeContents(getSaajBody());
79 SOAPFault saajFault =
80 getImplementation().addFault(getSaajBody(), faultCode, faultString, faultStringLocale);
81 return new SaajSoap12Fault(saajFault);
82 }
83 catch (SOAPException ex) {
84 throw new SaajSoapFaultException(ex);
85 }
86 }
87
88 }