Removed EndpointInterceptor.
This commit is contained in:
@@ -18,7 +18,6 @@ package org.springframework.integration.endpoint;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
|
||||
import org.springframework.integration.channel.ChannelRegistry;
|
||||
import org.springframework.integration.channel.ChannelRegistryAware;
|
||||
@@ -45,8 +44,6 @@ public abstract class AbstractMessageHandlingEndpoint extends AbstractMessageCon
|
||||
|
||||
private volatile boolean requiresReply = false;
|
||||
|
||||
private final List<EndpointInterceptor> interceptors = new CopyOnWriteArrayList<EndpointInterceptor>();
|
||||
|
||||
|
||||
public void setOutputChannel(MessageChannel outputChannel) {
|
||||
this.outputChannel = outputChannel;
|
||||
@@ -68,25 +65,9 @@ public abstract class AbstractMessageHandlingEndpoint extends AbstractMessageCon
|
||||
this.requiresReply = requiresReply;
|
||||
}
|
||||
|
||||
public void addInterceptor(EndpointInterceptor interceptor) {
|
||||
this.interceptors.add(interceptor);
|
||||
}
|
||||
|
||||
public void setInterceptors(List<EndpointInterceptor> interceptors) {
|
||||
this.interceptors.clear();
|
||||
for (EndpointInterceptor interceptor : interceptors) {
|
||||
this.addInterceptor(interceptor);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onMessageInternal(Message<?> message) {
|
||||
for (EndpointInterceptor interceptor : this.interceptors) {
|
||||
message = interceptor.preHandle(message);
|
||||
if (message == null) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (!this.supports(message)) {
|
||||
throw new MessageRejectedException(message, "unsupported message");
|
||||
}
|
||||
@@ -136,15 +117,6 @@ public abstract class AbstractMessageHandlingEndpoint extends AbstractMessageCon
|
||||
}
|
||||
|
||||
private boolean sendReplyMessage(Message<?> replyMessage, MessageChannel replyChannel) {
|
||||
for (int i = this.interceptors.size() - 1; i >= 0; i--) {
|
||||
EndpointInterceptor interceptor = this.interceptors.get(i);
|
||||
if (interceptor != null) {
|
||||
replyMessage = interceptor.postHandle(replyMessage);
|
||||
if (replyMessage == null) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return this.getChannelTemplate().send(replyMessage, replyChannel);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,30 +0,0 @@
|
||||
/*
|
||||
* Copyright 2002-2008 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.endpoint;
|
||||
|
||||
import org.springframework.integration.message.Message;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public interface EndpointInterceptor {
|
||||
|
||||
Message<?> preHandle(Message<?> requestMessage);
|
||||
|
||||
Message<?> postHandle(Message<?> replyMessage);
|
||||
|
||||
}
|
||||
@@ -1,37 +0,0 @@
|
||||
/*
|
||||
* Copyright 2002-2008 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.endpoint.interceptor;
|
||||
|
||||
import org.springframework.integration.endpoint.EndpointInterceptor;
|
||||
import org.springframework.integration.message.Message;
|
||||
|
||||
/**
|
||||
* A convenience base class for implementing {@link EndpointInterceptor EndpointInterceptors}.
|
||||
*
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public class EndpointInterceptorAdapter implements EndpointInterceptor {
|
||||
|
||||
public Message<?> preHandle(Message<?> requestMessage) {
|
||||
return requestMessage;
|
||||
}
|
||||
|
||||
public Message<?> postHandle(Message<?> replyMessage) {
|
||||
return replyMessage;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,80 +0,0 @@
|
||||
/*
|
||||
* Copyright 2002-2008 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.config;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.beans.DirectFieldAccessor;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.integration.channel.MessageChannel;
|
||||
import org.springframework.integration.endpoint.EndpointInterceptor;
|
||||
import org.springframework.integration.endpoint.MessageEndpoint;
|
||||
import org.springframework.integration.message.StringMessage;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public class EndpointInterceptorTests {
|
||||
|
||||
@Test
|
||||
public void testHandlerEndpointWithBeanInterceptors() {
|
||||
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
|
||||
"endpointInterceptorTests.xml", this.getClass());
|
||||
MessageEndpoint endpoint = (MessageEndpoint) context.getBean("endpointWithBeanInterceptors");
|
||||
testInterceptors(endpoint, context, true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHandlerEndpointWithRefInterceptors() {
|
||||
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
|
||||
"endpointInterceptorTests.xml", this.getClass());
|
||||
MessageEndpoint endpoint = (MessageEndpoint) context.getBean("endpointWithRefInterceptors");
|
||||
testInterceptors(endpoint, context, false);
|
||||
}
|
||||
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private static void testInterceptors(MessageEndpoint endpoint, ClassPathXmlApplicationContext context, boolean innerBeans) {
|
||||
MessageChannel channel = null;
|
||||
TestPreHandleInterceptor preInterceptor = null;
|
||||
TestPostHandleInterceptor postInterceptor = null;
|
||||
if (innerBeans) {
|
||||
channel = (MessageChannel) context.getBean("inputChannelForBeans");
|
||||
DirectFieldAccessor accessor = new DirectFieldAccessor(endpoint);
|
||||
List<EndpointInterceptor> interceptors = (List<EndpointInterceptor>) accessor.getPropertyValue("interceptors");
|
||||
preInterceptor = (TestPreHandleInterceptor) interceptors.get(0);
|
||||
postInterceptor = (TestPostHandleInterceptor) interceptors.get(1);
|
||||
}
|
||||
else {
|
||||
channel = (MessageChannel) context.getBean("inputChannelForRefs");
|
||||
preInterceptor = (TestPreHandleInterceptor) context.getBean("preInterceptor");
|
||||
postInterceptor = (TestPostHandleInterceptor) context.getBean("postInterceptor");
|
||||
}
|
||||
assertEquals(0, preInterceptor.getCount());
|
||||
assertEquals(0, postInterceptor.getCount());
|
||||
assertTrue(channel.send(new StringMessage("test")));
|
||||
assertEquals(1, preInterceptor.getCount());
|
||||
assertEquals(1, postInterceptor.getCount());
|
||||
context.stop();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,42 +0,0 @@
|
||||
/*
|
||||
* Copyright 2002-2008 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.config;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import org.springframework.integration.endpoint.interceptor.EndpointInterceptorAdapter;
|
||||
import org.springframework.integration.message.Message;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public class TestPostHandleInterceptor extends EndpointInterceptorAdapter {
|
||||
|
||||
private AtomicInteger counter = new AtomicInteger();
|
||||
|
||||
|
||||
public int getCount() {
|
||||
return this.counter.get();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Message<?> postHandle(Message<?> replyMessage) {
|
||||
this.counter.incrementAndGet();
|
||||
return replyMessage;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,42 +0,0 @@
|
||||
/*
|
||||
* Copyright 2002-2008 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.config;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import org.springframework.integration.endpoint.interceptor.EndpointInterceptorAdapter;
|
||||
import org.springframework.integration.message.Message;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public class TestPreHandleInterceptor extends EndpointInterceptorAdapter {
|
||||
|
||||
private AtomicInteger counter = new AtomicInteger();
|
||||
|
||||
|
||||
public int getCount() {
|
||||
return this.counter.get();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Message<?> preHandle(Message<?> message) {
|
||||
this.counter.incrementAndGet();
|
||||
return message;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user