Migrated RMI adapter and parser code from "org.springframework.integration.adapter" to the new "org.springframework.integration.rmi" module, and added a dedicated spring-integration-rmi-1.0.xsd schema and RmiNamespaceHandler.
This commit is contained in:
@@ -1,90 +0,0 @@
|
||||
/*
|
||||
* Copyright 2002-2008 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.integration.adapter.rmi;
|
||||
|
||||
import java.rmi.RemoteException;
|
||||
import java.rmi.registry.Registry;
|
||||
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.integration.adapter.AbstractRemotingGateway;
|
||||
import org.springframework.integration.channel.MessageChannel;
|
||||
import org.springframework.integration.handler.MessageHandler;
|
||||
import org.springframework.remoting.rmi.RmiServiceExporter;
|
||||
import org.springframework.remoting.support.RemoteInvocationExecutor;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
* A gateway adapter for RMI-based remoting.
|
||||
*
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public class RmiGateway extends AbstractRemotingGateway implements InitializingBean, MessageHandler {
|
||||
|
||||
public static final String SERVICE_NAME_PREFIX = "org.springframewok.integration.rmiGateway.";
|
||||
|
||||
|
||||
private final String requestChannelName;
|
||||
|
||||
private volatile String registryHost;
|
||||
|
||||
private volatile int registryPort = Registry.REGISTRY_PORT;
|
||||
|
||||
private volatile RemoteInvocationExecutor remoteInvocationExecutor;
|
||||
|
||||
|
||||
/**
|
||||
* Create an RmiGateway that sends to the provided request channel.
|
||||
*
|
||||
* @param requestChannel the channel where messages will be sent, must not be
|
||||
* <code>null</code>.
|
||||
*/
|
||||
public RmiGateway(MessageChannel requestChannel) {
|
||||
super(requestChannel);
|
||||
this.requestChannelName = requestChannel.getName();
|
||||
Assert.isTrue(StringUtils.hasText(this.requestChannelName), "RmiGateway's request channel must have a name.");
|
||||
}
|
||||
|
||||
|
||||
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 afterPropertiesSet() throws RemoteException {
|
||||
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 + this.requestChannelName);
|
||||
exporter.afterPropertiesSet();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,46 +0,0 @@
|
||||
/*
|
||||
* Copyright 2002-2008 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.integration.adapter.rmi;
|
||||
|
||||
import org.springframework.integration.adapter.AbstractRemotingHandler;
|
||||
import org.springframework.integration.handler.MessageHandler;
|
||||
import org.springframework.remoting.rmi.RmiProxyFactoryBean;
|
||||
|
||||
/**
|
||||
* A MessageHandler adapter for RMI-based remoting.
|
||||
*
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public class RmiHandler extends AbstractRemotingHandler {
|
||||
|
||||
public RmiHandler(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();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,55 +0,0 @@
|
||||
/*
|
||||
* Copyright 2002-2008 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.integration.adapter.rmi.config;
|
||||
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
|
||||
import org.springframework.integration.adapter.config.AbstractRemotingGatewayParser;
|
||||
import org.springframework.integration.adapter.rmi.RmiGateway;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
* Parser for the <rmi-gateway/> element.
|
||||
*
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public class RmiGatewayParser extends AbstractRemotingGatewayParser {
|
||||
|
||||
private static final String REMOTE_INVOCATION_EXECUTOR_ATTRIBUTE = "remote-invocation-executor";
|
||||
|
||||
|
||||
@Override
|
||||
protected Class<?> getBeanClass(Element element) {
|
||||
return RmiGateway.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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,65 +0,0 @@
|
||||
/*
|
||||
* Copyright 2002-2008 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.integration.adapter.rmi.config;
|
||||
|
||||
import java.rmi.registry.Registry;
|
||||
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
|
||||
import org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser;
|
||||
import org.springframework.integration.ConfigurationException;
|
||||
import org.springframework.integration.adapter.rmi.RmiGateway;
|
||||
import org.springframework.integration.adapter.rmi.RmiHandler;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
* Parser for the <rmi-handler/> element.
|
||||
*
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public class RmiHandlerParser extends AbstractSingleBeanDefinitionParser {
|
||||
|
||||
@Override
|
||||
protected Class<?> getBeanClass(Element element) {
|
||||
return RmiHandler.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean shouldGenerateId() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean shouldGenerateIdAsFallback() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doParse(Element element, BeanDefinitionBuilder builder) {
|
||||
String host = element.getAttribute("host");
|
||||
String remoteChannel = element.getAttribute("remote-channel");
|
||||
if (!(StringUtils.hasText(host) && StringUtils.hasText(remoteChannel))) {
|
||||
throw new ConfigurationException("The 'host' and 'remote-channel' attributes are both required");
|
||||
}
|
||||
String portAttribute = element.getAttribute("port");
|
||||
String port = StringUtils.hasText(portAttribute) ? portAttribute : "" + Registry.REGISTRY_PORT;
|
||||
String url = "rmi://" + host + ":" + port + "/" + RmiGateway.SERVICE_NAME_PREFIX + remoteChannel;
|
||||
builder.addConstructorArgValue(url);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -6,5 +6,3 @@ httpinvoker-handler=org.springframework.integration.adapter.httpinvoker.config.H
|
||||
mail-target=org.springframework.integration.adapter.mail.config.MailTargetParser
|
||||
polling-mail-source=org.springframework.integration.adapter.mail.config.PollingMailSourceParser
|
||||
imap-idle-mail-source=org.springframework.integration.adapter.mail.config.SubscribableImapIdleMailSourceParser
|
||||
rmi-gateway=org.springframework.integration.adapter.rmi.config.RmiGatewayParser
|
||||
rmi-handler=org.springframework.integration.adapter.rmi.config.RmiHandlerParser
|
||||
Reference in New Issue
Block a user