INT-842 moved gateway support base classes to core gateway package
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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);
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user