Skip to content

Commit d43b880

Browse files
author
Arjen Poutsma
committed
WS-Addressing EMs support SmartEndpointInterceptor
All WS-Addressing EndpointsMappings now support endpoint interceptors registered via a <sws:interceptors/> block (i.e. SmartEndpointInteceptors). Issue: SWS-874
1 parent bbc6bf5 commit d43b880

File tree

3 files changed

+79
-64
lines changed

3 files changed

+79
-64
lines changed

spring-ws-core/src/main/java/org/springframework/ws/soap/addressing/server/AbstractActionEndpointMapping.java

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@
2121
import java.util.Map;
2222

2323
import org.springframework.beans.BeansException;
24-
import org.springframework.context.ApplicationContext;
25-
import org.springframework.context.ApplicationContextAware;
2624
import org.springframework.util.Assert;
2725
import org.springframework.ws.soap.addressing.core.MessageAddressingProperties;
2826

@@ -37,8 +35,7 @@
3735
* @author Arjen Poutsma
3836
* @since 1.5.0
3937
*/
40-
public abstract class AbstractActionEndpointMapping extends AbstractAddressingEndpointMapping
41-
implements ApplicationContextAware {
38+
public abstract class AbstractActionEndpointMapping extends AbstractAddressingEndpointMapping {
4239

4340
/** The defaults suffix to add to the request {@code Action} for reply messages. */
4441
public static final String DEFAULT_OUTPUT_ACTION_SUFFIX = "Response";
@@ -53,7 +50,6 @@ public abstract class AbstractActionEndpointMapping extends AbstractAddressingEn
5350

5451
private String faultActionSuffix = DEFAULT_OUTPUT_ACTION_SUFFIX;
5552

56-
private ApplicationContext applicationContext;
5753

5854
/** Returns the suffix to add to request {@code Action}s for reply messages. */
5955
public String getOutputActionSuffix() {
@@ -85,11 +81,6 @@ public void setFaultActionSuffix(String faultActionSuffix) {
8581
this.faultActionSuffix = faultActionSuffix;
8682
}
8783

88-
@Override
89-
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
90-
this.applicationContext = applicationContext;
91-
}
92-
9384
@Override
9485
protected final Object getEndpointInternal(MessageAddressingProperties map) {
9586
URI action = map.getAction();
@@ -143,8 +134,8 @@ protected void registerEndpoint(URI action, Object endpoint) throws BeansExcepti
143134

144135
if (endpoint instanceof String) {
145136
String endpointName = (String) endpoint;
146-
if (applicationContext.isSingleton(endpointName)) {
147-
resolvedEndpoint = applicationContext.getBean(endpointName);
137+
if (getApplicationContext().isSingleton(endpointName)) {
138+
resolvedEndpoint = getApplicationContext().getBean(endpointName);
148139
}
149140
}
150141
Object mappedEndpoint = this.endpointMap.get(action);

spring-ws-core/src/main/java/org/springframework/ws/soap/addressing/server/AbstractAddressingEndpointMapping.java

Lines changed: 51 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,25 @@
1717
package org.springframework.ws.soap.addressing.server;
1818

1919
import java.net.URI;
20+
import java.util.ArrayList;
2021
import java.util.Arrays;
2122
import java.util.Iterator;
23+
import java.util.List;
24+
import java.util.Map;
2225
import javax.xml.transform.TransformerException;
2326

27+
import org.springframework.beans.BeansException;
28+
import org.springframework.beans.factory.BeanFactoryUtils;
2429
import org.springframework.beans.factory.InitializingBean;
30+
import org.springframework.context.ApplicationContext;
31+
import org.springframework.context.ApplicationContextAware;
2532
import org.springframework.core.Ordered;
2633
import org.springframework.util.Assert;
2734
import org.springframework.ws.context.MessageContext;
2835
import org.springframework.ws.server.EndpointInterceptor;
2936
import org.springframework.ws.server.EndpointInvocationChain;
3037
import org.springframework.ws.server.EndpointMapping;
38+
import org.springframework.ws.server.SmartEndpointInterceptor;
3139
import org.springframework.ws.soap.SoapHeader;
3240
import org.springframework.ws.soap.SoapHeaderElement;
3341
import org.springframework.ws.soap.SoapMessage;
@@ -64,7 +72,7 @@
6472
* @since 1.5.0
6573
*/
6674
public abstract class AbstractAddressingEndpointMapping extends TransformerObjectSupport
67-
implements SoapEndpointMapping, InitializingBean, Ordered {
75+
implements SoapEndpointMapping, ApplicationContextAware, InitializingBean, Ordered {
6876

6977
private String[] actorsOrRoles;
7078

@@ -80,6 +88,11 @@ public abstract class AbstractAddressingEndpointMapping extends TransformerObjec
8088

8189
private EndpointInterceptor[] postInterceptors = new EndpointInterceptor[0];
8290

91+
private SmartEndpointInterceptor[] smartInterceptors =
92+
new SmartEndpointInterceptor[0];
93+
94+
private ApplicationContext applicationContext;
95+
8396
private int order = Integer.MAX_VALUE; // default: same as non-Ordered
8497

8598

@@ -115,7 +128,17 @@ public final void setUltimateReceiver(boolean ultimateReceiver) {
115128
this.isUltimateReceiver = ultimateReceiver;
116129
}
117130

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
119142
public final int getOrder() {
120143
return order;
121144
}
@@ -210,12 +233,21 @@ public final void setVersions(AddressingVersion[] versions) {
210233
this.versions = versions;
211234
}
212235

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+
}
219251

220252
@Override
221253
public final EndpointInvocationChain getEndpoint(MessageContext messageContext) throws TransformerException {
@@ -253,15 +285,17 @@ private EndpointInvocationChain getEndpointInvocationChain(Object endpoint,
253285
WebServiceMessageSender[] messageSenders = getMessageSenders(endpoint);
254286
MessageIdStrategy messageIdStrategy = getMessageIdStrategy(endpoint);
255287

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);
265299
}
266300

267301
private boolean supports(AddressingVersion version, SoapMessage request) {
Lines changed: 25 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2005-2010 the original author or authors.
2+
* Copyright 2005-2014 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -23,24 +23,24 @@
2323
import javax.xml.soap.SOAPConstants;
2424
import javax.xml.soap.SOAPException;
2525

26+
import org.custommonkey.xmlunit.XMLUnit;
27+
import static org.junit.Assert.*;
28+
import org.junit.Before;
29+
import org.junit.Test;
30+
2631
import org.springframework.context.support.StaticApplicationContext;
2732
import org.springframework.ws.context.DefaultMessageContext;
2833
import org.springframework.ws.context.MessageContext;
2934
import org.springframework.ws.server.EndpointInvocationChain;
3035
import org.springframework.ws.server.endpoint.MethodEndpoint;
3136
import org.springframework.ws.server.endpoint.annotation.Endpoint;
37+
import org.springframework.ws.server.endpoint.interceptor.DelegatingSmartEndpointInterceptor;
38+
import org.springframework.ws.server.endpoint.interceptor.PayloadLoggingInterceptor;
3239
import org.springframework.ws.soap.addressing.server.annotation.Action;
3340
import org.springframework.ws.soap.addressing.server.annotation.Address;
3441
import org.springframework.ws.soap.saaj.SaajSoapMessage;
3542
import org.springframework.ws.soap.saaj.SaajSoapMessageFactory;
3643

37-
import org.custommonkey.xmlunit.XMLUnit;
38-
import org.junit.Assert;
39-
import org.junit.Before;
40-
import org.junit.Test;
41-
42-
import static org.junit.Assert.assertNotNull;
43-
4444
public class AnnotationActionMethodEndpointMappingTest {
4545

4646
private StaticApplicationContext applicationContext;
@@ -55,31 +55,23 @@ public void setUp() throws Exception {
5555
XMLUnit.setIgnoreWhitespace(true);
5656
applicationContext = new StaticApplicationContext();
5757
applicationContext.registerSingleton("mapping", AnnotationActionEndpointMapping.class);
58+
applicationContext.registerSingleton("interceptor", MyInterceptor.class);
59+
applicationContext.registerSingleton("endpoint", MyEndpoint.class);
60+
applicationContext.refresh();
5861
mapping = (AnnotationActionEndpointMapping) applicationContext.getBean("mapping");
5962
}
6063

6164
@Test
62-
public void testNoAddress() throws Exception {
63-
applicationContext.registerSingleton("endpoint", Endpoint1.class);
64-
applicationContext.refresh();
65+
public void mapping() throws Exception {
6566
MessageContext messageContext = createMessageContext();
6667

6768
EndpointInvocationChain chain = mapping.getEndpoint(messageContext);
68-
Assert.assertNotNull("MethodEndpoint not registered", chain);
69-
MethodEndpoint expected = new MethodEndpoint(applicationContext.getBean("endpoint"), "doIt", new Class[0]);
70-
Assert.assertEquals("Invalid endpoint registered", expected, chain.getEndpoint());
71-
}
72-
73-
@Test
74-
public void testAddress() throws Exception {
75-
applicationContext.registerSingleton("endpoint", Endpoint2.class);
76-
applicationContext.refresh();
77-
MessageContext messageContext = createMessageContext();
78-
79-
EndpointInvocationChain chain = mapping.getEndpoint(messageContext);
80-
Assert.assertNotNull("MethodEndpoint not registered", chain);
81-
MethodEndpoint expected = new MethodEndpoint(applicationContext.getBean("endpoint"), "doIt", new Class[0]);
82-
Assert.assertEquals("Invalid endpoint registered", expected, chain.getEndpoint());
69+
assertNotNull("MethodEndpoint not registered", chain);
70+
MethodEndpoint expected = new MethodEndpoint(applicationContext.getBean("endpoint"), "doIt");
71+
assertEquals("Invalid endpoint registered", expected, chain.getEndpoint());
72+
assertEquals("No smart interceptors registered", 2, chain.getInterceptors().length);
73+
assertTrue(chain.getInterceptors()[0] instanceof AddressingEndpointInterceptor);
74+
assertTrue(chain.getInterceptors()[1] instanceof MyInterceptor);
8375
}
8476

8577
private MessageContext createMessageContext() throws SOAPException, IOException {
@@ -97,21 +89,19 @@ private MessageContext createMessageContext() throws SOAPException, IOException
9789
}
9890

9991
@Endpoint
100-
private static class Endpoint1 {
92+
@Address("mailto:[email protected]")
93+
private static class MyEndpoint {
10194

10295
@Action("http://fabrikam123.example/mail/Delete")
10396
public void doIt() {
10497

10598
}
10699
}
107100

108-
@Endpoint
109-
@Address("mailto:[email protected]")
110-
private static class Endpoint2 {
101+
private static class MyInterceptor extends DelegatingSmartEndpointInterceptor {
111102

112-
@Action("http://fabrikam123.example/mail/Delete")
113-
public void doIt() {
114-
115-
}
116-
}
103+
public MyInterceptor() {
104+
super(new PayloadLoggingInterceptor());
105+
}
106+
}
117107
}

0 commit comments

Comments
 (0)