@Override
public Object invoke(Channel fromChannel, AsyncMessage message) {
String topicId = TopicId.normalize(((String)message.getHeader(AsyncMessage.SUBTOPIC_HEADER)));
AsyncMessage reply = null;
if (getSecurityPolicy().canPublish(fromChannel, topicId, message)) {
TopicId tid = getTopicId(topicId);
try {
fromChannel.publish(new AsyncPublishedMessage(rootTopic, tid, message));
reply = new AcknowledgeMessage(message);
reply.setMessageId(message.getMessageId());
}
catch (MessagePublishingException e) {
log.error(e, "Error while publishing message: %s from channel %s to topic: %s", message, fromChannel, tid);
reply = new ErrorMessage(message, null);
((ErrorMessage)reply).setFaultString("Server.Publish.Error");
}
}
else {
log.warn("Channel %s tried to publish a message to topic %s", fromChannel, topicId);
reply = new ErrorMessage(message, null);
((ErrorMessage)reply).setFaultString("Server.Publish.Denied");
}
return reply;
}