1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.springframework.ws.soap.server.endpoint;
18
19 import java.util.Iterator;
20 import java.util.Properties;
21
22 import org.springframework.util.CollectionUtils;
23
24
25
26
27
28
29
30
31 public class SoapFaultMappingExceptionResolver extends AbstractSoapFaultDefinitionExceptionResolver {
32
33 private Properties exceptionMappings;
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48 public void setExceptionMappings(Properties mappings) {
49 exceptionMappings = mappings;
50 }
51
52 protected SoapFaultDefinition getFaultDefinition(Object endpoint, Exception ex) {
53 if (!CollectionUtils.isEmpty(exceptionMappings)) {
54 String definitionText = null;
55 int deepest = Integer.MAX_VALUE;
56 for (Iterator iterator = exceptionMappings.keySet().iterator(); iterator.hasNext();) {
57 String exceptionMapping = (String) iterator.next();
58 int depth = getDepth(exceptionMapping, ex);
59 if (depth >= 0 && depth < deepest) {
60 deepest = depth;
61 definitionText = exceptionMappings.getProperty(exceptionMapping);
62 }
63 }
64 if (definitionText != null) {
65 SoapFaultDefinitionEditor editor = new SoapFaultDefinitionEditor();
66 editor.setAsText(definitionText);
67 return (SoapFaultDefinition) editor.getValue();
68 }
69 }
70 return null;
71 }
72
73
74
75
76
77
78
79 protected int getDepth(String exceptionMapping, Exception ex) {
80 return getDepth(exceptionMapping, ex.getClass(), 0);
81 }
82
83 private int getDepth(String exceptionMapping, Class exceptionClass, int depth) {
84 if (exceptionClass.getName().indexOf(exceptionMapping) != -1) {
85 return depth;
86 }
87 if (exceptionClass.equals(Throwable.class)) {
88 return -1;
89 }
90 return getDepth(exceptionMapping, exceptionClass.getSuperclass(), depth + 1);
91 }
92
93 }