if (!incomingMessage.hasResource(RequestDispatcher.class.getName())) {
throw new IllegalStateException("Cannot reply. Cannot find RequestDispatcher resource.");
}
RequestDispatcher dispatcher = (RequestDispatcher)
incomingMessage.getResource(ResourceProvider.class, RequestDispatcher.class.getName()).get();
if (dispatcher == null) {
throw new IllegalStateException("Cannot reply. Cannot find RequestDispatcher resource.");
}
Message msg = getIncomingMessage();
message.copyResource("Session", msg);
message.copyResource(RequestDispatcher.class.getName(), msg);
try {
dispatcher.dispatch(message);
}
catch (Exception e) {
throw new MessageDeliveryFailure("unable to deliver message: " + e.getMessage(), e);
}
}
@Override
public AsyncTask replyRepeating(TimeUnit unit, int interval) {
Message msg = getIncomingMessage();
message.copyResource("Session", msg);
RequestDispatcher dispatcher = (RequestDispatcher) msg.getResource(ResourceProvider.class, RequestDispatcher.class.getName()).get();
return _sendRepeatingWith(message, dispatcher, unit, interval);
}
@Override
public AsyncTask replyDelayed(TimeUnit unit, int interval) {
Message msg = getIncomingMessage();
message.copyResource("Session", msg);
RequestDispatcher dispatcher = (RequestDispatcher) msg.getResource(ResourceProvider.class, RequestDispatcher.class.getName()).get();
return _sendDelayedWith(message, dispatcher, unit, interval);
}
private Message getIncomingMessage() {
return ((ConversationMessageWrapper) message).getIncomingMessage();