INT-1056 added support for configurable ClientInterceptors on the AbstractWebServiceOutboundGateway

This commit is contained in:
Mark Fisher
2010-05-07 02:34:37 +00:00
parent ae262df26e
commit 752fd5df0f
6 changed files with 140 additions and 4 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2009 the original author or authors.
* Copyright 2002-2010 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.
@@ -30,6 +30,7 @@ import org.springframework.ws.client.core.FaultMessageResolver;
import org.springframework.ws.client.core.WebServiceMessageCallback;
import org.springframework.ws.client.core.WebServiceTemplate;
import org.springframework.ws.client.support.destination.DestinationProvider;
import org.springframework.ws.client.support.interceptor.ClientInterceptor;
import org.springframework.ws.soap.SoapMessage;
import org.springframework.ws.soap.client.core.SoapActionCallback;
import org.springframework.ws.transport.WebServiceMessageSender;
@@ -90,6 +91,10 @@ public abstract class AbstractWebServiceOutboundGateway extends AbstractReplyPro
this.webServiceTemplate.setMessageSenders(messageSenders);
}
public void setInterceptors(ClientInterceptor[] interceptors) {
this.webServiceTemplate.setInterceptors(interceptors);
}
protected WebServiceTemplate getWebServiceTemplate() {
return this.webServiceTemplate;
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2009 the original author or authors.
* Copyright 2002-2010 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.
@@ -19,7 +19,9 @@ package org.springframework.integration.ws.config;
import org.w3c.dom.Element;
import org.springframework.beans.factory.config.ConstructorArgumentValues;
import org.springframework.beans.factory.config.RuntimeBeanReference;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.support.ManagedList;
import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.beans.factory.xml.ParserContext;
import org.springframework.integration.adapter.config.AbstractRemotingOutboundGatewayParser;
@@ -73,6 +75,7 @@ public class WebServiceOutboundGatewayParser extends AbstractRemotingOutboundGat
}
@Override
@SuppressWarnings("unchecked")
protected void postProcessGateway(BeanDefinitionBuilder builder, Element element, ParserContext parserContext) {
String marshallerRef = element.getAttribute("marshaller");
if (StringUtils.hasText(marshallerRef)) {
@@ -115,6 +118,20 @@ public class WebServiceOutboundGatewayParser extends AbstractRemotingOutboundGat
if (StringUtils.hasText(messageSenderListRef)) {
builder.addPropertyReference("messageSenders", messageSenderListRef);
}
String interceptorRef = element.getAttribute("interceptor");
String interceptorListRef = element.getAttribute("interceptors");
if (StringUtils.hasText(interceptorRef) && StringUtils.hasText(interceptorListRef)) {
parserContext.getReaderContext().error(
"Only one of interceptor or interceptors should be specified.", element);
}
if (StringUtils.hasText(interceptorRef)) {
ManagedList interceptors = new ManagedList();
interceptors.add(new RuntimeBeanReference(interceptorRef));
builder.addPropertyValue("interceptors", interceptors);
}
if (StringUtils.hasText(interceptorListRef)) {
builder.addPropertyReference("interceptors", interceptorListRef);
}
}
}

View File

@@ -162,6 +162,9 @@
</xsd:attribute>
<xsd:attribute name="message-sender" type="xsd:string">
<xsd:annotation>
<xsd:documentation>
Reference to the bean definition of a WebServiceMessageSender.
</xsd:documentation>
<xsd:appinfo>
<tool:annotation kind="ref">
<tool:expected-type type="org.springframework.ws.transport.WebServiceMessageSender"/>
@@ -169,7 +172,32 @@
</xsd:appinfo>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="message-senders" type="xsd:string"/>
<xsd:attribute name="message-senders" type="xsd:string">
<xsd:annotation>
<xsd:documentation>
Reference to the bean definition for a list or array of WebServiceMessageSenders.
</xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="interceptor" type="xsd:string">
<xsd:annotation>
<xsd:documentation>
Reference to the bean definition of a ClientInterceptor.
</xsd:documentation>
<xsd:appinfo>
<tool:annotation kind="ref">
<tool:expected-type type="org.springframework.ws.client.support.interceptor.ClientInterceptor"/>
</tool:annotation>
</xsd:appinfo>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="interceptors" type="xsd:string">
<xsd:annotation>
<xsd:documentation>
Reference to the bean definition for a list or array of ClientInterceptors.
</xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="order" type="xsd:string"/>
<xsd:attribute name="auto-startup" type="xsd:string" default="true"/>
</xsd:complexType>

View File

@@ -0,0 +1,40 @@
/*
* Copyright 2002-2010 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.integration.ws.config;
import org.springframework.ws.client.WebServiceClientException;
import org.springframework.ws.client.support.interceptor.ClientInterceptor;
import org.springframework.ws.context.MessageContext;
/**
* @author Mark Fisher
*/
public class StubClientInterceptor implements ClientInterceptor {
public boolean handleRequest(MessageContext context) throws WebServiceClientException {
return true;
}
public boolean handleResponse(MessageContext context) throws WebServiceClientException {
return true;
}
public boolean handleFault(MessageContext context) throws WebServiceClientException {
return false;
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2009 the original author or authors.
* Copyright 2002-2010 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.
@@ -36,6 +36,7 @@ import org.springframework.ws.WebServiceMessageFactory;
import org.springframework.ws.client.core.FaultMessageResolver;
import org.springframework.ws.client.core.SourceExtractor;
import org.springframework.ws.client.core.WebServiceMessageCallback;
import org.springframework.ws.client.support.interceptor.ClientInterceptor;
import org.springframework.ws.transport.WebServiceMessageSender;
/**
@@ -192,6 +193,35 @@ public class WebServiceOutboundGatewayParserTests {
2 , ((WebServiceMessageSender[])accessor.getPropertyValue("messageSenders")).length);
}
@Test
public void simpleGatewayWithCustomInterceptor() {
ApplicationContext context = new ClassPathXmlApplicationContext(
"simpleWebServiceOutboundGatewayParserTests.xml", this.getClass());
AbstractEndpoint endpoint = (AbstractEndpoint) context.getBean("gatewayWithCustomInterceptor");
assertEquals(EventDrivenConsumer.class, endpoint.getClass());
Object gateway = new DirectFieldAccessor(endpoint).getPropertyValue("handler");
assertEquals(SimpleWebServiceOutboundGateway.class, gateway.getClass());
DirectFieldAccessor accessor = new DirectFieldAccessor(gateway);
accessor = new DirectFieldAccessor(accessor.getPropertyValue("webServiceTemplate"));
ClientInterceptor interceptor = (ClientInterceptor) context.getBean("interceptor");
assertEquals(interceptor, ((ClientInterceptor[]) accessor.getPropertyValue("interceptors"))[0]);
}
@Test
public void simpleGatewayWithCustomInterceptorList() {
ApplicationContext context = new ClassPathXmlApplicationContext(
"simpleWebServiceOutboundGatewayParserTests.xml", this.getClass());
AbstractEndpoint endpoint = (AbstractEndpoint) context.getBean("gatewayWithCustomInterceptorList");
assertEquals(EventDrivenConsumer.class, endpoint.getClass());
Object gateway = new DirectFieldAccessor(endpoint).getPropertyValue("handler");
assertEquals(SimpleWebServiceOutboundGateway.class, gateway.getClass());
DirectFieldAccessor accessor = new DirectFieldAccessor(gateway);
accessor = new DirectFieldAccessor(accessor.getPropertyValue("webServiceTemplate"));
ClientInterceptor interceptor = (ClientInterceptor) context.getBean("interceptor");
assertEquals(interceptor, ((ClientInterceptor[]) accessor.getPropertyValue("interceptors"))[0]);
assertEquals("Wrong number of interceptors ",
2 , ((ClientInterceptor[]) accessor.getPropertyValue("interceptors")).length);
}
@Test
public void simpleGatewayWithPoller() {
ApplicationContext context = new ClassPathXmlApplicationContext(

View File

@@ -72,6 +72,16 @@
request-channel="inputChannel"
uri="http://example.org"
message-senders="messageSenders"/>
<ws:outbound-gateway id="gatewayWithCustomInterceptor"
request-channel="inputChannel"
uri="http://example.org"
interceptor="interceptor"/>
<ws:outbound-gateway id="gatewayWithCustomInterceptorList"
request-channel="inputChannel"
uri="http://example.org"
interceptors="interceptors"/>
<ws:outbound-gateway id="gatewayWithPoller"
request-channel="pollableInputChannel"
@@ -106,6 +116,12 @@
<bean class="org.springframework.integration.ws.config.StubMessageSender"/>
</util:list>
<bean id="interceptor" class="org.springframework.integration.ws.config.StubClientInterceptor"/>
<util:list id="interceptors">
<ref bean="interceptor"/>
<bean class="org.springframework.integration.ws.config.StubClientInterceptor"/>
</util:list>
<bean id="destinationProvider" class="org.springframework.integration.ws.config.StubDestinationProvider"/>