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

@@ -0,0 +1,69 @@
/*
* 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.
* 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.gateway;
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 URL-based Messaging Gateways.
*
* @author Mark Fisher
*/
public abstract class AbstractRemotingOutboundGateway extends AbstractReplyProducingMessageHandler {
private final RequestReplyExchanger proxy;
public AbstractRemotingOutboundGateway(String url) {
this.proxy = this.createProxy(url);
}
public void setReplyChannel(MessageChannel replyChannel) {
this.setOutputChannel(replyChannel);
}
/**
* Subclasses must implement this method. It will be invoked from the constructor.
*/
protected abstract RequestReplyExchanger createProxy(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.proxy.exchange(requestMessage);
}
catch (RemoteAccessException e) {
throw new MessageHandlingException(message, "remote failure in Messaging Gateway", e);
}
}
}

View File

@@ -0,0 +1,47 @@
/*
* 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.
* 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.gateway;
import org.springframework.integration.core.Message;
/**
* Support class for inbound Messaging Gateways.
*
* @author Mark Fisher
*/
public abstract class RemotingInboundGatewaySupport extends SimpleMessagingGateway implements RequestReplyExchanger {
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<?> exchange(Message<?> message) {
if (this.expectReply) {
return this.sendAndReceiveMessage(message);
}
this.send(message);
return null;
}
}

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);
}