INT-599
This commit is contained in:
@@ -59,7 +59,6 @@
|
||||
</xsd:appinfo>
|
||||
</xsd:annotation>
|
||||
<xsd:complexType>
|
||||
|
||||
<xsd:complexContent>
|
||||
<xsd:extension base="channelType">
|
||||
<xsd:sequence>
|
||||
@@ -422,7 +421,7 @@
|
||||
</xsd:complexContent>
|
||||
</xsd:complexType>
|
||||
|
||||
<xsd:element name="bridge" type="inputOutputEndpointType">
|
||||
<xsd:element name="bridge">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation>
|
||||
Defines an endpoint that passes a Message to the
|
||||
@@ -430,6 +429,22 @@
|
||||
modifying it.
|
||||
</xsd:documentation>
|
||||
</xsd:annotation>
|
||||
<xsd:complexType>
|
||||
<xsd:complexContent>
|
||||
<xsd:extension base="inputEndpointType">
|
||||
<xsd:attribute name="output-channel" type="xsd:string" use="required">
|
||||
<xsd:annotation>
|
||||
<xsd:appinfo>
|
||||
<tool:annotation kind="ref">
|
||||
<tool:expected-type
|
||||
type="org.springframework.integration.core.MessageChannel" />
|
||||
</tool:annotation>
|
||||
</xsd:appinfo>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
</xsd:extension>
|
||||
</xsd:complexContent>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
|
||||
<xsd:element name="chain">
|
||||
|
||||
@@ -16,7 +16,9 @@
|
||||
|
||||
package org.springframework.integration.handler;
|
||||
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.integration.core.Message;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* A simple MessageHandler implementation that passes the request Message
|
||||
@@ -26,11 +28,20 @@ import org.springframework.integration.core.Message;
|
||||
*
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public class BridgeHandler extends AbstractReplyProducingMessageHandler {
|
||||
public class BridgeHandler extends AbstractReplyProducingMessageHandler implements InitializingBean {
|
||||
|
||||
public void afterPropertiesSet() {
|
||||
this.verifyOutputChannel();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void handleRequestMessage(Message<?> requestMessage, ReplyMessageHolder replyMessageHolder) {
|
||||
this.verifyOutputChannel();
|
||||
replyMessageHolder.set(requestMessage);
|
||||
}
|
||||
|
||||
private void verifyOutputChannel() {
|
||||
Assert.state(super.getOutputChannel() != null, "Bridge handler requires an output channel");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* Copyright 2002-2009 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.handler;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.integration.channel.QueueChannel;
|
||||
import org.springframework.integration.core.Message;
|
||||
import org.springframework.integration.message.MessageHandlingException;
|
||||
import org.springframework.integration.message.StringMessage;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public class BridgeHandlerTests {
|
||||
|
||||
@Test
|
||||
public void simpleBridge() {
|
||||
QueueChannel outputChannel = new QueueChannel();
|
||||
BridgeHandler handler = new BridgeHandler();
|
||||
handler.setOutputChannel(outputChannel);
|
||||
Message<?> request = new StringMessage("test");
|
||||
handler.handleMessage(request);
|
||||
Message<?> reply = outputChannel.receive(0);
|
||||
assertNotNull(reply);
|
||||
assertEquals(request, reply);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalStateException.class)
|
||||
public void missingOutputChannelVerifiedUponInitialization() {
|
||||
BridgeHandler handler = new BridgeHandler();
|
||||
handler.afterPropertiesSet();
|
||||
}
|
||||
|
||||
@Test(expected = MessageHandlingException.class)
|
||||
public void missingOutputChannelVerifiedAtRuntime() {
|
||||
BridgeHandler handler = new BridgeHandler();
|
||||
Message<?> request = new StringMessage("test");
|
||||
handler.handleMessage(request);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user