1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.apache.axis.message.addressing;
17
18 import javax.xml.namespace.QName;
19 import javax.xml.soap.SOAPException;
20
21 import org.apache.axis.AxisFault;
22 import org.apache.axis.MessageContext;
23 import org.apache.axis.message.MessageElement;
24 import org.apache.axis.message.SOAPHeaderElement;
25 import org.apache.axis.soap.SOAPConstants;
26
27
28
29
30
31
32
33
34 public class AddressingHeaderFault extends AxisFault {
35
36
37
38
39 private static final long serialVersionUID = -7037754917195807959L;
40
41
42
43
44 private static final String NS = Constants.NS_URI_ADDRESSING_2005_08;
45
46
47
48
49 private static final QName INVALID_ADDRESSING_HEADER = new QName(NS,
50 "InvalidAddressingHeader");
51
52
53
54
55 public static final QName INVALID_ADDRESS = new QName(NS, "InvalidAddress");
56
57
58
59
60 public static final QName INVALID_CARDINALITY = new QName(NS, "InvalidCardinality");
61
62
63
64
65 public static final QName HEADER_REQUIRED = new QName(NS,
66 "MessageAddressingHeaderRequired");
67
68
69
70
71 public static final QName INVALID_EPR = new QName(NS, "InvalidEPR");
72
73
74
75
76 public static final QName MISSING_ADDRESS = new QName(NS, "MissingAddressInEPR");
77
78
79
80
81 public static final QName DUPLICATE_MSGID = new QName(NS, "DuplicateMessageID");
82
83
84
85
86 public static final QName ACTION_MISMATCH = new QName(NS, "ActionMismatch");
87
88
89
90
91 public static final QName PROBLEM_HEADER = new QName(NS, "ProblemHeaderQName");
92
93
94
95
96 public static final QName FAULT_DETAIL = new QName(NS, "FaultDetail");
97
98
99
100
101
102
103 public AddressingHeaderFault(String faultString) {
104 this(faultString, null, null);
105 }
106
107
108
109
110
111
112
113 public AddressingHeaderFault(QName subSubCode, String problemHeader) {
114 this(buildMessage(subSubCode, problemHeader), subSubCode, problemHeader);
115 }
116
117
118
119
120
121
122
123
124 public AddressingHeaderFault(String faultString, QName subSubCode,
125 String problemHeader) {
126 MessageContext mc = MessageContext.getCurrentContext();
127
128 if (mc == null || mc.getSOAPConstants() == SOAPConstants.SOAP12_CONSTANTS) {
129 this.setFaultCode(org.apache.axis.Constants.FAULT_SOAP12_SENDER);
130 if (HEADER_REQUIRED.equals(subSubCode)) {
131 this.addFaultSubCode(HEADER_REQUIRED);
132 } else {
133 this.addFaultSubCode(INVALID_ADDRESSING_HEADER);
134 if (subSubCode != null) {
135 this.addFaultSubCode(subSubCode);
136 }
137 }
138
139 if (problemHeader != null) {
140 this.addFaultDetail(PROBLEM_HEADER, "wsa:" + problemHeader);
141 }
142 } else {
143 if (subSubCode != null && subSubCode.equals(HEADER_REQUIRED)) {
144 this.setFaultCode(HEADER_REQUIRED);
145 } else {
146 this.setFaultCode(INVALID_ADDRESSING_HEADER);
147 }
148
149 if (problemHeader != null) {
150 try {
151 SOAPHeaderElement detailHeader = new SOAPHeaderElement(FAULT_DETAIL);
152 MessageElement problemEl = new MessageElement(PROBLEM_HEADER, "wsa:"
153 + problemHeader);
154 detailHeader.addChild(problemEl);
155 this.addHeader(detailHeader);
156 } catch (SOAPException e) {
157
158 log.error(e);
159 }
160 }
161 }
162
163 this.setFaultString(faultString);
164 }
165
166
167
168
169
170
171
172 public AddressingHeaderFault(String faultString, String problemHeader) {
173 this(faultString, null, problemHeader);
174 }
175
176
177
178
179
180
181
182
183 private static String buildMessage(QName code, String header) {
184 String localName = (code == null) ? INVALID_ADDRESSING_HEADER.getLocalPart()
185 : code.getLocalPart();
186 if ("InvalidCardinality".equals(localName)) {
187 return "Duplicate " + header + " header";
188 } else {
189 return "Error in " + header + " header";
190 }
191 }
192 }