@Override public void onMessage(Message msg) { try { if (!msg.propertyExists(AppConsts.MESSAGE_TYPE) || !(msg instanceof TextMessage)) { throw new IOError(null); } String type = msg.getStringProperty(AppConsts.MESSAGE_TYPE); if (type.equals(AppConsts.CHANGE_BALANCE_MT)) { String text = ((TextMessage) msg).getText(); ChangeBalanceDTO dto = null; try { dto = ju.fromXml(text, ChangeBalanceDTO.class); } catch (Exception e) { log.error("Could not convert xml to object", e); throw new IOError(null); } if (db.changeBalance(dto.getPhoneNumber(), dto.getDelta()) == null) { throw new IOError(null); } } else { throw new IOError(null); } } catch (IOError e) { forwardMessageToNone(msg); } catch (JMSException e) { log.trace(e.getMessage(), e); } }
public static void addBalanceJMS(String from, int amount) throws Exception { // BalanceRequestDTO dto = new BalanceRequestDTO(BalanceRequestType.ADD, from, // BigDecimal.valueOf(amount)); ChangeBalanceDTO dto = new ChangeBalanceDTO(); dto.setPhoneNumber(from); dto.setDelta(BigDecimal.valueOf(amount)); ms.sendObjectMessage(balance, dto, AppConsts.CHANGE_BALANCE_MODIFIER); }