Created
February 6, 2012 03:33
-
-
Save jteso/1749373 to your computer and use it in GitHub Desktop.
Steps required to package your own SI adaptor for reuse
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<beans xmlns="http://www.springframework.org/schema/beans" | |
... | |
xmlns:int-ca="http://jteso.com/schema/integration" | |
xsi:schemaLocation="http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration-2.1.xsd | |
... | |
http://jteso.com/schema/integration http://jteso.com/schema/integration/jteso-integration-1.0.xsd | |
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd"> | |
... | |
<!-- messages found in this channel will be printed in the console --> | |
<int-ca:terminal-channel-adapter channel="result-channel" /> | |
DISCLAIMER: | |
This example is for illustration purposes only. In a real environment, you should consider using the out of the box 'logging-channel-adapter'. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<xsd:schema xmlns="http://jteso.com/schema/integration" | |
xmlns:xsd="http://www.w3.org/2001/XMLSchema" | |
xmlns:beans="http://www.springframework.org/schema/beans" | |
xmlns:tool="http://www.springframework.org/schema/tool" | |
xmlns:integration="http://www.springframework.org/schema/integration" | |
targetNamespace="http://jteso.com/schema/integration" | |
elementFormDefault="qualified" | |
attributeFormDefault="unqualified"> | |
<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-2.0.xsd"/> | |
<xsd:element name="terminal-channel-adapter"> | |
<xsd:annotation> | |
<xsd:documentation> | |
Send incoming messages into the console | |
</xsd:documentation> | |
</xsd:annotation> | |
<xsd:complexType> | |
<xsd:sequence> | |
<xsd:element ref="integration:poller" minOccurs="0" maxOccurs="1"/> | |
</xsd:sequence> | |
<xsd:attribute name="id" type="xsd:string"/> | |
<xsd:attribute name="channel" type="xsd:string"> | |
<xsd:annotation> | |
<xsd:appinfo> | |
<tool:annotation kind="ref"> | |
<tool:expected-type | |
type="org.springframework.integration.core.MessageChannel"/> | |
</tool:annotation> | |
</xsd:appinfo> | |
<xsd:documentation> | |
Identifies channel attached to this adapter. | |
</xsd:documentation> | |
</xsd:annotation> | |
</xsd:attribute> | |
</xsd:complexType> | |
</xsd:element> | |
</xsd:schema> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
META-INF/spring.handlers | |
------------------------ | |
http\://jteso.com/schema/integration=directlabs.experimental.springintegration.customadapters.outbound.config.TerminalMessagingNamespaceHandler | |
META-INF/spring.schemas | |
----------------------- | |
http\://jteso.com/schema/integration/jteso-integration-1.0.xsd=directlabs/experimental/springintegration/customadapters/outbound/config/jteso-integration-1.0.xsd | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package directlabs.experimental.springintegration.customadapters.outbound.config; | |
import org.springframework.beans.factory.support.AbstractBeanDefinition; | |
import org.springframework.beans.factory.support.BeanDefinitionBuilder; | |
import org.springframework.beans.factory.xml.ParserContext; | |
import org.springframework.integration.config.xml.AbstractIntegrationNamespaceHandler; | |
import org.springframework.integration.config.xml.AbstractOutboundChannelAdapterParser; | |
import org.w3c.dom.Element; | |
import directlabs.experimental.springintegration.customadapters.outbound.TerminalOutboundEndpoint; | |
public class TerminalMessagingNamespaceHandler extends AbstractIntegrationNamespaceHandler{ | |
@Override | |
public void init() { | |
registerBeanDefinitionParser("terminal-channel-adapter", new TerminalMessagingOutboundChannelAdapterParser()); | |
} | |
public class TerminalMessagingOutboundChannelAdapterParser extends AbstractOutboundChannelAdapterParser { | |
@Override | |
protected AbstractBeanDefinition parseConsumer(Element element, ParserContext parserContext) { | |
BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(TerminalOutboundEndpoint.class); | |
return builder.getBeanDefinition(); | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package directlabs.experimental.springintegration.customadapters.outbound; | |
import org.springframework.integration.Message; | |
import org.springframework.integration.handler.AbstractMessageHandler; | |
import org.springframework.stereotype.Component; | |
import org.springframework.util.Assert; | |
/** | |
* Spring Integration Outbound adapter to write messages in the console | |
* @author jtedilla | |
* | |
*/ | |
@Component | |
public class TerminalOutboundEndpoint extends AbstractMessageHandler{ | |
public TerminalOutboundEndpoint() { | |
super(); | |
} | |
@Override | |
protected void handleMessageInternal(Message<?> message) throws Exception { | |
Assert.isInstanceOf(String.class, message.getPayload(), "Payload must be a String"); | |
String msg = (String) message.getPayload(); | |
System.out.println(msg); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment