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,69 +0,0 @@
/*
* Copyright 2002-2009 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.integration.adapter;
import java.io.Serializable;
import org.springframework.integration.core.Message;
import org.springframework.integration.core.MessageChannel;
import org.springframework.integration.handler.AbstractReplyProducingMessageHandler;
import org.springframework.integration.message.MessageBuilder;
import org.springframework.integration.message.MessageHandlingException;
import org.springframework.remoting.RemoteAccessException;
/**
* A base class for outbound Messaging Gateways that use url-based remoting.
*
* @author Mark Fisher
*/
public abstract class AbstractRemotingOutboundGateway extends AbstractReplyProducingMessageHandler {
private final RemoteMessageHandler handlerProxy;
public AbstractRemotingOutboundGateway(String url) {
this.handlerProxy = this.createHandlerProxy(url);
}
public void setReplyChannel(MessageChannel replyChannel) {
this.setOutputChannel(replyChannel);
}
/**
* Subclasses must implement this method. It will be invoked from the constructor.
*/
protected abstract RemoteMessageHandler createHandlerProxy(String url);
@Override
public final Object handleRequestMessage(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() + "]");
}
Message<?> requestMessage = MessageBuilder.fromMessage(message).build();
try {
return this.handlerProxy.handle(requestMessage);
}
catch (RemoteAccessException e) {
throw new MessageHandlingException(message, "unable to handle message remotely", e);
}
}
}

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,48 +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;
import org.springframework.integration.gateway.SimpleMessagingGateway;
/**
* Support class for inbound Messaging Gateways.
*
* @author Mark Fisher
*/
public abstract class RemotingInboundGatewaySupport extends SimpleMessagingGateway implements RemoteMessageHandler {
private volatile boolean expectReply = true;
/**
* Specify whether the gateway should be expected to return a reply.
* The default is '<code>true</code>'.
*/
public void setExpectReply(boolean expectReply) {
this.expectReply = expectReply;
}
public Message<?> handle(Message<?> message) {
if (this.expectReply) {
return this.sendAndReceiveMessage(message);
}
this.send(message);
return null;
}
}