System.out.println("The Dtmf is " + dtmf);
int cause = Integer.parseInt(dtmf);
EntityManager mgr = null;
Order order = null;
boolean successful = false;
String audioFile = null;
String destinationName = "/queue/B";
InitialContext ic = null;
ConnectionFactory cf = null;
Connection jmsConnection = null;
switch (cause) {
case Basic.CAUSE_DIGIT_1:
audioFile = pathToAudioDirectory + "OrderApproved.wav";
if (this.getSfDemo()) {
System.out.println("Lookup the Queue and put value");
try {
ic = new InitialContext();
cf = (ConnectionFactory) ic.lookup("/ConnectionFactory");
Queue queue = (Queue) ic.lookup(destinationName);
logger.info("Queue " + destinationName + " exists");
jmsConnection = cf.createConnection();
javax.jms.Session jmsSession = jmsConnection.createSession(
false, javax.jms.Session.AUTO_ACKNOWLEDGE);
MessageProducer sender = jmsSession.createProducer(queue);
TextMessage message = jmsSession.createTextMessage(this
.getCustomEvent().getOrderId()
+ ",1");
sender.send(message);
logger.info("The message was successfully sent to the "
+ queue.getQueueName() + " queue");
} catch (Exception e) {
logger.error("Exception while trying to send message", e);
} finally {
if (ic != null) {
try {
ic.close();
} catch (Exception e) {
logger.error("Exception while closing the IC", e);
}
}
try {
if (jmsConnection != null) {
jmsConnection.close();
}
} catch (JMSException jmse) {
logger.error("Could not close connection "
+ jmsConnection + " exception was " + jmse,
jmse);
}
}
} else {
mgr = this.persistenceResourceAdaptorSbbInterface
.createEntityManager(new HashMap(), "custom-pu");
order = (Order) mgr.createQuery(
"select o from Order o where o.orderId = :orderId")
.setParameter("orderId",
this.getCustomEvent().getOrderId())
.getSingleResult();
order.setStatus(Order.Status.PROCESSING);
mgr.flush();
mgr.close();
}
successful = true;
break;
case Basic.CAUSE_DIGIT_2:
audioFile = pathToAudioDirectory + "OrderCancelled.wav";
if (this.getSfDemo()) {
System.out.println("Lookup the Queue and put value");
try {
ic = new InitialContext();
cf = (ConnectionFactory) ic.lookup("/ConnectionFactory");
Queue queue = (Queue) ic.lookup(destinationName);
logger.info("Queue " + destinationName + " exists");
jmsConnection = cf.createConnection();
javax.jms.Session jmsSession = jmsConnection.createSession(
false, javax.jms.Session.AUTO_ACKNOWLEDGE);
MessageProducer sender = jmsSession.createProducer(queue);
TextMessage message = jmsSession.createTextMessage(this
.getCustomEvent().getOrderId()
+ ",2");
sender.send(message);
logger.info("The message was successfully sent to the "
+ queue.getQueueName() + " queue");
} catch (Exception e) {
logger.error("Exception while trying to send message", e);
} finally {
if (ic != null) {
try {
ic.close();
} catch (Exception e) {
logger.error("Exception while closing the IC", e);
}
}
try {
if (jmsConnection != null) {
jmsConnection.close();
}
} catch (JMSException jmse) {
logger.error("Could not close connection "
+ jmsConnection + " exception was " + jmse,
jmse);
}
}
} else {
mgr = this.persistenceResourceAdaptorSbbInterface
.createEntityManager(new HashMap(), "custom-pu");
order = (Order) mgr.createQuery(
"select o from Order o where o.orderId = :orderId")
.setParameter("orderId",
this.getCustomEvent().getOrderId())
.getSingleResult();
order.setStatus(Order.Status.CANCELLED);
mgr.flush();
mgr.close();
}
successful = true;