SWS-713 - Order of interceptor calls is dependent on the way the interceptors are included

This commit is contained in:
Arjen Poutsma
2011-10-06 11:07:23 +00:00
parent 761c354177
commit 9f9e06d0d2
5 changed files with 161 additions and 70 deletions

View File

@@ -74,73 +74,71 @@ class InterceptorsBeanDefinitionParser implements BeanDefinitionParser {
}
else if ("payloadRoot".equals(childElement.getLocalName())) {
// bean elements
List<Element> beanElements = DomUtils.getChildElementsByTagName(childElement, "bean");
for (Element beanElement : beanElements) {
RootBeanDefinition smartInterceptorDef =
createSmartInterceptorDefinition(PayloadRootSmartSoapEndpointInterceptor.class, childElement,
parserContext);
BeanDefinitionHolder interceptorDef = createInterceptorDefinition(parserContext, beanElement);
List<Element> payloadRootChildren = DomUtils.getChildElements(childElement);
for (Element payloadRootChild : payloadRootChildren) {
if ("bean".equals(payloadRootChild.getLocalName())) {
RootBeanDefinition smartInterceptorDef =
createSmartInterceptorDefinition(PayloadRootSmartSoapEndpointInterceptor.class,
childElement, parserContext);
BeanDefinitionHolder interceptorDef =
createInterceptorDefinition(parserContext, payloadRootChild);
String namespaceUri = childElement.getAttribute("namespaceUri");
String localPart = childElement.getAttribute("localPart");
String namespaceUri = childElement.getAttribute("namespaceUri");
String localPart = childElement.getAttribute("localPart");
smartInterceptorDef.getConstructorArgumentValues().addIndexedArgumentValue(0, interceptorDef);
smartInterceptorDef.getConstructorArgumentValues().addIndexedArgumentValue(1, namespaceUri);
smartInterceptorDef.getConstructorArgumentValues().addIndexedArgumentValue(2, localPart);
smartInterceptorDef.getConstructorArgumentValues().addIndexedArgumentValue(0, interceptorDef);
smartInterceptorDef.getConstructorArgumentValues().addIndexedArgumentValue(1, namespaceUri);
smartInterceptorDef.getConstructorArgumentValues().addIndexedArgumentValue(2, localPart);
registerSmartInterceptor(parserContext, smartInterceptorDef);
}
registerSmartInterceptor(parserContext, smartInterceptorDef);
}
else if ("ref".equals(payloadRootChild.getLocalName())) {
RootBeanDefinition smartInterceptorDef =
createSmartInterceptorDefinition(PayloadRootSmartSoapEndpointInterceptor.class,
childElement, parserContext);
BeanReference interceptorRef = createInterceptorReference(parserContext, payloadRootChild);
// ref elements
List<Element> refElements = DomUtils.getChildElementsByTagName(childElement, "ref");
for (Element refElement : refElements) {
RootBeanDefinition smartInterceptorDef =
createSmartInterceptorDefinition(PayloadRootSmartSoapEndpointInterceptor.class, childElement,
parserContext);
BeanReference interceptorRef = createInterceptorReference(parserContext, refElement);
String namespaceUri = childElement.getAttribute("namespaceUri");
String localPart = childElement.getAttribute("localPart");
String namespaceUri = childElement.getAttribute("namespaceUri");
String localPart = childElement.getAttribute("localPart");
smartInterceptorDef.getConstructorArgumentValues().addIndexedArgumentValue(0, interceptorRef);
smartInterceptorDef.getConstructorArgumentValues().addIndexedArgumentValue(1, namespaceUri);
smartInterceptorDef.getConstructorArgumentValues().addIndexedArgumentValue(2, localPart);
smartInterceptorDef.getConstructorArgumentValues().addIndexedArgumentValue(0, interceptorRef);
smartInterceptorDef.getConstructorArgumentValues().addIndexedArgumentValue(1, namespaceUri);
smartInterceptorDef.getConstructorArgumentValues().addIndexedArgumentValue(2, localPart);
registerSmartInterceptor(parserContext, smartInterceptorDef);
registerSmartInterceptor(parserContext, smartInterceptorDef);
}
}
}
else if ("soapAction".equals(childElement.getLocalName())) {
// bean elements
List<Element> beanElements = DomUtils.getChildElementsByTagName(childElement, "bean");
for (Element beanElement : beanElements) {
RootBeanDefinition smartInterceptorDef =
createSmartInterceptorDefinition(SoapActionSmartEndpointInterceptor.class, childElement,
parserContext);
BeanDefinitionHolder interceptorDef = createInterceptorDefinition(parserContext, beanElement);
List<Element> soapActionChildren = DomUtils.getChildElements(childElement);
for (Element soapActionChild : soapActionChildren) {
if ("bean".equals(soapActionChild.getLocalName())) {
RootBeanDefinition smartInterceptorDef =
createSmartInterceptorDefinition(SoapActionSmartEndpointInterceptor.class, childElement,
parserContext);
BeanDefinitionHolder interceptorDef =
createInterceptorDefinition(parserContext, soapActionChild);
String soapAction = childElement.getAttribute("value");
String soapAction = childElement.getAttribute("value");
smartInterceptorDef.getConstructorArgumentValues().addIndexedArgumentValue(0, interceptorDef);
smartInterceptorDef.getConstructorArgumentValues().addIndexedArgumentValue(1, soapAction);
smartInterceptorDef.getConstructorArgumentValues().addIndexedArgumentValue(0, interceptorDef);
smartInterceptorDef.getConstructorArgumentValues().addIndexedArgumentValue(1, soapAction);
registerSmartInterceptor(parserContext, smartInterceptorDef);
}
registerSmartInterceptor(parserContext, smartInterceptorDef);
}
else if ("ref".equals(soapActionChild.getLocalName())) {
RootBeanDefinition smartInterceptorDef =
createSmartInterceptorDefinition(SoapActionSmartEndpointInterceptor.class, childElement,
parserContext);
BeanReference interceptorRef = createInterceptorReference(parserContext, soapActionChild);
// ref elements
List<Element> refElements = DomUtils.getChildElementsByTagName(childElement, "ref");
for (Element refElement : refElements) {
RootBeanDefinition smartInterceptorDef =
createSmartInterceptorDefinition(SoapActionSmartEndpointInterceptor.class, childElement,
parserContext);
BeanReference interceptorRef = createInterceptorReference(parserContext, refElement);
String soapAction = childElement.getAttribute("value");
String soapAction = childElement.getAttribute("value");
smartInterceptorDef.getConstructorArgumentValues().addIndexedArgumentValue(0, interceptorRef);
smartInterceptorDef.getConstructorArgumentValues().addIndexedArgumentValue(1, soapAction);
smartInterceptorDef.getConstructorArgumentValues().addIndexedArgumentValue(0, interceptorRef);
smartInterceptorDef.getConstructorArgumentValues().addIndexedArgumentValue(1, soapAction);
registerSmartInterceptor(parserContext, smartInterceptorDef);
registerSmartInterceptor(parserContext, smartInterceptorDef);
}
}
}
}
@@ -150,17 +148,13 @@ class InterceptorsBeanDefinitionParser implements BeanDefinitionParser {
}
private void registerSmartInterceptor(ParserContext parserContext, RootBeanDefinition smartInterceptorDef) {
String mappedInterceptorName =
parserContext.getReaderContext().registerWithGeneratedName(smartInterceptorDef);
parserContext
.registerComponent(new BeanComponentDefinition(smartInterceptorDef, mappedInterceptorName));
String mappedInterceptorName = parserContext.getReaderContext().registerWithGeneratedName(smartInterceptorDef);
parserContext.registerComponent(new BeanComponentDefinition(smartInterceptorDef, mappedInterceptorName));
}
private BeanDefinitionHolder createInterceptorDefinition(ParserContext parserContext, Element element) {
BeanDefinitionHolder interceptorDef =
parserContext.getDelegate().parseBeanDefinitionElement(element);
interceptorDef =
parserContext.getDelegate().decorateBeanDefinitionIfRequired(element, interceptorDef);
BeanDefinitionHolder interceptorDef = parserContext.getDelegate().parseBeanDefinitionElement(element);
interceptorDef = parserContext.getDelegate().decorateBeanDefinitionIfRequired(element, interceptorDef);
return interceptorDef;
}

View File

@@ -45,9 +45,9 @@ public class DelegatingSmartEndpointInterceptor implements SmartEndpointIntercep
/**
* Returns the delegate.
* @return
* @return the delegate
*/
protected EndpointInterceptor getDelegate() {
public EndpointInterceptor getDelegate() {
return delegate;
}

View File

@@ -16,6 +16,8 @@
package org.springframework.ws.config;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.springframework.context.ApplicationContext;
@@ -24,22 +26,16 @@ import org.springframework.ws.server.endpoint.interceptor.DelegatingSmartEndpoin
import org.springframework.ws.soap.server.endpoint.interceptor.PayloadRootSmartSoapEndpointInterceptor;
import org.springframework.ws.soap.server.endpoint.interceptor.SoapActionSmartEndpointInterceptor;
import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
public class InterceptorsBeanDefinitionParserTest {
private ApplicationContext applicationContext;
@Before
public void setUp() throws Exception {
applicationContext = new ClassPathXmlApplicationContext("interceptorsBeanDefinitionParserTest.xml", getClass());
}
@Test
public void namespace() throws Exception {
ApplicationContext applicationContext =
new ClassPathXmlApplicationContext("interceptorsBeanDefinitionParserTest.xml", getClass());
Map<String, ?> result = applicationContext.getBeansOfType(DelegatingSmartEndpointInterceptor.class);
assertEquals("no smart interceptors found", 8, result.size());
@@ -50,4 +46,20 @@ public class InterceptorsBeanDefinitionParserTest {
assertEquals("no interceptors found", 3, result.size());
}
@Test
public void ordering() throws Exception {
ApplicationContext applicationContext =
new ClassPathXmlApplicationContext("interceptorsBeanDefinitionParserOrderTest.xml", getClass());
List<DelegatingSmartEndpointInterceptor> interceptors = new ArrayList<DelegatingSmartEndpointInterceptor>(
applicationContext.getBeansOfType(DelegatingSmartEndpointInterceptor.class).values());
assertEquals("not enough smart interceptors found", 6, interceptors.size());
for (int i = 0; i < interceptors.size(); i++) {
DelegatingSmartEndpointInterceptor delegatingInterceptor = interceptors.get(i);
MyInterceptor interceptor = (MyInterceptor) delegatingInterceptor.getDelegate();
assertEquals("Invalid ordering found for [" + delegatingInterceptor + "]", i, interceptor.getOrder());
}
}
}

View File

@@ -0,0 +1,51 @@
/*
* Copyright 2005-2011 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.ws.config;
import org.springframework.ws.context.MessageContext;
import org.springframework.ws.server.EndpointInterceptor;
/**
* @author Arjen Poutsma
*/
public class MyInterceptor implements EndpointInterceptor {
private int order;
public int getOrder() {
return order;
}
public void setOrder(int order) {
this.order = order;
}
public boolean handleRequest(MessageContext messageContext, Object endpoint) throws Exception {
return true;
}
public boolean handleResponse(MessageContext messageContext, Object endpoint) throws Exception {
return true;
}
public boolean handleFault(MessageContext messageContext, Object endpoint) throws Exception {
return true;
}
public void afterCompletion(MessageContext messageContext, Object endpoint, Exception ex) {
}
}

View File

@@ -0,0 +1,34 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:sws="http://www.springframework.org/schema/web-services"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/web-services http://www.springframework.org/schema/web-services/web-services.xsd">
<sws:interceptors>
<ref bean="externalGlobalInterceptor"/>
<bean class="org.springframework.ws.config.MyInterceptor">
<property name="order" value="1"/>
</bean>
<sws:payloadRoot namespaceUri="http://www.springframework.org/spring-ws">
<ref bean="externalPayloadRootInterceptor"/>
<bean class="org.springframework.ws.config.MyInterceptor">
<property name="order" value="3"/>
</bean>
</sws:payloadRoot>
<sws:soapAction value="mySoapAction">
<ref local="externalSoapActionInterceptor"/>
<bean class="org.springframework.ws.config.MyInterceptor">
<property name="order" value="5"/>
</bean>
</sws:soapAction>
</sws:interceptors>
<bean id="externalGlobalInterceptor" class="org.springframework.ws.config.MyInterceptor" p:order="0"/>
<bean id="externalPayloadRootInterceptor" class="org.springframework.ws.config.MyInterceptor" p:order="2"/>
<bean id="externalSoapActionInterceptor" class="org.springframework.ws.config.MyInterceptor" p:order="4"/>
</beans>