Updated the names of the projects
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
console-source=org.springframework.integration.adapter.stream.config.ConsoleSourceParser
|
||||
console-target=org.springframework.integration.adapter.stream.config.ConsoleTargetParser
|
||||
file-source=org.springframework.integration.adapter.file.config.FileSourceParser
|
||||
file-target=org.springframework.integration.adapter.file.config.FileTargetParser
|
||||
ftp-source=org.springframework.integration.adapter.ftp.config.FtpSourceParser
|
||||
httpinvoker-source=org.springframework.integration.adapter.httpinvoker.config.HttpInvokerSourceAdapterParser
|
||||
httpinvoker-target=org.springframework.integration.adapter.httpinvoker.config.HttpInvokerTargetAdapterParser
|
||||
jms-gateway=org.springframework.integration.adapter.jms.config.JmsGatewayParser
|
||||
jms-source=org.springframework.integration.adapter.jms.config.JmsSourceParser
|
||||
jms-target=org.springframework.integration.adapter.jms.config.JmsTargetParser
|
||||
mail-target=org.springframework.integration.adapter.mail.config.MailTargetParser
|
||||
rmi-source=org.springframework.integration.adapter.rmi.config.RmiSourceAdapterParser
|
||||
rmi-target=org.springframework.integration.adapter.rmi.config.RmiTargetAdapterParser
|
||||
@@ -0,0 +1,2 @@
|
||||
http\://www.springframework.org/schema/integration/spring-integration-adapters-1.0.xsd=org/springframework/integration/adapter/config/spring-integration-adapters-1.0.xsd
|
||||
http\://www.springframework.org/schema/integration/spring-integration-1.0.xsd=org/springframework/integration/adapter/config/spring-integration-1.0.xsd
|
||||
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
* 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.adapter;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import org.springframework.integration.handler.MessageHandler;
|
||||
import org.springframework.integration.message.Message;
|
||||
import org.springframework.integration.message.MessageHandlingException;
|
||||
import org.springframework.remoting.RemoteAccessException;
|
||||
|
||||
/**
|
||||
* A base class for remoting target adapters.
|
||||
*
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public abstract class AbstractRemotingTargetAdapter implements MessageHandler {
|
||||
|
||||
private final MessageHandler handlerProxy;
|
||||
|
||||
|
||||
public AbstractRemotingTargetAdapter(String url) {
|
||||
this.handlerProxy = this.createHandlerProxy(url);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Subclasses must implement this method. It will be invoked from the constructor.
|
||||
*/
|
||||
protected abstract MessageHandler createHandlerProxy(String url);
|
||||
|
||||
|
||||
public final Message<?> handle(Message<?> message) {
|
||||
this.verifySerializability(message);
|
||||
try {
|
||||
return this.handlerProxy.handle(message);
|
||||
}
|
||||
catch (RemoteAccessException e) {
|
||||
throw new MessageHandlingException(message, "unable to handle message remotely", e);
|
||||
}
|
||||
}
|
||||
|
||||
private void verifySerializability(Message<?> message) {
|
||||
if (!(message.getPayload() instanceof Serializable)) {
|
||||
throw new MessageHandlingException(message,
|
||||
this.getClass().getName() + " expects a Serializable payload type " +
|
||||
"but encountered '" + message.getPayload().getClass().getName() + "'");
|
||||
}
|
||||
for (String attributeName : message.getHeader().getAttributeNames()) {
|
||||
Object attribute = message.getHeader().getAttribute(attributeName);
|
||||
if (!(attribute instanceof Serializable)) {
|
||||
throw new MessageHandlingException(message,
|
||||
this.getClass().getName() + " expects Serializable attribute types " +
|
||||
"but encountered '" + attribute.getClass().getName() + "' for the attribute '" +
|
||||
attributeName + "'");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,119 @@
|
||||
/*
|
||||
* 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.adapter;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.integration.ConfigurationException;
|
||||
import org.springframework.integration.channel.MessageChannel;
|
||||
import org.springframework.integration.channel.RequestReplyTemplate;
|
||||
import org.springframework.integration.handler.MessageHandler;
|
||||
import org.springframework.integration.message.Message;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* A source adapter that implements the {@link MessageHandler} interface. It may
|
||||
* be used as a base class for source adapters with request-reply behavior.
|
||||
*
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public class MessageHandlingSourceAdapter implements MessageHandler, InitializingBean {
|
||||
|
||||
private final Log logger = LogFactory.getLog(this.getClass());
|
||||
|
||||
private final MessageChannel requestChannel;
|
||||
|
||||
private final RequestReplyTemplate requestReplyTemplate = new RequestReplyTemplate();
|
||||
|
||||
private volatile boolean expectReply = true;
|
||||
|
||||
protected final Object lifecycleMonitor = new Object();
|
||||
|
||||
private volatile boolean initialized;
|
||||
|
||||
|
||||
/**
|
||||
* Create an adapter that sends to the provided channel.
|
||||
*
|
||||
* @param requestChannel the channel where messages will be sent, must not be
|
||||
* <code>null</code>.
|
||||
*/
|
||||
public MessageHandlingSourceAdapter(MessageChannel requestChannel) {
|
||||
Assert.notNull(requestChannel, "request channel must not be null");
|
||||
this.requestChannel = requestChannel;
|
||||
this.requestReplyTemplate.setRequestChannel(requestChannel);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Specify whether the handle method should be expected to return a reply.
|
||||
* The default is '<code>true</code>'.
|
||||
*/
|
||||
public void setExpectReply(boolean expectReply) {
|
||||
this.expectReply = expectReply;
|
||||
}
|
||||
|
||||
public void setRequestTimeout(long requestTimeout) {
|
||||
this.requestReplyTemplate.setRequestTimeout(requestTimeout);
|
||||
}
|
||||
|
||||
public void setReplyTimeout(long replyTimeout) {
|
||||
this.requestReplyTemplate.setReplyTimeout(replyTimeout);
|
||||
}
|
||||
|
||||
protected MessageChannel getChannel() {
|
||||
return this.requestChannel;
|
||||
}
|
||||
|
||||
public final void afterPropertiesSet() throws Exception {
|
||||
synchronized (this.lifecycleMonitor) {
|
||||
if (this.initialized) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
this.initialize();
|
||||
this.initialized = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Subclasses may override this method for initialization.
|
||||
*/
|
||||
protected void initialize() throws Exception {
|
||||
}
|
||||
|
||||
public final Message<?> handle(Message<?> message) {
|
||||
if (!this.initialized) {
|
||||
try {
|
||||
this.afterPropertiesSet();
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new ConfigurationException("unable to initialize " + this.getClass().getName(), e);
|
||||
}
|
||||
}
|
||||
if (!this.expectReply) {
|
||||
boolean sent = this.requestReplyTemplate.send(message);
|
||||
if (!sent && logger.isWarnEnabled()) {
|
||||
logger.warn("failed to send message to channel within timeout");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
return this.requestReplyTemplate.request(message);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* 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.adapter;
|
||||
|
||||
import org.springframework.integration.message.MessageHeader;
|
||||
|
||||
/**
|
||||
* Strategy interface for mapping between a source or target object and an
|
||||
* integration {@link MessageHeader}.
|
||||
*
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public interface MessageHeaderMapper<T> {
|
||||
|
||||
void mapFromMessageHeader(MessageHeader header, T target);
|
||||
|
||||
void mapToMessageHeader(T source, MessageHeader header);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* 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.adapter;
|
||||
|
||||
import org.springframework.integration.message.Message;
|
||||
import org.springframework.integration.message.MessageHandlingException;
|
||||
|
||||
/**
|
||||
* Exception that indicates an error during message mapping.
|
||||
*
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public class MessageMappingException extends MessageHandlingException {
|
||||
|
||||
public MessageMappingException(Message<?> failedMessage, String description) {
|
||||
super(failedMessage, description);
|
||||
}
|
||||
|
||||
public MessageMappingException(Message<?> failedMessage, String description, Throwable cause) {
|
||||
super(failedMessage, description, cause);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
/*
|
||||
* 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.adapter.config;
|
||||
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
import org.springframework.beans.factory.BeanDefinitionStoreException;
|
||||
import org.springframework.beans.factory.support.AbstractBeanDefinition;
|
||||
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
|
||||
import org.springframework.beans.factory.xml.AbstractSimpleBeanDefinitionParser;
|
||||
import org.springframework.beans.factory.xml.ParserContext;
|
||||
import org.springframework.integration.ConfigurationException;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
* Base class for request-reply source adapter parsers.
|
||||
*
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public abstract class AbstractRequestReplySourceAdapterParser extends AbstractSimpleBeanDefinitionParser {
|
||||
|
||||
protected abstract Class<?> getBeanClass(Element element);
|
||||
|
||||
@Override
|
||||
protected String resolveId(Element element, AbstractBeanDefinition definition, ParserContext parserContext)
|
||||
throws BeanDefinitionStoreException {
|
||||
String id = super.resolveId(element, definition, parserContext);
|
||||
if (!StringUtils.hasText(id)) {
|
||||
id = element.getAttribute("name");
|
||||
}
|
||||
if (!StringUtils.hasText(id)) {
|
||||
id = parserContext.getReaderContext().generateBeanName(definition);
|
||||
}
|
||||
return id;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isEligibleAttribute(String attributeName) {
|
||||
return !attributeName.equals("name") && !attributeName.equals("request-channel") && super.isEligibleAttribute(attributeName);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void postProcess(BeanDefinitionBuilder builder, Element element) {
|
||||
String channelRef = element.getAttribute("request-channel");
|
||||
if (!StringUtils.hasText(channelRef)) {
|
||||
throw new ConfigurationException("a 'request-channel' reference is required");
|
||||
}
|
||||
builder.addConstructorArgReference(channelRef);
|
||||
builder.addPropertyValue("expectReply", element.getAttribute("expect-reply").equals("true"));
|
||||
String requestTimeout = element.getAttribute("request-timeout");
|
||||
if (StringUtils.hasText(requestTimeout)) {
|
||||
builder.addPropertyValue("requestTimeout", Long.parseLong(requestTimeout));
|
||||
}
|
||||
String replyTimeout = element.getAttribute("reply-timeout");
|
||||
if (StringUtils.hasText(replyTimeout)) {
|
||||
builder.addPropertyValue("replyTimeout", Long.parseLong(replyTimeout));
|
||||
}
|
||||
this.doPostProcess(builder, element);
|
||||
}
|
||||
|
||||
/**
|
||||
* Subclasses may add to the bean definition by overriding this method.
|
||||
*/
|
||||
protected void doPostProcess(BeanDefinitionBuilder builder, Element element) {
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<xsd:schema xmlns="http://www.springframework.org/schema/integration"
|
||||
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
|
||||
targetNamespace="http://www.springframework.org/schema/integration"
|
||||
elementFormDefault="qualified"
|
||||
attributeFormDefault="unqualified">
|
||||
|
||||
<xsd:include schemaLocation="http://www.springframework.org/schema/integration/spring-integration-core-1.0.xsd"/>
|
||||
<xsd:include schemaLocation="http://www.springframework.org/schema/integration/spring-integration-adapters-1.0.xsd"/>
|
||||
|
||||
</xsd:schema>
|
||||
@@ -0,0 +1,263 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<xsd:schema xmlns="http://www.springframework.org/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"
|
||||
targetNamespace="http://www.springframework.org/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:annotation>
|
||||
<xsd:documentation><![CDATA[
|
||||
Defines the configuration elements for Spring Integration adapters.
|
||||
]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
|
||||
<xsd:element name="file-source">
|
||||
<xsd:complexType>
|
||||
<xsd:annotation>
|
||||
<xsd:documentation>
|
||||
Defines a file-based source channel adapter.
|
||||
</xsd:documentation>
|
||||
</xsd:annotation>
|
||||
<xsd:attribute name="id" type="xsd:string"/>
|
||||
<xsd:attribute name="directory" type="xsd:string" use="required"/>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
|
||||
<xsd:element name="file-target">
|
||||
<xsd:complexType>
|
||||
<xsd:annotation>
|
||||
<xsd:documentation>
|
||||
Defines a file-based target.
|
||||
</xsd:documentation>
|
||||
</xsd:annotation>
|
||||
<xsd:attribute name="id" type="xsd:string"/>
|
||||
<xsd:attribute name="directory" type="xsd:string" use="required"/>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
|
||||
<xsd:element name="ftp-source">
|
||||
<xsd:complexType>
|
||||
<xsd:annotation>
|
||||
<xsd:documentation>
|
||||
Defines an ftp-receiving target channel adapter.
|
||||
</xsd:documentation>
|
||||
</xsd:annotation>
|
||||
<xsd:attribute name="id" type="xsd:string"/>
|
||||
<xsd:attribute name="username" type="xsd:string" use="optional"/>
|
||||
<xsd:attribute name="password" type="xsd:string" use="optional"/>
|
||||
<xsd:attribute name="host" type="xsd:string" use="required"/>
|
||||
<xsd:attribute name="port" type="xsd:int" use="optional"/>
|
||||
<xsd:attribute name="local-working-directory" type="xsd:string" use="required"/>
|
||||
<xsd:attribute name="remote-working-directory" type="xsd:string" use="optional"/>
|
||||
<xsd:attribute name="text-based" type="xsd:boolean" use="optional"/>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
|
||||
<xsd:element name="jms-source">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation>
|
||||
Defines a JMS-based source channel adapter.
|
||||
</xsd:documentation>
|
||||
</xsd:annotation>
|
||||
<xsd:complexType>
|
||||
<xsd:complexContent>
|
||||
<xsd:extension base="jmsInboundAdapterType">
|
||||
<xsd:attribute name="header-mapper" type="xsd:string"/>
|
||||
</xsd:extension>
|
||||
</xsd:complexContent>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
|
||||
<xsd:element name="jms-gateway">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation>
|
||||
Defines a JMS-based gateway adapter.
|
||||
</xsd:documentation>
|
||||
</xsd:annotation>
|
||||
<xsd:complexType>
|
||||
<xsd:complexContent>
|
||||
<xsd:extension base="jmsInboundAdapterType">
|
||||
<xsd:attribute name="message-converter" type="xsd:string"/>
|
||||
<xsd:attribute name="expect-reply" type="xsd:boolean" default="false"/>
|
||||
<xsd:attribute name="request-channel" type="xsd:string" use="required"/>
|
||||
<xsd:attribute name="reply-channel" type="xsd:string"/>
|
||||
<xsd:attribute name="request-timeout" type="xsd:long"/>
|
||||
<xsd:attribute name="reply-timeout" type="xsd:long"/>
|
||||
</xsd:extension>
|
||||
</xsd:complexContent>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
|
||||
<xsd:element name="jms-target">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation>
|
||||
Defines a target that sends JMS Messages.
|
||||
</xsd:documentation>
|
||||
</xsd:annotation>
|
||||
<xsd:complexType>
|
||||
<xsd:complexContent>
|
||||
<xsd:extension base="jmsAdapterType">
|
||||
<xsd:attribute name="header-mapper" type="xsd:string"/>
|
||||
</xsd:extension>
|
||||
</xsd:complexContent>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
|
||||
<xsd:complexType name="jmsInboundAdapterType">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation>
|
||||
Common configuration for inbound JMS-based adapters.
|
||||
</xsd:documentation>
|
||||
</xsd:annotation>
|
||||
<xsd:complexContent>
|
||||
<xsd:extension base="jmsAdapterType">
|
||||
<xsd:attribute name="acknowledge" default="auto">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation><![CDATA[
|
||||
The native JMS acknowledge mode: "auto", "client", "dups-ok" or "transacted".
|
||||
The latter effectively activates a locally transacted Session.
|
||||
]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
<xsd:simpleType>
|
||||
<xsd:restriction base="xsd:NMTOKEN">
|
||||
<xsd:enumeration value="auto"/>
|
||||
<xsd:enumeration value="client"/>
|
||||
<xsd:enumeration value="dups-ok"/>
|
||||
<xsd:enumeration value="transacted"/>
|
||||
</xsd:restriction>
|
||||
</xsd:simpleType>
|
||||
</xsd:attribute>
|
||||
</xsd:extension>
|
||||
</xsd:complexContent>
|
||||
</xsd:complexType>
|
||||
|
||||
<xsd:complexType name="jmsAdapterType">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation>
|
||||
Common configuration for JMS-based adapters.
|
||||
</xsd:documentation>
|
||||
</xsd:annotation>
|
||||
<xsd:attribute name="id" type="xsd:string"/>
|
||||
<xsd:attribute name="jms-template" type="xsd:string"/>
|
||||
<xsd:attribute name="connection-factory" type="xsd:string"/>
|
||||
<xsd:attribute name="destination" type="xsd:string"/>
|
||||
<xsd:attribute name="destination-name" type="xsd:string"/>
|
||||
</xsd:complexType>
|
||||
|
||||
<xsd:element name="rmi-source">
|
||||
<xsd:complexType>
|
||||
<xsd:annotation>
|
||||
<xsd:documentation>
|
||||
Defines an rmi-based source channel adapter.
|
||||
</xsd:documentation>
|
||||
</xsd:annotation>
|
||||
<xsd:complexContent>
|
||||
<xsd:extension base="gatewayType">
|
||||
<xsd:attribute name="registry-host" type="xsd:string"/>
|
||||
<xsd:attribute name="registry-port" type="xsd:integer"/>
|
||||
<xsd:attribute name="remote-invocation-executor" type="xsd:string"/>
|
||||
</xsd:extension>
|
||||
</xsd:complexContent>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
|
||||
<xsd:element name="rmi-target">
|
||||
<xsd:complexType>
|
||||
<xsd:annotation>
|
||||
<xsd:documentation>
|
||||
Defines an rmi-based target channel adapter.
|
||||
</xsd:documentation>
|
||||
</xsd:annotation>
|
||||
<xsd:attribute name="id" type="xsd:string"/>
|
||||
<xsd:attribute name="host" type="xsd:string" use="required"/>
|
||||
<xsd:attribute name="port" type="xsd:integer"/>
|
||||
<xsd:attribute name="local-channel" type="xsd:string" use="required"/>
|
||||
<xsd:attribute name="remote-channel" type="xsd:string" use="required"/>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
|
||||
<xsd:element name="httpinvoker-source" type="gatewayType">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation>
|
||||
Defines an httpinvoker-based source channel adapter.
|
||||
</xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:element>
|
||||
|
||||
<xsd:element name="httpinvoker-target">
|
||||
<xsd:complexType>
|
||||
<xsd:annotation>
|
||||
<xsd:documentation>
|
||||
Defines an httpinvoker-based target channel adapter.
|
||||
</xsd:documentation>
|
||||
</xsd:annotation>
|
||||
<xsd:attribute name="id" type="xsd:string"/>
|
||||
<xsd:attribute name="channel" type="xsd:string" use="required"/>
|
||||
<xsd:attribute name="url" type="xsd:string" use="required"/>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
|
||||
<xsd:element name="mail-target">
|
||||
<xsd:complexType>
|
||||
<xsd:annotation>
|
||||
<xsd:documentation>
|
||||
Defines a mail-sending target.
|
||||
</xsd:documentation>
|
||||
</xsd:annotation>
|
||||
<xsd:attribute name="id" type="xsd:string"/>
|
||||
<xsd:attribute name="mail-sender" type="xsd:string"/>
|
||||
<xsd:attribute name="header-generator" type="xsd:string"/>
|
||||
<xsd:attribute name="host" type="xsd:string"/>
|
||||
<xsd:attribute name="username" type="xsd:string"/>
|
||||
<xsd:attribute name="password" type="xsd:string"/>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
|
||||
<xsd:element name="console-source">
|
||||
<xsd:complexType>
|
||||
<xsd:annotation>
|
||||
<xsd:documentation>
|
||||
Configures a source that reads from stdin (System.in).
|
||||
</xsd:documentation>
|
||||
</xsd:annotation>
|
||||
<xsd:attribute name="id" type="xsd:string"/>
|
||||
<xsd:attribute name="charset" type="xsd:string"/>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
|
||||
<xsd:element name="console-target">
|
||||
<xsd:complexType>
|
||||
<xsd:annotation>
|
||||
<xsd:documentation>
|
||||
Configures a target that writes to stdout (System.out) or to stderr (System.err)
|
||||
if the "error" attribute is set to true.
|
||||
</xsd:documentation>
|
||||
</xsd:annotation>
|
||||
<xsd:attribute name="id" type="xsd:string"/>
|
||||
<xsd:attribute name="charset" type="xsd:string"/>
|
||||
<xsd:attribute name="error" type="xsd:boolean" default="false"/>
|
||||
<xsd:attribute name="append-newline" type="xsd:boolean" default="false"/>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
|
||||
<xsd:complexType name="gatewayType">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation>
|
||||
Defines common configuration for gateway adapters.
|
||||
</xsd:documentation>
|
||||
</xsd:annotation>
|
||||
<xsd:attribute name="id" type="xsd:ID"/>
|
||||
<xsd:attribute name="name" type="xsd:string"/>
|
||||
<xsd:attribute name="expect-reply" type="xsd:boolean" default="true"/>
|
||||
<xsd:attribute name="request-channel" type="xsd:string" use="required"/>
|
||||
<xsd:attribute name="reply-channel" type="xsd:string"/>
|
||||
<xsd:attribute name="request-timeout" type="xsd:long"/>
|
||||
<xsd:attribute name="reply-timeout" type="xsd:long"/>
|
||||
</xsd:complexType>
|
||||
|
||||
</xsd:schema>
|
||||
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
* 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.adapter.event;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.context.ApplicationEvent;
|
||||
import org.springframework.context.ApplicationListener;
|
||||
import org.springframework.integration.channel.ChannelPublisher;
|
||||
import org.springframework.integration.channel.MessageChannel;
|
||||
import org.springframework.integration.message.GenericMessage;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
/**
|
||||
* A message source for passing Spring
|
||||
* {@link ApplicationEvent ApplicationEvents} within messages.
|
||||
*
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public class ApplicationEventSource extends ChannelPublisher implements ApplicationListener {
|
||||
|
||||
private List<Class<? extends ApplicationEvent>> eventTypes = new ArrayList<Class<? extends ApplicationEvent>>();
|
||||
|
||||
|
||||
public ApplicationEventSource(MessageChannel channel) {
|
||||
super(channel);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set the list of event types (classes that extend ApplicationEvent) that
|
||||
* this adapter should send to the message channel. By default, all event
|
||||
* types will be sent.
|
||||
*/
|
||||
public void setEventTypes(List<Class<? extends ApplicationEvent>> eventTypes) {
|
||||
Assert.notEmpty(eventTypes, "at least one event type is required");
|
||||
this.eventTypes = eventTypes;
|
||||
}
|
||||
|
||||
public void onApplicationEvent(ApplicationEvent event) {
|
||||
if (CollectionUtils.isEmpty(this.eventTypes)) {
|
||||
this.sendMessage(event);
|
||||
return;
|
||||
}
|
||||
for (Class<? extends ApplicationEvent> eventType : this.eventTypes) {
|
||||
if (eventType.isAssignableFrom(event.getClass())) {
|
||||
this.sendMessage(event);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean sendMessage(ApplicationEvent event) {
|
||||
return this.publish(new GenericMessage<ApplicationEvent>(event));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* 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.adapter.event;
|
||||
|
||||
import org.springframework.context.ApplicationEvent;
|
||||
import org.springframework.context.ApplicationEventPublisher;
|
||||
import org.springframework.context.ApplicationEventPublisherAware;
|
||||
import org.springframework.integration.message.Message;
|
||||
import org.springframework.integration.message.MessageMapper;
|
||||
import org.springframework.integration.message.Target;
|
||||
|
||||
/**
|
||||
* A message target for publishing {@link MessagingEvent MessagingEvents}. The
|
||||
* {@link MessagingEvent} is a subclass of Spring's {@link ApplicationEvent}
|
||||
* used by this adapter to wrap any {@link Message} sent to this target.
|
||||
*
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public class ApplicationEventTarget<T> implements Target, ApplicationEventPublisherAware {
|
||||
|
||||
private final MessageMapper<T, MessagingEvent<T>> mapper = new MessagingEventMapper<T>();
|
||||
|
||||
private ApplicationEventPublisher applicationEventPublisher;
|
||||
|
||||
|
||||
public void setApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher) {
|
||||
this.applicationEventPublisher = applicationEventPublisher;
|
||||
}
|
||||
|
||||
public boolean send(Message<?> message) {
|
||||
this.applicationEventPublisher.publishEvent(this.mapper.mapMessage((Message<T>) message));
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright 2002-2007 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.adapter.event;
|
||||
|
||||
import org.springframework.context.ApplicationEvent;
|
||||
import org.springframework.integration.message.Message;
|
||||
|
||||
/**
|
||||
* A subclass of {@link ApplicationEvent} that wraps a {@link Message}.
|
||||
*
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public class MessagingEvent<T> extends ApplicationEvent {
|
||||
|
||||
public MessagingEvent(Message<T> message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public Message<T> getMessage() {
|
||||
return (Message<T>) this.getSource();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* 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.adapter.event;
|
||||
|
||||
import org.springframework.integration.message.Message;
|
||||
import org.springframework.integration.message.MessageCreator;
|
||||
import org.springframework.integration.message.MessageMapper;
|
||||
|
||||
/**
|
||||
* Maps between {@link Message Messages} and {@link MessagingEvent MessagingEvents}.
|
||||
*
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public class MessagingEventMapper<T> implements MessageCreator<MessagingEvent<T>, T>, MessageMapper<T, MessagingEvent<T>> {
|
||||
|
||||
public Message<T> createMessage(MessagingEvent<T> event) {
|
||||
return event.getMessage();
|
||||
}
|
||||
|
||||
public MessagingEvent<T> mapMessage(Message<T> message) {
|
||||
return new MessagingEvent<T>(message);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,104 @@
|
||||
/*
|
||||
* 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.adapter.file;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.io.FileWriter;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import org.springframework.integration.message.GenericMessage;
|
||||
import org.springframework.integration.message.Message;
|
||||
import org.springframework.integration.message.MessageCreator;
|
||||
import org.springframework.integration.message.MessageHandlingException;
|
||||
import org.springframework.integration.message.MessageMapper;
|
||||
import org.springframework.integration.message.MessagingException;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.FileCopyUtils;
|
||||
|
||||
/**
|
||||
* Base class providing common behavior for file-based message mappers.
|
||||
*
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public abstract class AbstractFileMapper<T> implements MessageCreator<File, T>, MessageMapper<T, File> {
|
||||
|
||||
protected Log logger = LogFactory.getLog(this.getClass());
|
||||
|
||||
private File parentDirectory;
|
||||
|
||||
private File backupDirectory;
|
||||
|
||||
private FileNameGenerator fileNameGenerator = new DefaultFileNameGenerator();
|
||||
|
||||
|
||||
public AbstractFileMapper(File parentDirectory) {
|
||||
this.parentDirectory = parentDirectory;
|
||||
}
|
||||
|
||||
public void setBackupDirectory(File backupDirectory) {
|
||||
this.backupDirectory = backupDirectory;
|
||||
}
|
||||
|
||||
public void setFileNameGenerator(FileNameGenerator fileNameGenerator) {
|
||||
Assert.notNull(fileNameGenerator, "'fileNameGenerator' must not be null");
|
||||
this.fileNameGenerator = fileNameGenerator;
|
||||
}
|
||||
|
||||
public File mapMessage(Message<T> message) {
|
||||
try {
|
||||
File file = new File(parentDirectory, this.fileNameGenerator.generateFileName(message));
|
||||
this.writeToFile(file, message.getPayload());
|
||||
return file;
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new MessageHandlingException(message, "failure occurred mapping file to message", e);
|
||||
}
|
||||
}
|
||||
|
||||
public Message<T> createMessage(File file) {
|
||||
try {
|
||||
T payload = this.readMessagePayload(file);
|
||||
if (payload == null) {
|
||||
return null;
|
||||
}
|
||||
Message<T> message = new GenericMessage<T>(payload);
|
||||
message.getHeader().setProperty(FileNameGenerator.FILENAME_PROPERTY_KEY, file.getName());
|
||||
if (this.backupDirectory != null) {
|
||||
FileWriter writer = new FileWriter(this.backupDirectory.getAbsolutePath() +
|
||||
File.separator + file.getName());
|
||||
FileCopyUtils.copy(new FileReader(file), writer);
|
||||
}
|
||||
file.delete();
|
||||
return message;
|
||||
}
|
||||
catch (Exception e) {
|
||||
String description = "failure occurred mapping file to message";
|
||||
if (logger.isWarnEnabled()) {
|
||||
logger.warn(description, e);
|
||||
}
|
||||
throw new MessagingException(description, e);
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract T readMessagePayload(File file) throws Exception;
|
||||
|
||||
protected abstract void writeToFile(File file, T payload) throws Exception;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Copyright 2002-2007 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.adapter.file;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import org.springframework.util.FileCopyUtils;
|
||||
|
||||
/**
|
||||
* A {@link org.springframework.integration.message.MessageMapper}
|
||||
* implementation for messages with a byte array payload.
|
||||
*
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public class ByteArrayFileMapper extends AbstractFileMapper<byte[]> {
|
||||
|
||||
public ByteArrayFileMapper(File parentDirectory) {
|
||||
super(parentDirectory);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected byte[] readMessagePayload(File file) throws Exception {
|
||||
return FileCopyUtils.copyToByteArray(file);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void writeToFile(File file, byte[] payload) throws Exception {
|
||||
FileCopyUtils.copy(payload, file);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* Copyright 2002-2007 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.adapter.file;
|
||||
|
||||
import org.springframework.integration.message.Message;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
* Default implementation of the filename generator strategy. Concatenates the
|
||||
* message id and the current timestamp.
|
||||
*
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public class DefaultFileNameGenerator implements FileNameGenerator {
|
||||
|
||||
public String generateFileName(Message<?> message) {
|
||||
String filenameProperty = message.getHeader().getProperty(FILENAME_PROPERTY_KEY);
|
||||
return StringUtils.hasText(filenameProperty) ?
|
||||
filenameProperty : message.getId() + "-" + System.currentTimeMillis() + ".msg";
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* Copyright 2002-2007 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.adapter.file;
|
||||
|
||||
import org.springframework.integration.message.Message;
|
||||
|
||||
/**
|
||||
* Strategy interface for generating a file name from a message.
|
||||
*
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public interface FileNameGenerator {
|
||||
|
||||
String FILENAME_PROPERTY_KEY = "filename";
|
||||
|
||||
|
||||
String generateFileName(Message<?> message);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,110 @@
|
||||
/*
|
||||
* 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.adapter.file;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileFilter;
|
||||
import java.io.FilenameFilter;
|
||||
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.integration.message.Message;
|
||||
import org.springframework.integration.message.MessagingException;
|
||||
import org.springframework.integration.message.Source;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* A messaging source that polls a directory to retrieve files.
|
||||
*
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public class FileSource implements Source<Object>, InitializingBean {
|
||||
|
||||
private final File directory;
|
||||
|
||||
private volatile boolean textBased = true;
|
||||
|
||||
private volatile AbstractFileMapper<?> mapper;
|
||||
|
||||
private volatile FileNameGenerator fileNameGenerator;
|
||||
|
||||
private volatile FileFilter fileFilter;
|
||||
|
||||
private volatile FilenameFilter filenameFilter;
|
||||
|
||||
|
||||
public FileSource(File directory) {
|
||||
Assert.notNull(directory, "directory must not be null");
|
||||
this.directory = directory;
|
||||
}
|
||||
|
||||
|
||||
public boolean isTextBased() {
|
||||
return this.textBased;
|
||||
}
|
||||
|
||||
public void setTextBased(boolean textBased) {
|
||||
this.textBased = textBased;
|
||||
}
|
||||
|
||||
public void setFileFilter(FileFilter fileFilter) {
|
||||
this.fileFilter = fileFilter;
|
||||
}
|
||||
|
||||
public void setFilenameFilter(FilenameFilter filenameFilter) {
|
||||
this.filenameFilter = filenameFilter;
|
||||
}
|
||||
|
||||
public void setFileNameGenerator(FileNameGenerator fileNameGenerator) {
|
||||
this.fileNameGenerator = fileNameGenerator;
|
||||
}
|
||||
|
||||
public void afterPropertiesSet() {
|
||||
if (this.isTextBased()) {
|
||||
this.mapper = new TextFileMapper(this.directory);
|
||||
}
|
||||
else {
|
||||
this.mapper = new ByteArrayFileMapper(this.directory);
|
||||
}
|
||||
if (this.fileNameGenerator != null) {
|
||||
this.mapper.setFileNameGenerator(this.fileNameGenerator);
|
||||
}
|
||||
}
|
||||
|
||||
public Message receive() {
|
||||
File[] files = null;
|
||||
if (this.fileFilter != null) {
|
||||
files = this.directory.listFiles(this.fileFilter);
|
||||
}
|
||||
else if (this.filenameFilter != null) {
|
||||
files = this.directory.listFiles(this.filenameFilter);
|
||||
}
|
||||
else {
|
||||
files = this.directory.listFiles();
|
||||
}
|
||||
if (files == null) {
|
||||
throw new MessagingException("Problem occurred while polling for files. " +
|
||||
"Is '" + directory.getAbsolutePath() + "' a directory?");
|
||||
}
|
||||
for (int i = 0; i < files.length; i++) {
|
||||
if (files[i].isFile()) {
|
||||
return this.mapper.createMessage(files[i]);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* 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.adapter.file;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import org.springframework.integration.message.Message;
|
||||
import org.springframework.integration.message.Target;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* A message target for writing files. The actual file writing occurs in
|
||||
* the message mapper ({@link TextFileMapper} or {@link ByteArrayFileMapper}).
|
||||
*
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public class FileTarget implements Target {
|
||||
|
||||
private AbstractFileMapper<?> mapper;
|
||||
|
||||
|
||||
public FileTarget(File directory) {
|
||||
this(directory, true);
|
||||
}
|
||||
|
||||
public FileTarget(File directory, boolean isTextBased) {
|
||||
if (isTextBased) {
|
||||
this.mapper = new TextFileMapper(directory);
|
||||
}
|
||||
else {
|
||||
this.mapper = new ByteArrayFileMapper(directory);
|
||||
}
|
||||
}
|
||||
|
||||
public void setFileNameGenerator(FileNameGenerator fileNameGenerator) {
|
||||
Assert.notNull(fileNameGenerator, "'fileNameGenerator' must not be null");
|
||||
if (mapper instanceof AbstractFileMapper<?>) {
|
||||
((AbstractFileMapper<?>) mapper).setFileNameGenerator(fileNameGenerator);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean send(Message message) {
|
||||
File file = this.mapper.mapMessage(message);
|
||||
return file.exists();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* 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.adapter.file;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.io.FileWriter;
|
||||
|
||||
import org.springframework.util.FileCopyUtils;
|
||||
|
||||
/**
|
||||
* A {@link org.springframework.integration.message.MessageMapper}
|
||||
* implementation for messages with a String payload.
|
||||
*
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public class TextFileMapper extends AbstractFileMapper<String> {
|
||||
|
||||
public TextFileMapper(File parentDirectory) {
|
||||
super(parentDirectory);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected String readMessagePayload(File file) throws Exception {
|
||||
return FileCopyUtils.copyToString(new FileReader(file));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void writeToFile(File file, String payload) throws Exception {
|
||||
FileCopyUtils.copy(payload, new FileWriter(file));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* 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.adapter.file.config;
|
||||
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
|
||||
import org.springframework.beans.factory.xml.AbstractSimpleBeanDefinitionParser;
|
||||
import org.springframework.integration.adapter.file.FileSource;
|
||||
|
||||
/**
|
||||
* Parser for the <file-source/> element.
|
||||
*
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public class FileSourceParser extends AbstractSimpleBeanDefinitionParser {
|
||||
|
||||
@Override
|
||||
protected Class<?> getBeanClass(Element element) {
|
||||
return FileSource.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isEligibleAttribute(String attributeName) {
|
||||
return (!"directory".equals(attributeName)) && super.isEligibleAttribute(attributeName);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void postProcess(BeanDefinitionBuilder beanDefinition, Element element) {
|
||||
beanDefinition.addConstructorArgValue(element.getAttribute("directory"));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* 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.adapter.file.config;
|
||||
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
|
||||
import org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser;
|
||||
import org.springframework.beans.factory.xml.ParserContext;
|
||||
import org.springframework.integration.adapter.file.FileTarget;
|
||||
|
||||
/**
|
||||
* Parser for the <file-target/> element.
|
||||
*
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public class FileTargetParser extends AbstractSingleBeanDefinitionParser {
|
||||
|
||||
protected Class<?> getBeanClass(Element element) {
|
||||
return FileTarget.class;
|
||||
}
|
||||
|
||||
protected boolean shouldGenerateId() {
|
||||
return false;
|
||||
}
|
||||
|
||||
protected boolean shouldGenerateIdAsFallback() {
|
||||
return true;
|
||||
}
|
||||
|
||||
protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
|
||||
builder.addConstructorArgValue(element.getAttribute("directory"));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
/*
|
||||
* 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.adapter.ftp;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
/**
|
||||
* Tracks changes in a directory. This implementation is thread-safe as it
|
||||
* allows to synchronously process a new directory structure.
|
||||
*
|
||||
* @author Marius Bogoevici
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public class DirectoryContentManager {
|
||||
|
||||
private final Log logger = LogFactory.getLog(this.getClass());
|
||||
|
||||
private Map<String, FileInfo> previousSnapshot = new HashMap<String, FileInfo>();
|
||||
|
||||
private final Map<String, FileInfo> backlog = new HashMap<String, FileInfo>();
|
||||
|
||||
|
||||
public synchronized void processSnapshot(Map<String, FileInfo> currentSnapshot) {
|
||||
Iterator<Map.Entry<String, FileInfo>> iter = this.backlog.entrySet().iterator();
|
||||
while (iter.hasNext()) {
|
||||
String fileName = iter.next().getKey();
|
||||
if (!currentSnapshot.containsKey(fileName)) {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Removing file '" + fileName + "' from backlog. It no longer exists in remote directory.");
|
||||
}
|
||||
iter.remove();
|
||||
}
|
||||
}
|
||||
for (String fileName : currentSnapshot.keySet()) {
|
||||
if (!this.previousSnapshot.containsKey(fileName)
|
||||
|| (!this.previousSnapshot.get(fileName).equals(currentSnapshot.get(fileName)))) {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Adding new or modified file '" + fileName + "' to backlog.");
|
||||
}
|
||||
this.backlog.put(fileName, currentSnapshot.get(fileName));
|
||||
}
|
||||
}
|
||||
this.previousSnapshot = new HashMap<String, FileInfo>(currentSnapshot);
|
||||
}
|
||||
|
||||
public synchronized void fileProcessed(String fileName) {
|
||||
if (fileName != null) {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Removing file '" + fileName + "' from the backlog. It has been processed.");
|
||||
}
|
||||
this.backlog.remove(fileName);
|
||||
}
|
||||
}
|
||||
|
||||
public Map<String, FileInfo> getBacklog() {
|
||||
return Collections.unmodifiableMap(this.backlog);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
/*
|
||||
* 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.adapter.ftp;
|
||||
|
||||
/**
|
||||
* Information about a file in a directory.
|
||||
*
|
||||
* @author Marius Bogoevici
|
||||
*/
|
||||
public class FileInfo {
|
||||
|
||||
private final String fileName;
|
||||
|
||||
private final long modificationTimestamp;
|
||||
|
||||
private final long size;
|
||||
|
||||
|
||||
public FileInfo(String fileName, long modificationTimestamp, long size) {
|
||||
this.fileName = fileName;
|
||||
this.modificationTimestamp = modificationTimestamp;
|
||||
this.size = size;
|
||||
}
|
||||
|
||||
|
||||
public String getFileName() {
|
||||
return fileName;
|
||||
}
|
||||
|
||||
public long getModificationTimestamp() {
|
||||
return modificationTimestamp;
|
||||
}
|
||||
|
||||
public long getSize() {
|
||||
return size;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object other) {
|
||||
if (other == null || !(other instanceof FileInfo)) {
|
||||
return false;
|
||||
}
|
||||
FileInfo otherInfo = (FileInfo) other;
|
||||
return this.getSize() == otherInfo.getSize()
|
||||
&& this.getModificationTimestamp() == otherInfo.getModificationTimestamp()
|
||||
&& this.fileName.equals(otherInfo.getFileName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return (fileName == null ? 0 : fileName.hashCode()) ^ new Long(modificationTimestamp).hashCode()
|
||||
^ new Long(size).hashCode();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,199 @@
|
||||
/*
|
||||
* 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.adapter.ftp;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.apache.commons.net.ftp.FTP;
|
||||
import org.apache.commons.net.ftp.FTPClient;
|
||||
import org.apache.commons.net.ftp.FTPFile;
|
||||
|
||||
import org.springframework.integration.adapter.file.ByteArrayFileMapper;
|
||||
import org.springframework.integration.adapter.file.FileNameGenerator;
|
||||
import org.springframework.integration.adapter.file.TextFileMapper;
|
||||
import org.springframework.integration.message.Message;
|
||||
import org.springframework.integration.message.MessageCreator;
|
||||
import org.springframework.integration.message.MessageDeliveryAware;
|
||||
import org.springframework.integration.message.MessagingException;
|
||||
import org.springframework.integration.message.Source;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
* A source adapter for receiving files via FTP.
|
||||
*
|
||||
* @author Marius Bogoevici
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public class FtpSource implements Source<Object>, MessageDeliveryAware {
|
||||
|
||||
private final static String DEFAULT_HOST = "localhost";
|
||||
|
||||
private final static int DEFAULT_PORT = 21;
|
||||
|
||||
private final static String DEFAULT_REMOTE_WORKING_DIRECTORY = "/";
|
||||
|
||||
|
||||
private final Log logger = LogFactory.getLog(this.getClass());
|
||||
|
||||
private volatile String username;
|
||||
|
||||
private volatile String password;
|
||||
|
||||
private volatile String host = DEFAULT_HOST;
|
||||
|
||||
private volatile int port = DEFAULT_PORT;
|
||||
|
||||
private volatile String remoteWorkingDirectory = DEFAULT_REMOTE_WORKING_DIRECTORY;
|
||||
|
||||
private volatile File localWorkingDirectory;
|
||||
|
||||
private volatile boolean textBased = true;
|
||||
|
||||
private volatile MessageCreator<File, ?> messageCreator;
|
||||
|
||||
private final DirectoryContentManager directoryContentManager = new DirectoryContentManager();
|
||||
|
||||
private final FTPClient client = new FTPClient();
|
||||
|
||||
|
||||
public void setHost(String host) {
|
||||
this.host = host;
|
||||
}
|
||||
|
||||
public void setPort(int port) {
|
||||
this.port = port;
|
||||
}
|
||||
|
||||
public void setUsername(String username) {
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
public void setPassword(String password) {
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
public void setRemoteWorkingDirectory(String remoteWorkingDirectory) {
|
||||
Assert.hasText(remoteWorkingDirectory, "'remoteWorkingDirectory' is required");
|
||||
this.remoteWorkingDirectory = remoteWorkingDirectory;
|
||||
}
|
||||
|
||||
public void setLocalWorkingDirectory(File localWorkingDirectory) {
|
||||
Assert.notNull(localWorkingDirectory, "'localWorkingDirectory' must not be null");
|
||||
this.localWorkingDirectory = localWorkingDirectory;
|
||||
}
|
||||
|
||||
public boolean isTextBased() {
|
||||
return this.textBased;
|
||||
}
|
||||
|
||||
public void setTextBased(boolean textBased) {
|
||||
this.textBased = textBased;
|
||||
}
|
||||
|
||||
public void afterPropertiesSet() {
|
||||
if (this.isTextBased()) {
|
||||
this.messageCreator = new TextFileMapper(this.localWorkingDirectory);
|
||||
}
|
||||
else {
|
||||
this.messageCreator = new ByteArrayFileMapper(this.localWorkingDirectory);
|
||||
}
|
||||
}
|
||||
|
||||
public final Message receive() {
|
||||
try {
|
||||
this.establishConnection();
|
||||
FTPFile[] fileList = this.client.listFiles();
|
||||
HashMap<String, FileInfo> snapshot = new HashMap<String, FileInfo>();
|
||||
for (FTPFile ftpFile : fileList) {
|
||||
FileInfo fileInfo = new FileInfo(
|
||||
ftpFile.getName(), ftpFile.getTimestamp().getTimeInMillis(), ftpFile.getSize());
|
||||
snapshot.put(ftpFile.getName(), fileInfo);
|
||||
}
|
||||
this.directoryContentManager.processSnapshot(snapshot);
|
||||
Map<String, FileInfo> backlog = this.directoryContentManager.getBacklog();
|
||||
if (backlog.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
String fileName = backlog.keySet().iterator().next();
|
||||
File file = new File(this.localWorkingDirectory, fileName);
|
||||
if (file.exists()) {
|
||||
file.delete();
|
||||
}
|
||||
FileOutputStream fileOutputStream = new FileOutputStream(file);
|
||||
this.client.retrieveFile(fileName, fileOutputStream);
|
||||
fileOutputStream.close();
|
||||
return this.messageCreator.createMessage(file);
|
||||
}
|
||||
catch (Exception e) {
|
||||
try {
|
||||
if (this.client.isConnected()) {
|
||||
this.client.disconnect();
|
||||
}
|
||||
}
|
||||
catch (IOException ioe) {
|
||||
throw new MessagingException("Error when disconnecting from ftp.", ioe);
|
||||
}
|
||||
throw new MessagingException("Error while polling for messages.", e);
|
||||
}
|
||||
}
|
||||
|
||||
private void establishConnection() throws IOException {
|
||||
if (!StringUtils.hasText(this.username)) {
|
||||
throw new MessagingException("username is required");
|
||||
}
|
||||
this.client.connect(this.host, this.port);
|
||||
if (!this.client.login(this.username, this.password)) {
|
||||
throw new MessagingException("Login failed. Please check the username and password.");
|
||||
}
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("login successful");
|
||||
}
|
||||
this.client.setFileType(FTP.IMAGE_FILE_TYPE);
|
||||
if (!this.remoteWorkingDirectory.equals(this.client.printWorkingDirectory())
|
||||
&& !this.client.changeWorkingDirectory(this.remoteWorkingDirectory)) {
|
||||
throw new MessagingException("Could not change directory to '" +
|
||||
remoteWorkingDirectory + "'. Please check the path.");
|
||||
}
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("working directory is: " + this.client.printWorkingDirectory());
|
||||
}
|
||||
}
|
||||
|
||||
public void onSend(Message<?> message) {
|
||||
String filename = message.getHeader().getProperty(FileNameGenerator.FILENAME_PROPERTY_KEY);
|
||||
if (StringUtils.hasText(filename)) {
|
||||
this.directoryContentManager.fileProcessed(filename);
|
||||
}
|
||||
else if (this.logger.isWarnEnabled()) {
|
||||
logger.warn("No filename in Message header, cannot send notification of processing.");
|
||||
}
|
||||
}
|
||||
|
||||
public void onFailure(MessagingException exception) {
|
||||
if (this.logger.isWarnEnabled()) {
|
||||
logger.warn("FtpSource received failure notifcation", exception);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* 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.adapter.ftp.config;
|
||||
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
import org.springframework.beans.factory.xml.AbstractSimpleBeanDefinitionParser;
|
||||
import org.springframework.integration.adapter.ftp.FtpSource;
|
||||
|
||||
/**
|
||||
* Parser for the <ftp-source/> element.
|
||||
*
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public class FtpSourceParser extends AbstractSimpleBeanDefinitionParser {
|
||||
|
||||
@Override
|
||||
protected Class<?> getBeanClass(Element element) {
|
||||
return FtpSource.class;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
/*
|
||||
* 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.adapter.httpinvoker;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.springframework.integration.adapter.MessageHandlingSourceAdapter;
|
||||
import org.springframework.integration.channel.MessageChannel;
|
||||
import org.springframework.integration.handler.MessageHandler;
|
||||
import org.springframework.integration.message.MessagingException;
|
||||
import org.springframework.remoting.httpinvoker.HttpInvokerServiceExporter;
|
||||
import org.springframework.web.HttpRequestHandler;
|
||||
|
||||
/**
|
||||
* A source channel adapter for HttpInvoker-based remoting. Since this class implements
|
||||
* {@link HttpRequestHandler}, it can be configured with a delegating Servlet where the
|
||||
* servlet-name matches this adapter's bean name. For example, the following servlet can
|
||||
* be defined in web.xml:
|
||||
*
|
||||
* <pre class="code">
|
||||
* <servlet>
|
||||
* <servlet-name>httpInvokerSourceAdapter</servlet-name>
|
||||
* <servlet-class>org.springframework.web.context.support.HttpRequestHandlerServlet</servlet-class>
|
||||
* </servlet>
|
||||
* </pre>
|
||||
*
|
||||
* And, this would match the following bean definition in the application context loaded
|
||||
* by a {@link org.springframework.web.contextContextLoaderListener}:
|
||||
*
|
||||
* <pre class="code">
|
||||
* <bean id="httpInvokerSourceAdapter" class="org.springframework.integration.adapter.httpinvoker.HttpInvokerSourceAdapter">
|
||||
* <constructor-arg ref="exampleChannel"/>
|
||||
* </bean>
|
||||
* </pre>
|
||||
*
|
||||
* <p>
|
||||
* Alternatively, in a Spring MVC application, the DispatcherServlet can delegate to the
|
||||
* "httpInvokerSourceAdapter" bean based on a handler mapping configuration. In that case,
|
||||
* the HttpRequestHandlerServlet would not be necessary.
|
||||
* </p>
|
||||
*
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public class HttpInvokerSourceAdapter extends MessageHandlingSourceAdapter implements HttpRequestHandler {
|
||||
|
||||
private volatile HttpInvokerServiceExporter exporter;
|
||||
|
||||
|
||||
public HttpInvokerSourceAdapter(MessageChannel channel) {
|
||||
super(channel);
|
||||
}
|
||||
|
||||
|
||||
public void initialize() {
|
||||
HttpInvokerServiceExporter exporter = new HttpInvokerServiceExporter();
|
||||
exporter.setService(this);
|
||||
exporter.setServiceInterface(MessageHandler.class);
|
||||
exporter.afterPropertiesSet();
|
||||
this.exporter = exporter;
|
||||
}
|
||||
|
||||
public void handleRequest(HttpServletRequest request, HttpServletResponse response)
|
||||
throws ServletException, IOException {
|
||||
if (this.exporter == null) {
|
||||
throw new MessagingException("adapter has not been initialized");
|
||||
}
|
||||
this.exporter.handleRequest(request, response);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* 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.adapter.httpinvoker;
|
||||
|
||||
import org.springframework.integration.adapter.AbstractRemotingTargetAdapter;
|
||||
import org.springframework.integration.handler.MessageHandler;
|
||||
import org.springframework.remoting.httpinvoker.HttpInvokerProxyFactoryBean;
|
||||
|
||||
/**
|
||||
* A target channel adapter for HttpInvoker-based remoting.
|
||||
*
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public class HttpInvokerTargetAdapter extends AbstractRemotingTargetAdapter {
|
||||
|
||||
public HttpInvokerTargetAdapter(String url) {
|
||||
super(url);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected MessageHandler createHandlerProxy(String url) {
|
||||
HttpInvokerProxyFactoryBean proxyFactory = new HttpInvokerProxyFactoryBean();
|
||||
proxyFactory.setServiceInterface(MessageHandler.class);
|
||||
proxyFactory.setServiceUrl(url);
|
||||
proxyFactory.afterPropertiesSet();
|
||||
return (MessageHandler) proxyFactory.getObject();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* 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.adapter.httpinvoker.config;
|
||||
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
import org.springframework.integration.adapter.config.AbstractRequestReplySourceAdapterParser;
|
||||
import org.springframework.integration.adapter.httpinvoker.HttpInvokerSourceAdapter;
|
||||
|
||||
/**
|
||||
* Parser for the <httpinvoker-source/> element.
|
||||
*
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public class HttpInvokerSourceAdapterParser extends AbstractRequestReplySourceAdapterParser {
|
||||
|
||||
@Override
|
||||
protected Class<?> getBeanClass(Element element) {
|
||||
return HttpInvokerSourceAdapter.class;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
/*
|
||||
* 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.adapter.httpinvoker.config;
|
||||
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
import org.springframework.beans.factory.parsing.BeanComponentDefinition;
|
||||
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
|
||||
import org.springframework.beans.factory.support.RootBeanDefinition;
|
||||
import org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser;
|
||||
import org.springframework.beans.factory.xml.ParserContext;
|
||||
import org.springframework.integration.ConfigurationException;
|
||||
import org.springframework.integration.adapter.httpinvoker.HttpInvokerTargetAdapter;
|
||||
import org.springframework.integration.endpoint.HandlerEndpoint;
|
||||
import org.springframework.integration.scheduling.Subscription;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
* Parser for the <httpinvoker-target/> element.
|
||||
*
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public class HttpInvokerTargetAdapterParser extends AbstractSingleBeanDefinitionParser {
|
||||
|
||||
protected Class<?> getBeanClass(Element element) {
|
||||
return HandlerEndpoint.class;
|
||||
}
|
||||
|
||||
protected boolean shouldGenerateId() {
|
||||
return false;
|
||||
}
|
||||
|
||||
protected boolean shouldGenerateIdAsFallback() {
|
||||
return true;
|
||||
}
|
||||
|
||||
protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
|
||||
RootBeanDefinition adapterDef = new RootBeanDefinition(HttpInvokerTargetAdapter.class);
|
||||
String channel = element.getAttribute("channel");
|
||||
String url = element.getAttribute("url");
|
||||
if (!StringUtils.hasText(channel)) {
|
||||
throw new ConfigurationException("The 'channel' attribute is required.");
|
||||
}
|
||||
if (!StringUtils.hasText(url)) {
|
||||
throw new ConfigurationException("The 'url' attribute is required.");
|
||||
}
|
||||
adapterDef.getConstructorArgumentValues().addGenericArgumentValue(url);
|
||||
String adapterBeanName = parserContext.getReaderContext().generateBeanName(adapterDef);
|
||||
parserContext.registerBeanComponent(new BeanComponentDefinition(adapterDef, adapterBeanName));
|
||||
builder.addConstructorArgReference(adapterBeanName);
|
||||
Subscription subscription = new Subscription(channel);
|
||||
builder.addPropertyValue("subscription", subscription);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,131 @@
|
||||
/*
|
||||
* 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.adapter.jms;
|
||||
|
||||
import javax.jms.ConnectionFactory;
|
||||
import javax.jms.Destination;
|
||||
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.integration.ConfigurationException;
|
||||
import org.springframework.integration.adapter.MessageHeaderMapper;
|
||||
import org.springframework.jms.core.JmsTemplate;
|
||||
import org.springframework.jms.support.converter.MessageConverter;
|
||||
|
||||
/**
|
||||
* Base class for adapters that delegate to a {@link JmsTemplate}.
|
||||
*
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public abstract class AbstractJmsTemplateBasedAdapter implements InitializingBean {
|
||||
|
||||
private volatile ConnectionFactory connectionFactory;
|
||||
|
||||
private volatile Destination destination;
|
||||
|
||||
private volatile String destinationName;
|
||||
|
||||
private volatile JmsTemplate jmsTemplate;
|
||||
|
||||
private volatile MessageHeaderMapper<javax.jms.Message> headerMapper;
|
||||
|
||||
private volatile boolean initialized;
|
||||
|
||||
private final Object initializationMonitor = new Object();
|
||||
|
||||
|
||||
public AbstractJmsTemplateBasedAdapter(JmsTemplate jmsTemplate) {
|
||||
this.jmsTemplate = jmsTemplate;
|
||||
}
|
||||
|
||||
public AbstractJmsTemplateBasedAdapter(ConnectionFactory connectionFactory, Destination destination) {
|
||||
this.connectionFactory = connectionFactory;
|
||||
this.destination = destination;
|
||||
this.jmsTemplate = createDefaultJmsTemplate();
|
||||
}
|
||||
|
||||
public AbstractJmsTemplateBasedAdapter(ConnectionFactory connectionFactory, String destinationName) {
|
||||
this.connectionFactory = connectionFactory;
|
||||
this.destinationName = destinationName;
|
||||
this.jmsTemplate = createDefaultJmsTemplate();
|
||||
}
|
||||
|
||||
/**
|
||||
* No-arg constructor provided for convenience when configuring with
|
||||
* setters. Note that the initialization callback will validate.
|
||||
*/
|
||||
public AbstractJmsTemplateBasedAdapter() {
|
||||
}
|
||||
|
||||
|
||||
public void setConnectionFactory(ConnectionFactory connectionFactory) {
|
||||
this.connectionFactory = connectionFactory;
|
||||
}
|
||||
|
||||
public void setDestination(Destination destination) {
|
||||
this.destination = destination;
|
||||
}
|
||||
|
||||
public void setDestinationName(String destinationName) {
|
||||
this.destinationName = destinationName;
|
||||
}
|
||||
|
||||
public void setJmsTemplate(JmsTemplate jmsTemplate) {
|
||||
this.jmsTemplate = jmsTemplate;
|
||||
}
|
||||
|
||||
public void setHeaderMapper(MessageHeaderMapper<javax.jms.Message> headerMapper) {
|
||||
this.headerMapper = headerMapper;
|
||||
}
|
||||
|
||||
protected JmsTemplate getJmsTemplate() {
|
||||
if (this.jmsTemplate == null) {
|
||||
this.afterPropertiesSet();
|
||||
}
|
||||
return this.jmsTemplate;
|
||||
}
|
||||
|
||||
public void afterPropertiesSet() {
|
||||
synchronized (this.initializationMonitor) {
|
||||
if (this.initialized) {
|
||||
return;
|
||||
}
|
||||
if (this.jmsTemplate == null) {
|
||||
if (this.connectionFactory == null || (this.destination == null && this.destinationName == null)) {
|
||||
throw new ConfigurationException("Either a 'jmsTemplate' or " +
|
||||
"*both* 'connectionFactory' and 'destination' (or 'destination-name') are required.");
|
||||
}
|
||||
this.jmsTemplate = this.createDefaultJmsTemplate();
|
||||
}
|
||||
MessageConverter converter = this.jmsTemplate.getMessageConverter();
|
||||
this.jmsTemplate.setMessageConverter(new HeaderMappingMessageConverter(converter, this.headerMapper));
|
||||
this.initialized = true;
|
||||
}
|
||||
}
|
||||
|
||||
private JmsTemplate createDefaultJmsTemplate() {
|
||||
JmsTemplate jmsTemplate = new JmsTemplate();
|
||||
jmsTemplate.setConnectionFactory(this.connectionFactory);
|
||||
if (this.destination != null) {
|
||||
jmsTemplate.setDefaultDestination(this.destination);
|
||||
}
|
||||
else {
|
||||
jmsTemplate.setDefaultDestinationName(this.destinationName);
|
||||
}
|
||||
return jmsTemplate;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* 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.adapter.jms;
|
||||
|
||||
import javax.jms.MessageListener;
|
||||
|
||||
import org.springframework.integration.channel.ChannelPublisher;
|
||||
import org.springframework.integration.channel.MessageChannel;
|
||||
import org.springframework.integration.message.Message;
|
||||
import org.springframework.integration.message.MessageDeliveryException;
|
||||
import org.springframework.integration.message.MessagingException;
|
||||
import org.springframework.jms.support.converter.MessageConverter;
|
||||
|
||||
/**
|
||||
* JMS {@link MessageListener} implementation that converts the received JMS
|
||||
* message into a Spring Integration message and then sends that to a channel.
|
||||
*
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public class ChannelPublishingJmsListener extends ChannelPublisher implements MessageListener {
|
||||
|
||||
private final MessageConverter converter;
|
||||
|
||||
|
||||
public ChannelPublishingJmsListener(MessageChannel channel, MessageConverter converter) {
|
||||
super(channel);
|
||||
this.converter = (converter != null && converter instanceof HeaderMappingMessageConverter) ?
|
||||
converter : new HeaderMappingMessageConverter(converter);
|
||||
}
|
||||
|
||||
|
||||
public void onMessage(javax.jms.Message jmsMessage) {
|
||||
try {
|
||||
Message<?> messageToSend = (Message<?>) this.converter.fromMessage(jmsMessage);
|
||||
if (!this.publish(messageToSend)){
|
||||
throw new MessageDeliveryException(messageToSend, "failed to send Message to channel: " + this.getChannel());
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new MessagingException("failed to convert and send JMS Message", e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,120 @@
|
||||
/*
|
||||
* 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.adapter.jms;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Enumeration;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.jms.Destination;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import org.springframework.integration.adapter.MessageHeaderMapper;
|
||||
import org.springframework.integration.message.MessageHeader;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
* A {@link HeaderMapper} implementation for JMS {@link javax.jms.Message Messages}.
|
||||
*
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public class DefaultJmsHeaderMapper implements MessageHeaderMapper<javax.jms.Message> {
|
||||
|
||||
private static List<Class<?>> SUPPORTED_PROPERTY_TYPES = Arrays.asList(new Class<?>[] {
|
||||
Boolean.class, Byte.class, Double.class, Float.class, Integer.class, Long.class, Short.class, String.class });
|
||||
|
||||
|
||||
private final Log logger = LogFactory.getLog(this.getClass());
|
||||
|
||||
|
||||
public void mapFromMessageHeader(MessageHeader header, javax.jms.Message jmsMessage) {
|
||||
try {
|
||||
Object jmsCorrelationId = header.getAttribute(JmsAttributeKeys.CORRELATION_ID);
|
||||
if (jmsCorrelationId != null && (jmsCorrelationId instanceof String)) {
|
||||
jmsMessage.setJMSCorrelationID((String) jmsCorrelationId);
|
||||
}
|
||||
Object jmsReplyTo = header.getAttribute(JmsAttributeKeys.REPLY_TO);
|
||||
if (jmsReplyTo != null && (jmsReplyTo instanceof Destination)) {
|
||||
jmsMessage.setJMSReplyTo((Destination) jmsReplyTo);
|
||||
}
|
||||
Object jmsType = header.getAttribute(JmsAttributeKeys.TYPE);
|
||||
if (jmsType != null && (jmsType instanceof String)) {
|
||||
jmsMessage.setJMSType((String) jmsType);
|
||||
}
|
||||
String prefix = JmsAttributeKeys.USER_DEFINED_ATTRIBUTE_PREFIX;
|
||||
Set<String> attributeNames = header.getAttributeNames();
|
||||
for (String attributeName : attributeNames) {
|
||||
if (attributeName.startsWith(prefix)) {
|
||||
String jmsAttributeName = attributeName.substring(prefix.length());
|
||||
if (StringUtils.hasText(attributeName)) {
|
||||
Object value = header.getAttribute(attributeName);
|
||||
if (value != null && SUPPORTED_PROPERTY_TYPES.contains(value.getClass())) {
|
||||
try {
|
||||
jmsMessage.setObjectProperty(jmsAttributeName, value);
|
||||
}
|
||||
catch (Throwable t) {
|
||||
if (logger.isWarnEnabled()) {
|
||||
logger.warn("failed to map property '" + jmsAttributeName + "' from MessageHeader", t);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Throwable t) {
|
||||
if (logger.isWarnEnabled()) {
|
||||
logger.warn("error occurred while mapping properties from MessageHeader", t);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void mapToMessageHeader(javax.jms.Message jmsMessage, MessageHeader header) {
|
||||
try {
|
||||
String correlationId = jmsMessage.getJMSCorrelationID();
|
||||
if (correlationId != null) {
|
||||
header.setAttribute(JmsAttributeKeys.CORRELATION_ID, correlationId);
|
||||
}
|
||||
Destination replyTo = jmsMessage.getJMSReplyTo();
|
||||
if (replyTo != null) {
|
||||
header.setAttribute(JmsAttributeKeys.REPLY_TO, replyTo);
|
||||
}
|
||||
header.setAttribute(JmsAttributeKeys.REDELIVERED, jmsMessage.getJMSRedelivered());
|
||||
String type = jmsMessage.getJMSType();
|
||||
if (type != null) {
|
||||
header.setAttribute(JmsAttributeKeys.TYPE, type);
|
||||
}
|
||||
Enumeration<?> jmsPropertyNames = jmsMessage.getPropertyNames();
|
||||
if (jmsPropertyNames != null) {
|
||||
while (jmsPropertyNames.hasMoreElements()) {
|
||||
String propertyName = jmsPropertyNames.nextElement().toString();
|
||||
header.setAttribute(JmsAttributeKeys.USER_DEFINED_ATTRIBUTE_PREFIX + propertyName,
|
||||
jmsMessage.getObjectProperty(propertyName));
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Throwable t) {
|
||||
if (logger.isWarnEnabled()) {
|
||||
logger.warn("error occurred while mapping properties to MessageHeader", t);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
* 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.adapter.jms;
|
||||
|
||||
import javax.jms.JMSException;
|
||||
import javax.jms.Session;
|
||||
|
||||
import org.springframework.integration.adapter.MessageHeaderMapper;
|
||||
import org.springframework.integration.message.GenericMessage;
|
||||
import org.springframework.integration.message.Message;
|
||||
import org.springframework.integration.message.MessagingException;
|
||||
import org.springframework.jms.support.converter.MessageConversionException;
|
||||
import org.springframework.jms.support.converter.MessageConverter;
|
||||
import org.springframework.jms.support.converter.SimpleMessageConverter;
|
||||
|
||||
/**
|
||||
* A {@link MessageConverter} implementation that delegates to an existing
|
||||
* converter as well as an implementation of {@link MessageHeaderMapper}.
|
||||
*
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public class HeaderMappingMessageConverter implements MessageConverter {
|
||||
|
||||
private final MessageConverter converter;
|
||||
|
||||
private final MessageHeaderMapper<javax.jms.Message> headerMapper;
|
||||
|
||||
|
||||
public HeaderMappingMessageConverter(MessageConverter converter) {
|
||||
this(converter, null);
|
||||
}
|
||||
|
||||
public HeaderMappingMessageConverter(MessageConverter converter, MessageHeaderMapper<javax.jms.Message> headerMapper) {
|
||||
this.converter = (converter != null ? converter : new SimpleMessageConverter());
|
||||
this.headerMapper = (headerMapper != null ? headerMapper : new DefaultJmsHeaderMapper());
|
||||
}
|
||||
|
||||
|
||||
public Object fromMessage(javax.jms.Message jmsMessage) throws JMSException, MessageConversionException {
|
||||
Object payload = this.converter.fromMessage(jmsMessage);
|
||||
Message<?> message = new GenericMessage<Object>(payload);
|
||||
this.headerMapper.mapToMessageHeader(jmsMessage, message.getHeader());
|
||||
return message;
|
||||
}
|
||||
|
||||
public javax.jms.Message toMessage(Object object, Session session) throws JMSException, MessageConversionException {
|
||||
if (!(object instanceof Message<?>)) {
|
||||
throw new MessagingException("expected a '" + Message.class.getName() +
|
||||
"', but received '" + object.getClass() + "'");
|
||||
}
|
||||
Message<?> message = (Message<?>) object;
|
||||
javax.jms.Message jmsMessage = this.converter.toMessage(message.getPayload(), session);
|
||||
this.headerMapper.mapFromMessageHeader(message.getHeader(), jmsMessage);
|
||||
return jmsMessage;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* 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.adapter.jms;
|
||||
|
||||
/**
|
||||
* Keys to be used for setting and/or retrieving JMS attributes stored in the
|
||||
* integration message header.
|
||||
*
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public abstract class JmsAttributeKeys {
|
||||
|
||||
public static final String USER_DEFINED_ATTRIBUTE_PREFIX = "jms.";
|
||||
|
||||
public static final String CORRELATION_ID = "_jms.JMSCorrelationID";
|
||||
|
||||
public static final String REPLY_TO = "_jms.JMSReplyTo";
|
||||
|
||||
public static final String REDELIVERED = "_jms.JMSRedelivered";
|
||||
|
||||
public static final String TYPE = "_jms.JMSType";
|
||||
|
||||
}
|
||||
@@ -0,0 +1,167 @@
|
||||
/*
|
||||
* 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.adapter.jms;
|
||||
|
||||
import javax.jms.ConnectionFactory;
|
||||
import javax.jms.Destination;
|
||||
import javax.jms.Session;
|
||||
|
||||
import org.springframework.beans.factory.DisposableBean;
|
||||
import org.springframework.context.Lifecycle;
|
||||
import org.springframework.core.task.TaskExecutor;
|
||||
import org.springframework.integration.ConfigurationException;
|
||||
import org.springframework.integration.gateway.SimpleMessagingGateway;
|
||||
import org.springframework.jms.listener.AbstractMessageListenerContainer;
|
||||
import org.springframework.jms.listener.DefaultMessageListenerContainer;
|
||||
import org.springframework.jms.listener.adapter.MessageListenerAdapter;
|
||||
import org.springframework.jms.support.converter.MessageConverter;
|
||||
import org.springframework.jms.support.converter.SimpleMessageConverter;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* A message-driven adapter for receiving JMS messages and sending to a channel.
|
||||
*
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public class JmsGateway extends SimpleMessagingGateway implements Lifecycle, DisposableBean {
|
||||
|
||||
private volatile AbstractMessageListenerContainer container;
|
||||
|
||||
private volatile ConnectionFactory connectionFactory;
|
||||
|
||||
private volatile Destination destination;
|
||||
|
||||
private volatile String destinationName;
|
||||
|
||||
private volatile MessageConverter messageConverter = new SimpleMessageConverter();
|
||||
|
||||
private volatile TaskExecutor taskExecutor;
|
||||
|
||||
private volatile boolean sessionTransacted;
|
||||
|
||||
private volatile int sessionAcknowledgeMode = Session.AUTO_ACKNOWLEDGE;
|
||||
|
||||
private volatile int concurrentConsumers = 1;
|
||||
|
||||
private volatile int maxConcurrentConsumers = 1;
|
||||
|
||||
private volatile int maxMessagesPerTask = Integer.MIN_VALUE;
|
||||
|
||||
private volatile int idleTaskExecutionLimit = 1;
|
||||
|
||||
private boolean expectReply = false;
|
||||
|
||||
|
||||
public void setContainer(AbstractMessageListenerContainer container) {
|
||||
this.container = container;
|
||||
}
|
||||
|
||||
public void setConnectionFactory(ConnectionFactory connectionFactory) {
|
||||
this.connectionFactory = connectionFactory;
|
||||
}
|
||||
|
||||
public void setDestination(Destination destination) {
|
||||
this.destination = destination;
|
||||
}
|
||||
|
||||
public void setDestinationName(String destinationName) {
|
||||
this.destinationName = destinationName;
|
||||
}
|
||||
|
||||
public void setMessageConverter(MessageConverter messageConverter) {
|
||||
Assert.notNull(messageConverter, "'messageConverter' must not be null");
|
||||
this.messageConverter = messageConverter;
|
||||
}
|
||||
|
||||
public void setTaskExecutor(TaskExecutor taskExecutor) {
|
||||
this.taskExecutor = taskExecutor;
|
||||
}
|
||||
|
||||
public void setSessionTransacted(boolean sessionTransacted) {
|
||||
this.sessionTransacted = sessionTransacted;
|
||||
}
|
||||
|
||||
public void setSessionAcknowledgeMode(int sessionAcknowledgeMode) {
|
||||
this.sessionAcknowledgeMode = sessionAcknowledgeMode;
|
||||
}
|
||||
|
||||
public void setExpectReply(boolean expectReply) {
|
||||
this.expectReply = expectReply;
|
||||
}
|
||||
|
||||
private void initialize() {
|
||||
if (this.container == null) {
|
||||
this.container = createDefaultContainer();
|
||||
}
|
||||
MessageListenerAdapter listener = new MessageListenerAdapter();
|
||||
listener.setDelegate(this);
|
||||
listener.setDefaultListenerMethod(this.expectReply ? "sendAndReceive" : "send");
|
||||
listener.setMessageConverter(this.messageConverter);
|
||||
this.container.setMessageListener(listener);
|
||||
if (!this.container.isActive()) {
|
||||
this.container.afterPropertiesSet();
|
||||
}
|
||||
}
|
||||
|
||||
private AbstractMessageListenerContainer createDefaultContainer() {
|
||||
if (this.connectionFactory == null || (this.destination == null && this.destinationName == null)) {
|
||||
throw new ConfigurationException("If a 'container' reference is not provided, then "
|
||||
+ "'connectionFactory' and 'destination' (or 'destinationName') are required.");
|
||||
}
|
||||
DefaultMessageListenerContainer dmlc = new DefaultMessageListenerContainer();
|
||||
dmlc.setConcurrentConsumers(this.concurrentConsumers);
|
||||
dmlc.setMaxConcurrentConsumers(this.maxConcurrentConsumers);
|
||||
dmlc.setMaxMessagesPerTask(this.maxMessagesPerTask);
|
||||
dmlc.setIdleTaskExecutionLimit(this.idleTaskExecutionLimit);
|
||||
dmlc.setConnectionFactory(this.connectionFactory);
|
||||
if (this.destination != null) {
|
||||
dmlc.setDestination(this.destination);
|
||||
}
|
||||
if (this.destinationName != null) {
|
||||
dmlc.setDestinationName(this.destinationName);
|
||||
}
|
||||
dmlc.setSessionTransacted(this.sessionTransacted);
|
||||
dmlc.setSessionAcknowledgeMode(this.sessionAcknowledgeMode);
|
||||
dmlc.setAutoStartup(false);
|
||||
if (this.taskExecutor != null) {
|
||||
dmlc.setTaskExecutor(this.taskExecutor);
|
||||
}
|
||||
return dmlc;
|
||||
}
|
||||
|
||||
public boolean isRunning() {
|
||||
return (this.container != null && this.container.isRunning());
|
||||
}
|
||||
|
||||
public void start() {
|
||||
this.initialize();
|
||||
this.container.start();
|
||||
}
|
||||
|
||||
public void stop() {
|
||||
if (this.container != null) {
|
||||
this.container.stop();
|
||||
}
|
||||
}
|
||||
|
||||
public void destroy() {
|
||||
if (this.container != null) {
|
||||
this.container.destroy();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* 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.adapter.jms;
|
||||
|
||||
import javax.jms.ConnectionFactory;
|
||||
import javax.jms.Destination;
|
||||
|
||||
import org.springframework.integration.message.GenericMessage;
|
||||
import org.springframework.integration.message.Message;
|
||||
import org.springframework.integration.message.Source;
|
||||
import org.springframework.jms.core.JmsTemplate;
|
||||
|
||||
/**
|
||||
* A source for receiving JMS Messages with a polling listener. This source is
|
||||
* only recommended for very low message volume. Otherwise, the
|
||||
* {@link JmsGateway} that uses Spring's MessageListener
|
||||
* container support is highly recommended.
|
||||
*
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public class JmsSource extends AbstractJmsTemplateBasedAdapter implements Source<Object> {
|
||||
|
||||
public JmsSource(JmsTemplate jmsTemplate) {
|
||||
super(jmsTemplate);
|
||||
}
|
||||
|
||||
public JmsSource(ConnectionFactory connectionFactory, Destination destination) {
|
||||
super(connectionFactory, destination);
|
||||
}
|
||||
|
||||
public JmsSource(ConnectionFactory connectionFactory, String destinationName) {
|
||||
super(connectionFactory, destinationName);
|
||||
}
|
||||
|
||||
|
||||
public Message<Object> receive() {
|
||||
Object receivedObject = this.getJmsTemplate().receiveAndConvert();
|
||||
if (receivedObject == null) {
|
||||
return null;
|
||||
}
|
||||
if (receivedObject instanceof Message) {
|
||||
return (Message<Object>) receivedObject;
|
||||
}
|
||||
return new GenericMessage<Object>(receivedObject);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* 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.adapter.jms;
|
||||
|
||||
import javax.jms.ConnectionFactory;
|
||||
import javax.jms.Destination;
|
||||
|
||||
import org.springframework.integration.message.Message;
|
||||
import org.springframework.integration.message.Target;
|
||||
import org.springframework.jms.core.JmsTemplate;
|
||||
|
||||
/**
|
||||
* A target for sending JMS Messages.
|
||||
*
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public class JmsTarget extends AbstractJmsTemplateBasedAdapter implements Target {
|
||||
|
||||
public JmsTarget(JmsTemplate jmsTemplate) {
|
||||
super(jmsTemplate);
|
||||
}
|
||||
|
||||
public JmsTarget(ConnectionFactory connectionFactory, Destination destination) {
|
||||
super(connectionFactory, destination);
|
||||
}
|
||||
|
||||
public JmsTarget(ConnectionFactory connectionFactory, String destinationName) {
|
||||
super(connectionFactory, destinationName);
|
||||
}
|
||||
|
||||
public JmsTarget() {
|
||||
super();
|
||||
}
|
||||
|
||||
|
||||
public final boolean send(final Message<?> message) {
|
||||
if (message == null) {
|
||||
throw new IllegalArgumentException("message must not be null");
|
||||
}
|
||||
this.getJmsTemplate().convertAndSend(message);
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,104 @@
|
||||
/*
|
||||
* 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.adapter.jms.config;
|
||||
|
||||
import javax.jms.Session;
|
||||
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
import org.springframework.beans.factory.BeanCreationException;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
* Utility methods and constants for JMS adapter parsers.
|
||||
*
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public abstract class JmsAdapterParserUtils {
|
||||
|
||||
public static final String JMS_TEMPLATE_ATTRIBUTE = "jms-template";
|
||||
|
||||
public static final String JMS_TEMPLATE_PROPERTY = "jmsTemplate";
|
||||
|
||||
public static final String CONNECTION_FACTORY_ATTRIBUTE = "connection-factory";
|
||||
|
||||
public static final String CONNECTION_FACTORY_PROPERTY = "connectionFactory";
|
||||
|
||||
public static final String DESTINATION_ATTRIBUTE = "destination";
|
||||
|
||||
public static final String DESTINATION_PROPERTY = "destination";
|
||||
|
||||
public static final String DESTINATION_NAME_ATTRIBUTE = "destination-name";
|
||||
|
||||
public static final String DESTINATION_NAME_PROPERTY = "destinationName";
|
||||
|
||||
public static final String HEADER_MAPPER_ATTRIBUTE = "header-mapper";
|
||||
|
||||
public static final String HEADER_MAPPER_PROPERTY = "headerMapper";
|
||||
|
||||
public static final String MESSAGE_CONVERTER_ATTRIBUTE = "message-converter";
|
||||
|
||||
public static final String MESSAGE_CONVERTER_PROPERTY = "messageConverter";
|
||||
|
||||
private static final String ACKNOWLEDGE_ATTRIBUTE = "acknowledge";
|
||||
|
||||
private static final String ACKNOWLEDGE_AUTO = "auto";
|
||||
|
||||
private static final String ACKNOWLEDGE_CLIENT = "client";
|
||||
|
||||
private static final String ACKNOWLEDGE_DUPS_OK = "dups-ok";
|
||||
|
||||
private static final String ACKNOWLEDGE_TRANSACTED = "transacted";
|
||||
|
||||
|
||||
public static String determineConnectionFactoryBeanName(Element element) {
|
||||
String connectionFactoryBeanName = "connectionFactory";
|
||||
if (element.hasAttribute(CONNECTION_FACTORY_ATTRIBUTE)) {
|
||||
connectionFactoryBeanName = element.getAttribute(CONNECTION_FACTORY_ATTRIBUTE);
|
||||
if (!StringUtils.hasText(connectionFactoryBeanName)) {
|
||||
throw new BeanCreationException(
|
||||
"JMS adapter 'connection-factory' attribute must not be empty");
|
||||
}
|
||||
}
|
||||
return connectionFactoryBeanName;
|
||||
}
|
||||
|
||||
public static Integer parseAcknowledgeMode(Element element) {
|
||||
String acknowledge = element.getAttribute(ACKNOWLEDGE_ATTRIBUTE);
|
||||
if (StringUtils.hasText(acknowledge)) {
|
||||
int acknowledgeMode = Session.AUTO_ACKNOWLEDGE;
|
||||
if (ACKNOWLEDGE_TRANSACTED.equals(acknowledge)) {
|
||||
acknowledgeMode = Session.SESSION_TRANSACTED;
|
||||
}
|
||||
else if (ACKNOWLEDGE_DUPS_OK.equals(acknowledge)) {
|
||||
acknowledgeMode = Session.DUPS_OK_ACKNOWLEDGE;
|
||||
}
|
||||
else if (ACKNOWLEDGE_CLIENT.equals(acknowledge)) {
|
||||
acknowledgeMode = Session.CLIENT_ACKNOWLEDGE;
|
||||
}
|
||||
else if (!ACKNOWLEDGE_AUTO.equals(acknowledge)) {
|
||||
throw new BeanCreationException("Invalid JMS 'acknowledge' setting: " +
|
||||
"only \"auto\", \"client\", \"dups-ok\" and \"transacted\" supported.");
|
||||
}
|
||||
return acknowledgeMode;
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,110 @@
|
||||
/*
|
||||
* 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.adapter.jms.config;
|
||||
|
||||
import javax.jms.Session;
|
||||
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
import org.springframework.beans.factory.BeanCreationException;
|
||||
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
|
||||
import org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser;
|
||||
import org.springframework.beans.factory.xml.ParserContext;
|
||||
import org.springframework.integration.adapter.jms.JmsGateway;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
* Parser for the <jms-gateway> element.
|
||||
*
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public class JmsGatewayParser extends AbstractSingleBeanDefinitionParser {
|
||||
|
||||
@Override
|
||||
protected Class<?> getBeanClass(Element element) {
|
||||
return JmsGateway.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean shouldGenerateId() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean shouldGenerateIdAsFallback() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
|
||||
String destination = element.getAttribute(JmsAdapterParserUtils.DESTINATION_ATTRIBUTE);
|
||||
String destinationName = element.getAttribute(JmsAdapterParserUtils.DESTINATION_NAME_ATTRIBUTE);
|
||||
String messageConverter = element.getAttribute(JmsAdapterParserUtils.MESSAGE_CONVERTER_ATTRIBUTE);
|
||||
if (StringUtils.hasText(element.getAttribute(JmsAdapterParserUtils.JMS_TEMPLATE_ATTRIBUTE))) {
|
||||
throw new BeanCreationException(JmsGateway.class.getSimpleName() +
|
||||
" does not accept a '" + JmsAdapterParserUtils.JMS_TEMPLATE_ATTRIBUTE +
|
||||
"' reference. One of '" + JmsAdapterParserUtils.DESTINATION_ATTRIBUTE + "' or '" +
|
||||
JmsAdapterParserUtils.DESTINATION_NAME_ATTRIBUTE + "' must be provided.");
|
||||
}
|
||||
if (StringUtils.hasText(destination) || StringUtils.hasText(destinationName)) {
|
||||
builder.addPropertyReference(JmsAdapterParserUtils.CONNECTION_FACTORY_PROPERTY,
|
||||
JmsAdapterParserUtils.determineConnectionFactoryBeanName(element));
|
||||
if (StringUtils.hasText(destination)) {
|
||||
builder.addPropertyReference(JmsAdapterParserUtils.DESTINATION_PROPERTY, destination);
|
||||
}
|
||||
else {
|
||||
builder.addPropertyValue(JmsAdapterParserUtils.DESTINATION_NAME_PROPERTY, destinationName);
|
||||
}
|
||||
}
|
||||
else {
|
||||
throw new BeanCreationException("One of '" + JmsAdapterParserUtils.DESTINATION_ATTRIBUTE +
|
||||
"' or '" + JmsAdapterParserUtils.DESTINATION_NAME_ATTRIBUTE + "' must be provided.");
|
||||
}
|
||||
if (StringUtils.hasText(messageConverter)) {
|
||||
builder.addPropertyReference(JmsAdapterParserUtils.MESSAGE_CONVERTER_PROPERTY, messageConverter);
|
||||
}
|
||||
Integer acknowledgeMode = JmsAdapterParserUtils.parseAcknowledgeMode(element);
|
||||
if (acknowledgeMode != null) {
|
||||
if (acknowledgeMode.intValue() == Session.SESSION_TRANSACTED) {
|
||||
builder.addPropertyValue("sessionTransacted", Boolean.TRUE);
|
||||
}
|
||||
else {
|
||||
builder.addPropertyValue("sessionAcknowledgeMode", acknowledgeMode);
|
||||
}
|
||||
}
|
||||
String requestChannel = element.getAttribute("request-channel");
|
||||
if (StringUtils.hasText(requestChannel)) {
|
||||
builder.addPropertyReference("requestChannel", requestChannel);
|
||||
}
|
||||
String requestTimeout = element.getAttribute("request-timeout");
|
||||
if (StringUtils.hasText(requestTimeout)) {
|
||||
builder.addPropertyValue("requestTimeout", Long.parseLong(requestTimeout));
|
||||
}
|
||||
String replyChannel = element.getAttribute("reply-channel");
|
||||
if (StringUtils.hasText(replyChannel)) {
|
||||
builder.addPropertyReference("replyChannel", replyChannel);
|
||||
}
|
||||
String replyTimeout = element.getAttribute("reply-timeout");
|
||||
if (StringUtils.hasText(replyTimeout)) {
|
||||
builder.addPropertyValue("replyTimeout", Long.parseLong(replyTimeout));
|
||||
}
|
||||
if ("true".equals(element.getAttribute("expect-reply"))) {
|
||||
builder.addPropertyValue("expectReply", Boolean.TRUE);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
/*
|
||||
* 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.adapter.jms.config;
|
||||
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
import org.springframework.beans.factory.BeanCreationException;
|
||||
import org.springframework.beans.factory.support.AbstractBeanDefinition;
|
||||
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
|
||||
import org.springframework.beans.factory.xml.AbstractBeanDefinitionParser;
|
||||
import org.springframework.beans.factory.xml.ParserContext;
|
||||
import org.springframework.integration.adapter.jms.JmsSource;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
* Parser for the <jms-source/> element.
|
||||
*
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public class JmsSourceParser extends AbstractBeanDefinitionParser {
|
||||
|
||||
protected boolean shouldGenerateId() {
|
||||
return false;
|
||||
}
|
||||
|
||||
protected boolean shouldGenerateIdAsFallback() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AbstractBeanDefinition parseInternal(Element element, ParserContext parserContext) {
|
||||
BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(JmsSource.class);
|
||||
String jmsTemplate = element.getAttribute(JmsAdapterParserUtils.JMS_TEMPLATE_ATTRIBUTE);
|
||||
String destination = element.getAttribute(JmsAdapterParserUtils.DESTINATION_ATTRIBUTE);
|
||||
String destinationName = element.getAttribute(JmsAdapterParserUtils.DESTINATION_NAME_ATTRIBUTE);
|
||||
String headerMapper = element.getAttribute(JmsAdapterParserUtils.HEADER_MAPPER_ATTRIBUTE);
|
||||
if (StringUtils.hasText(jmsTemplate)) {
|
||||
if (element.hasAttribute(JmsAdapterParserUtils.CONNECTION_FACTORY_ATTRIBUTE) ||
|
||||
element.hasAttribute(JmsAdapterParserUtils.DESTINATION_NAME_ATTRIBUTE) ||
|
||||
element.hasAttribute(JmsAdapterParserUtils.DESTINATION_ATTRIBUTE)) {
|
||||
throw new BeanCreationException(
|
||||
"When providing '" + JmsAdapterParserUtils.JMS_TEMPLATE_ATTRIBUTE +
|
||||
"', none of '" + JmsAdapterParserUtils.CONNECTION_FACTORY_ATTRIBUTE +
|
||||
"', '" + JmsAdapterParserUtils.DESTINATION_ATTRIBUTE + "', or '" +
|
||||
JmsAdapterParserUtils.DESTINATION_NAME_ATTRIBUTE + "' should be provided.");
|
||||
}
|
||||
builder.addConstructorArgReference(jmsTemplate);
|
||||
}
|
||||
else if (StringUtils.hasText(destination) || StringUtils.hasText(destinationName)) {
|
||||
builder.addConstructorArgReference(JmsAdapterParserUtils.determineConnectionFactoryBeanName(element));
|
||||
if (StringUtils.hasText(destination)) {
|
||||
builder.addConstructorArgReference(destination);
|
||||
}
|
||||
else if (StringUtils.hasText(destinationName)) {
|
||||
builder.addConstructorArgValue(destinationName);
|
||||
}
|
||||
}
|
||||
else {
|
||||
throw new BeanCreationException("either a '" + JmsAdapterParserUtils.JMS_TEMPLATE_ATTRIBUTE + "' or one of '" +
|
||||
JmsAdapterParserUtils.DESTINATION_ATTRIBUTE + "' or '" + JmsAdapterParserUtils.DESTINATION_NAME_ATTRIBUTE +
|
||||
"' attributes must be provided for a polling JMS adapter");
|
||||
}
|
||||
if (StringUtils.hasText(headerMapper)) {
|
||||
builder.addPropertyReference(JmsAdapterParserUtils.HEADER_MAPPER_PROPERTY, headerMapper);
|
||||
}
|
||||
return builder.getBeanDefinition();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
/*
|
||||
* 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.adapter.jms.config;
|
||||
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
import org.springframework.beans.factory.BeanCreationException;
|
||||
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
|
||||
import org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser;
|
||||
import org.springframework.beans.factory.xml.ParserContext;
|
||||
import org.springframework.integration.adapter.jms.JmsTarget;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
* Parser for the <jms-target/> element.
|
||||
*
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public class JmsTargetParser extends AbstractSingleBeanDefinitionParser {
|
||||
|
||||
protected Class<?> getBeanClass(Element element) {
|
||||
return JmsTarget.class;
|
||||
}
|
||||
|
||||
protected boolean shouldGenerateId() {
|
||||
return false;
|
||||
}
|
||||
|
||||
protected boolean shouldGenerateIdAsFallback() {
|
||||
return true;
|
||||
}
|
||||
|
||||
protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
|
||||
String jmsTemplate = element.getAttribute(JmsAdapterParserUtils.JMS_TEMPLATE_ATTRIBUTE);
|
||||
String destination = element.getAttribute(JmsAdapterParserUtils.DESTINATION_ATTRIBUTE);
|
||||
String destinationName = element.getAttribute(JmsAdapterParserUtils.DESTINATION_NAME_ATTRIBUTE);
|
||||
String headerMapper = element.getAttribute(JmsAdapterParserUtils.HEADER_MAPPER_ATTRIBUTE);
|
||||
if (StringUtils.hasText(jmsTemplate)) {
|
||||
if (element.hasAttribute(JmsAdapterParserUtils.CONNECTION_FACTORY_ATTRIBUTE) ||
|
||||
element.hasAttribute(JmsAdapterParserUtils.DESTINATION_ATTRIBUTE) ||
|
||||
element.hasAttribute(JmsAdapterParserUtils.DESTINATION_NAME_ATTRIBUTE)) {
|
||||
throw new BeanCreationException("when providing a 'jms-template' reference, none of " +
|
||||
"'connection-factory', 'destination', or 'destination-name' should be provided.");
|
||||
}
|
||||
builder.addPropertyReference(JmsAdapterParserUtils.JMS_TEMPLATE_PROPERTY, jmsTemplate);
|
||||
}
|
||||
else if (StringUtils.hasText(destination) ^ StringUtils.hasText(destinationName)) {
|
||||
builder.addPropertyReference(JmsAdapterParserUtils.CONNECTION_FACTORY_PROPERTY,
|
||||
JmsAdapterParserUtils.determineConnectionFactoryBeanName(element));
|
||||
if (StringUtils.hasText(destination)) {
|
||||
builder.addPropertyReference(JmsAdapterParserUtils.DESTINATION_PROPERTY, destination);
|
||||
}
|
||||
else {
|
||||
builder.addPropertyValue(JmsAdapterParserUtils.DESTINATION_NAME_PROPERTY, destinationName);
|
||||
}
|
||||
}
|
||||
else {
|
||||
throw new BeanCreationException("Either a 'jms-template' reference or " +
|
||||
"one of 'destination' or 'destination-name' attributes must be provided.");
|
||||
}
|
||||
if (StringUtils.hasText(headerMapper)) {
|
||||
builder.addPropertyReference(JmsAdapterParserUtils.HEADER_MAPPER_PROPERTY, headerMapper);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,126 @@
|
||||
/*
|
||||
* 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.adapter.mail;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import org.springframework.integration.message.Message;
|
||||
import org.springframework.mail.MailMessage;
|
||||
|
||||
/**
|
||||
* Base implementation for {@link MailHeaderGenerator MailHeaderGenerators}.
|
||||
* This class is abstract. Subclasses must implement the corresponding template
|
||||
* methods to retrieve the values for the mail message's subject, recipients,
|
||||
* and from/reply-to addresses based on the integration {@link Message}.
|
||||
*
|
||||
* @author Marius Bogoevici
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public abstract class AbstractMailHeaderGenerator implements MailHeaderGenerator {
|
||||
|
||||
private final Log logger = LogFactory.getLog(this.getClass());
|
||||
|
||||
|
||||
/**
|
||||
* Retrieve the subject of an e-mail message from an integration message.
|
||||
*
|
||||
* @param message the integration {@link Message}
|
||||
* @return the e-mail message subject
|
||||
*/
|
||||
protected abstract String getSubject(Message<?> message);
|
||||
|
||||
/**
|
||||
* Retrieve the recipients list from an integration message.
|
||||
*
|
||||
* @param message the integration {@link Message}
|
||||
* @return recipients list (TO)
|
||||
*/
|
||||
protected abstract String[] getTo(Message<?> message);
|
||||
|
||||
/**
|
||||
* Retrieve the CC recipients list from an integration message.
|
||||
*
|
||||
* @param message the integration {@link Message}
|
||||
* @return CC recipients list (e-mail addresses)
|
||||
*/
|
||||
protected abstract String[] getCc(Message<?> message);
|
||||
|
||||
/**
|
||||
* Retrieve the BCC recipients list from an integration message.
|
||||
*
|
||||
* @param message the integration {@link Message}
|
||||
* @return BCC recipients list (e-mail addresses)
|
||||
*/
|
||||
protected abstract String[] getBcc(Message<?> message);
|
||||
|
||||
/**
|
||||
* Retrieve the From: e-mail address from an integration message.
|
||||
*
|
||||
* @param message the integration {@link Message}
|
||||
* @return the From: e-mail address
|
||||
*/
|
||||
protected abstract String getFrom(Message<?> message);
|
||||
|
||||
/**
|
||||
* Retrieve the Reply To: e-mail address from an integration message.
|
||||
*
|
||||
* @param message the integration {@link Message}
|
||||
* @return the ReplyTo: e-mail address
|
||||
*/
|
||||
protected abstract String getReplyTo(Message<?> message);
|
||||
|
||||
/**
|
||||
* Populate the mail message using the results of the template methods.
|
||||
*/
|
||||
public final void populateMailMessageHeader(MailMessage mailMessage, Message<?> message) {
|
||||
final String subject = getSubject(message);
|
||||
final String[] to = getTo(message);
|
||||
final String[] cc = getCc(message);
|
||||
final String[] bcc = getBcc(message);
|
||||
final String from = getFrom(message);
|
||||
final String replyTo = getReplyTo(message);
|
||||
if (subject != null) {
|
||||
mailMessage.setSubject(subject);
|
||||
}
|
||||
else if (logger.isWarnEnabled()) {
|
||||
logger.warn("no 'SUBJECT' property available for mail message");
|
||||
}
|
||||
if (to != null) {
|
||||
mailMessage.setTo(to);
|
||||
}
|
||||
else if (logger.isWarnEnabled()) {
|
||||
logger.warn("no 'TO' property available for mail message");
|
||||
}
|
||||
if (cc != null) {
|
||||
mailMessage.setCc(cc);
|
||||
}
|
||||
if (bcc != null) {
|
||||
mailMessage.setBcc(bcc);
|
||||
}
|
||||
if (from != null) {
|
||||
mailMessage.setFrom(from);
|
||||
}
|
||||
else if (logger.isWarnEnabled()) {
|
||||
logger.warn("no 'FROM' property available for mail message");
|
||||
}
|
||||
if (replyTo != null) {
|
||||
mailMessage.setReplyTo(replyTo);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
/*
|
||||
* 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.adapter.mail;
|
||||
|
||||
import javax.mail.MessagingException;
|
||||
import javax.mail.internet.MimeMessage;
|
||||
|
||||
import org.springframework.core.io.ByteArrayResource;
|
||||
import org.springframework.integration.adapter.MessageMappingException;
|
||||
import org.springframework.integration.message.Message;
|
||||
import org.springframework.integration.message.MessageMapper;
|
||||
import org.springframework.mail.MailMessage;
|
||||
import org.springframework.mail.javamail.JavaMailSender;
|
||||
import org.springframework.mail.javamail.MimeMailMessage;
|
||||
import org.springframework.mail.javamail.MimeMessageHelper;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* Message mapper used for mapping byte array messages to mail messages.
|
||||
* Generates an e-mail message with the byte array as an attachment. The
|
||||
* multipart mode and attachment name are configurable.
|
||||
*
|
||||
* @author Marius Bogoevici
|
||||
*/
|
||||
public class ByteArrayMailMessageMapper implements MessageMapper<byte[], MailMessage> {
|
||||
|
||||
private final JavaMailSender mailSender;
|
||||
|
||||
private volatile int multipartMode = MimeMessageHelper.MULTIPART_MODE_MIXED;
|
||||
|
||||
private volatile String attachmentFilename = "content";
|
||||
|
||||
|
||||
public ByteArrayMailMessageMapper(JavaMailSender mailSender) {
|
||||
Assert.notNull(mailSender, "'mailSender' must not be null");
|
||||
this.mailSender = mailSender;
|
||||
}
|
||||
|
||||
|
||||
public void setMultipartMode(int multipartMode) {
|
||||
this.multipartMode = multipartMode;
|
||||
}
|
||||
|
||||
public void setAttachmentFilename(String attachmentFilename) {
|
||||
this.attachmentFilename = attachmentFilename;
|
||||
}
|
||||
|
||||
public Message<byte[]> toMessage(MailMessage source) {
|
||||
throw new UnsupportedOperationException("mapping from MailMessage to byte array not supported");
|
||||
}
|
||||
|
||||
public MailMessage mapMessage(Message<byte[]> message) {
|
||||
try {
|
||||
MimeMessage mimeMessage = this.mailSender.createMimeMessage();
|
||||
MimeMessageHelper helper = new MimeMessageHelper(mimeMessage, this.multipartMode);
|
||||
helper.addAttachment(this.attachmentFilename, new ByteArrayResource(message.getPayload()));
|
||||
return new MimeMailMessage(helper);
|
||||
}
|
||||
catch (MessagingException e) {
|
||||
throw new MessageMappingException(message, "failed to create MimeMessage", e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
/*
|
||||
* 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.adapter.mail;
|
||||
|
||||
import org.springframework.integration.message.Message;
|
||||
|
||||
/**
|
||||
* The default implementation of {@link MailHeaderGenerator}. Configures the
|
||||
* {@link org.springframework.mail.MailMessage} properties based on attributes
|
||||
* provided with known attribute keys as defined in {@link MailAttributeKeys}.
|
||||
*
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public class DefaultMailHeaderGenerator extends AbstractMailHeaderGenerator {
|
||||
|
||||
@Override
|
||||
protected String getSubject(Message<?> message) {
|
||||
return this.retrieveAsString(message, MailAttributeKeys.SUBJECT);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String[] getTo(Message<?> message) {
|
||||
return this.retrieveAsStringArray(message, MailAttributeKeys.TO);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String[] getCc(Message<?> message) {
|
||||
return this.retrieveAsStringArray(message, MailAttributeKeys.CC);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String[] getBcc(Message<?> message) {
|
||||
return this.retrieveAsStringArray(message, MailAttributeKeys.BCC);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getFrom(Message<?> message) {
|
||||
return this.retrieveAsString(message, MailAttributeKeys.FROM);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getReplyTo(Message<?> message) {
|
||||
return this.retrieveAsString(message, MailAttributeKeys.REPLY_TO);
|
||||
}
|
||||
|
||||
|
||||
private String retrieveAsString(Message<?> message, String key) {
|
||||
Object value = message.getHeader().getAttribute(key);
|
||||
return (value instanceof String) ? (String) value : null;
|
||||
}
|
||||
|
||||
private String[] retrieveAsStringArray(Message<?> message, String key) {
|
||||
Object value = message.getHeader().getAttribute(key);
|
||||
if (value instanceof String[]) {
|
||||
return (String[]) value;
|
||||
}
|
||||
if (value instanceof String) {
|
||||
return new String[] { (String) value };
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* 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.adapter.mail;
|
||||
|
||||
/**
|
||||
* Keys to be used for setting and/or retrieving mail attributes stored in the
|
||||
* integration message header.
|
||||
*
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public class MailAttributeKeys {
|
||||
|
||||
public static final String SUBJECT = "_mail.SUBJECT";
|
||||
|
||||
public static final String TO = "_mail.TO";
|
||||
|
||||
public static final String CC = "_mail.CC";
|
||||
|
||||
public static final String BCC = "_mail.BCC";
|
||||
|
||||
public static final String FROM = "_mail.FROM";
|
||||
|
||||
public static final String REPLY_TO = "_mail.REPLY_TO";
|
||||
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* 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.adapter.mail;
|
||||
|
||||
import org.springframework.integration.message.Message;
|
||||
import org.springframework.mail.MailMessage;
|
||||
|
||||
/**
|
||||
* Strategy interface for generating header information for an e-mail message
|
||||
* from the content of the integration message. Minimal configuration should
|
||||
* include the recipients list, the subject, from/reply-to, etc. However, this
|
||||
* strategy allows the implementation of more complex business logic, when these
|
||||
* parameters are depending on the integration message itself.
|
||||
*
|
||||
* @author Marius Bogoevici
|
||||
*/
|
||||
public interface MailHeaderGenerator {
|
||||
|
||||
/**
|
||||
* Populate the e-mail message header based on the content of the
|
||||
* integration message.
|
||||
*/
|
||||
void populateMailMessageHeader(MailMessage mailMessage, Message<?> message);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,132 @@
|
||||
/*
|
||||
* 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.adapter.mail;
|
||||
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.integration.message.Message;
|
||||
import org.springframework.integration.message.MessageMapper;
|
||||
import org.springframework.integration.message.Target;
|
||||
import org.springframework.mail.MailMessage;
|
||||
import org.springframework.mail.SimpleMailMessage;
|
||||
import org.springframework.mail.javamail.JavaMailSender;
|
||||
import org.springframework.mail.javamail.MimeMailMessage;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* A target adapter for sending mail.
|
||||
*
|
||||
* @author Marius Bogoevici
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public class MailTarget implements Target, InitializingBean {
|
||||
|
||||
private final JavaMailSender mailSender;
|
||||
|
||||
private volatile MailHeaderGenerator mailHeaderGenerator = new DefaultMailHeaderGenerator();
|
||||
|
||||
private volatile MessageMapper<String, MailMessage> textMessageMapper;
|
||||
|
||||
private volatile MessageMapper<byte[], MailMessage> byteArrayMessageMapper;
|
||||
|
||||
private volatile MessageMapper<Object, MailMessage> objectMessageMapper;
|
||||
|
||||
|
||||
/**
|
||||
* Create a MailTargetAdapter.
|
||||
*
|
||||
* @param mailSender the {@link JavaMailSender} instance to which this
|
||||
* adapter will delegate.
|
||||
*/
|
||||
public MailTarget(JavaMailSender mailSender) {
|
||||
Assert.notNull(mailSender, "'mailSender' must not be null");
|
||||
this.mailSender = mailSender;
|
||||
}
|
||||
|
||||
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
this.textMessageMapper = (this.textMessageMapper != null) ?
|
||||
this.textMessageMapper : new TextMailMessageMapper();
|
||||
this.byteArrayMessageMapper = (byteArrayMessageMapper != null) ?
|
||||
this.byteArrayMessageMapper : new ByteArrayMailMessageMapper(this.mailSender);
|
||||
this.objectMessageMapper = (objectMessageMapper != null) ?
|
||||
this.objectMessageMapper : new DefaultObjectMailMessageMapper();
|
||||
}
|
||||
|
||||
public void setHeaderGenerator(MailHeaderGenerator mailHeaderGenerator) {
|
||||
Assert.notNull(mailHeaderGenerator, "'mailHeaderGenerator' must not be null");
|
||||
this.mailHeaderGenerator = mailHeaderGenerator;
|
||||
}
|
||||
|
||||
public void setTextMessageMapper(MessageMapper<String, MailMessage> textMessageMapper) {
|
||||
this.textMessageMapper = textMessageMapper;
|
||||
}
|
||||
|
||||
public void setByteArrayMessageMapper(MessageMapper<byte[], MailMessage> byteArrayMessageMapper) {
|
||||
this.byteArrayMessageMapper = byteArrayMessageMapper;
|
||||
}
|
||||
|
||||
public void setObjectMessageMapper(MessageMapper<Object, MailMessage> objectMessageMapper) {
|
||||
this.objectMessageMapper = objectMessageMapper;
|
||||
}
|
||||
|
||||
public final boolean send(Message<?> message) {
|
||||
MailMessage mailMessage = this.convertMessageToMailMessage(message);
|
||||
this.mailHeaderGenerator.populateMailMessageHeader(mailMessage, message);
|
||||
this.sendMailMessage(mailMessage);
|
||||
return true;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private MailMessage convertMessageToMailMessage(Message<?> message) {
|
||||
if (message.getPayload() instanceof String) {
|
||||
return this.textMessageMapper.mapMessage((Message<String>) message);
|
||||
}
|
||||
else if (message.getPayload() instanceof byte[]) {
|
||||
return this.byteArrayMessageMapper.mapMessage((Message<byte[]>) message);
|
||||
}
|
||||
return this.objectMessageMapper.mapMessage((Message<Object>) message);
|
||||
}
|
||||
|
||||
private void sendMailMessage(MailMessage mailMessage) {
|
||||
if (mailMessage instanceof SimpleMailMessage) {
|
||||
this.mailSender.send((SimpleMailMessage) mailMessage);
|
||||
}
|
||||
else if (mailMessage instanceof MimeMailMessage) {
|
||||
this.mailSender.send(((MimeMailMessage) mailMessage).getMimeMessage());
|
||||
}
|
||||
else {
|
||||
throw new IllegalArgumentException(
|
||||
"MailMessage subclass '" + mailMessage.getClass().getName() + "' not supported");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static class DefaultObjectMailMessageMapper implements MessageMapper<Object, MailMessage> {
|
||||
|
||||
public Message<Object> toMessage(MailMessage source) {
|
||||
throw new UnsupportedOperationException("mapping from MailMessage to Object not supported");
|
||||
}
|
||||
|
||||
public MailMessage mapMessage(Message<Object> objectMessage) {
|
||||
SimpleMailMessage message = new SimpleMailMessage();
|
||||
message.setText(objectMessage.getPayload().toString());
|
||||
return message;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
/*
|
||||
* Copyright 2002-2007 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.adapter.mail;
|
||||
|
||||
import org.springframework.integration.message.Message;
|
||||
|
||||
/**
|
||||
* Mail header generator implementation that populates a mail message header
|
||||
* from statically configured properties.
|
||||
*
|
||||
* @author Marius Bogoevici
|
||||
*/
|
||||
public class StaticMailHeaderGenerator extends AbstractMailHeaderGenerator {
|
||||
|
||||
private String subject;
|
||||
|
||||
private String[] to;
|
||||
|
||||
private String[] cc;
|
||||
|
||||
private String[] bcc;
|
||||
|
||||
private String from;
|
||||
|
||||
private String replyTo;
|
||||
|
||||
|
||||
public void setSubject(String subject) {
|
||||
this.subject = subject;
|
||||
}
|
||||
|
||||
protected String getSubject(Message<?> message) {
|
||||
return this.subject;
|
||||
}
|
||||
|
||||
public void setTo(String[] to) {
|
||||
this.to = to;
|
||||
}
|
||||
|
||||
protected String[] getTo(Message<?> message) {
|
||||
return this.to;
|
||||
}
|
||||
|
||||
public void setCc(String[] cc) {
|
||||
this.cc = cc;
|
||||
}
|
||||
|
||||
protected String[] getCc(Message<?> message) {
|
||||
return this.cc;
|
||||
}
|
||||
|
||||
public void setBcc(String[] bcc) {
|
||||
this.bcc = bcc;
|
||||
}
|
||||
|
||||
protected String[] getBcc(Message<?> message) {
|
||||
return this.bcc;
|
||||
}
|
||||
|
||||
public void setFrom(String from) {
|
||||
this.from = from;
|
||||
}
|
||||
|
||||
protected String getFrom(Message<?> message) {
|
||||
return this.from;
|
||||
}
|
||||
|
||||
public void setReplyTo(String replyTo) {
|
||||
this.replyTo = replyTo;
|
||||
}
|
||||
|
||||
protected String getReplyTo(Message<?> message) {
|
||||
return this.replyTo;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* 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.adapter.mail;
|
||||
|
||||
import org.springframework.integration.message.Message;
|
||||
import org.springframework.integration.message.MessageMapper;
|
||||
import org.springframework.integration.message.StringMessage;
|
||||
import org.springframework.mail.MailMessage;
|
||||
import org.springframework.mail.SimpleMailMessage;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* Message mapper for transforming integration messages with a String payload
|
||||
* into simple text e-mail messages. The body of the e-mail message will be the
|
||||
* content of the integration message's payload.
|
||||
*
|
||||
* @author Marius Bogoevici
|
||||
*/
|
||||
public class TextMailMessageMapper implements MessageMapper<String, MailMessage> {
|
||||
|
||||
public Message<String> toMessage(MailMessage source) {
|
||||
Assert.isInstanceOf(SimpleMailMessage.class, source, "source must be a SimpleMailMessage");
|
||||
return new StringMessage(((SimpleMailMessage) source).getText());
|
||||
}
|
||||
|
||||
public MailMessage mapMessage(Message<String> stringMessage) {
|
||||
SimpleMailMessage mailMessage = new SimpleMailMessage();
|
||||
mailMessage.setText(stringMessage.getPayload());
|
||||
return mailMessage;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
/*
|
||||
* 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.adapter.mail.config;
|
||||
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
|
||||
import org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser;
|
||||
import org.springframework.beans.factory.xml.ParserContext;
|
||||
import org.springframework.integration.ConfigurationException;
|
||||
import org.springframework.integration.adapter.mail.MailTarget;
|
||||
import org.springframework.mail.javamail.JavaMailSenderImpl;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
* Parser for the <mail-target/> element.
|
||||
*
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public class MailTargetParser extends AbstractSingleBeanDefinitionParser {
|
||||
|
||||
protected Class<?> getBeanClass(Element element) {
|
||||
return MailTarget.class;
|
||||
}
|
||||
|
||||
protected boolean shouldGenerateId() {
|
||||
return false;
|
||||
}
|
||||
|
||||
protected boolean shouldGenerateIdAsFallback() {
|
||||
return true;
|
||||
}
|
||||
|
||||
protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
|
||||
String mailSenderRef = element.getAttribute("mail-sender");
|
||||
String host = element.getAttribute("host");
|
||||
String username = element.getAttribute("username");
|
||||
String password = element.getAttribute("password");
|
||||
String headerGeneratorRef = element.getAttribute("header-generator");
|
||||
if (StringUtils.hasText(mailSenderRef)) {
|
||||
if (StringUtils.hasText(host) || StringUtils.hasText(username) || StringUtils.hasText(password)) {
|
||||
throw new ConfigurationException("The 'host', 'username', and 'password' properties " +
|
||||
"should not be provided when using a 'mail-sender' reference.");
|
||||
}
|
||||
builder.addConstructorArgReference(mailSenderRef);
|
||||
}
|
||||
else if (StringUtils.hasText(host)) {
|
||||
JavaMailSenderImpl mailSender = new JavaMailSenderImpl();
|
||||
mailSender.setHost(host);
|
||||
if (StringUtils.hasText(username)) {
|
||||
mailSender.setUsername(username);
|
||||
}
|
||||
if (StringUtils.hasText(password)) {
|
||||
mailSender.setPassword(password);
|
||||
}
|
||||
builder.addConstructorArgValue(mailSender);
|
||||
}
|
||||
else {
|
||||
throw new ConfigurationException("Either a 'mail-sender' reference or 'host' property is required.");
|
||||
}
|
||||
if (StringUtils.hasText(headerGeneratorRef)) {
|
||||
builder.addPropertyReference("headerGenerator", headerGeneratorRef);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
/*
|
||||
* 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.adapter.rmi;
|
||||
|
||||
import java.rmi.RemoteException;
|
||||
import java.rmi.registry.Registry;
|
||||
|
||||
import org.springframework.integration.ConfigurationException;
|
||||
import org.springframework.integration.adapter.MessageHandlingSourceAdapter;
|
||||
import org.springframework.integration.channel.MessageChannel;
|
||||
import org.springframework.integration.handler.MessageHandler;
|
||||
import org.springframework.remoting.rmi.RmiServiceExporter;
|
||||
import org.springframework.remoting.support.RemoteInvocationExecutor;
|
||||
|
||||
/**
|
||||
* A source channel adapter for RMI-based remoting.
|
||||
*
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public class RmiSourceAdapter extends MessageHandlingSourceAdapter {
|
||||
|
||||
public static final String SERVICE_NAME_PREFIX = "internal.rmiSourceAdapter.";
|
||||
|
||||
|
||||
private volatile String registryHost;
|
||||
|
||||
private volatile int registryPort = Registry.REGISTRY_PORT;
|
||||
|
||||
private volatile RemoteInvocationExecutor remoteInvocationExecutor;
|
||||
|
||||
|
||||
public RmiSourceAdapter(MessageChannel channel) {
|
||||
super(channel);
|
||||
}
|
||||
|
||||
|
||||
public void setRegistryHost(String registryHost) {
|
||||
this.registryHost = registryHost;
|
||||
}
|
||||
|
||||
public void setRegistryPort(int registryPort) {
|
||||
this.registryPort = registryPort;
|
||||
}
|
||||
|
||||
public void setRemoteInvocationExecutor(RemoteInvocationExecutor remoteInvocationExecutor) {
|
||||
this.remoteInvocationExecutor = remoteInvocationExecutor;
|
||||
}
|
||||
|
||||
public void initialize() throws RemoteException {
|
||||
String channelName = this.getChannel().getName();
|
||||
if (channelName == null) {
|
||||
throw new ConfigurationException("RmiSourceAdapter's MessageChannel must have a 'name'");
|
||||
}
|
||||
RmiServiceExporter exporter = new RmiServiceExporter();
|
||||
if (this.registryHost != null) {
|
||||
exporter.setRegistryHost(this.registryHost);
|
||||
}
|
||||
exporter.setRegistryPort(this.registryPort);
|
||||
if (this.remoteInvocationExecutor != null) {
|
||||
exporter.setRemoteInvocationExecutor(this.remoteInvocationExecutor);
|
||||
}
|
||||
exporter.setService(this);
|
||||
exporter.setServiceInterface(MessageHandler.class);
|
||||
exporter.setServiceName(SERVICE_NAME_PREFIX + channelName);
|
||||
exporter.afterPropertiesSet();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* 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.adapter.rmi;
|
||||
|
||||
import org.springframework.integration.adapter.AbstractRemotingTargetAdapter;
|
||||
import org.springframework.integration.handler.MessageHandler;
|
||||
import org.springframework.remoting.rmi.RmiProxyFactoryBean;
|
||||
|
||||
/**
|
||||
* A target channel adapter for RMI-based remoting.
|
||||
*
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public class RmiTargetAdapter extends AbstractRemotingTargetAdapter {
|
||||
|
||||
|
||||
public RmiTargetAdapter(String url) {
|
||||
super(url);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public MessageHandler createHandlerProxy(String url) {
|
||||
RmiProxyFactoryBean proxyFactory = new RmiProxyFactoryBean();
|
||||
proxyFactory.setServiceInterface(MessageHandler.class);
|
||||
proxyFactory.setServiceUrl(url);
|
||||
proxyFactory.setLookupStubOnStartup(false);
|
||||
proxyFactory.setRefreshStubOnConnectFailure(true);
|
||||
proxyFactory.afterPropertiesSet();
|
||||
return (MessageHandler) proxyFactory.getObject();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* 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.adapter.rmi.config;
|
||||
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
|
||||
import org.springframework.integration.adapter.config.AbstractRequestReplySourceAdapterParser;
|
||||
import org.springframework.integration.adapter.rmi.RmiSourceAdapter;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
* Parser for the <rmi-source/> element.
|
||||
*
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public class RmiSourceAdapterParser extends AbstractRequestReplySourceAdapterParser {
|
||||
|
||||
private static final String REMOTE_INVOCATION_EXECUTOR_ATTRIBUTE = "remote-invocation-executor";
|
||||
|
||||
|
||||
@Override
|
||||
protected Class<?> getBeanClass(Element element) {
|
||||
return RmiSourceAdapter.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isEligibleAttribute(String attributeName) {
|
||||
return !attributeName.equals(REMOTE_INVOCATION_EXECUTOR_ATTRIBUTE)
|
||||
&& super.isEligibleAttribute(attributeName);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doPostProcess(BeanDefinitionBuilder builder, Element element) {
|
||||
String executorRef = element.getAttribute(REMOTE_INVOCATION_EXECUTOR_ATTRIBUTE);
|
||||
if (StringUtils.hasText(executorRef)) {
|
||||
builder.addPropertyReference("remoteInvocationExecutor", executorRef);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
* 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.adapter.rmi.config;
|
||||
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
import org.springframework.beans.factory.parsing.BeanComponentDefinition;
|
||||
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
|
||||
import org.springframework.beans.factory.support.RootBeanDefinition;
|
||||
import org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser;
|
||||
import org.springframework.beans.factory.xml.ParserContext;
|
||||
import org.springframework.integration.ConfigurationException;
|
||||
import org.springframework.integration.adapter.rmi.RmiSourceAdapter;
|
||||
import org.springframework.integration.adapter.rmi.RmiTargetAdapter;
|
||||
import org.springframework.integration.endpoint.HandlerEndpoint;
|
||||
import org.springframework.integration.scheduling.Subscription;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
* Parser for the <rmi-target/> element.
|
||||
*
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public class RmiTargetAdapterParser extends AbstractSingleBeanDefinitionParser {
|
||||
|
||||
protected Class<?> getBeanClass(Element element) {
|
||||
return HandlerEndpoint.class;
|
||||
}
|
||||
|
||||
protected boolean shouldGenerateId() {
|
||||
return false;
|
||||
}
|
||||
|
||||
protected boolean shouldGenerateIdAsFallback() {
|
||||
return true;
|
||||
}
|
||||
|
||||
protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
|
||||
RootBeanDefinition adapterDef = new RootBeanDefinition(RmiTargetAdapter.class);
|
||||
String host = element.getAttribute("host");
|
||||
String localChannel = element.getAttribute("local-channel");
|
||||
String remoteChannel = element.getAttribute("remote-channel");
|
||||
if (!(StringUtils.hasText(host) && StringUtils.hasText(localChannel) && StringUtils.hasText(remoteChannel))) {
|
||||
throw new ConfigurationException(
|
||||
"The 'host', 'local-channel', and 'remote-channel' attributes are all required");
|
||||
}
|
||||
String portAttribute = element.getAttribute("port");
|
||||
String port = StringUtils.hasText(portAttribute) ? portAttribute : "1099";
|
||||
String url = "rmi://" + host + ":" + port + "/" + RmiSourceAdapter.SERVICE_NAME_PREFIX + remoteChannel;
|
||||
adapterDef.getConstructorArgumentValues().addGenericArgumentValue(url);
|
||||
String adapterBeanName = parserContext.getReaderContext().generateBeanName(adapterDef);
|
||||
parserContext.registerBeanComponent(new BeanComponentDefinition(adapterDef, adapterBeanName));
|
||||
builder.addConstructorArgReference(adapterBeanName);
|
||||
Subscription subscription = new Subscription(localChannel);
|
||||
builder.addPropertyValue("subscription", subscription);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
/*
|
||||
* 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.adapter.stream;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
import org.springframework.integration.message.GenericMessage;
|
||||
import org.springframework.integration.message.Message;
|
||||
import org.springframework.integration.message.MessagingException;
|
||||
import org.springframework.integration.message.Source;
|
||||
|
||||
/**
|
||||
* A pollable source for receiving bytes from an {@link InputStream}.
|
||||
*
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public class ByteStreamSource implements Source<byte[]> {
|
||||
|
||||
private BufferedInputStream stream;
|
||||
|
||||
private Object streamMonitor;
|
||||
|
||||
private int bytesPerMessage = 1024;
|
||||
|
||||
private boolean shouldTruncate = true;
|
||||
|
||||
|
||||
public ByteStreamSource(InputStream stream) {
|
||||
this(stream, -1);
|
||||
}
|
||||
|
||||
public ByteStreamSource(InputStream stream, int bufferSize) {
|
||||
this.streamMonitor = stream;
|
||||
if (stream instanceof BufferedInputStream) {
|
||||
this.stream = (BufferedInputStream) stream;
|
||||
}
|
||||
else if (bufferSize > 0) {
|
||||
this.stream = new BufferedInputStream(stream, bufferSize);
|
||||
}
|
||||
else {
|
||||
this.stream = new BufferedInputStream(stream);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void setBytesPerMessage(int bytesPerMessage) {
|
||||
this.bytesPerMessage = bytesPerMessage;
|
||||
}
|
||||
|
||||
public void setShouldTruncate(boolean shouldTruncate) {
|
||||
this.shouldTruncate = shouldTruncate;
|
||||
}
|
||||
|
||||
public Message<byte[]> receive() {
|
||||
try {
|
||||
byte[] bytes;
|
||||
int bytesRead = 0;
|
||||
synchronized (this.streamMonitor) {
|
||||
if (stream.available() == 0) {
|
||||
return null;
|
||||
}
|
||||
bytes = new byte[bytesPerMessage];
|
||||
bytesRead = stream.read(bytes, 0, bytes.length);
|
||||
}
|
||||
if (bytesRead <= 0) {
|
||||
return null;
|
||||
}
|
||||
if (!this.shouldTruncate) {
|
||||
return new GenericMessage<byte[]>(bytes);
|
||||
}
|
||||
else {
|
||||
byte[] result = new byte[bytesRead];
|
||||
System.arraycopy(bytes, 0, result, 0, result.length);
|
||||
return new GenericMessage<byte[]>(result);
|
||||
}
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new MessagingException("IO failure occurred in adapter", e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
/*
|
||||
* 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.adapter.stream;
|
||||
|
||||
import java.io.BufferedOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import org.springframework.integration.message.Message;
|
||||
import org.springframework.integration.message.MessagingException;
|
||||
import org.springframework.integration.message.Target;
|
||||
|
||||
/**
|
||||
* A target that writes a byte array to an {@link OutputStream}.
|
||||
*
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public class ByteStreamTarget implements Target {
|
||||
|
||||
private final Log logger = LogFactory.getLog(this.getClass());
|
||||
|
||||
private final BufferedOutputStream stream;
|
||||
|
||||
|
||||
public ByteStreamTarget(OutputStream stream) {
|
||||
this(stream, -1);
|
||||
}
|
||||
|
||||
public ByteStreamTarget(OutputStream stream, int bufferSize) {
|
||||
if (bufferSize > 0) {
|
||||
this.stream = new BufferedOutputStream(stream, bufferSize);
|
||||
}
|
||||
else {
|
||||
this.stream = new BufferedOutputStream(stream);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public boolean send(Message message) {
|
||||
Object payload = message.getPayload();
|
||||
if (payload == null) {
|
||||
if (logger.isWarnEnabled()) {
|
||||
logger.warn(this.getClass().getSimpleName() + " received null object");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
if (payload instanceof String) {
|
||||
this.stream.write(((String) payload).getBytes());
|
||||
}
|
||||
else if (payload instanceof byte[]){
|
||||
this.stream.write((byte[]) payload);
|
||||
}
|
||||
else {
|
||||
throw new MessagingException(this.getClass().getSimpleName() +
|
||||
" only supports byte array and String-based messages");
|
||||
}
|
||||
this.stream.flush();
|
||||
return true;
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new MessagingException("IO failure occurred in target", e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
/*
|
||||
* 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.adapter.stream;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.Reader;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
|
||||
import org.springframework.integration.ConfigurationException;
|
||||
import org.springframework.integration.message.MessagingException;
|
||||
import org.springframework.integration.message.Source;
|
||||
import org.springframework.integration.message.StringMessage;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* A pollable source for {@link Reader Readers}.
|
||||
*
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public class CharacterStreamSource implements Source<String> {
|
||||
|
||||
private final BufferedReader reader;
|
||||
|
||||
private final Object monitor;
|
||||
|
||||
|
||||
public CharacterStreamSource(Reader reader) {
|
||||
this(reader, -1);
|
||||
}
|
||||
|
||||
public CharacterStreamSource(Reader reader, int bufferSize) {
|
||||
Assert.notNull(reader, "reader must not be null");
|
||||
this.monitor = reader;
|
||||
if (reader instanceof BufferedReader) {
|
||||
this.reader = (BufferedReader) reader;
|
||||
}
|
||||
else if (bufferSize > 0) {
|
||||
this.reader = new BufferedReader(reader, bufferSize);
|
||||
}
|
||||
else {
|
||||
this.reader = new BufferedReader(reader);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public StringMessage receive() {
|
||||
try {
|
||||
synchronized (this.monitor) {
|
||||
if (!this.reader.ready()) {
|
||||
return null;
|
||||
}
|
||||
String line = this.reader.readLine();
|
||||
return (line != null) ? new StringMessage(line) : null;
|
||||
}
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new MessagingException("IO failure occurred in adapter", e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static final CharacterStreamSource stdin() {
|
||||
return new CharacterStreamSource(new InputStreamReader(System.in));
|
||||
}
|
||||
|
||||
public static final CharacterStreamSource stdin(String charsetName) {
|
||||
try {
|
||||
return new CharacterStreamSource(new InputStreamReader(System.in, charsetName));
|
||||
}
|
||||
catch (UnsupportedEncodingException e) {
|
||||
throw new ConfigurationException("unsupported encoding: " + charsetName, e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,152 @@
|
||||
/*
|
||||
* 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.adapter.stream;
|
||||
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.io.Writer;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import org.springframework.integration.ConfigurationException;
|
||||
import org.springframework.integration.message.Message;
|
||||
import org.springframework.integration.message.MessagingException;
|
||||
import org.springframework.integration.message.Target;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* A target that writes to a {@link Writer}. String-based objects will be
|
||||
* written directly, but if the object is not itself a {@link String}, the
|
||||
* target will write the result of the object's {@link #toString()} method.
|
||||
* To append a new-line after each write, set the {@link #shouldAppendNewLine}
|
||||
* flag to <em>true</em>. It is <em>false</em> by default.
|
||||
*
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public class CharacterStreamTarget implements Target {
|
||||
|
||||
private final Log logger = LogFactory.getLog(this.getClass());
|
||||
|
||||
private final BufferedWriter writer;
|
||||
|
||||
private volatile boolean shouldAppendNewLine = false;
|
||||
|
||||
|
||||
public CharacterStreamTarget(Writer writer) {
|
||||
this(writer, -1);
|
||||
}
|
||||
|
||||
public CharacterStreamTarget(Writer writer, int bufferSize) {
|
||||
Assert.notNull(writer, "writer must not be null");
|
||||
if (writer instanceof BufferedWriter) {
|
||||
this.writer = (BufferedWriter) writer;
|
||||
}
|
||||
else if (bufferSize > 0) {
|
||||
this.writer = new BufferedWriter(writer, bufferSize);
|
||||
}
|
||||
else {
|
||||
this.writer = new BufferedWriter(writer);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Factory method that creates a target for stdout (System.out) with the
|
||||
* default charset encoding.
|
||||
*/
|
||||
public static CharacterStreamTarget stdout() {
|
||||
return stdout(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Factory method that creates a target for stdout (System.out) with the
|
||||
* specified charset encoding.
|
||||
*/
|
||||
public static CharacterStreamTarget stdout(String charsetName) {
|
||||
return createTargetForStream(System.out, charsetName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Factory method that creates a target for stderr (System.err) with the
|
||||
* default charset encoding.
|
||||
*/
|
||||
public static CharacterStreamTarget stderr() {
|
||||
return stderr(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Factory method that creates a target for stderr (System.err) with the
|
||||
* specified charset encoding.
|
||||
*/
|
||||
public static CharacterStreamTarget stderr(String charsetName) {
|
||||
return createTargetForStream(System.err, charsetName);
|
||||
}
|
||||
|
||||
private static CharacterStreamTarget createTargetForStream(OutputStream stream, String charsetName) {
|
||||
if (charsetName == null) {
|
||||
return new CharacterStreamTarget(new OutputStreamWriter(stream));
|
||||
}
|
||||
try {
|
||||
return new CharacterStreamTarget(new OutputStreamWriter(stream, charsetName));
|
||||
}
|
||||
catch (UnsupportedEncodingException e) {
|
||||
throw new ConfigurationException("unsupported encoding: " + charsetName, e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void setShouldAppendNewLine(boolean shouldAppendNewLine) {
|
||||
this.shouldAppendNewLine = shouldAppendNewLine;
|
||||
}
|
||||
|
||||
public boolean send(Message message) {
|
||||
Object payload = message.getPayload();
|
||||
if (payload == null) {
|
||||
if (logger.isWarnEnabled()) {
|
||||
logger.warn("target received null payload");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
if (payload instanceof String) {
|
||||
writer.write((String) payload);
|
||||
}
|
||||
else if (payload instanceof char[]) {
|
||||
this.writer.write((char[]) payload);
|
||||
}
|
||||
else if (payload instanceof byte[]) {
|
||||
this.writer.write(new String((byte[]) payload));
|
||||
}
|
||||
else {
|
||||
writer.write(payload.toString());
|
||||
}
|
||||
if (this.shouldAppendNewLine) {
|
||||
writer.newLine();
|
||||
}
|
||||
writer.flush();
|
||||
return true;
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new MessagingException("IO failure occurred in target", e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* 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.adapter.stream.config;
|
||||
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
|
||||
import org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser;
|
||||
import org.springframework.integration.adapter.stream.CharacterStreamSource;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
* Parser for the <console-source> element.
|
||||
*
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public class ConsoleSourceParser extends AbstractSingleBeanDefinitionParser {
|
||||
|
||||
@Override
|
||||
protected Class<?> getBeanClass(Element element) {
|
||||
return CharacterStreamSource.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean shouldGenerateId() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean shouldGenerateIdAsFallback() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doParse(Element element, BeanDefinitionBuilder builder) {
|
||||
builder.setFactoryMethod("stdin");
|
||||
String charsetName = element.getAttribute("charset");
|
||||
if (StringUtils.hasText(charsetName)) {
|
||||
builder.addConstructorArgValue(charsetName);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
* 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.adapter.stream.config;
|
||||
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
|
||||
import org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser;
|
||||
import org.springframework.integration.adapter.stream.CharacterStreamTarget;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
* Parser for the <console-target> element.
|
||||
*
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public class ConsoleTargetParser extends AbstractSingleBeanDefinitionParser {
|
||||
|
||||
@Override
|
||||
protected Class<?> getBeanClass(Element element) {
|
||||
return CharacterStreamTarget.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean shouldGenerateId() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean shouldGenerateIdAsFallback() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doParse(Element element, BeanDefinitionBuilder builder) {
|
||||
if ("true".equals(element.getAttribute("error"))) {
|
||||
builder.setFactoryMethod("stderr");
|
||||
}
|
||||
else {
|
||||
builder.setFactoryMethod("stdout");
|
||||
}
|
||||
String charsetName = element.getAttribute("charset");
|
||||
if (StringUtils.hasText(charsetName)) {
|
||||
builder.addConstructorArgValue(charsetName);
|
||||
}
|
||||
if ("true".equals(element.getAttribute("append-newline"))) {
|
||||
builder.addPropertyValue("shouldAppendNewLine", Boolean.TRUE);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,126 @@
|
||||
Import-Package: javax.jms;resolution:=optional,javax.mail;resolution:=
|
||||
optional,javax.mail.internet;resolution:=optional,javax.servlet;resol
|
||||
ution:=optional,javax.servlet.http;resolution:=optional,org.apache.co
|
||||
mmons.logging;resolution:=optional,org.apache.commons.net.ftp;resolut
|
||||
ion:=optional,org.springframework.beans;resolution:=optional,org.spri
|
||||
ngframework.beans.factory;resolution:=optional,org.springframework.be
|
||||
ans.factory.config;resolution:=optional,org.springframework.beans.fac
|
||||
tory.parsing;resolution:=optional,org.springframework.beans.factory.s
|
||||
upport;resolution:=optional,org.springframework.beans.factory.xml;res
|
||||
olution:=optional,org.springframework.context;resolution:=optional,or
|
||||
g.springframework.core;resolution:=optional,org.springframework.core.
|
||||
io;resolution:=optional,org.springframework.core.task;resolution:=opt
|
||||
ional,org.springframework.integration;resolution:=optional,org.spring
|
||||
framework.integration.adapter;resolution:=optional,org.springframewor
|
||||
k.integration.adapter.config;resolution:=optional,org.springframework
|
||||
.integration.adapter.event;resolution:=optional,org.springframework.i
|
||||
ntegration.adapter.file;resolution:=optional,org.springframework.inte
|
||||
gration.adapter.file.config;resolution:=optional,org.springframework.
|
||||
integration.adapter.ftp;resolution:=optional,org.springframework.inte
|
||||
gration.adapter.ftp.config;resolution:=optional,org.springframework.i
|
||||
ntegration.adapter.httpinvoker;resolution:=optional,org.springframewo
|
||||
rk.integration.adapter.httpinvoker.config;resolution:=optional,org.sp
|
||||
ringframework.integration.adapter.jms;resolution:=optional,org.spring
|
||||
framework.integration.adapter.jms.config;resolution:=optional,org.spr
|
||||
ingframework.integration.adapter.mail;resolution:=optional,org.spring
|
||||
framework.integration.adapter.mail.config;resolution:=optional,org.sp
|
||||
ringframework.integration.adapter.rmi;resolution:=optional,org.spring
|
||||
framework.integration.adapter.rmi.config;resolution:=optional,org.spr
|
||||
ingframework.integration.adapter.stream;resolution:=optional,org.spri
|
||||
ngframework.integration.channel;resolution:=optional,org.springframew
|
||||
ork.integration.endpoint;resolution:=optional,org.springframework.int
|
||||
egration.handler;resolution:=optional,org.springframework.integration
|
||||
.message;resolution:=optional,org.springframework.integration.schedul
|
||||
ing;resolution:=optional,org.springframework.integration.util;resolut
|
||||
ion:=optional,org.springframework.jms.core;resolution:=optional,org.s
|
||||
pringframework.jms.listener;resolution:=optional,org.springframework.
|
||||
jms.support.converter;resolution:=optional,org.springframework.mail;r
|
||||
esolution:=optional,org.springframework.mail.javamail;resolution:=opt
|
||||
ional,org.springframework.remoting;resolution:=optional,org.springfra
|
||||
mework.remoting.httpinvoker;resolution:=optional,org.springframework.
|
||||
remoting.rmi;resolution:=optional,org.springframework.remoting.suppor
|
||||
t;resolution:=optional,org.springframework.util;resolution:=optional,
|
||||
org.springframework.web;resolution:=optional,org.w3c.dom;resolution:=
|
||||
optional
|
||||
Export-Package: org.springframework.integration.adapter.rmi.config;use
|
||||
s:="org.springframework.beans.factory.parsing,org.w3c.dom,org.springf
|
||||
ramework.integration.scheduling,org.springframework.integration.adapt
|
||||
er.config,org.springframework.beans.factory.support,org.springframewo
|
||||
rk.integration.endpoint,org.springframework.integration.adapter.rmi,o
|
||||
rg.springframework.beans.factory.config,org.springframework.beans.fac
|
||||
tory.xml,org.springframework.integration,org.springframework.util",or
|
||||
g.springframework.integration.adapter.ftp;uses:="org.springframework.
|
||||
integration.adapter.file,org.apache.commons.net.ftp,org.springframewo
|
||||
rk.integration.adapter,org.apache.commons.logging,org.springframework
|
||||
.util,org.springframework.integration.message",org.springframework.in
|
||||
tegration.adapter.mail;uses:="org.springframework.integration.handler
|
||||
,org.springframework.mail,org.springframework.core.io,javax.mail.inte
|
||||
rnet,javax.mail,org.apache.commons.logging,org.springframework.mail.j
|
||||
avamail,org.springframework.util,org.springframework.beans.factory,or
|
||||
g.springframework.integration.message",org.springframework.integratio
|
||||
n.adapter.jms;uses:="org.springframework.jms.listener,org.springframe
|
||||
work.integration.handler,org.springframework.jms.core,org.springframe
|
||||
work.context,org.springframework.integration.channel,org.springframew
|
||||
ork.jms.support.converter,org.springframework.integration,org.springf
|
||||
ramework.core.task,org.springframework.integration.adapter,org.spring
|
||||
framework.util,org.springframework.beans.factory,javax.jms,org.spring
|
||||
framework.integration.message",org.springframework.integration.adapte
|
||||
r.httpinvoker;uses:="javax.servlet.http,org.springframework.integrati
|
||||
on.handler,javax.servlet,org.springframework.remoting.httpinvoker,org
|
||||
.springframework.integration.adapter,org.springframework.web,org.spri
|
||||
ngframework.integration.channel,org.springframework.integration.messa
|
||||
ge",org.springframework.integration.adapter.file.config;uses:="org.sp
|
||||
ringframework.beans.factory.support,org.springframework.integration.a
|
||||
dapter.file,org.springframework.integration.endpoint,org.springframew
|
||||
ork.beans.factory.config,org.springframework.beans.factory.xml,org.sp
|
||||
ringframework.beans.factory.parsing,org.springframework.integration.s
|
||||
cheduling,org.w3c.dom",org.springframework.integration.adapter.mail.c
|
||||
onfig;uses:="org.springframework.integration.adapter.mail,org.springf
|
||||
ramework.beans.factory.parsing,org.springframework.integration.schedu
|
||||
ling,org.w3c.dom,org.springframework.beans.factory.support,org.spring
|
||||
framework.integration.endpoint,org.springframework.beans.factory.conf
|
||||
ig,org.springframework.beans.factory.xml,org.springframework.integrat
|
||||
ion,org.springframework.beans,org.springframework.mail.javamail,org.s
|
||||
pringframework.util",org.springframework.integration.adapter.config;u
|
||||
ses:="org.springframework.beans.factory.support,org.springframework.b
|
||||
eans.factory.config,org.springframework.beans.factory.xml,org.springf
|
||||
ramework.integration,org.w3c.dom,org.springframework.util,org.springf
|
||||
ramework.beans.factory",org.springframework.integration.adapter.file;
|
||||
uses:="org.springframework.integration.adapter,org.apache.commons.log
|
||||
ging,org.springframework.util,org.springframework.integration.channel
|
||||
,org.springframework.integration.message,org.springframework.integrat
|
||||
ion.util",org.springframework.integration.adapter.stream;uses:="org.s
|
||||
pringframework.integration,org.apache.commons.logging,org.springframe
|
||||
work.integration.adapter,org.springframework.util,org.springframework
|
||||
.integration.channel,org.springframework.integration.message",org.spr
|
||||
ingframework.integration.adapter.ftp.config;uses:="org.springframewor
|
||||
k.beans.factory.support,org.springframework.integration.adapter.ftp,o
|
||||
rg.springframework.beans.factory.xml,org.springframework.core,org.w3c
|
||||
.dom,org.springframework.util",org.springframework.integration.adapte
|
||||
r.rmi;uses:="org.springframework.integration.handler,org.springframew
|
||||
ork.remoting.support,org.springframework.integration,org.springframew
|
||||
ork.integration.adapter,org.springframework.remoting.rmi,org.springfr
|
||||
amework.integration.channel",org.springframework.integration.adapter.
|
||||
jms.config;uses:="org.springframework.integration.adapter.jms,org.spr
|
||||
ingframework.beans.factory.parsing,org.w3c.dom,org.springframework.in
|
||||
tegration.scheduling,org.springframework.beans.factory.support,org.sp
|
||||
ringframework.integration.endpoint,org.springframework.beans.factory.
|
||||
config,org.springframework.beans.factory.xml,org.springframework.bean
|
||||
s,org.springframework.util,org.springframework.beans.factory",org.spr
|
||||
ingframework.integration.adapter.httpinvoker.config;uses:="org.spring
|
||||
framework.beans.factory.support,org.springframework.integration.endpo
|
||||
int,org.springframework.beans.factory.config,org.springframework.bean
|
||||
s.factory.xml,org.springframework.integration,org.springframework.int
|
||||
egration.adapter.httpinvoker,org.springframework.beans.factory.parsin
|
||||
g,org.springframework.integration.scheduling,org.w3c.dom,org.springfr
|
||||
amework.util,org.springframework.integration.adapter.config",org.spri
|
||||
ngframework.integration.adapter;uses:="org.springframework.remoting,o
|
||||
rg.springframework.integration.handler,org.springframework.integratio
|
||||
n,org.apache.commons.logging,org.springframework.util,org.springframe
|
||||
work.integration.channel,org.springframework.beans.factory,org.spring
|
||||
framework.integration.message",org.springframework.integration.adapte
|
||||
r.event;uses:="org.springframework.integration.adapter,org.springfram
|
||||
ework.util,org.springframework.context,org.springframework.integratio
|
||||
n.message"
|
||||
Bundle-Name: Spring Integration Adapters
|
||||
|
||||
@@ -0,0 +1,114 @@
|
||||
/*
|
||||
* 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.adapter.event;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.context.ApplicationEvent;
|
||||
import org.springframework.context.event.ContextClosedEvent;
|
||||
import org.springframework.context.event.ContextRefreshedEvent;
|
||||
import org.springframework.context.event.ContextStartedEvent;
|
||||
import org.springframework.context.event.ContextStoppedEvent;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.integration.channel.MessageChannel;
|
||||
import org.springframework.integration.channel.QueueChannel;
|
||||
import org.springframework.integration.message.Message;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public class ApplicationEventSourceTests {
|
||||
|
||||
@Test
|
||||
public void testAnyApplicationEventSentByDefault() {
|
||||
MessageChannel channel = new QueueChannel();
|
||||
ApplicationEventSource adapter = new ApplicationEventSource(channel);
|
||||
Message<?> message1 = channel.receive(0);
|
||||
assertNull(message1);
|
||||
adapter.onApplicationEvent(new TestApplicationEvent1());
|
||||
adapter.onApplicationEvent(new TestApplicationEvent2());
|
||||
Message<?> message2 = channel.receive(20);
|
||||
assertNotNull(message2);
|
||||
assertEquals("event1", ((ApplicationEvent) message2.getPayload()).getSource());
|
||||
Message<?> message3 = channel.receive(20);
|
||||
assertNotNull(message3);
|
||||
assertEquals("event2", ((ApplicationEvent) message3.getPayload()).getSource());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOnlyConfiguredEventTypesAreSent() {
|
||||
MessageChannel channel = new QueueChannel();
|
||||
ApplicationEventSource adapter = new ApplicationEventSource(channel);
|
||||
List<Class<? extends ApplicationEvent>> eventTypes = new ArrayList<Class<? extends ApplicationEvent>>();
|
||||
eventTypes.add(TestApplicationEvent1.class);
|
||||
adapter.setEventTypes(eventTypes);
|
||||
Message<?> message1 = channel.receive(0);
|
||||
assertNull(message1);
|
||||
adapter.onApplicationEvent(new TestApplicationEvent1());
|
||||
adapter.onApplicationEvent(new TestApplicationEvent2());
|
||||
Message<?> message2 = channel.receive(20);
|
||||
assertNotNull(message2);
|
||||
assertEquals("event1", ((ApplicationEvent) message2.getPayload()).getSource());
|
||||
Message<?> message3 = channel.receive(0);
|
||||
assertNull(message3);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testApplicationContextEvents() {
|
||||
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("applicationEventSourceTests.xml", this.getClass());
|
||||
MessageChannel channel = (MessageChannel) context.getBean("channel");
|
||||
Message<?> refreshedEventMessage = channel.receive(0);
|
||||
assertNotNull(refreshedEventMessage);
|
||||
assertEquals(ContextRefreshedEvent.class, refreshedEventMessage.getPayload().getClass());
|
||||
context.start();
|
||||
Message<?> startedEventMessage = channel.receive(0);
|
||||
assertNotNull(startedEventMessage);
|
||||
assertEquals(ContextStartedEvent.class, startedEventMessage.getPayload().getClass());
|
||||
context.stop();
|
||||
Message<?> stoppedEventMessage = channel.receive(0);
|
||||
assertNotNull(stoppedEventMessage);
|
||||
assertEquals(ContextStoppedEvent.class, stoppedEventMessage.getPayload().getClass());
|
||||
context.close();
|
||||
Message<?> closedEventMessage = channel.receive(0);
|
||||
assertNotNull(closedEventMessage);
|
||||
assertEquals(ContextClosedEvent.class, closedEventMessage.getPayload().getClass());
|
||||
}
|
||||
|
||||
|
||||
private static class TestApplicationEvent1 extends ApplicationEvent {
|
||||
|
||||
public TestApplicationEvent1() {
|
||||
super("event1");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static class TestApplicationEvent2 extends ApplicationEvent {
|
||||
|
||||
public TestApplicationEvent2() {
|
||||
super("event2");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
* Copyright 2002-2007 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.adapter.event;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.context.ApplicationEvent;
|
||||
import org.springframework.context.ApplicationEventPublisher;
|
||||
import org.springframework.integration.bus.MessageBus;
|
||||
import org.springframework.integration.channel.MessageChannel;
|
||||
import org.springframework.integration.channel.QueueChannel;
|
||||
import org.springframework.integration.message.GenericMessage;
|
||||
import org.springframework.integration.message.StringMessage;
|
||||
import org.springframework.integration.scheduling.Subscription;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public class ApplicationEventTargetTests {
|
||||
|
||||
@Test
|
||||
public void testSendingEvent() throws InterruptedException {
|
||||
final CountDownLatch latch = new CountDownLatch(1);
|
||||
ApplicationEventPublisher publisher = new ApplicationEventPublisher() {
|
||||
public void publishEvent(ApplicationEvent event) {
|
||||
latch.countDown();
|
||||
}
|
||||
};
|
||||
MessageChannel channel = new QueueChannel();
|
||||
ApplicationEventTarget adapter = new ApplicationEventTarget();
|
||||
adapter.setApplicationEventPublisher(publisher);
|
||||
MessageBus bus = new MessageBus();
|
||||
bus.registerChannel("channel", channel);
|
||||
bus.registerTarget("adapter", adapter, new Subscription(channel));
|
||||
bus.start();
|
||||
assertEquals(1, latch.getCount());
|
||||
channel.send(new StringMessage("123", "testing"));
|
||||
latch.await(100, TimeUnit.MILLISECONDS);
|
||||
assertEquals(0, latch.getCount());
|
||||
bus.stop();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
|
||||
|
||||
<bean id="bus" class="org.springframework.integration.bus.MessageBus"/>
|
||||
|
||||
<bean id="channel" class="org.springframework.integration.channel.QueueChannel"/>
|
||||
|
||||
<bean id="source" class="org.springframework.integration.adapter.event.ApplicationEventSource">
|
||||
<constructor-arg ref="channel"/>
|
||||
</bean>
|
||||
|
||||
</beans>
|
||||
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* Copyright 2002-2007 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.adapter.file;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.integration.message.GenericMessage;
|
||||
import org.springframework.integration.message.Message;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public class DefaultFileNameGeneratorTests {
|
||||
|
||||
@Test
|
||||
public void testWithFileNamePropertyProvided() {
|
||||
Message<String> message = new GenericMessage<String>("123", "testing");
|
||||
message.getHeader().setProperty(FileNameGenerator.FILENAME_PROPERTY_KEY, "foo.bar");
|
||||
FileNameGenerator generator = new DefaultFileNameGenerator();
|
||||
String filename = generator.generateFileName(message);
|
||||
assertEquals("foo.bar", filename);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWithoutFileNamePropertyProvided() {
|
||||
Message<String> message = new GenericMessage<String>("123", "testing");
|
||||
FileNameGenerator generator = new DefaultFileNameGenerator();
|
||||
String filename = generator.generateFileName(message);
|
||||
assertTrue(filename.startsWith("123-"));
|
||||
assertTrue(filename.endsWith(".msg"));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* 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.adapter.file.config;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.beans.DirectFieldAccessor;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.integration.adapter.file.FileSource;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public class FileSourceParserTests {
|
||||
|
||||
@Test
|
||||
public void testFileSource() {
|
||||
ApplicationContext context = new ClassPathXmlApplicationContext("fileSourceParserTests.xml", this.getClass());
|
||||
FileSource fileSource = (FileSource) context.getBean("fileSource");
|
||||
DirectFieldAccessor sourceAccessor = new DirectFieldAccessor(fileSource);
|
||||
File directory = (File) sourceAccessor.getPropertyValue("directory");
|
||||
assertEquals(System.getProperty("java.io.tmpdir"), directory.getAbsolutePath());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* 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.adapter.file.config;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.integration.adapter.file.FileTarget;
|
||||
import org.springframework.integration.message.Target;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public class FileTargetParserTests {
|
||||
|
||||
@Test
|
||||
public void testFileTarget() {
|
||||
ApplicationContext context = new ClassPathXmlApplicationContext("fileTargetParserTests.xml", this.getClass());
|
||||
Target target = (Target) context.getBean("target");
|
||||
assertEquals(FileTarget.class, target.getClass());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:si="http://www.springframework.org/schema/integration"
|
||||
xmlns:context="http://www.springframework.org/schema/context"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
|
||||
http://www.springframework.org/schema/context
|
||||
http://www.springframework.org/schema/context/spring-context-2.5.xsd
|
||||
http://www.springframework.org/schema/integration
|
||||
http://www.springframework.org/schema/integration/spring-integration-1.0.xsd">
|
||||
|
||||
<si:file-source id="fileSource" directory="${java.io.tmpdir}"/>
|
||||
|
||||
<context:property-placeholder/>
|
||||
|
||||
</beans>
|
||||
@@ -0,0 +1,21 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:si="http://www.springframework.org/schema/integration"
|
||||
xmlns:context="http://www.springframework.org/schema/context"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
|
||||
http://www.springframework.org/schema/context
|
||||
http://www.springframework.org/schema/context/spring-context-2.5.xsd
|
||||
http://www.springframework.org/schema/integration
|
||||
http://www.springframework.org/schema/integration/spring-integration-1.0.xsd">
|
||||
|
||||
<si:message-bus/>
|
||||
|
||||
<si:channel id="testChannel"/>
|
||||
|
||||
<si:file-target id="target" directory="${java.io.tmpdir}"/>
|
||||
|
||||
<context:property-placeholder/>
|
||||
|
||||
</beans>
|
||||
@@ -0,0 +1,177 @@
|
||||
/*
|
||||
* 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.adapter.ftp;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* @author Marius Bogoevici
|
||||
*/
|
||||
public class DirectoryContentManagerTests {
|
||||
|
||||
private DirectoryContentManager directoryContentManager;
|
||||
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
directoryContentManager = new DirectoryContentManager();
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testInitialization() {
|
||||
Assert.assertTrue(directoryContentManager.getBacklog().isEmpty());
|
||||
Map<String, FileInfo> remoteSnapshot = generateInitialSnapshot();
|
||||
directoryContentManager.processSnapshot(remoteSnapshot);
|
||||
Assert.assertEquals(3, directoryContentManager.getBacklog().size());
|
||||
Assert.assertTrue(directoryContentManager.getBacklog().containsKey("a.txt"));
|
||||
Assert.assertTrue(directoryContentManager.getBacklog().containsKey("b.txt"));
|
||||
Assert.assertTrue(directoryContentManager.getBacklog().containsKey("c.txt"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFullProcessingInOneStep() {
|
||||
Assert.assertTrue(directoryContentManager.getBacklog().isEmpty());
|
||||
Map<String, FileInfo> remoteSnapshot = generateInitialSnapshot();
|
||||
directoryContentManager.processSnapshot(remoteSnapshot);
|
||||
directoryContentManager.fileProcessed("a.txt");
|
||||
directoryContentManager.fileProcessed("b.txt");
|
||||
directoryContentManager.fileProcessed("c.txt");
|
||||
Assert.assertTrue(directoryContentManager.getBacklog().isEmpty());
|
||||
directoryContentManager.processSnapshot(remoteSnapshot);
|
||||
Assert.assertTrue(directoryContentManager.getBacklog().isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFullProcessingInTwoSteps() {
|
||||
Assert.assertTrue(directoryContentManager.getBacklog().isEmpty());
|
||||
Map<String, FileInfo> remoteSnapshot = generateInitialSnapshot();
|
||||
directoryContentManager.processSnapshot(remoteSnapshot);
|
||||
directoryContentManager.fileProcessed("a.txt");
|
||||
directoryContentManager.fileProcessed("b.txt");
|
||||
Assert.assertEquals(1, directoryContentManager.getBacklog().size());
|
||||
Assert.assertTrue(directoryContentManager.getBacklog().containsKey("c.txt"));
|
||||
directoryContentManager.processSnapshot(remoteSnapshot);
|
||||
Assert.assertEquals(1, directoryContentManager.getBacklog().size());
|
||||
Assert.assertTrue(directoryContentManager.getBacklog().containsKey("c.txt"));
|
||||
directoryContentManager.fileProcessed("c.txt");
|
||||
Assert.assertTrue(directoryContentManager.getBacklog().isEmpty());
|
||||
directoryContentManager.processSnapshot(remoteSnapshot);
|
||||
Assert.assertTrue(directoryContentManager.getBacklog().isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOneFileChangedSize() {
|
||||
Assert.assertTrue(directoryContentManager.getBacklog().isEmpty());
|
||||
Map<String, FileInfo> remoteSnapshot = generateInitialSnapshot();
|
||||
directoryContentManager.processSnapshot(remoteSnapshot);
|
||||
directoryContentManager.fileProcessed("a.txt");
|
||||
directoryContentManager.fileProcessed("b.txt");
|
||||
Assert.assertEquals(1, directoryContentManager.getBacklog().size());
|
||||
Assert.assertTrue(directoryContentManager.getBacklog().containsKey("c.txt"));
|
||||
directoryContentManager.processSnapshot(remoteSnapshot);
|
||||
Assert.assertEquals(1, directoryContentManager.getBacklog().size());
|
||||
Assert.assertTrue(directoryContentManager.getBacklog().containsKey("c.txt"));
|
||||
directoryContentManager.fileProcessed("c.txt");
|
||||
Assert.assertTrue(directoryContentManager.getBacklog().isEmpty());
|
||||
directoryContentManager.processSnapshot(remoteSnapshot);
|
||||
remoteSnapshot.put("c.txt", new FileInfo("c.txt", 1001, 112));
|
||||
directoryContentManager.processSnapshot(remoteSnapshot);
|
||||
Assert.assertEquals(1, directoryContentManager.getBacklog().size());
|
||||
Assert.assertTrue(directoryContentManager.getBacklog().containsKey("c.txt"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOneFileChangedDate() {
|
||||
Assert.assertTrue(directoryContentManager.getBacklog().isEmpty());
|
||||
Map<String, FileInfo> remoteSnapshot = generateInitialSnapshot();
|
||||
directoryContentManager.processSnapshot(remoteSnapshot);
|
||||
directoryContentManager.fileProcessed("a.txt");
|
||||
directoryContentManager.fileProcessed("b.txt");
|
||||
Assert.assertEquals(1, directoryContentManager.getBacklog().size());
|
||||
Assert.assertTrue(directoryContentManager.getBacklog().containsKey("c.txt"));
|
||||
directoryContentManager.processSnapshot(remoteSnapshot);
|
||||
Assert.assertEquals(1, directoryContentManager.getBacklog().size());
|
||||
Assert.assertTrue(directoryContentManager.getBacklog().containsKey("c.txt"));
|
||||
directoryContentManager.fileProcessed("c.txt");
|
||||
Assert.assertTrue(directoryContentManager.getBacklog().isEmpty());
|
||||
directoryContentManager.processSnapshot(remoteSnapshot);
|
||||
remoteSnapshot.put("c.txt", new FileInfo("c.txt", 1011, 102));
|
||||
directoryContentManager.processSnapshot(remoteSnapshot);
|
||||
Assert.assertEquals(1, directoryContentManager.getBacklog().size());
|
||||
Assert.assertTrue(directoryContentManager.getBacklog().containsKey("c.txt"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOneFileAdded() {
|
||||
Assert.assertTrue(directoryContentManager.getBacklog().isEmpty());
|
||||
Map<String, FileInfo> remoteSnapshot = generateInitialSnapshot();
|
||||
directoryContentManager.processSnapshot(remoteSnapshot);
|
||||
directoryContentManager.fileProcessed("a.txt");
|
||||
directoryContentManager.fileProcessed("b.txt");
|
||||
directoryContentManager.fileProcessed("c.txt");
|
||||
Assert.assertTrue(directoryContentManager.getBacklog().isEmpty());
|
||||
directoryContentManager.processSnapshot(remoteSnapshot);
|
||||
remoteSnapshot.put("d.txt", new FileInfo("d.txt", 1003, 103));
|
||||
directoryContentManager.processSnapshot(remoteSnapshot);
|
||||
Assert.assertEquals(1, directoryContentManager.getBacklog().size());
|
||||
Assert.assertTrue(directoryContentManager.getBacklog().containsKey("d.txt"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOneFileRemoved() {
|
||||
Assert.assertTrue(directoryContentManager.getBacklog().isEmpty());
|
||||
Map<String, FileInfo> remoteSnapshot = generateInitialSnapshot();
|
||||
directoryContentManager.processSnapshot(remoteSnapshot);
|
||||
directoryContentManager.fileProcessed("a.txt");
|
||||
directoryContentManager.fileProcessed("b.txt");
|
||||
directoryContentManager.fileProcessed("c.txt");
|
||||
Assert.assertTrue(directoryContentManager.getBacklog().isEmpty());
|
||||
directoryContentManager.processSnapshot(remoteSnapshot);
|
||||
remoteSnapshot.remove("c.txt");
|
||||
directoryContentManager.processSnapshot(remoteSnapshot);
|
||||
Assert.assertTrue(directoryContentManager.getBacklog().isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOneFileRemovedBeforeBeingProcessedInTheNextStep() {
|
||||
Assert.assertTrue(directoryContentManager.getBacklog().isEmpty());
|
||||
Map<String, FileInfo> remoteSnapshot = generateInitialSnapshot();
|
||||
directoryContentManager.processSnapshot(remoteSnapshot);
|
||||
Assert.assertTrue(directoryContentManager.getBacklog().containsKey("c.txt"));
|
||||
remoteSnapshot.remove("c.txt");
|
||||
directoryContentManager.processSnapshot(remoteSnapshot);
|
||||
Assert.assertEquals(2, directoryContentManager.getBacklog().size());
|
||||
directoryContentManager.processSnapshot(remoteSnapshot);
|
||||
Assert.assertEquals(2, directoryContentManager.getBacklog().size());
|
||||
}
|
||||
|
||||
|
||||
private static Map<String, FileInfo> generateInitialSnapshot() {
|
||||
Map<String, FileInfo> remoteSnapshot = new HashMap<String, FileInfo>();
|
||||
remoteSnapshot.put("a.txt", new FileInfo("a.txt", 1000, 100));
|
||||
remoteSnapshot.put("b.txt", new FileInfo("b.txt", 1001, 101));
|
||||
remoteSnapshot.put("c.txt", new FileInfo("c.txt", 1002, 102));
|
||||
return remoteSnapshot;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* 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.adapter.ftp.config;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.beans.DirectFieldAccessor;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.integration.adapter.ftp.FtpSource;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public class FtpSourceParserTests {
|
||||
|
||||
@Test
|
||||
public void testFtpSourceAdapterParser() {
|
||||
ApplicationContext context = new ClassPathXmlApplicationContext("ftpSourceParserTests.xml", this.getClass());
|
||||
FtpSource ftpSource = (FtpSource) context.getBean("ftpSource");
|
||||
DirectFieldAccessor accessor = new DirectFieldAccessor(ftpSource);
|
||||
assertEquals("testHost", accessor.getPropertyValue("host"));
|
||||
assertEquals(2121, accessor.getPropertyValue("port"));
|
||||
assertEquals(new File("/local"), accessor.getPropertyValue("localWorkingDirectory"));
|
||||
assertEquals("/remote", accessor.getPropertyValue("remoteWorkingDirectory"));
|
||||
assertEquals("testUser", accessor.getPropertyValue("username"));
|
||||
assertEquals("testPassword", accessor.getPropertyValue("password"));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:si="http://www.springframework.org/schema/integration"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
|
||||
http://www.springframework.org/schema/integration
|
||||
http://www.springframework.org/schema/integration/spring-integration-1.0.xsd">
|
||||
|
||||
<si:ftp-source id="ftpSource"
|
||||
host="testHost"
|
||||
port="2121"
|
||||
local-working-directory="/local"
|
||||
remote-working-directory="/remote"
|
||||
username="testUser"
|
||||
password="testPassword"/>
|
||||
|
||||
</beans>
|
||||
@@ -0,0 +1,108 @@
|
||||
/*
|
||||
* 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.adapter.httpinvoker;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.integration.channel.MessageChannel;
|
||||
import org.springframework.integration.channel.QueueChannel;
|
||||
import org.springframework.integration.message.Message;
|
||||
import org.springframework.integration.message.StringMessage;
|
||||
import org.springframework.mock.web.MockHttpServletRequest;
|
||||
import org.springframework.mock.web.MockHttpServletResponse;
|
||||
import org.springframework.remoting.support.RemoteInvocation;
|
||||
import org.springframework.remoting.support.RemoteInvocationResult;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public class HttpInvokerSourceAdapterTests {
|
||||
|
||||
@Test
|
||||
public void testRequestOnly() throws Exception {
|
||||
MessageChannel channel = new QueueChannel();
|
||||
HttpInvokerSourceAdapter adapter = new HttpInvokerSourceAdapter(channel);
|
||||
adapter.setExpectReply(false);
|
||||
adapter.afterPropertiesSet();
|
||||
MockHttpServletRequest request = new MockHttpServletRequest();
|
||||
MockHttpServletResponse response = new MockHttpServletResponse();
|
||||
request.setContent(createRequestContent(new StringMessage("test")));
|
||||
adapter.handleRequest(request, response);
|
||||
Message<?> message = channel.receive(500);
|
||||
assertNotNull(message);
|
||||
assertEquals("test", message.getPayload());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRequestExpectingReply() throws Exception {
|
||||
final MessageChannel channel = new QueueChannel();
|
||||
Executors.newSingleThreadExecutor().execute(new Runnable() {
|
||||
public void run() {
|
||||
Message<?> message = channel.receive();
|
||||
MessageChannel replyChannel = (MessageChannel) message.getHeader().getReturnAddress();
|
||||
replyChannel.send(new StringMessage(message.getPayload().toString().toUpperCase()));
|
||||
}
|
||||
});
|
||||
HttpInvokerSourceAdapter adapter = new HttpInvokerSourceAdapter(channel);
|
||||
adapter.setExpectReply(true);
|
||||
adapter.afterPropertiesSet();
|
||||
MockHttpServletRequest request = new MockHttpServletRequest();
|
||||
MockHttpServletResponse response = new MockHttpServletResponse();
|
||||
request.setContent(createRequestContent(new StringMessage("test")));
|
||||
adapter.handleRequest(request, response);
|
||||
Message<?> reply = extractMessageFromResponse(response);
|
||||
assertEquals("TEST", reply.getPayload());
|
||||
}
|
||||
|
||||
|
||||
private static byte[] createRequestContent(Message<?> message) throws IOException {
|
||||
RemoteInvocation invocation = new RemoteInvocation(
|
||||
"handle", new Class[] { Message.class }, new Object[] { message });
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream(1024);
|
||||
ObjectOutputStream oos = new ObjectOutputStream(baos);
|
||||
try {
|
||||
oos.writeObject(invocation);
|
||||
oos.flush();
|
||||
}
|
||||
finally {
|
||||
oos.close();
|
||||
}
|
||||
return baos.toByteArray();
|
||||
}
|
||||
|
||||
private static Message<?> extractMessageFromResponse(MockHttpServletResponse response) throws IOException, ClassNotFoundException {
|
||||
byte[] responseContent = response.getContentAsByteArray();
|
||||
ByteArrayInputStream bais = new ByteArrayInputStream(responseContent);
|
||||
ObjectInputStream ois = new ObjectInputStream(bais);
|
||||
RemoteInvocationResult remoteResult = (RemoteInvocationResult) ois.readObject();
|
||||
Object resultValue = remoteResult.getValue();
|
||||
assertTrue(resultValue instanceof Message);
|
||||
return (Message<?>) resultValue;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
/*
|
||||
* 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.adapter.httpinvoker.config;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.beans.DirectFieldAccessor;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.integration.adapter.httpinvoker.HttpInvokerSourceAdapter;
|
||||
import org.springframework.integration.channel.MessageChannel;
|
||||
import org.springframework.integration.channel.RequestReplyTemplate;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public class HttpInvokerSourceAdapterParserTests {
|
||||
|
||||
@Test
|
||||
public void testAdapterWithDefaults() {
|
||||
ApplicationContext context = new ClassPathXmlApplicationContext(
|
||||
"httpInvokerSourceAdapterParserTests.xml", this.getClass());
|
||||
MessageChannel channel = (MessageChannel) context.getBean("testChannel");
|
||||
HttpInvokerSourceAdapter adapter = (HttpInvokerSourceAdapter) context.getBean("adapterWithDefaults");
|
||||
DirectFieldAccessor accessor = new DirectFieldAccessor(adapter);
|
||||
assertEquals(channel, accessor.getPropertyValue("requestChannel"));
|
||||
assertEquals(true, accessor.getPropertyValue("expectReply"));
|
||||
RequestReplyTemplate template = (RequestReplyTemplate)
|
||||
accessor.getPropertyValue("requestReplyTemplate");
|
||||
DirectFieldAccessor templateAccessor = new DirectFieldAccessor(template);
|
||||
assertEquals(-1L, templateAccessor.getPropertyValue("requestTimeout"));
|
||||
assertEquals(-1L, templateAccessor.getPropertyValue("replyTimeout"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAdapterWithName() {
|
||||
ApplicationContext context = new ClassPathXmlApplicationContext(
|
||||
"httpInvokerSourceAdapterParserTests.xml", this.getClass());
|
||||
MessageChannel channel = (MessageChannel) context.getBean("testChannel");
|
||||
HttpInvokerSourceAdapter adapter = (HttpInvokerSourceAdapter) context.getBean("/adapter/with/name");
|
||||
DirectFieldAccessor accessor = new DirectFieldAccessor(adapter);
|
||||
assertEquals(channel, accessor.getPropertyValue("requestChannel"));
|
||||
assertEquals(true, accessor.getPropertyValue("expectReply"));
|
||||
RequestReplyTemplate template = (RequestReplyTemplate)
|
||||
accessor.getPropertyValue("requestReplyTemplate");
|
||||
DirectFieldAccessor templateAccessor = new DirectFieldAccessor(template);
|
||||
assertEquals(-1L, templateAccessor.getPropertyValue("requestTimeout"));
|
||||
assertEquals(-1L, templateAccessor.getPropertyValue("replyTimeout"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAdapterWithCustomProperties() {
|
||||
ApplicationContext context = new ClassPathXmlApplicationContext(
|
||||
"httpInvokerSourceAdapterParserTests.xml", this.getClass());
|
||||
MessageChannel channel = (MessageChannel) context.getBean("testChannel");
|
||||
HttpInvokerSourceAdapter adapter = (HttpInvokerSourceAdapter) context.getBean("adapterWithCustomProperties");
|
||||
DirectFieldAccessor accessor = new DirectFieldAccessor(adapter);
|
||||
assertEquals(channel, accessor.getPropertyValue("requestChannel"));
|
||||
assertEquals(false, accessor.getPropertyValue("expectReply"));
|
||||
RequestReplyTemplate template = (RequestReplyTemplate)
|
||||
accessor.getPropertyValue("requestReplyTemplate");
|
||||
DirectFieldAccessor templateAccessor = new DirectFieldAccessor(template);
|
||||
assertEquals(123L, templateAccessor.getPropertyValue("requestTimeout"));
|
||||
assertEquals(456L, templateAccessor.getPropertyValue("replyTimeout"));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* 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.adapter.httpinvoker.config;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.integration.adapter.httpinvoker.HttpInvokerTargetAdapter;
|
||||
import org.springframework.integration.endpoint.HandlerEndpoint;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public class HttpInvokerTargetAdapterParserTests {
|
||||
|
||||
@Test
|
||||
public void testHttpInvokerTargetAdapter() {
|
||||
ApplicationContext context = new ClassPathXmlApplicationContext(
|
||||
"httpInvokerTargetAdapterParserTests.xml", this.getClass());
|
||||
HandlerEndpoint endpoint = (HandlerEndpoint) context.getBean("adapter");
|
||||
assertNotNull(endpoint);
|
||||
assertEquals(HttpInvokerTargetAdapter.class, endpoint.getHandler().getClass());
|
||||
assertEquals("testChannel", endpoint.getSubscription().getChannelName());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans:beans xmlns="http://www.springframework.org/schema/integration"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:beans="http://www.springframework.org/schema/beans"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
|
||||
http://www.springframework.org/schema/integration
|
||||
http://www.springframework.org/schema/integration/spring-integration-1.0.xsd">
|
||||
|
||||
<message-bus/>
|
||||
|
||||
<channel id="testChannel"/>
|
||||
|
||||
<httpinvoker-source id="adapterWithDefaults" request-channel="testChannel"/>
|
||||
|
||||
<httpinvoker-source name="/adapter/with/name" request-channel="testChannel"/>
|
||||
|
||||
<httpinvoker-source id="adapterWithCustomProperties"
|
||||
request-channel="testChannel" request-timeout="123"
|
||||
expect-reply="false" reply-timeout="456"/>
|
||||
|
||||
</beans:beans>
|
||||
@@ -0,0 +1,16 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans:beans xmlns="http://www.springframework.org/schema/integration"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:beans="http://www.springframework.org/schema/beans"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
|
||||
http://www.springframework.org/schema/integration
|
||||
http://www.springframework.org/schema/integration/spring-integration-1.0.xsd">
|
||||
|
||||
<message-bus/>
|
||||
|
||||
<channel id="testChannel"/>
|
||||
|
||||
<httpinvoker-target id="adapter" channel="testChannel" url="http://localhost:8080/test"/>
|
||||
|
||||
</beans:beans>
|
||||
@@ -0,0 +1,229 @@
|
||||
/*
|
||||
* 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.adapter.jms;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertSame;
|
||||
|
||||
import javax.jms.Destination;
|
||||
import javax.jms.JMSException;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.integration.message.StringMessage;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public class DefaultJmsHeaderMapperTests {
|
||||
|
||||
@Test
|
||||
public void testJmsReplyToMappedFromHeader() throws JMSException {
|
||||
StringMessage message = new StringMessage("test");
|
||||
Destination replyTo = new Destination() {};
|
||||
message.getHeader().setAttribute(JmsAttributeKeys.REPLY_TO, replyTo);
|
||||
DefaultJmsHeaderMapper mapper = new DefaultJmsHeaderMapper();
|
||||
javax.jms.Message jmsMessage = new StubTextMessage();
|
||||
mapper.mapFromMessageHeader(message.getHeader(), jmsMessage);
|
||||
assertNotNull(jmsMessage.getJMSReplyTo());
|
||||
assertSame(replyTo, jmsMessage.getJMSReplyTo());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testJmsReplyToIgnoredIfIncorrectType() throws JMSException {
|
||||
StringMessage message = new StringMessage("test");
|
||||
message.getHeader().setAttribute(JmsAttributeKeys.REPLY_TO, "not-a-destination");
|
||||
DefaultJmsHeaderMapper mapper = new DefaultJmsHeaderMapper();
|
||||
javax.jms.Message jmsMessage = new StubTextMessage();
|
||||
mapper.mapFromMessageHeader(message.getHeader(), jmsMessage);
|
||||
assertNull(jmsMessage.getJMSReplyTo());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testJmsCorrelationIdMappedFromHeader() throws JMSException {
|
||||
StringMessage message = new StringMessage("test");
|
||||
String jmsCorrelationId = "ABC-123";
|
||||
message.getHeader().setAttribute(JmsAttributeKeys.CORRELATION_ID, jmsCorrelationId);
|
||||
DefaultJmsHeaderMapper mapper = new DefaultJmsHeaderMapper();
|
||||
javax.jms.Message jmsMessage = new StubTextMessage();
|
||||
mapper.mapFromMessageHeader(message.getHeader(), jmsMessage);
|
||||
assertNotNull(jmsMessage.getJMSCorrelationID());
|
||||
assertEquals(jmsCorrelationId, jmsMessage.getJMSCorrelationID());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testJmsCorrelationIdIgnoredIfIncorrectType() throws JMSException {
|
||||
StringMessage message = new StringMessage("test");
|
||||
message.getHeader().setAttribute(JmsAttributeKeys.CORRELATION_ID, new Integer(123));
|
||||
DefaultJmsHeaderMapper mapper = new DefaultJmsHeaderMapper();
|
||||
javax.jms.Message jmsMessage = new StubTextMessage();
|
||||
mapper.mapFromMessageHeader(message.getHeader(), jmsMessage);
|
||||
assertNull(jmsMessage.getJMSCorrelationID());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testJmsTypeMappedFromHeader() throws JMSException {
|
||||
StringMessage message = new StringMessage("test");
|
||||
String jmsType = "testing";
|
||||
message.getHeader().setAttribute(JmsAttributeKeys.TYPE, jmsType);
|
||||
DefaultJmsHeaderMapper mapper = new DefaultJmsHeaderMapper();
|
||||
javax.jms.Message jmsMessage = new StubTextMessage();
|
||||
mapper.mapFromMessageHeader(message.getHeader(), jmsMessage);
|
||||
assertNotNull(jmsMessage.getJMSType());
|
||||
assertEquals(jmsType, jmsMessage.getJMSType());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testJmsTypeIgnoredIfIncorrectType() throws JMSException {
|
||||
StringMessage message = new StringMessage("test");
|
||||
message.getHeader().setAttribute(JmsAttributeKeys.TYPE, new Integer(123));
|
||||
DefaultJmsHeaderMapper mapper = new DefaultJmsHeaderMapper();
|
||||
javax.jms.Message jmsMessage = new StubTextMessage();
|
||||
mapper.mapFromMessageHeader(message.getHeader(), jmsMessage);
|
||||
assertNull(jmsMessage.getJMSType());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUserDefinedPropertyMappedFromHeader() throws JMSException {
|
||||
StringMessage message = new StringMessage("test");
|
||||
message.getHeader().setAttribute(JmsAttributeKeys.USER_DEFINED_ATTRIBUTE_PREFIX + "foo", new Integer(123));
|
||||
DefaultJmsHeaderMapper mapper = new DefaultJmsHeaderMapper();
|
||||
javax.jms.Message jmsMessage = new StubTextMessage();
|
||||
mapper.mapFromMessageHeader(message.getHeader(), jmsMessage);
|
||||
Object value = jmsMessage.getObjectProperty("foo");
|
||||
assertNotNull(value);
|
||||
assertEquals(Integer.class, value.getClass());
|
||||
assertEquals(123, ((Integer) value).intValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUserDefinedPropertyWithUnsupportedType() throws JMSException {
|
||||
StringMessage message = new StringMessage("test");
|
||||
Destination destination = new Destination() {};
|
||||
message.getHeader().setAttribute(JmsAttributeKeys.USER_DEFINED_ATTRIBUTE_PREFIX + "destination", destination);
|
||||
DefaultJmsHeaderMapper mapper = new DefaultJmsHeaderMapper();
|
||||
javax.jms.Message jmsMessage = new StubTextMessage();
|
||||
mapper.mapFromMessageHeader(message.getHeader(), jmsMessage);
|
||||
Object value = jmsMessage.getObjectProperty("foo");
|
||||
assertNull(value);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testJmsReplyToMappedToHeader() throws JMSException {
|
||||
StringMessage message = new StringMessage("test");
|
||||
Destination replyTo = new Destination() {};
|
||||
javax.jms.Message jmsMessage = new StubTextMessage();
|
||||
jmsMessage.setJMSReplyTo(replyTo);
|
||||
DefaultJmsHeaderMapper mapper = new DefaultJmsHeaderMapper();
|
||||
mapper.mapToMessageHeader(jmsMessage, message.getHeader());
|
||||
Object attrib = message.getHeader().getAttribute(JmsAttributeKeys.REPLY_TO);
|
||||
assertNotNull(attrib);
|
||||
assertSame(replyTo, attrib);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testJmsCorrelationIdMappedToHeader() throws JMSException {
|
||||
StringMessage message = new StringMessage("test");
|
||||
String correlationId = "ABC-123";
|
||||
javax.jms.Message jmsMessage = new StubTextMessage();
|
||||
jmsMessage.setJMSCorrelationID(correlationId);
|
||||
DefaultJmsHeaderMapper mapper = new DefaultJmsHeaderMapper();
|
||||
mapper.mapToMessageHeader(jmsMessage, message.getHeader());
|
||||
Object attrib = message.getHeader().getAttribute(JmsAttributeKeys.CORRELATION_ID);
|
||||
assertNotNull(attrib);
|
||||
assertSame(correlationId, attrib);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testJmsTypeMappedToHeader() throws JMSException {
|
||||
StringMessage message = new StringMessage("test");
|
||||
String type = "testing";
|
||||
javax.jms.Message jmsMessage = new StubTextMessage();
|
||||
jmsMessage.setJMSType(type);
|
||||
DefaultJmsHeaderMapper mapper = new DefaultJmsHeaderMapper();
|
||||
mapper.mapToMessageHeader(jmsMessage, message.getHeader());
|
||||
Object attrib = message.getHeader().getAttribute(JmsAttributeKeys.TYPE);
|
||||
assertNotNull(attrib);
|
||||
assertSame(type, attrib);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUserDefinedPropertyMappedToHeader() throws JMSException {
|
||||
StringMessage message = new StringMessage("test");
|
||||
javax.jms.Message jmsMessage = new StubTextMessage();
|
||||
jmsMessage.setIntProperty("foo", 123);
|
||||
DefaultJmsHeaderMapper mapper = new DefaultJmsHeaderMapper();
|
||||
mapper.mapToMessageHeader(jmsMessage, message.getHeader());
|
||||
Object attrib = message.getHeader().getAttribute(JmsAttributeKeys.USER_DEFINED_ATTRIBUTE_PREFIX + "foo");
|
||||
assertNotNull(attrib);
|
||||
assertEquals(Integer.class, attrib.getClass());
|
||||
assertEquals(123, ((Integer) attrib).intValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testJMSExceptionIsNotFatal() throws JMSException {
|
||||
StringMessage message = new StringMessage("test");
|
||||
message.getHeader().setAttribute(JmsAttributeKeys.USER_DEFINED_ATTRIBUTE_PREFIX + "foo", new Integer(123));
|
||||
message.getHeader().setAttribute(JmsAttributeKeys.USER_DEFINED_ATTRIBUTE_PREFIX + "bad", new Integer(456));
|
||||
message.getHeader().setAttribute(JmsAttributeKeys.USER_DEFINED_ATTRIBUTE_PREFIX + "bar", new Integer(789));
|
||||
DefaultJmsHeaderMapper mapper = new DefaultJmsHeaderMapper();
|
||||
javax.jms.Message jmsMessage = new StubTextMessage() {
|
||||
@Override
|
||||
public void setObjectProperty(String name, Object value) throws JMSException {
|
||||
if (name.equals("bad")) {
|
||||
throw new JMSException("illegal property");
|
||||
}
|
||||
super.setObjectProperty(name, value);
|
||||
}
|
||||
};
|
||||
mapper.mapFromMessageHeader(message.getHeader(), jmsMessage);
|
||||
Object foo = jmsMessage.getObjectProperty("foo");
|
||||
assertNotNull(foo);
|
||||
Object bar = jmsMessage.getObjectProperty("bar");
|
||||
assertNotNull(bar);
|
||||
Object bad = jmsMessage.getObjectProperty("bad");
|
||||
assertNull(bad);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIllegalArgumentExceptionIsNotFatal() throws JMSException {
|
||||
StringMessage message = new StringMessage("test");
|
||||
message.getHeader().setAttribute(JmsAttributeKeys.USER_DEFINED_ATTRIBUTE_PREFIX + "foo", new Integer(123));
|
||||
message.getHeader().setAttribute(JmsAttributeKeys.USER_DEFINED_ATTRIBUTE_PREFIX + "bad", new Integer(456));
|
||||
message.getHeader().setAttribute(JmsAttributeKeys.USER_DEFINED_ATTRIBUTE_PREFIX + "bar", new Integer(789));
|
||||
DefaultJmsHeaderMapper mapper = new DefaultJmsHeaderMapper();
|
||||
javax.jms.Message jmsMessage = new StubTextMessage() {
|
||||
@Override
|
||||
public void setObjectProperty(String name, Object value) throws JMSException {
|
||||
if (name.equals("bad")) {
|
||||
throw new IllegalArgumentException("illegal property");
|
||||
}
|
||||
super.setObjectProperty(name, value);
|
||||
}
|
||||
};
|
||||
mapper.mapFromMessageHeader(message.getHeader(), jmsMessage);
|
||||
Object foo = jmsMessage.getObjectProperty("foo");
|
||||
assertNotNull(foo);
|
||||
Object bar = jmsMessage.getObjectProperty("bar");
|
||||
assertNotNull(bar);
|
||||
Object bad = jmsMessage.getObjectProperty("bad");
|
||||
assertNull(bad);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
/*
|
||||
* Copyright 2002-2007 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.adapter.jms;
|
||||
|
||||
import javax.jms.Connection;
|
||||
import javax.jms.ConnectionConsumer;
|
||||
import javax.jms.ConnectionMetaData;
|
||||
import javax.jms.Destination;
|
||||
import javax.jms.ExceptionListener;
|
||||
import javax.jms.JMSException;
|
||||
import javax.jms.ServerSessionPool;
|
||||
import javax.jms.Session;
|
||||
import javax.jms.Topic;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public class StubConnection implements Connection {
|
||||
|
||||
private String messageText;
|
||||
|
||||
|
||||
public StubConnection(String messageText) {
|
||||
this.messageText = messageText;
|
||||
}
|
||||
|
||||
|
||||
public void close() throws JMSException {
|
||||
}
|
||||
|
||||
public ConnectionConsumer createConnectionConsumer(Destination destination, String messageSelector,
|
||||
ServerSessionPool sessionPool, int maxMessages) throws JMSException {
|
||||
return null;
|
||||
}
|
||||
|
||||
public ConnectionConsumer createDurableConnectionConsumer(Topic topic, String subscriptionName,
|
||||
String messageSelector, ServerSessionPool sessionPool, int maxMessages) throws JMSException {
|
||||
return null;
|
||||
}
|
||||
|
||||
public Session createSession(boolean transacted, int acknowledgeMode) throws JMSException {
|
||||
return new StubSession(this.messageText);
|
||||
}
|
||||
|
||||
public String getClientID() throws JMSException {
|
||||
return null;
|
||||
}
|
||||
|
||||
public ExceptionListener getExceptionListener() throws JMSException {
|
||||
return null;
|
||||
}
|
||||
|
||||
public ConnectionMetaData getMetaData() throws JMSException {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void setClientID(String clientID) throws JMSException {
|
||||
}
|
||||
|
||||
public void setExceptionListener(ExceptionListener listener) throws JMSException {
|
||||
}
|
||||
|
||||
public void start() throws JMSException {
|
||||
}
|
||||
|
||||
public void stop() throws JMSException {
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
* Copyright 2002-2007 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.adapter.jms;
|
||||
|
||||
import javax.jms.JMSException;
|
||||
import javax.jms.Message;
|
||||
import javax.jms.MessageConsumer;
|
||||
import javax.jms.MessageListener;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public class StubConsumer implements MessageConsumer {
|
||||
|
||||
private String messageText;
|
||||
|
||||
|
||||
public StubConsumer(String messageText) {
|
||||
this.messageText = messageText;
|
||||
}
|
||||
|
||||
|
||||
public void close() throws JMSException {
|
||||
}
|
||||
|
||||
public MessageListener getMessageListener() throws JMSException {
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getMessageSelector() throws JMSException {
|
||||
return null;
|
||||
}
|
||||
|
||||
public Message receive() throws JMSException {
|
||||
StubTextMessage message = new StubTextMessage();
|
||||
message.setText(this.messageText);
|
||||
return message;
|
||||
}
|
||||
|
||||
public Message receive(long timeout) throws JMSException {
|
||||
return this.receive();
|
||||
}
|
||||
|
||||
public Message receiveNoWait() throws JMSException {
|
||||
return this.receive();
|
||||
}
|
||||
|
||||
public void setMessageListener(MessageListener listener) throws JMSException {
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* Copyright 2002-2007 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.adapter.jms;
|
||||
|
||||
import javax.jms.Destination;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public class StubDestination implements Destination {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,168 @@
|
||||
/*
|
||||
* Copyright 2002-2007 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.adapter.jms;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import javax.jms.BytesMessage;
|
||||
import javax.jms.Destination;
|
||||
import javax.jms.JMSException;
|
||||
import javax.jms.MapMessage;
|
||||
import javax.jms.Message;
|
||||
import javax.jms.MessageConsumer;
|
||||
import javax.jms.MessageListener;
|
||||
import javax.jms.MessageProducer;
|
||||
import javax.jms.ObjectMessage;
|
||||
import javax.jms.Queue;
|
||||
import javax.jms.QueueBrowser;
|
||||
import javax.jms.Session;
|
||||
import javax.jms.StreamMessage;
|
||||
import javax.jms.TemporaryQueue;
|
||||
import javax.jms.TemporaryTopic;
|
||||
import javax.jms.TextMessage;
|
||||
import javax.jms.Topic;
|
||||
import javax.jms.TopicSubscriber;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public class StubSession implements Session {
|
||||
|
||||
private String messageText;
|
||||
|
||||
|
||||
public StubSession(String messageText) {
|
||||
this.messageText = messageText;
|
||||
}
|
||||
|
||||
|
||||
public void close() throws JMSException {
|
||||
}
|
||||
|
||||
public void commit() throws JMSException {
|
||||
}
|
||||
|
||||
public QueueBrowser createBrowser(Queue queue) throws JMSException {
|
||||
return null;
|
||||
}
|
||||
|
||||
public QueueBrowser createBrowser(Queue queue, String messageSelector) throws JMSException {
|
||||
return null;
|
||||
}
|
||||
|
||||
public BytesMessage createBytesMessage() throws JMSException {
|
||||
return null;
|
||||
}
|
||||
|
||||
public MessageConsumer createConsumer(Destination destination) throws JMSException {
|
||||
return new StubConsumer(this.messageText);
|
||||
}
|
||||
|
||||
public MessageConsumer createConsumer(Destination destination, String messageSelector) throws JMSException {
|
||||
return new StubConsumer(this.messageText);
|
||||
}
|
||||
|
||||
public MessageConsumer createConsumer(Destination destination, String messageSelector, boolean NoLocal)
|
||||
throws JMSException {
|
||||
return new StubConsumer(this.messageText);
|
||||
}
|
||||
|
||||
public TopicSubscriber createDurableSubscriber(Topic topic, String name) throws JMSException {
|
||||
return null;
|
||||
}
|
||||
|
||||
public TopicSubscriber createDurableSubscriber(Topic topic, String name, String messageSelector, boolean noLocal)
|
||||
throws JMSException {
|
||||
return null;
|
||||
}
|
||||
|
||||
public MapMessage createMapMessage() throws JMSException {
|
||||
return null;
|
||||
}
|
||||
|
||||
public Message createMessage() throws JMSException {
|
||||
return null;
|
||||
}
|
||||
|
||||
public ObjectMessage createObjectMessage() throws JMSException {
|
||||
return null;
|
||||
}
|
||||
|
||||
public ObjectMessage createObjectMessage(Serializable object) throws JMSException {
|
||||
return null;
|
||||
}
|
||||
|
||||
public MessageProducer createProducer(Destination destination) throws JMSException {
|
||||
return null;
|
||||
}
|
||||
|
||||
public Queue createQueue(String queueName) throws JMSException {
|
||||
return null;
|
||||
}
|
||||
|
||||
public StreamMessage createStreamMessage() throws JMSException {
|
||||
return null;
|
||||
}
|
||||
|
||||
public TemporaryQueue createTemporaryQueue() throws JMSException {
|
||||
return null;
|
||||
}
|
||||
|
||||
public TemporaryTopic createTemporaryTopic() throws JMSException {
|
||||
return null;
|
||||
}
|
||||
|
||||
public TextMessage createTextMessage() throws JMSException {
|
||||
return null;
|
||||
}
|
||||
|
||||
public TextMessage createTextMessage(String text) throws JMSException {
|
||||
return null;
|
||||
}
|
||||
|
||||
public Topic createTopic(String topicName) throws JMSException {
|
||||
return null;
|
||||
}
|
||||
|
||||
public int getAcknowledgeMode() throws JMSException {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public MessageListener getMessageListener() throws JMSException {
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean getTransacted() throws JMSException {
|
||||
return false;
|
||||
}
|
||||
|
||||
public void recover() throws JMSException {
|
||||
}
|
||||
|
||||
public void rollback() throws JMSException {
|
||||
}
|
||||
|
||||
public void run() {
|
||||
}
|
||||
|
||||
public void setMessageListener(MessageListener listener) throws JMSException {
|
||||
}
|
||||
|
||||
public void unsubscribe(String name) throws JMSException {
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,216 @@
|
||||
/*
|
||||
* 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.adapter.jms;
|
||||
|
||||
import java.util.Enumeration;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import javax.jms.Destination;
|
||||
import javax.jms.JMSException;
|
||||
import javax.jms.TextMessage;
|
||||
|
||||
public class StubTextMessage implements TextMessage {
|
||||
|
||||
private String text;
|
||||
|
||||
private Destination replyTo;
|
||||
|
||||
private String correlationID;
|
||||
|
||||
private String type;
|
||||
|
||||
private ConcurrentHashMap<String, Object> properties = new ConcurrentHashMap<String, Object>();
|
||||
|
||||
|
||||
public String getText() throws JMSException {
|
||||
return this.text;
|
||||
}
|
||||
|
||||
public void setText(String text) throws JMSException {
|
||||
this.text = text;
|
||||
}
|
||||
|
||||
public void acknowledge() throws JMSException {
|
||||
}
|
||||
|
||||
public void clearBody() throws JMSException {
|
||||
}
|
||||
|
||||
public void clearProperties() throws JMSException {
|
||||
}
|
||||
|
||||
public boolean getBooleanProperty(String name) throws JMSException {
|
||||
return false;
|
||||
}
|
||||
|
||||
public byte getByteProperty(String name) throws JMSException {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public double getDoubleProperty(String name) throws JMSException {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public float getFloatProperty(String name) throws JMSException {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public int getIntProperty(String name) throws JMSException {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public String getJMSCorrelationID() throws JMSException {
|
||||
return this.correlationID;
|
||||
}
|
||||
|
||||
public byte[] getJMSCorrelationIDAsBytes() throws JMSException {
|
||||
return null;
|
||||
}
|
||||
|
||||
public int getJMSDeliveryMode() throws JMSException {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public Destination getJMSDestination() throws JMSException {
|
||||
return null;
|
||||
}
|
||||
|
||||
public long getJMSExpiration() throws JMSException {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public String getJMSMessageID() throws JMSException {
|
||||
return null;
|
||||
}
|
||||
|
||||
public int getJMSPriority() throws JMSException {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public boolean getJMSRedelivered() throws JMSException {
|
||||
return false;
|
||||
}
|
||||
|
||||
public Destination getJMSReplyTo() throws JMSException {
|
||||
return this.replyTo;
|
||||
}
|
||||
|
||||
public long getJMSTimestamp() throws JMSException {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public String getJMSType() throws JMSException {
|
||||
return this.type;
|
||||
}
|
||||
|
||||
public long getLongProperty(String name) throws JMSException {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public Object getObjectProperty(String name) throws JMSException {
|
||||
return this.properties.get(name);
|
||||
}
|
||||
|
||||
public Enumeration getPropertyNames() throws JMSException {
|
||||
return this.properties.keys();
|
||||
}
|
||||
|
||||
public short getShortProperty(String name) throws JMSException {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public String getStringProperty(String name) throws JMSException {
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean propertyExists(String name) throws JMSException {
|
||||
return this.properties.containsKey(name);
|
||||
}
|
||||
|
||||
public void setBooleanProperty(String name, boolean value) throws JMSException {
|
||||
this.properties.put(name, value);
|
||||
}
|
||||
|
||||
public void setByteProperty(String name, byte value) throws JMSException {
|
||||
this.properties.put(name, value);
|
||||
}
|
||||
|
||||
public void setDoubleProperty(String name, double value) throws JMSException {
|
||||
this.properties.put(name, value);
|
||||
}
|
||||
|
||||
public void setFloatProperty(String name, float value) throws JMSException {
|
||||
this.properties.put(name, value);
|
||||
}
|
||||
|
||||
public void setIntProperty(String name, int value) throws JMSException {
|
||||
this.properties.put(name, value);
|
||||
}
|
||||
|
||||
public void setJMSCorrelationID(String correlationID) throws JMSException {
|
||||
this.correlationID = correlationID;
|
||||
}
|
||||
|
||||
public void setJMSCorrelationIDAsBytes(byte[] correlationID) throws JMSException {
|
||||
}
|
||||
|
||||
public void setJMSDeliveryMode(int deliveryMode) throws JMSException {
|
||||
}
|
||||
|
||||
public void setJMSDestination(Destination destination) throws JMSException {
|
||||
}
|
||||
|
||||
public void setJMSExpiration(long expiration) throws JMSException {
|
||||
}
|
||||
|
||||
public void setJMSMessageID(String id) throws JMSException {
|
||||
}
|
||||
|
||||
public void setJMSPriority(int priority) throws JMSException {
|
||||
}
|
||||
|
||||
public void setJMSRedelivered(boolean redelivered) throws JMSException {
|
||||
}
|
||||
|
||||
public void setJMSReplyTo(Destination replyTo) throws JMSException {
|
||||
this.replyTo = replyTo;
|
||||
}
|
||||
|
||||
public void setJMSTimestamp(long timestamp) throws JMSException {
|
||||
}
|
||||
|
||||
public void setJMSType(String type) throws JMSException {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public void setLongProperty(String name, long value) throws JMSException {
|
||||
this.properties.put(name, value);
|
||||
}
|
||||
|
||||
public void setObjectProperty(String name, Object value) throws JMSException {
|
||||
this.properties.put(name, value);
|
||||
}
|
||||
|
||||
public void setShortProperty(String name, short value) throws JMSException {
|
||||
this.properties.put(name, value);
|
||||
}
|
||||
|
||||
public void setStringProperty(String name, String value) throws JMSException {
|
||||
this.properties.put(name, value);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,143 @@
|
||||
/*
|
||||
* 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.adapter.jms.config;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.beans.DirectFieldAccessor;
|
||||
import org.springframework.beans.factory.BeanCreationException;
|
||||
import org.springframework.beans.factory.BeanDefinitionStoreException;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.integration.adapter.jms.JmsGateway;
|
||||
import org.springframework.integration.channel.MessageChannel;
|
||||
import org.springframework.integration.channel.QueueChannel;
|
||||
import org.springframework.integration.message.Message;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public class JmsGatewayParserTests {
|
||||
|
||||
@Test
|
||||
public void testGatewayWithConnectionFactoryAndDestination() {
|
||||
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
|
||||
"jmsGatewayWithConnectionFactoryAndDestination.xml", this.getClass());
|
||||
MessageChannel channel = new QueueChannel(1);
|
||||
JmsGateway gateway = (JmsGateway) context.getBean("jmsGateway");
|
||||
gateway.setRequestChannel(channel);
|
||||
context.start();
|
||||
Message<?> message = channel.receive(3000);
|
||||
assertNotNull("message should not be null", message);
|
||||
assertEquals("message-driven-test", message.getPayload());
|
||||
context.stop();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGatewayWithConnectionFactoryAndDestinationName() {
|
||||
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
|
||||
"jmsGatewayWithConnectionFactoryAndDestinationName.xml", this.getClass());
|
||||
MessageChannel channel = new QueueChannel(1);
|
||||
JmsGateway gateway = (JmsGateway) context.getBean("jmsGateway");
|
||||
gateway.setRequestChannel(channel);
|
||||
context.start();
|
||||
Message<?> message = channel.receive(3000);
|
||||
assertNotNull("message should not be null", message);
|
||||
assertEquals("message-driven-test", message.getPayload());
|
||||
context.stop();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGatewayWithMessageConverter() {
|
||||
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
|
||||
"jmsGatewayWithMessageConverter.xml", this.getClass());
|
||||
MessageChannel channel = new QueueChannel(1);
|
||||
JmsGateway gateway = (JmsGateway) context.getBean("jmsGateway");
|
||||
gateway.setRequestChannel(channel);
|
||||
context.start();
|
||||
Message<?> message = channel.receive(3000);
|
||||
assertNotNull("message should not be null", message);
|
||||
assertEquals("converted-test-message", message.getPayload());
|
||||
context.stop();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGatewayWithDefaultExpectReply() {
|
||||
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
|
||||
"jmsGatewaysWithExpectReplyAttributes.xml", this.getClass());
|
||||
JmsGateway gateway = (JmsGateway) context.getBean("defaultGateway");
|
||||
DirectFieldAccessor accessor = new DirectFieldAccessor(gateway);
|
||||
assertEquals(Boolean.FALSE, accessor.getPropertyValue("expectReply"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGatewayExpectingReply() {
|
||||
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
|
||||
"jmsGatewaysWithExpectReplyAttributes.xml", this.getClass());
|
||||
JmsGateway gateway = (JmsGateway) context.getBean("gatewayExpectingReply");
|
||||
DirectFieldAccessor accessor = new DirectFieldAccessor(gateway);
|
||||
assertEquals(Boolean.TRUE, accessor.getPropertyValue("expectReply"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGatewayNotExpectingReply() {
|
||||
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
|
||||
"jmsGatewaysWithExpectReplyAttributes.xml", this.getClass());
|
||||
JmsGateway gateway = (JmsGateway) context.getBean("gatewayNotExpectingReply");
|
||||
DirectFieldAccessor accessor = new DirectFieldAccessor(gateway);
|
||||
assertEquals(Boolean.FALSE, accessor.getPropertyValue("expectReply"));
|
||||
}
|
||||
|
||||
@Test(expected=BeanDefinitionStoreException.class)
|
||||
public void testGatewayWithConnectionFactoryOnly() {
|
||||
try {
|
||||
new ClassPathXmlApplicationContext("jmsGatewayWithConnectionFactoryOnly.xml", this.getClass());
|
||||
}
|
||||
catch (RuntimeException e) {
|
||||
assertEquals(BeanCreationException.class, e.getCause().getClass());
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
@Test(expected=BeanDefinitionStoreException.class)
|
||||
public void testGatewayWithEmptyConnectionFactory() {
|
||||
try {
|
||||
new ClassPathXmlApplicationContext("jmsGatewayWithEmptyConnectionFactory.xml", this.getClass());
|
||||
}
|
||||
catch (RuntimeException e) {
|
||||
assertEquals(BeanCreationException.class, e.getCause().getClass());
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGatewayWithDefaultConnectionFactory() {
|
||||
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
|
||||
"jmsGatewayWithDefaultConnectionFactory.xml", this.getClass());
|
||||
MessageChannel channel = new QueueChannel(1);
|
||||
JmsGateway gateway = (JmsGateway) context.getBean("jmsGateway");
|
||||
gateway.setRequestChannel(channel);
|
||||
context.start();
|
||||
Message<?> message = channel.receive(3000);
|
||||
assertNotNull("message should not be null", message);
|
||||
assertEquals("message-driven-test", message.getPayload());
|
||||
context.stop();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,141 @@
|
||||
/*
|
||||
* 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.adapter.jms.config;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.beans.factory.BeanCreationException;
|
||||
import org.springframework.beans.factory.BeanDefinitionStoreException;
|
||||
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.integration.adapter.jms.JmsSource;
|
||||
import org.springframework.integration.channel.MessageChannel;
|
||||
import org.springframework.integration.message.Message;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public class JmsSourceParserTests {
|
||||
|
||||
@Test
|
||||
public void testSourceWithJmsTemplate() {
|
||||
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
|
||||
"jmsSourceWithJmsTemplate.xml", this.getClass());
|
||||
JmsSource source = (JmsSource) context.getBean("jmsSource");
|
||||
Message<?> message = source.receive();
|
||||
assertNotNull("message should not be null", message);
|
||||
assertEquals("polling-test", message.getPayload());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSourceWithConnectionFactoryAndDestination() {
|
||||
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
|
||||
"jmsSourceWithConnectionFactoryAndDestination.xml", this.getClass());
|
||||
JmsSource source = (JmsSource) context.getBean("jmsSource");
|
||||
Message<?> message = source.receive();
|
||||
assertNotNull("message should not be null", message);
|
||||
assertEquals("polling-test", message.getPayload());
|
||||
context.stop();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSourceWithConnectionFactoryAndDestinationName() {
|
||||
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
|
||||
"jmsSourceWithConnectionFactoryAndDestinationName.xml", this.getClass());
|
||||
JmsSource source = (JmsSource) context.getBean("jmsSource");
|
||||
Message<?> message = source.receive();
|
||||
assertNotNull("message should not be null", message);
|
||||
assertEquals("polling-test", message.getPayload());
|
||||
context.stop();
|
||||
}
|
||||
|
||||
@Test(expected=BeanDefinitionStoreException.class)
|
||||
public void testSourceWithConnectionFactoryOnly() {
|
||||
try {
|
||||
new ClassPathXmlApplicationContext("jmsSourceWithConnectionFactoryOnly.xml", this.getClass());
|
||||
}
|
||||
catch (RuntimeException e) {
|
||||
assertEquals(BeanCreationException.class, e.getCause().getClass());
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
@Test(expected=BeanCreationException.class)
|
||||
public void testSourceWithDestinationOnly() {
|
||||
try {
|
||||
new ClassPathXmlApplicationContext("jmsSourceWithDestinationOnly.xml", this.getClass());
|
||||
}
|
||||
catch (RuntimeException e) {
|
||||
assertEquals(NoSuchBeanDefinitionException.class, e.getCause().getClass());
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSourceWithDestinationAndDefaultConnectionFactory() {
|
||||
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
|
||||
"jmsSourceWithDestinationAndDefaultConnectionFactory.xml", this.getClass());
|
||||
JmsSource source = (JmsSource) context.getBean("jmsSource");
|
||||
Message<?> message = source.receive();
|
||||
assertNotNull("message should not be null", message);
|
||||
assertEquals("polling-test", message.getPayload());
|
||||
context.stop();
|
||||
}
|
||||
|
||||
@Test(expected=BeanCreationException.class)
|
||||
public void testSourceWithDestinationNameOnly() {
|
||||
new ClassPathXmlApplicationContext("jmsSourceWithDestinationNameOnly.xml", this.getClass());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSourceWithDestinationNameAndDefaultConnectionFactory() {
|
||||
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
|
||||
"jmsSourceWithDestinationNameAndDefaultConnectionFactory.xml", this.getClass());
|
||||
JmsSource source = (JmsSource) context.getBean("jmsSource");
|
||||
Message<?> message = source.receive();
|
||||
assertNotNull("message should not be null", message);
|
||||
assertEquals("polling-test", message.getPayload());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSourceWithHeaderMapper() {
|
||||
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
|
||||
"jmsSourceWithHeaderMapper.xml", this.getClass());
|
||||
JmsSource source = (JmsSource) context.getBean("jmsSource");
|
||||
Message<?> message = source.receive();
|
||||
assertNotNull("message should not be null", message);
|
||||
assertEquals("polling-test", message.getPayload());
|
||||
assertEquals("foo", message.getHeader().getProperty("testProperty"));
|
||||
assertEquals(new Integer(123), message.getHeader().getAttribute("testAttribute"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSourceEndpoint() {
|
||||
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
|
||||
"jmsSourceEndpoint.xml", this.getClass());
|
||||
context.start();
|
||||
MessageChannel channel = (MessageChannel) context.getBean("channel");
|
||||
Message<?> message = channel.receive(3000);
|
||||
assertNotNull("message should not be null", message);
|
||||
assertEquals("polling-test", message.getPayload());
|
||||
context.stop();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
/*
|
||||
* 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.adapter.jms.config;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.beans.DirectFieldAccessor;
|
||||
import org.springframework.beans.factory.BeanCreationException;
|
||||
import org.springframework.beans.factory.BeanDefinitionStoreException;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.integration.adapter.MessageHeaderMapper;
|
||||
import org.springframework.integration.adapter.jms.JmsTarget;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public class JmsTargetParserTests {
|
||||
|
||||
@Test
|
||||
public void testTargetWithConnectionFactoryAndDestination() {
|
||||
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
|
||||
"targetWithConnectionFactoryAndDestination.xml", this.getClass());
|
||||
JmsTarget target = (JmsTarget) context.getBean("target");
|
||||
DirectFieldAccessor accessor = new DirectFieldAccessor(target);
|
||||
assertNotNull(accessor.getPropertyValue("jmsTemplate"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTargetWithConnectionFactoryAndDestinationName() {
|
||||
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
|
||||
"targetWithConnectionFactoryAndDestinationName.xml", this.getClass());
|
||||
JmsTarget target = (JmsTarget) context.getBean("target");
|
||||
DirectFieldAccessor accessor = new DirectFieldAccessor(target);
|
||||
assertNotNull(accessor.getPropertyValue("jmsTemplate"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTargetWithDefaultConnectionFactory() {
|
||||
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
|
||||
"targetWithDefaultConnectionFactory.xml", this.getClass());
|
||||
JmsTarget target = (JmsTarget) context.getBean("target");
|
||||
DirectFieldAccessor accessor = new DirectFieldAccessor(target);
|
||||
assertNotNull(accessor.getPropertyValue("jmsTemplate"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void testTargetWithHeaderMapper() {
|
||||
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
|
||||
"targetWithHeaderMapper.xml", this.getClass());
|
||||
JmsTarget target = (JmsTarget) context.getBean("target");
|
||||
DirectFieldAccessor accessor = new DirectFieldAccessor(target);
|
||||
MessageHeaderMapper headerMapper = (MessageHeaderMapper)
|
||||
accessor.getPropertyValue("headerMapper");
|
||||
assertNotNull(headerMapper);
|
||||
assertEquals(TestMessageHeaderMapper.class, headerMapper.getClass());
|
||||
}
|
||||
|
||||
@Test(expected=BeanDefinitionStoreException.class)
|
||||
public void testTargetWithEmptyConnectionFactory() {
|
||||
try {
|
||||
new ClassPathXmlApplicationContext("targetWithEmptyConnectionFactory.xml", this.getClass());
|
||||
}
|
||||
catch (RuntimeException e) {
|
||||
assertEquals(BeanCreationException.class, e.getCause().getClass());
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* 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.adapter.jms.config;
|
||||
|
||||
import javax.jms.JMSException;
|
||||
import javax.jms.Message;
|
||||
import javax.jms.Session;
|
||||
import javax.jms.TextMessage;
|
||||
|
||||
import org.springframework.jms.support.converter.MessageConversionException;
|
||||
import org.springframework.jms.support.converter.MessageConverter;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public class TestMessageConverter implements MessageConverter {
|
||||
|
||||
public Object fromMessage(Message message) throws JMSException, MessageConversionException {
|
||||
String original = ((TextMessage) message).getText();
|
||||
return "converted-" + original;
|
||||
}
|
||||
|
||||
public javax.jms.Message toMessage(Object object, Session session) throws JMSException, MessageConversionException {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* 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.adapter.jms.config;
|
||||
|
||||
import javax.jms.Message;
|
||||
|
||||
import org.springframework.integration.adapter.MessageHeaderMapper;
|
||||
import org.springframework.integration.message.MessageHeader;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public class TestMessageHeaderMapper implements MessageHeaderMapper<Message> {
|
||||
|
||||
public void mapFromMessageHeader(MessageHeader header, Message target) {
|
||||
}
|
||||
|
||||
public void mapToMessageHeader(Message source, MessageHeader header) {
|
||||
header.setProperty("testProperty", "foo");
|
||||
header.setAttribute("testAttribute", new Integer(123));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:si="http://www.springframework.org/schema/integration"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
|
||||
http://www.springframework.org/schema/integration
|
||||
http://www.springframework.org/schema/integration/spring-integration-1.0.xsd">
|
||||
|
||||
<si:channel id="requestChannel"/>
|
||||
|
||||
<si:jms-gateway id="jmsGateway"
|
||||
connection-factory="testConnectionFactory"
|
||||
destination="testDestination"
|
||||
request-channel="requestChannel"/>
|
||||
|
||||
<bean id="testConnectionFactory" class="org.springframework.jms.connection.SingleConnectionFactory">
|
||||
<constructor-arg>
|
||||
<bean class="org.springframework.integration.adapter.jms.StubConnection">
|
||||
<constructor-arg value="message-driven-test"/>
|
||||
</bean>
|
||||
</constructor-arg>
|
||||
</bean>
|
||||
|
||||
<bean id="testDestination" class="org.springframework.integration.adapter.jms.StubDestination"/>
|
||||
|
||||
</beans>
|
||||
@@ -0,0 +1,27 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:si="http://www.springframework.org/schema/integration"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
|
||||
http://www.springframework.org/schema/integration
|
||||
http://www.springframework.org/schema/integration/spring-integration-1.0.xsd">
|
||||
|
||||
<si:message-bus/>
|
||||
|
||||
<si:channel id="requestChannel"/>
|
||||
|
||||
<si:jms-gateway id="jmsGateway"
|
||||
connection-factory="testConnectionFactory"
|
||||
destination-name="testDestinationName"
|
||||
request-channel="requestChannel"/>
|
||||
|
||||
<bean id="testConnectionFactory" class="org.springframework.jms.connection.SingleConnectionFactory">
|
||||
<constructor-arg>
|
||||
<bean class="org.springframework.integration.adapter.jms.StubConnection">
|
||||
<constructor-arg value="message-driven-test"/>
|
||||
</bean>
|
||||
</constructor-arg>
|
||||
</bean>
|
||||
|
||||
</beans>
|
||||
@@ -0,0 +1,26 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:si="http://www.springframework.org/schema/integration"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
|
||||
http://www.springframework.org/schema/integration
|
||||
http://www.springframework.org/schema/integration/spring-integration-1.0.xsd">
|
||||
|
||||
<si:message-bus/>
|
||||
|
||||
<si:channel id="requestChannel"/>
|
||||
|
||||
<si:jms-gateway id="jmsGateway"
|
||||
connection-factory="testConnectionFactory"
|
||||
request-channel="requestChannel"/>
|
||||
|
||||
<bean id="testConnectionFactory" class="org.springframework.jms.connection.SingleConnectionFactory">
|
||||
<constructor-arg>
|
||||
<bean class="org.springframework.integration.adapter.jms.StubConnection">
|
||||
<constructor-arg value="message-driven-test"/>
|
||||
</bean>
|
||||
</constructor-arg>
|
||||
</bean>
|
||||
|
||||
</beans>
|
||||
@@ -0,0 +1,26 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:si="http://www.springframework.org/schema/integration"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
|
||||
http://www.springframework.org/schema/integration
|
||||
http://www.springframework.org/schema/integration/spring-integration-1.0.xsd">
|
||||
|
||||
<si:message-bus/>
|
||||
|
||||
<si:channel id="requestChannel"/>
|
||||
|
||||
<si:jms-gateway id="jmsGateway"
|
||||
destination-name="testDestinationName"
|
||||
request-channel="requestChannel"/>
|
||||
|
||||
<bean id="connectionFactory" class="org.springframework.jms.connection.SingleConnectionFactory">
|
||||
<constructor-arg>
|
||||
<bean class="org.springframework.integration.adapter.jms.StubConnection">
|
||||
<constructor-arg value="message-driven-test"/>
|
||||
</bean>
|
||||
</constructor-arg>
|
||||
</bean>
|
||||
|
||||
</beans>
|
||||
@@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:si="http://www.springframework.org/schema/integration"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
|
||||
http://www.springframework.org/schema/integration
|
||||
http://www.springframework.org/schema/integration/spring-integration-1.0.xsd">
|
||||
|
||||
<si:channel id="requestChannel"/>
|
||||
|
||||
<si:jms-gateway id="jmsGateway"
|
||||
connection-factory=""
|
||||
destination-name="testDestinationName"
|
||||
request-channel="requestChannel"/>
|
||||
|
||||
</beans>
|
||||
@@ -0,0 +1,32 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:si="http://www.springframework.org/schema/integration"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
|
||||
http://www.springframework.org/schema/integration
|
||||
http://www.springframework.org/schema/integration/spring-integration-1.0.xsd">
|
||||
|
||||
<si:message-bus/>
|
||||
|
||||
<si:channel id="requestChannel"/>
|
||||
|
||||
<si:jms-gateway id="jmsGateway"
|
||||
connection-factory="testConnectionFactory"
|
||||
destination="testDestination"
|
||||
message-converter="converter"
|
||||
request-channel="requestChannel"/>
|
||||
|
||||
<bean id="converter" class="org.springframework.integration.adapter.jms.config.TestMessageConverter"/>
|
||||
|
||||
<bean id="testConnectionFactory" class="org.springframework.jms.connection.SingleConnectionFactory">
|
||||
<constructor-arg>
|
||||
<bean class="org.springframework.integration.adapter.jms.StubConnection">
|
||||
<constructor-arg value="test-message"/>
|
||||
</bean>
|
||||
</constructor-arg>
|
||||
</bean>
|
||||
|
||||
<bean id="testDestination" class="org.springframework.integration.adapter.jms.StubDestination"/>
|
||||
|
||||
</beans>
|
||||
@@ -0,0 +1,38 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:si="http://www.springframework.org/schema/integration"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
|
||||
http://www.springframework.org/schema/integration
|
||||
http://www.springframework.org/schema/integration/spring-integration-1.0.xsd">
|
||||
|
||||
<si:message-bus/>
|
||||
|
||||
<si:channel id="requestChannel"/>
|
||||
|
||||
<si:jms-gateway id="defaultGateway"
|
||||
destination="testDestination"
|
||||
request-channel="requestChannel"/>
|
||||
|
||||
<si:jms-gateway id="gatewayNotExpectingReply"
|
||||
destination="testDestination"
|
||||
request-channel="requestChannel"
|
||||
expect-reply="false"/>
|
||||
|
||||
<si:jms-gateway id="gatewayExpectingReply"
|
||||
destination="testDestination"
|
||||
request-channel="requestChannel"
|
||||
expect-reply="true"/>
|
||||
|
||||
<bean id="connectionFactory" class="org.springframework.jms.connection.SingleConnectionFactory">
|
||||
<constructor-arg>
|
||||
<bean class="org.springframework.integration.adapter.jms.StubConnection">
|
||||
<constructor-arg value="test-message"/>
|
||||
</bean>
|
||||
</constructor-arg>
|
||||
</bean>
|
||||
|
||||
<bean id="testDestination" class="org.springframework.integration.adapter.jms.StubDestination"/>
|
||||
|
||||
</beans>
|
||||
@@ -0,0 +1,33 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:si="http://www.springframework.org/schema/integration"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
|
||||
http://www.springframework.org/schema/integration
|
||||
http://www.springframework.org/schema/integration/spring-integration-1.0.xsd">
|
||||
|
||||
<si:message-bus/>
|
||||
|
||||
<si:channel id="channel"/>
|
||||
|
||||
<si:source-endpoint id="endpoint" source="jmsSource" channel="channel">
|
||||
<si:schedule period="5000"/>
|
||||
</si:source-endpoint>
|
||||
|
||||
<si:jms-source id="jmsSource" jms-template="jmsTemplate"/>
|
||||
|
||||
<bean id="jmsTemplate" class="org.springframework.jms.core.JmsTemplate">
|
||||
<property name="connectionFactory" ref="connectionFactory"/>
|
||||
<property name="defaultDestinationName" value="test"/>
|
||||
</bean>
|
||||
|
||||
<bean id="connectionFactory" class="org.springframework.jms.connection.SingleConnectionFactory">
|
||||
<constructor-arg>
|
||||
<bean class="org.springframework.integration.adapter.jms.StubConnection">
|
||||
<constructor-arg value="polling-test"/>
|
||||
</bean>
|
||||
</constructor-arg>
|
||||
</bean>
|
||||
|
||||
</beans>
|
||||
@@ -0,0 +1,24 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:si="http://www.springframework.org/schema/integration"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
|
||||
http://www.springframework.org/schema/integration
|
||||
http://www.springframework.org/schema/integration/spring-integration-1.0.xsd">
|
||||
|
||||
<si:jms-source id="jmsSource"
|
||||
connection-factory="testConnectionFactory"
|
||||
destination="testDestination"/>
|
||||
|
||||
<bean id="testConnectionFactory" class="org.springframework.jms.connection.SingleConnectionFactory">
|
||||
<constructor-arg>
|
||||
<bean class="org.springframework.integration.adapter.jms.StubConnection">
|
||||
<constructor-arg value="polling-test"/>
|
||||
</bean>
|
||||
</constructor-arg>
|
||||
</bean>
|
||||
|
||||
<bean id="testDestination" class="org.springframework.integration.adapter.jms.StubDestination"/>
|
||||
|
||||
</beans>
|
||||
@@ -0,0 +1,22 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:si="http://www.springframework.org/schema/integration"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
|
||||
http://www.springframework.org/schema/integration
|
||||
http://www.springframework.org/schema/integration/spring-integration-1.0.xsd">
|
||||
|
||||
<si:jms-source id="jmsSource"
|
||||
connection-factory="testConnectionFactory"
|
||||
destination-name="testDestinationName"/>
|
||||
|
||||
<bean id="testConnectionFactory" class="org.springframework.jms.connection.SingleConnectionFactory">
|
||||
<constructor-arg>
|
||||
<bean class="org.springframework.integration.adapter.jms.StubConnection">
|
||||
<constructor-arg value="polling-test"/>
|
||||
</bean>
|
||||
</constructor-arg>
|
||||
</bean>
|
||||
|
||||
</beans>
|
||||
@@ -0,0 +1,20 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:si="http://www.springframework.org/schema/integration"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
|
||||
http://www.springframework.org/schema/integration
|
||||
http://www.springframework.org/schema/integration/spring-integration-1.0.xsd">
|
||||
|
||||
<si:jms-source id="adapter" connection-factory="testConnectionFactory"/>
|
||||
|
||||
<bean id="testConnectionFactory" class="org.springframework.jms.connection.SingleConnectionFactory">
|
||||
<constructor-arg>
|
||||
<bean class="org.springframework.integration.adapter.jms.StubConnection">
|
||||
<constructor-arg value="polling-test"/>
|
||||
</bean>
|
||||
</constructor-arg>
|
||||
</bean>
|
||||
|
||||
</beans>
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user