INT-842 moved gateway support base classes to core gateway package

This commit is contained in:
Mark Fisher
2010-04-30 23:03:54 +00:00
parent 2eda315aa6
commit e0cc920d56
10 changed files with 41 additions and 73 deletions

View File

@@ -1,31 +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;
import org.springframework.integration.core.Message;
/**
* Interface used for proxy-based remoting adapters (e.g. RMI and HttpInvoker).
* Enables serializable Messages to be exchanged across a remote invocation.
*
* @author Mark Fisher
*/
public interface RemoteMessageHandler {
Message<?> handle(Message<?> message);
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2008 the original author or authors.
* Copyright 2002-2010 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.
@@ -22,9 +22,9 @@ import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.integration.adapter.RemoteMessageHandler;
import org.springframework.integration.adapter.RemotingInboundGatewaySupport;
import org.springframework.integration.core.MessagingException;
import org.springframework.integration.gateway.RemotingInboundGatewaySupport;
import org.springframework.integration.gateway.RequestReplyExchanger;
import org.springframework.remoting.httpinvoker.HttpInvokerServiceExporter;
import org.springframework.web.HttpRequestHandler;
@@ -74,7 +74,7 @@ public class HttpInvokerInboundGateway extends RemotingInboundGatewaySupport imp
if (this.exporter == null) {
HttpInvokerServiceExporter exporter = new HttpInvokerServiceExporter();
exporter.setService(this);
exporter.setServiceInterface(RemoteMessageHandler.class);
exporter.setServiceInterface(RequestReplyExchanger.class);
exporter.afterPropertiesSet();
this.exporter = exporter;
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2008 the original author or authors.
* Copyright 2002-2010 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.
@@ -16,8 +16,8 @@
package org.springframework.integration.httpinvoker;
import org.springframework.integration.adapter.AbstractRemotingOutboundGateway;
import org.springframework.integration.adapter.RemoteMessageHandler;
import org.springframework.integration.gateway.AbstractRemotingOutboundGateway;
import org.springframework.integration.gateway.RequestReplyExchanger;
import org.springframework.remoting.httpinvoker.HttpInvokerProxyFactoryBean;
/**
@@ -36,12 +36,12 @@ public class HttpInvokerOutboundGateway extends AbstractRemotingOutboundGateway
@Override
protected RemoteMessageHandler createHandlerProxy(String url) {
protected RequestReplyExchanger createProxy(String url) {
HttpInvokerProxyFactoryBean proxyFactory = new HttpInvokerProxyFactoryBean();
proxyFactory.setServiceInterface(RemoteMessageHandler.class);
proxyFactory.setServiceInterface(RequestReplyExchanger.class);
proxyFactory.setServiceUrl(url);
proxyFactory.afterPropertiesSet();
return (RemoteMessageHandler) proxyFactory.getObject();
return (RequestReplyExchanger) proxyFactory.getObject();
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2008 the original author or authors.
* Copyright 2002-2010 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.
@@ -85,7 +85,7 @@ public class HttpInvokerInboundGatewayTests {
private static byte[] createRequestContent(Message<?> message) throws IOException {
RemoteInvocation invocation = new RemoteInvocation(
"handle", new Class[] { Message.class }, new Object[] { message });
"exchange", new Class[] { Message.class }, new Object[] { message });
ByteArrayOutputStream baos = new ByteArrayOutputStream(1024);
ObjectOutputStream oos = new ObjectOutputStream(baos);
try {

View File

@@ -19,10 +19,10 @@ package org.springframework.integration.rmi;
import java.rmi.registry.Registry;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.integration.adapter.RemoteMessageHandler;
import org.springframework.integration.adapter.RemotingInboundGatewaySupport;
import org.springframework.integration.context.NamedComponent;
import org.springframework.integration.core.MessageChannel;
import org.springframework.integration.gateway.RemotingInboundGatewaySupport;
import org.springframework.integration.gateway.RequestReplyExchanger;
import org.springframework.remoting.rmi.RmiServiceExporter;
import org.springframework.remoting.support.RemoteInvocationExecutor;
import org.springframework.util.Assert;
@@ -91,7 +91,7 @@ public class RmiInboundGateway extends RemotingInboundGatewaySupport implements
exporter.setRemoteInvocationExecutor(this.remoteInvocationExecutor);
}
exporter.setService(this);
exporter.setServiceInterface(RemoteMessageHandler.class);
exporter.setServiceInterface(RequestReplyExchanger.class);
exporter.setServiceName(SERVICE_NAME_PREFIX + this.requestChannelName);
exporter.afterPropertiesSet();
this.exporter = exporter;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2008 the original author or authors.
* Copyright 2002-2010 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.
@@ -16,8 +16,8 @@
package org.springframework.integration.rmi;
import org.springframework.integration.adapter.AbstractRemotingOutboundGateway;
import org.springframework.integration.adapter.RemoteMessageHandler;
import org.springframework.integration.gateway.AbstractRemotingOutboundGateway;
import org.springframework.integration.gateway.RequestReplyExchanger;
import org.springframework.remoting.rmi.RmiProxyFactoryBean;
/**
@@ -33,14 +33,14 @@ public class RmiOutboundGateway extends AbstractRemotingOutboundGateway {
@Override
public RemoteMessageHandler createHandlerProxy(String url) {
public RequestReplyExchanger createProxy(String url) {
RmiProxyFactoryBean proxyFactory = new RmiProxyFactoryBean();
proxyFactory.setServiceInterface(RemoteMessageHandler.class);
proxyFactory.setServiceInterface(RequestReplyExchanger.class);
proxyFactory.setServiceUrl(url);
proxyFactory.setLookupStubOnStartup(false);
proxyFactory.setRefreshStubOnConnectFailure(true);
proxyFactory.afterPropertiesSet();
return (RemoteMessageHandler) proxyFactory.getObject();
return (RequestReplyExchanger) proxyFactory.getObject();
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2008 the original author or authors.
* Copyright 2002-2010 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.
@@ -25,9 +25,9 @@ import java.rmi.RemoteException;
import org.junit.Before;
import org.junit.Test;
import org.springframework.integration.adapter.RemoteMessageHandler;
import org.springframework.integration.channel.QueueChannel;
import org.springframework.integration.core.Message;
import org.springframework.integration.gateway.RequestReplyExchanger;
import org.springframework.integration.message.GenericMessage;
import org.springframework.integration.message.MessageBuilder;
import org.springframework.integration.message.MessageHandlingException;
@@ -54,8 +54,8 @@ public class RmiOutboundGatewayTests {
@Before
public void createExporter() throws RemoteException {
RmiServiceExporter exporter = new RmiServiceExporter();
exporter.setService(new TestHandler());
exporter.setServiceInterface(RemoteMessageHandler.class);
exporter.setService(new TestExchanger());
exporter.setServiceInterface(RequestReplyExchanger.class);
exporter.setServiceName("testRemoteHandler");
exporter.afterPropertiesSet();
}
@@ -139,9 +139,9 @@ public class RmiOutboundGatewayTests {
}
private static class TestHandler implements RemoteMessageHandler {
private static class TestExchanger implements RequestReplyExchanger {
public Message<?> handle(Message<?> message) {
public Message<?> exchange(Message<?> message) {
return new GenericMessage<String>(message.getPayload().toString().toUpperCase(), message.getHeaders());
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2009 the original author or authors.
* Copyright 2002-2010 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.
@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.integration.adapter;
package org.springframework.integration.gateway;
import java.io.Serializable;
@@ -26,17 +26,17 @@ import org.springframework.integration.message.MessageHandlingException;
import org.springframework.remoting.RemoteAccessException;
/**
* A base class for outbound Messaging Gateways that use url-based remoting.
* A base class for outbound URL-based Messaging Gateways.
*
* @author Mark Fisher
*/
public abstract class AbstractRemotingOutboundGateway extends AbstractReplyProducingMessageHandler {
private final RemoteMessageHandler handlerProxy;
private final RequestReplyExchanger proxy;
public AbstractRemotingOutboundGateway(String url) {
this.handlerProxy = this.createHandlerProxy(url);
this.proxy = this.createProxy(url);
}
@@ -47,7 +47,7 @@ public abstract class AbstractRemotingOutboundGateway extends AbstractReplyProdu
/**
* Subclasses must implement this method. It will be invoked from the constructor.
*/
protected abstract RemoteMessageHandler createHandlerProxy(String url);
protected abstract RequestReplyExchanger createProxy(String url);
@Override
@@ -59,10 +59,10 @@ public abstract class AbstractRemotingOutboundGateway extends AbstractReplyProdu
}
Message<?> requestMessage = MessageBuilder.fromMessage(message).build();
try {
return this.handlerProxy.handle(requestMessage);
return this.proxy.exchange(requestMessage);
}
catch (RemoteAccessException e) {
throw new MessageHandlingException(message, "unable to handle message remotely", e);
throw new MessageHandlingException(message, "remote failure in Messaging Gateway", e);
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2008 the original author or authors.
* Copyright 2002-2010 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.
@@ -14,17 +14,16 @@
* limitations under the License.
*/
package org.springframework.integration.adapter;
package org.springframework.integration.gateway;
import org.springframework.integration.core.Message;
import org.springframework.integration.gateway.SimpleMessagingGateway;
/**
* Support class for inbound Messaging Gateways.
*
* @author Mark Fisher
*/
public abstract class RemotingInboundGatewaySupport extends SimpleMessagingGateway implements RemoteMessageHandler {
public abstract class RemotingInboundGatewaySupport extends SimpleMessagingGateway implements RequestReplyExchanger {
private volatile boolean expectReply = true;
@@ -37,7 +36,7 @@ public abstract class RemotingInboundGatewaySupport extends SimpleMessagingGatew
this.expectReply = expectReply;
}
public Message<?> handle(Message<?> message) {
public Message<?> exchange(Message<?> message) {
if (this.expectReply) {
return this.sendAndReceiveMessage(message);
}

View File

@@ -26,8 +26,8 @@ import org.springframework.integration.core.Message;
* @author Mark Fisher
* @since 2.0
*/
interface RequestReplyExchanger {
public interface RequestReplyExchanger {
public Message<?> exchange(Message<?> request);
Message<?> exchange(Message<?> request);
}