fix for AbstractAddressingEndpointMapping to filter SmartEndpointInterceptors

This commit is contained in:
nstoddar
2014-12-04 09:24:41 -05:00
committed by Greg Turnquist
parent 5fd6e568fb
commit a46cb2b1d4
2 changed files with 48 additions and 32 deletions

View File

@@ -16,14 +16,6 @@
package org.springframework.ws.soap.addressing.server;
import java.net.URI;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import javax.xml.transform.TransformerException;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanFactoryUtils;
import org.springframework.beans.factory.InitializingBean;
@@ -50,6 +42,10 @@ import org.springframework.ws.soap.server.SoapEndpointMapping;
import org.springframework.ws.transport.WebServiceMessageSender;
import org.springframework.xml.transform.TransformerObjectSupport;
import javax.xml.transform.TransformerException;
import java.net.URI;
import java.util.*;
/**
* Abstract base class for {@link EndpointMapping} implementations that handle WS-Addressing. Besides the normal {@link
* SoapEndpointMapping} properties, this mapping has a {@link #setVersions(org.springframework.ws.soap.addressing.version.AddressingVersion[])
@@ -266,7 +262,7 @@ public abstract class AbstractAddressingEndpointMapping extends TransformerObjec
if (endpoint == null) {
return null;
}
return getEndpointInvocationChain(endpoint, version, requestMap);
return getEndpointInvocationChain(endpoint, version, requestMap, messageContext);
}
}
return null;
@@ -278,21 +274,29 @@ public abstract class AbstractAddressingEndpointMapping extends TransformerObjec
*/
private EndpointInvocationChain getEndpointInvocationChain(Object endpoint,
AddressingVersion version,
MessageAddressingProperties requestMap) {
MessageAddressingProperties requestMap,
MessageContext messageContext) {
URI responseAction = getResponseAction(endpoint, requestMap);
URI faultAction = getFaultAction(endpoint, requestMap);
WebServiceMessageSender[] messageSenders = getMessageSenders(endpoint);
MessageIdStrategy messageIdStrategy = getMessageIdStrategy(endpoint);
WebServiceMessageSender[] messageSenders = getMessageSenders(endpoint);
MessageIdStrategy messageIdStrategy = getMessageIdStrategy(endpoint);
List<EndpointInterceptor> interceptors = new ArrayList<EndpointInterceptor>(preInterceptors.length + postInterceptors.length + smartInterceptors.length + 1);
AddressingEndpointInterceptor addressingInterceptor = new AddressingEndpointInterceptor(version, messageIdStrategy,
messageSenders, responseAction, faultAction);
List<EndpointInterceptor> interceptors = new ArrayList<EndpointInterceptor>();
interceptors.addAll(Arrays.asList(preInterceptors));
interceptors.addAll(Arrays.asList(preInterceptors));
interceptors.add(addressingInterceptor);
interceptors.addAll(Arrays.asList(postInterceptors));
interceptors.addAll(Arrays.asList(smartInterceptors));
AddressingEndpointInterceptor addressingInterceptor = new AddressingEndpointInterceptor(version, messageIdStrategy,
messageSenders, responseAction, faultAction);
interceptors.add(addressingInterceptor);
interceptors.addAll(Arrays.asList(postInterceptors));
if (this.smartInterceptors != null) {
for (SmartEndpointInterceptor smartInterceptor : smartInterceptors) {
if (smartInterceptor.shouldIntercept(messageContext, endpoint)) {
interceptors.add(smartInterceptor);
}
}
}
return new SoapEndpointInvocationChain(endpoint,
interceptors.toArray(new EndpointInterceptor[interceptors.size()]), actorsOrRoles, isUltimateReceiver);

View File

@@ -16,18 +16,9 @@
package org.springframework.ws.soap.addressing.server;
import java.io.IOException;
import java.io.InputStream;
import javax.xml.soap.MessageFactory;
import javax.xml.soap.MimeHeaders;
import javax.xml.soap.SOAPConstants;
import javax.xml.soap.SOAPException;
import org.custommonkey.xmlunit.XMLUnit;
import static org.junit.Assert.*;
import org.junit.Before;
import org.junit.Test;
import org.springframework.context.support.StaticApplicationContext;
import org.springframework.ws.context.DefaultMessageContext;
import org.springframework.ws.context.MessageContext;
@@ -41,6 +32,15 @@ import org.springframework.ws.soap.addressing.server.annotation.Address;
import org.springframework.ws.soap.saaj.SaajSoapMessage;
import org.springframework.ws.soap.saaj.SaajSoapMessageFactory;
import javax.xml.soap.MessageFactory;
import javax.xml.soap.MimeHeaders;
import javax.xml.soap.SOAPConstants;
import javax.xml.soap.SOAPException;
import java.io.IOException;
import java.io.InputStream;
import static org.junit.Assert.*;
public class AnnotationActionMethodEndpointMappingTest {
private StaticApplicationContext applicationContext;
@@ -55,9 +55,10 @@ public class AnnotationActionMethodEndpointMappingTest {
XMLUnit.setIgnoreWhitespace(true);
applicationContext = new StaticApplicationContext();
applicationContext.registerSingleton("mapping", AnnotationActionEndpointMapping.class);
applicationContext.registerSingleton("interceptor", MyInterceptor.class);
applicationContext.registerSingleton("endpoint", MyEndpoint.class);
applicationContext.refresh();
applicationContext.registerSingleton("interceptor", MyInterceptor.class);
applicationContext.registerSingleton("smartIntercepter", MySmartInterceptor.class);
applicationContext.registerSingleton("endpoint", MyEndpoint.class);
applicationContext.refresh();
mapping = (AnnotationActionEndpointMapping) applicationContext.getBean("mapping");
}
@@ -104,4 +105,15 @@ public class AnnotationActionMethodEndpointMappingTest {
super(new PayloadLoggingInterceptor());
}
}
}
private static class MySmartInterceptor extends DelegatingSmartEndpointInterceptor {
public MySmartInterceptor() {
super(new PayloadLoggingInterceptor());
}
public boolean shouldIntercept(MessageContext messageContext, Object endpoint) {
return false;
}
}
}