if (message == null) throw new IllegalArgumentException("No message specified");
// check if the direction of the message is valid
if (!Direction.TO_CONNECTIONS.equals(message.getDirection())
&& !Direction.TO_APPLICATIONS.equals(message.getDirection())) {
throw new RejectedException("can't save/update a message with direction: "
+ message.getDirection() == null ? "null" : message.getDirection().toString());
}
try {
if (message.getId() == null) { // hasn't been persisted