17
17
package org .springframework .ws .soap .addressing .server ;
18
18
19
19
import java .net .URI ;
20
+ import java .util .ArrayList ;
20
21
import java .util .Arrays ;
21
22
import java .util .Iterator ;
23
+ import java .util .List ;
24
+ import java .util .Map ;
22
25
import javax .xml .transform .TransformerException ;
23
26
27
+ import org .springframework .beans .BeansException ;
28
+ import org .springframework .beans .factory .BeanFactoryUtils ;
24
29
import org .springframework .beans .factory .InitializingBean ;
30
+ import org .springframework .context .ApplicationContext ;
31
+ import org .springframework .context .ApplicationContextAware ;
25
32
import org .springframework .core .Ordered ;
26
33
import org .springframework .util .Assert ;
27
34
import org .springframework .ws .context .MessageContext ;
28
35
import org .springframework .ws .server .EndpointInterceptor ;
29
36
import org .springframework .ws .server .EndpointInvocationChain ;
30
37
import org .springframework .ws .server .EndpointMapping ;
38
+ import org .springframework .ws .server .SmartEndpointInterceptor ;
31
39
import org .springframework .ws .soap .SoapHeader ;
32
40
import org .springframework .ws .soap .SoapHeaderElement ;
33
41
import org .springframework .ws .soap .SoapMessage ;
64
72
* @since 1.5.0
65
73
*/
66
74
public abstract class AbstractAddressingEndpointMapping extends TransformerObjectSupport
67
- implements SoapEndpointMapping , InitializingBean , Ordered {
75
+ implements SoapEndpointMapping , ApplicationContextAware , InitializingBean , Ordered {
68
76
69
77
private String [] actorsOrRoles ;
70
78
@@ -80,6 +88,11 @@ public abstract class AbstractAddressingEndpointMapping extends TransformerObjec
80
88
81
89
private EndpointInterceptor [] postInterceptors = new EndpointInterceptor [0 ];
82
90
91
+ private SmartEndpointInterceptor [] smartInterceptors =
92
+ new SmartEndpointInterceptor [0 ];
93
+
94
+ private ApplicationContext applicationContext ;
95
+
83
96
private int order = Integer .MAX_VALUE ; // default: same as non-Ordered
84
97
85
98
@@ -115,7 +128,17 @@ public final void setUltimateReceiver(boolean ultimateReceiver) {
115
128
this .isUltimateReceiver = ultimateReceiver ;
116
129
}
117
130
118
- @ Override
131
+ public ApplicationContext getApplicationContext () {
132
+ return applicationContext ;
133
+ }
134
+
135
+ @ Override
136
+ public void setApplicationContext (ApplicationContext applicationContext )
137
+ throws BeansException {
138
+ this .applicationContext = applicationContext ;
139
+ }
140
+
141
+ @ Override
119
142
public final int getOrder () {
120
143
return order ;
121
144
}
@@ -210,12 +233,21 @@ public final void setVersions(AddressingVersion[] versions) {
210
233
this .versions = versions ;
211
234
}
212
235
213
- @ Override
214
- public void afterPropertiesSet () throws Exception {
215
- if (logger .isInfoEnabled ()) {
216
- logger .info ("Supporting " + Arrays .asList (versions ));
217
- }
218
- }
236
+ @ Override
237
+ public void afterPropertiesSet () throws Exception {
238
+ if (logger .isInfoEnabled ()) {
239
+ logger .info ("Supporting " + Arrays .asList (versions ));
240
+ }
241
+ if (getApplicationContext () != null ) {
242
+ Map <String , SmartEndpointInterceptor > smartInterceptors = BeanFactoryUtils
243
+ .beansOfTypeIncludingAncestors (getApplicationContext (),
244
+ SmartEndpointInterceptor .class , true , false );
245
+ if (!smartInterceptors .isEmpty ()) {
246
+ this .smartInterceptors = smartInterceptors .values ()
247
+ .toArray (new SmartEndpointInterceptor [smartInterceptors .size ()]);
248
+ }
249
+ }
250
+ }
219
251
220
252
@ Override
221
253
public final EndpointInvocationChain getEndpoint (MessageContext messageContext ) throws TransformerException {
@@ -253,15 +285,17 @@ private EndpointInvocationChain getEndpointInvocationChain(Object endpoint,
253
285
WebServiceMessageSender [] messageSenders = getMessageSenders (endpoint );
254
286
MessageIdStrategy messageIdStrategy = getMessageIdStrategy (endpoint );
255
287
256
- EndpointInterceptor [] interceptors =
257
- new EndpointInterceptor [preInterceptors .length + postInterceptors .length +
258
- 1 ];
259
- System .arraycopy (preInterceptors , 0 , interceptors , 0 , preInterceptors .length );
260
- AddressingEndpointInterceptor interceptor = new AddressingEndpointInterceptor (version , messageIdStrategy ,
261
- messageSenders , responseAction , faultAction );
262
- interceptors [preInterceptors .length ] = interceptor ;
263
- System .arraycopy (postInterceptors , 0 , interceptors , preInterceptors .length + 1 , postInterceptors .length );
264
- return new SoapEndpointInvocationChain (endpoint , interceptors , actorsOrRoles , isUltimateReceiver );
288
+ List <EndpointInterceptor > interceptors = new ArrayList <EndpointInterceptor >(preInterceptors .length + postInterceptors .length + smartInterceptors .length + 1 );
289
+ AddressingEndpointInterceptor addressingInterceptor = new AddressingEndpointInterceptor (version , messageIdStrategy ,
290
+ messageSenders , responseAction , faultAction );
291
+
292
+ interceptors .addAll (Arrays .asList (preInterceptors ));
293
+ interceptors .add (addressingInterceptor );
294
+ interceptors .addAll (Arrays .asList (postInterceptors ));
295
+ interceptors .addAll (Arrays .asList (smartInterceptors ));
296
+
297
+ return new SoapEndpointInvocationChain (endpoint ,
298
+ interceptors .toArray (new EndpointInterceptor [interceptors .size ()]), actorsOrRoles , isUltimateReceiver );
265
299
}
266
300
267
301
private boolean supports (AddressingVersion version , SoapMessage request ) {
0 commit comments