Skip to content

Commit

Permalink
INT-3581: Support selector-expression on WireTap
Browse files Browse the repository at this point in the history
JIRA: https://jira.spring.io/browse/INT-3581

Move schemas to 4.2.

Add `selector-expression` to `<wire-tap/>`.

INT-3781: Fix What's New

Bump Namespace Version to 4.2
  • Loading branch information
garyrussell committed Jan 13, 2015
1 parent 6b7bbdc commit 15eb011
Show file tree
Hide file tree
Showing 68 changed files with 508 additions and 424 deletions.
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
http\://www.springframework.org/schema/integration/amqp/spring-integration-amqp-4.1.xsd=org/springframework/integration/amqp/config/spring-integration-amqp-4.1.xsd
http\://www.springframework.org/schema/integration/amqp/spring-integration-amqp.xsd=org/springframework/integration/amqp/config/spring-integration-amqp-4.1.xsd
http\://www.springframework.org/schema/integration/amqp/spring-integration-amqp-4.2.xsd=org/springframework/integration/amqp/config/spring-integration-amqp-4.2.xsd
http\://www.springframework.org/schema/integration/amqp/spring-integration-amqp.xsd=org/springframework/integration/amqp/config/spring-integration-amqp-4.2.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<xsd:import namespace="http://www.springframework.org/schema/beans" />
<xsd:import namespace="http://www.springframework.org/schema/tool" />
<xsd:import namespace="http://www.springframework.org/schema/integration"
schemaLocation="http://www.springframework.org/schema/integration/spring-integration-4.1.xsd"/>
schemaLocation="http://www.springframework.org/schema/integration/spring-integration-4.2.xsd"/>

<xsd:element name="outbound-channel-adapter">
<xsd:annotation>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public abstract class AbstractIntegrationNamespaceHandler implements NamespaceHa

protected final Log logger = LogFactory.getLog(this.getClass());

private static final String VERSION = "4.1";
private static final String VERSION = "4.2";

private final NamespaceHandlerDelegate delegate = new NamespaceHandlerDelegate();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,26 +20,43 @@
import org.springframework.beans.factory.support.BeanDefinitionReaderUtils;
import org.springframework.beans.factory.xml.ParserContext;
import org.springframework.integration.channel.interceptor.WireTap;
import org.springframework.integration.config.ExpressionFactoryBean;
import org.springframework.integration.filter.ExpressionEvaluatingSelector;
import org.springframework.util.StringUtils;

/**
* Parser for the &lt;wire-tap&gt; element.
*
* @author Mark Fisher
* @author Gary Russell
*/
public class WireTapParser implements BeanDefinitionRegisteringParser {

@Override
public String parse(Element element, ParserContext parserContext) {
Object source = parserContext.extractSource(element);
BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(WireTap.class);
String targetRef = element.getAttribute("channel");
if (!StringUtils.hasText(targetRef)) {
parserContext.getReaderContext().error("The 'channel' attribute is required.", element);
}
builder.addConstructorArgReference(targetRef);
String selectorRef = element.getAttribute("selector");
String selectorExpression = element.getAttribute("selector-expression");
if (StringUtils.hasText(selectorRef) && StringUtils.hasText(selectorExpression)) {
parserContext.getReaderContext().error("Only one of 'selector' or 'selector-expression' is allowed", source);
}
if (StringUtils.hasText(selectorRef)) {
builder.addConstructorArgReference(selectorRef);
}
else if (StringUtils.hasText(selectorExpression)) {
BeanDefinitionBuilder expressionBuilder = BeanDefinitionBuilder
.genericBeanDefinition(ExpressionFactoryBean.class);
expressionBuilder.addConstructorArgValue(selectorExpression);
BeanDefinitionBuilder eemsBuilder = BeanDefinitionBuilder.genericBeanDefinition(ExpressionEvaluatingSelector.class);
eemsBuilder.addConstructorArgValue(expressionBuilder.getBeanDefinition());
builder.addConstructorArgValue(eemsBuilder.getBeanDefinition());
}
String timeout = element.getAttribute("timeout");
if (StringUtils.hasText(timeout)) {
builder.addPropertyValue("timeout", Long.parseLong(timeout));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
http\://www.springframework.org/schema/integration/spring-integration-4.1.xsd=org/springframework/integration/config/xml/spring-integration-4.1.xsd
http\://www.springframework.org/schema/integration/spring-integration.xsd=org/springframework/integration/config/xml/spring-integration-4.1.xsd
http\://www.springframework.org/schema/integration/spring-integration-4.2.xsd=org/springframework/integration/config/xml/spring-integration-4.2.xsd
http\://www.springframework.org/schema/integration/spring-integration.xsd=org/springframework/integration/config/xml/spring-integration-4.2.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -3749,7 +3749,15 @@
<xsd:documentation>
A reference to a bean in the Application Context
which implements MessageSelector that must accept a message for it to be
sent to the intercepting channel
sent to the intercepting channel. Mutually exclusive with 'selector-expression'.
</xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="selector-expression" type="xsd:string">
<xsd:annotation>
<xsd:documentation>
A boolean expression evaluated against the message to determine whether it should
sent to the intercepting channel. Mutually exclusive with 'selector'.
</xsd:documentation>
</xsd:annotation>
</xsd:attribute>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<channel id="withId">
<queue capacity="10"/>
<interceptors>
<wire-tap id="wireTap" channel="wireTapChannel"/>
<wire-tap id="wireTap" channel="wireTapChannel" selector-expression="@booleanTrue" />
</interceptors>
</channel>

Expand Down Expand Up @@ -54,4 +54,8 @@
<beans:constructor-arg value="false"/>
</beans:bean>

<beans:bean id="booleanTrue" class="java.lang.Boolean">
<beans:constructor-arg value="true" />
</beans:bean>

</beans:beans>
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2010 the original author or authors.
* Copyright 2002-2014 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.
Expand All @@ -16,85 +16,104 @@

package org.springframework.integration.config;

import static org.hamcrest.Matchers.instanceOf;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThat;

import java.util.Map;
import java.util.List;

import org.junit.Test;
import org.junit.runner.RunWith;

import org.springframework.beans.DirectFieldAccessor;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.integration.channel.interceptor.WireTap;
import org.springframework.integration.filter.ExpressionEvaluatingSelector;
import org.springframework.integration.test.util.TestUtils;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageChannel;
import org.springframework.integration.channel.interceptor.WireTap;
import org.springframework.messaging.PollableChannel;
import org.springframework.messaging.support.GenericMessage;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

/**
* @author Mark Fisher
* @author Gary Russell
*/
@ContextConfiguration
@RunWith(SpringJUnit4ClassRunner.class)
public class WireTapParserTests {

@Autowired
MessageChannel noSelectors;

@Autowired
MessageChannel accepting;

@Autowired
MessageChannel rejecting;

@Autowired
MessageChannel withId;

@Autowired
PollableChannel wireTapChannel;

@Autowired @Qualifier("wireTap")
WireTap wireTap;

@Autowired
List<WireTap> wireTaps;

@Test
public void simpleWireTap() {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
"wireTapParserTests.xml", this.getClass());
MessageChannel mainChannel = (MessageChannel) context.getBean("noSelectors");
PollableChannel wireTapChannel = (PollableChannel) context.getBean("wireTapChannel");
assertNull(wireTapChannel.receive(0));
Message<?> original = new GenericMessage<String>("test");
mainChannel.send(original);
noSelectors.send(original);
Message<?> intercepted = wireTapChannel.receive(0);
assertNotNull(intercepted);
assertEquals(original, intercepted);
}

@Test
public void simpleWireTapWithId() {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
"wireTapParserTests.xml", this.getClass());
WireTap wireTap = (WireTap) context.getBean("wireTap");
assertNotNull(wireTap);
public void simpleWireTapWithIdAndSelectorExpression() {
assertThat(TestUtils.getPropertyValue(wireTap, "selector"), instanceOf(ExpressionEvaluatingSelector.class));
Message<?> original = new GenericMessage<String>("test");
withId.send(original);
Message<?> intercepted = wireTapChannel.receive(0);
assertNotNull(intercepted);
assertEquals(original, intercepted);
}

@Test
public void wireTapWithAcceptingSelector() {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
"wireTapParserTests.xml", this.getClass());
MessageChannel mainChannel = (MessageChannel) context.getBean("accepting");
PollableChannel wireTapChannel = (PollableChannel) context.getBean("wireTapChannel");
assertNull(wireTapChannel.receive(0));
Message<?> original = new GenericMessage<String>("test");
mainChannel.send(original);
accepting.send(original);
Message<?> intercepted = wireTapChannel.receive(0);
assertNotNull(intercepted);
assertEquals(original, intercepted);
}

@Test
public void wireTapWithRejectingSelector() {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
"wireTapParserTests.xml", this.getClass());
MessageChannel mainChannel = (MessageChannel) context.getBean("rejecting");
PollableChannel wireTapChannel = (PollableChannel) context.getBean("wireTapChannel");
assertNull(wireTapChannel.receive(0));
Message<?> original = new GenericMessage<String>("test");
mainChannel.send(original);
rejecting.send(original);
Message<?> intercepted = wireTapChannel.receive(0);
assertNull(intercepted);
}

@Test
public void wireTapTimeouts() {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
"wireTapParserTests.xml", this.getClass());
Map<String, WireTap> beans = context.getBeansOfType(WireTap.class);
int defaultTimeoutCount = 0;
int expectedTimeoutCount = 0;
int otherTimeoutCount = 0;
for (WireTap wireTap : beans.values()) {
for (WireTap wireTap : wireTaps) {
long timeout = ((Long) new DirectFieldAccessor(wireTap).getPropertyValue("timeout")).longValue();
if (timeout == 0) {
defaultTimeoutCount++;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
http\://www.springframework.org/schema/integration/event/spring-integration-event-4.1.xsd=org/springframework/integration/event/config/spring-integration-event-4.1.xsd
http\://www.springframework.org/schema/integration/event/spring-integration-event.xsd=org/springframework/integration/event/config/spring-integration-event-4.1.xsd
http\://www.springframework.org/schema/integration/event/spring-integration-event-4.2.xsd=org/springframework/integration/event/config/spring-integration-event-4.2.xsd
http\://www.springframework.org/schema/integration/event/spring-integration-event.xsd=org/springframework/integration/event/config/spring-integration-event-4.2.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

<xsd:import namespace="http://www.springframework.org/schema/beans" />
<xsd:import namespace="http://www.springframework.org/schema/integration"
schemaLocation="http://www.springframework.org/schema/integration/spring-integration-4.1.xsd" />
schemaLocation="http://www.springframework.org/schema/integration/spring-integration-4.2.xsd" />

<xsd:annotation>
<xsd:documentation><![CDATA[
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
http\://www.springframework.org/schema/integration/feed/spring-integration-feed-4.1.xsd=org/springframework/integration/feed/config/spring-integration-feed-4.1.xsd
http\://www.springframework.org/schema/integration/feed/spring-integration-feed.xsd=org/springframework/integration/feed/config/spring-integration-feed-4.1.xsd
http\://www.springframework.org/schema/integration/feed/spring-integration-feed-4.2.xsd=org/springframework/integration/feed/config/spring-integration-feed-4.2.xsd
http\://www.springframework.org/schema/integration/feed/spring-integration-feed.xsd=org/springframework/integration/feed/config/spring-integration-feed-4.2.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

<xsd:import namespace="http://www.springframework.org/schema/beans" />
<xsd:import namespace="http://www.springframework.org/schema/integration"
schemaLocation="http://www.springframework.org/schema/integration/spring-integration-4.1.xsd" />
schemaLocation="http://www.springframework.org/schema/integration/spring-integration-4.2.xsd" />

<xsd:element name="inbound-channel-adapter">
<xsd:annotation>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
http\://www.springframework.org/schema/integration/file/spring-integration-file-4.1.xsd=org/springframework/integration/file/config/spring-integration-file-4.1.xsd
http\://www.springframework.org/schema/integration/file/spring-integration-file.xsd=org/springframework/integration/file/config/spring-integration-file-4.1.xsd
http\://www.springframework.org/schema/integration/file/spring-integration-file-4.2.xsd=org/springframework/integration/file/config/spring-integration-file-4.2.xsd
http\://www.springframework.org/schema/integration/file/spring-integration-file.xsd=org/springframework/integration/file/config/spring-integration-file-4.2.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

<xsd:import namespace="http://www.springframework.org/schema/beans"/>
<xsd:import namespace="http://www.springframework.org/schema/integration"
schemaLocation="http://www.springframework.org/schema/integration/spring-integration-4.1.xsd"/>
schemaLocation="http://www.springframework.org/schema/integration/spring-integration-4.2.xsd"/>

<xsd:annotation>
<xsd:documentation><![CDATA[
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
http\://www.springframework.org/schema/integration/ftp/spring-integration-ftp-4.1.xsd=org/springframework/integration/ftp/config/spring-integration-ftp-4.1.xsd
http\://www.springframework.org/schema/integration/ftp/spring-integration-ftp.xsd=org/springframework/integration/ftp/config/spring-integration-ftp-4.1.xsd
http\://www.springframework.org/schema/integration/ftp/spring-integration-ftp-4.2.xsd=org/springframework/integration/ftp/config/spring-integration-ftp-4.2.xsd
http\://www.springframework.org/schema/integration/ftp/spring-integration-ftp.xsd=org/springframework/integration/ftp/config/spring-integration-ftp-4.2.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
<xsd:import namespace="http://www.springframework.org/schema/beans" />
<xsd:import namespace="http://www.springframework.org/schema/tool" />
<xsd:import namespace="http://www.springframework.org/schema/integration"
schemaLocation="http://www.springframework.org/schema/integration/spring-integration-4.1.xsd" />
schemaLocation="http://www.springframework.org/schema/integration/spring-integration-4.2.xsd" />
<xsd:import namespace="http://www.springframework.org/schema/integration/file"
schemaLocation="http://www.springframework.org/schema/integration/file/spring-integration-file-4.1.xsd" />
schemaLocation="http://www.springframework.org/schema/integration/file/spring-integration-file-4.2.xsd" />

<xsd:element name="outbound-channel-adapter">
<xsd:annotation>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
http\://www.springframework.org/schema/integration/gemfire/spring-integration-gemfire-4.1.xsd=org/springframework/integration/gemfire/config/xml/spring-integration-gemfire-4.1.xsd
http\://www.springframework.org/schema/integration/gemfire/spring-integration-gemfire.xsd=org/springframework/integration/gemfire/config/xml/spring-integration-gemfire-4.1.xsd
http\://www.springframework.org/schema/integration/gemfire/spring-integration-gemfire-4.2.xsd=org/springframework/integration/gemfire/config/xml/spring-integration-gemfire-4.2.xsd
http\://www.springframework.org/schema/integration/gemfire/spring-integration-gemfire.xsd=org/springframework/integration/gemfire/config/xml/spring-integration-gemfire-4.2.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
schemaLocation="http://www.springframework.org/schema/beans/spring-beans.xsd"/>
<xsd:import namespace="http://www.springframework.org/schema/tool"/>
<xsd:import namespace="http://www.springframework.org/schema/integration"
schemaLocation="http://www.springframework.org/schema/integration/spring-integration-4.1.xsd"/>
schemaLocation="http://www.springframework.org/schema/integration/spring-integration-4.2.xsd"/>
<xsd:annotation>
<xsd:documentation><![CDATA[
Defines the core configuration elements for Spring Integration GemFire Support.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
http\://www.springframework.org/schema/integration/groovy/spring-integration-groovy-4.1.xsd=org/springframework/integration/groovy/config/spring-integration-groovy-4.1.xsd
http\://www.springframework.org/schema/integration/groovy/spring-integration-groovy.xsd=org/springframework/integration/groovy/config/spring-integration-groovy-4.1.xsd
http\://www.springframework.org/schema/integration/groovy/spring-integration-groovy-4.2.xsd=org/springframework/integration/groovy/config/spring-integration-groovy-4.2.xsd
http\://www.springframework.org/schema/integration/groovy/spring-integration-groovy.xsd=org/springframework/integration/groovy/config/spring-integration-groovy-4.2.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
elementFormDefault="qualified" attributeFormDefault="unqualified">

<xsd:include
schemaLocation="http://www.springframework.org/schema/integration/scripting/spring-integration-scripting-core-4.1.xsd"
schemaLocation="http://www.springframework.org/schema/integration/scripting/spring-integration-scripting-core-4.2.xsd"
/>

<xsd:import namespace="http://www.springframework.org/schema/integration"
schemaLocation="http://www.springframework.org/schema/integration/spring-integration-4.1.xsd" />
schemaLocation="http://www.springframework.org/schema/integration/spring-integration-4.2.xsd" />

<xsd:element name="script" type="GroovyScript">
<xsd:annotation>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
http\://www.springframework.org/schema/integration/http/spring-integration-http-4.1.xsd=org/springframework/integration/http/config/spring-integration-http-4.1.xsd
http\://www.springframework.org/schema/integration/http/spring-integration-http.xsd=org/springframework/integration/http/config/spring-integration-http-4.1.xsd
http\://www.springframework.org/schema/integration/http/spring-integration-http-4.2.xsd=org/springframework/integration/http/config/spring-integration-http-4.2.xsd
http\://www.springframework.org/schema/integration/http/spring-integration-http.xsd=org/springframework/integration/http/config/spring-integration-http-4.2.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<xsd:import namespace="http://www.springframework.org/schema/beans" />
<xsd:import namespace="http://www.springframework.org/schema/tool" />
<xsd:import namespace="http://www.springframework.org/schema/integration"
schemaLocation="http://www.springframework.org/schema/integration/spring-integration-4.1.xsd" />
schemaLocation="http://www.springframework.org/schema/integration/spring-integration-4.2.xsd" />

<xsd:annotation>
<xsd:documentation><![CDATA[
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
http\://www.springframework.org/schema/integration/ip/spring-integration-ip-4.1.xsd=org/springframework/integration/ip/config/spring-integration-ip-4.1.xsd
http\://www.springframework.org/schema/integration/ip/spring-integration-ip.xsd=org/springframework/integration/ip/config/spring-integration-ip-4.1.xsd
http\://www.springframework.org/schema/integration/ip/spring-integration-ip-4.2.xsd=org/springframework/integration/ip/config/spring-integration-ip-4.2.xsd
http\://www.springframework.org/schema/integration/ip/spring-integration-ip.xsd=org/springframework/integration/ip/config/spring-integration-ip-4.2.xsd
Loading

0 comments on commit 15eb011

Please sign in to comment.