QueueSession session = null;
try
{
System.out.println("*** AccountsConfirmInterceptor intercepting");
long orderId = (Long)ctx.getParameters()[0];
if (em.find(Confirmation.class, orderId) == null)
{
System.out.println("*** AccountsConfirmInterceptor - recording confirmation");
Confirmation confirmation = new Confirmation(orderId, new Date());
em.persist(confirmation);
}
else
{
System.out.println("*** AccountsConfirmInterceptor - order has already been confirmed aborting");
return null;
}
System.out.println("*** AccountsConfirmInterceptor - notifying accounts dept " + ctx.getMethod().getName());
session = getConnection().createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
Message msg = session.createTextMessage("Confirming order " + orderId);
QueueSender sender = session.createSender(queue);
sender.send(msg);
return ctx.proceed();
}
catch(Exception e)
{
throw new RuntimeException(e);
}
finally
{
try{session.close();}catch(Exception e) {}
System.out.println("*** AccountsConfirmInterceptor exiting");
}