if (!incomingMessage.hasResource(RequestDispatcher.class.getName())) {
throw new IllegalStateException("Cannot reply. Cannot find RequestDispatcher resource.");
}
final RequestDispatcher dispatcher = (RequestDispatcher)
incomingMessage.getResource(ResourceProvider.class, RequestDispatcher.class.getName()).get();
if (dispatcher == null) {
throw new IllegalStateException("Cannot reply. Cannot find RequestDispatcher resource.");
}
final 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(final TimeUnit unit, final int interval) {
final Message msg = getIncomingMessage();
message.copyResource("Session", msg);
final RequestDispatcher dispatcher = (RequestDispatcher) msg.getResource(ResourceProvider.class, RequestDispatcher.class.getName()).get();
return _sendRepeatingWith(message, dispatcher, unit, interval);
}
@Override
public AsyncTask replyDelayed(final TimeUnit unit, final int interval) {
final Message msg = getIncomingMessage();
message.copyResource("Session", msg);
final RequestDispatcher dispatcher = (RequestDispatcher) msg.getResource(ResourceProvider.class, RequestDispatcher.class.getName()).get();
return _sendDelayedWith(message, dispatcher, unit, interval);
}
private Message getIncomingMessage() {
return ((ConversationMessageWrapper) message).getIncomingMessage();