@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 reserveCall(String from, String to) throws Exception { CallSessionRequestDTO dto = new CallSessionRequestDTO(CallSessionRequestType.RESERVE, from, to, 30); String xml = ju.toXml(dto).replaceAll("\n", "").replaceAll(">[ ]+", ">"); String cmd = String.format("curl --data %s %s", xml, CALL_URL); exec(cmd); }
static { ju.a(CallSessionRequestDTO.ALIAS, CallSessionRequestDTO.class); ju.a(BalanceRequestDTO.ALIAS, BalanceRequestDTO.class); Hashtable<String, String> p = new Hashtable<String, String>(); p.put("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory"); p.put("java.naming.factory.url.pkgs=", "org.jboss.naming:org.jnp.interfaces"); try { InitialContext ic = new InitialContext(p); cf = (ConnectionFactory) ic.lookup("/ConnectionFactory"); balance = (Destination) ic.lookup(AppConsts.BALANCE_QUEUE_NAME); sessionReq = (Destination) ic.lookup(AppConsts.REQSESS_QUEUE_NAME); ms = new MessagingUtils(cf); } catch (Exception e) { e.printStackTrace(); } };
@PostConstruct public void init() { ju = new XStreamUtils(); ju.a(ChangeBalanceDTO.ALIAS, ChangeBalanceDTO.class); }
public static void addBalance(BalanceRequestDTO dto) throws Exception { String xml = ju.toXml(dto).replaceAll("\n", "").replaceAll(">[ ]+", ">"); String cmd = String.format("curl --data %s %s", xml, BALANCE_URL); exec(cmd); }