1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.springframework.ws.server.endpoint.mapping;
18
19 import java.util.ArrayList;
20 import java.util.Arrays;
21 import java.util.List;
22 import java.util.Map;
23
24 import org.springframework.beans.BeansException;
25 import org.springframework.beans.factory.BeanFactoryUtils;
26 import org.springframework.context.support.ApplicationObjectSupport;
27 import org.springframework.core.Ordered;
28 import org.springframework.ws.context.MessageContext;
29 import org.springframework.ws.server.EndpointInterceptor;
30 import org.springframework.ws.server.EndpointInvocationChain;
31 import org.springframework.ws.server.EndpointMapping;
32 import org.springframework.ws.server.SmartEndpointInterceptor;
33
34
35
36
37
38
39
40
41
42 public abstract class AbstractEndpointMapping extends ApplicationObjectSupport implements EndpointMapping, Ordered {
43
44 private int order = Integer.MAX_VALUE;
45
46 private Object defaultEndpoint;
47
48 private EndpointInterceptor[] interceptors;
49
50 private SmartEndpointInterceptor[] smartInterceptors;
51
52
53
54
55
56
57 public EndpointInterceptor[] getInterceptors() {
58 return interceptors;
59 }
60
61
62
63
64
65
66 public final void setInterceptors(EndpointInterceptor[] interceptors) {
67 this.interceptors = interceptors;
68 }
69
70 public final int getOrder() {
71 return order;
72 }
73
74
75
76
77
78
79
80
81 public final void setOrder(int order) {
82 this.order = order;
83 }
84
85
86
87
88
89
90 @Override
91 protected void initApplicationContext() throws BeansException {
92 initInterceptors();
93 }
94
95
96
97
98
99
100 protected void initInterceptors() {
101 Map<String, SmartEndpointInterceptor> smartInterceptors = BeanFactoryUtils
102 .beansOfTypeIncludingAncestors(getApplicationContext(), SmartEndpointInterceptor.class, true, false);
103 if (!smartInterceptors.isEmpty()) {
104 this.smartInterceptors =
105 smartInterceptors.values().toArray(new SmartEndpointInterceptor[smartInterceptors.size()]);
106 }
107 }
108
109
110
111
112
113
114
115
116 public final EndpointInvocationChain getEndpoint(MessageContext messageContext) throws Exception {
117 Object endpoint = getEndpointInternal(messageContext);
118 if (endpoint == null) {
119 endpoint = defaultEndpoint;
120 }
121 if (endpoint == null) {
122 return null;
123 }
124 if (endpoint instanceof String) {
125 String endpointName = (String) endpoint;
126 endpoint = resolveStringEndpoint(endpointName);
127 if (endpoint == null) {
128 return null;
129 }
130 }
131
132 List<EndpointInterceptor> interceptors = new ArrayList<EndpointInterceptor>();
133 if (this.interceptors != null) {
134 interceptors.addAll(Arrays.asList(this.interceptors));
135 }
136
137 if (this.smartInterceptors != null) {
138 for (SmartEndpointInterceptor smartInterceptor : smartInterceptors) {
139 if (smartInterceptor.shouldIntercept(messageContext, endpoint)) {
140 interceptors.add(smartInterceptor);
141 }
142 }
143 }
144
145 return createEndpointInvocationChain(messageContext, endpoint,
146 interceptors.toArray(new EndpointInterceptor[interceptors.size()]));
147 }
148
149
150
151
152
153
154
155
156
157
158
159 protected EndpointInvocationChain createEndpointInvocationChain(MessageContext messageContext,
160 Object endpoint,
161 EndpointInterceptor[] interceptors) {
162 return new EndpointInvocationChain(endpoint, interceptors);
163 }
164
165
166
167
168
169
170 protected final Object getDefaultEndpoint() {
171 return defaultEndpoint;
172 }
173
174
175
176
177
178
179
180
181
182 public final void setDefaultEndpoint(Object defaultEndpoint) {
183 this.defaultEndpoint = defaultEndpoint;
184 }
185
186
187
188
189
190
191
192
193 protected Object resolveStringEndpoint(String endpointName) {
194 if (getApplicationContext().containsBean(endpointName)) {
195 return getApplicationContext().getBean(endpointName);
196 }
197 else {
198 return null;
199 }
200 }
201
202
203
204
205
206
207
208
209
210
211
212
213 protected abstract Object getEndpointInternal(MessageContext messageContext) throws Exception;
214 }