public class POProcessBeanJMS implements SessionBean {
  public OrderData order(String shipId, String billId, String sku, int quantity) throws POProcessException
  {
    try {
      Product product = productHome.findByPrimaryKey(sku);
      if (quantity > product.getInStock()) {
        throw new POProcessException("Stock is not enough");
      }    
      product.setInStock(product.getInStock() - quantity);
      OrderData order = new OrderData("" + System.currentTimeMillis());
      order.setBillTo(billId);
      order.setShipTo(shipId);
      order.setSKU(sku);
      order.setProductName(product.getName());
      order.setQuantity(quantity);
      int total = quantity * product.getPrice();
      order.setTotalPrice(total);
      queueConnectionFactory = (QueueConnectionFactory) jndiContext.lookup("QueueConnectionFactory");
      queue = (Queue) jndiContext.lookup(queueName);
      queueConnection = queueConnectionFactory.createQueueConnection();
      queueSession = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
      queueSender = queueSession.createSender(queue);
      ObjectMessage message = queueSession.createObjectMessage();
      message.setObject(order);
      queueSender.send(message);
      if (total > MAX_TOTAL) {
        throw new POProcessException("Exceed the max charge (" + MAX_TOTAL + ")");
      }
      return order;
    } catch (POProcessException e) {
      mySessionContext.setRollbackOnly();
      throw e;
    } catch (RemoteException e) {
      throw new EJBException("Fail in Order.order: " +e.getMessage());
    } catch (Exception e) {
      throw new EJBException("Fail in Order.order: " +e.getMessage());
    }
  }
}
