1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.springframework.ws.soap.axiom;
18
19 import java.util.Locale;
20 import javax.xml.namespace.QName;
21
22 import org.springframework.util.Assert;
23 import org.springframework.ws.soap.axiom.support.AxiomUtils;
24 import org.springframework.ws.soap.soap12.Soap12Body;
25 import org.springframework.ws.soap.soap12.Soap12Fault;
26
27 import org.apache.axiom.soap.SOAP12Constants;
28 import org.apache.axiom.soap.SOAPBody;
29 import org.apache.axiom.soap.SOAPFactory;
30 import org.apache.axiom.soap.SOAPFault;
31 import org.apache.axiom.soap.SOAPFaultCode;
32 import org.apache.axiom.soap.SOAPFaultReason;
33 import org.apache.axiom.soap.SOAPFaultText;
34 import org.apache.axiom.soap.SOAPFaultValue;
35 import org.apache.axiom.soap.SOAPProcessingException;
36
37
38
39
40
41
42
43 class AxiomSoap12Body extends AxiomSoapBody implements Soap12Body {
44
45 AxiomSoap12Body(SOAPBody axiomBody, SOAPFactory axiomFactory, boolean payloadCaching) {
46 super(axiomBody, axiomFactory, payloadCaching);
47 }
48
49 public Soap12Fault addMustUnderstandFault(String reason, Locale locale) {
50 Assert.notNull(locale, "No locale given");
51 SOAPFault fault = addStandardFault(SOAP12Constants.FAULT_CODE_MUST_UNDERSTAND, reason, locale);
52 return new AxiomSoap12Fault(fault, getAxiomFactory());
53 }
54
55 public Soap12Fault addClientOrSenderFault(String reason, Locale locale) {
56 Assert.notNull(locale, "No locale given");
57 SOAPFault fault = addStandardFault(SOAP12Constants.FAULT_CODE_SENDER, reason, locale);
58 return new AxiomSoap12Fault(fault, getAxiomFactory());
59 }
60
61 public Soap12Fault addServerOrReceiverFault(String reason, Locale locale) {
62 Assert.notNull(locale, "No locale given");
63 SOAPFault fault = addStandardFault(SOAP12Constants.FAULT_CODE_RECEIVER, reason, locale);
64 return new AxiomSoap12Fault(fault, getAxiomFactory());
65 }
66
67 public Soap12Fault addVersionMismatchFault(String reason, Locale locale) {
68 Assert.notNull(locale, "No locale given");
69 SOAPFault fault = addStandardFault(SOAP12Constants.FAULT_CODE_VERSION_MISMATCH, reason, locale);
70 return new AxiomSoap12Fault(fault, getAxiomFactory());
71 }
72
73 public Soap12Fault addDataEncodingUnknownFault(QName[] subcodes, String reason, Locale locale) {
74 Assert.notNull(locale, "No locale given");
75 SOAPFault fault = addStandardFault(SOAP12Constants.FAULT_CODE_DATA_ENCODING_UNKNOWN, reason, locale);
76 return new AxiomSoap12Fault(fault, getAxiomFactory());
77 }
78
79 private SOAPFault addStandardFault(String localName, String faultStringOrReason, Locale locale) {
80 Assert.notNull(faultStringOrReason, "No faultStringOrReason given");
81 try {
82 AxiomUtils.removeContents(getAxiomBody());
83 SOAPFault fault = getAxiomFactory().createSOAPFault(getAxiomBody());
84 SOAPFaultCode code = getAxiomFactory().createSOAPFaultCode(fault);
85 SOAPFaultValue value = getAxiomFactory().createSOAPFaultValue(code);
86 value.setText(fault.getNamespace().getPrefix() + ":" + localName);
87 SOAPFaultReason reason = getAxiomFactory().createSOAPFaultReason(fault);
88 SOAPFaultText text = getAxiomFactory().createSOAPFaultText(reason);
89 if (locale != null) {
90 text.setLang(AxiomUtils.toLanguage(locale));
91 }
92 text.setText(faultStringOrReason);
93 return fault;
94 }
95 catch (SOAPProcessingException ex) {
96 throw new AxiomSoapFaultException(ex);
97 }
98 }
99
100 public Soap12Fault getFault() {
101 SOAPFault axiomFault = getAxiomBody().getFault();
102 return axiomFault != null ? new AxiomSoap12Fault(axiomFault, getAxiomFactory()) : null;
103 }
104
105 }