December 18, 2014
Hot Topics:

A Dynamic e-Business Application Using Web Services

  • May 22, 2003
  • By Simon John
  • Send Email »
  • More Articles »

The manufacturer application is built on the SUN ONE application server based on a Web-centric approach. It features use of servlets and other components to implement the business logics. The JAXPRC servlet provided by the container at deployment time services the JAX-RPC requests from clients and invokes the appropriate Web service method. The Web service implementation in turn invokes controller objects to perform the required functions. The BusinessController is an abstract base class for all controller objects. The controllers in turn use data access objects to access and manipulate the database.

The ManufacturerContextListener a servlet context listener, on receipt of the servlet initialized ServletContext life cycle event instantiates a ManufacturerAsyncRecv object in a separate thread. This object sets up the JMS resources lookups and listens for messages in the receive queue. Below is the code snippet of ManufacturerAsyncRecv object listening to the receive message queue.

public void listen() {

  System.out.println("ManufacturerAsync>>Starting receive loop");
  try  {
    while(!shutdown)  {
      Message m = queueReceiver.receiveNoWait();
      // received a message, process it now
      if(m!=null) processMessage(m);
      try  {
        Thread.sleep(2000);
      }
      catch (InterruptedException ie)  {}
    }
  }
  catch (JMSException jmse)  {
      System.out.println("ManufacturerAsync>>doGet: "+
                          jmse.toString());
    jmse.printStackTrace();
  } finally {
    cleanup();
  }
}

On receipt of a place order message, it makes an order entry in the database and sends an acknowledgement JAXM message via the ManufacturerAsyncSend. An extract from the processMessage code that separates the PO document from the SOAP message and process the order is shown below.

. . . . . . . . . .

//locate the body node and extract the data portion
Element poNode = (Element)XPathUtil.selectSingleNode(
                  envelopeRoot, "//PurchaseOrder");

//locate the PO data
String custId      = poNode.getAttribute("custId");
String poNbr       = poNode.getAttribute("poRef");
String poDate      = poNode.getAttribute("poDate");
String poValue     = poNode.getAttribute("poValue");
NodeList itemNodes = XPathUtil.selectNodes(poNode,
                     "//orderItems/orderItem");

// get the reqd controller and update the database with the
// status set
OrderController oc = (OrderController)(context.getAttribute(
                      IConstants.ORDER_CTRL_KEY));
if(oc== null) System.out.println("ManufacturerAsync:
                                  Order controller not found");

// create the Customer order object and populate it
CustomerOrder co = new CustomerOrder();
co.setCustomerId(custId);
co.setDate(poDate);
co.setPoRef(poNbr);
co.setStatus("Pending");
co.setValue(Double.parseDouble(poValue));

// create the line item vector and insert into the Customer
// order object
Vector itemVect = new Vector();
for(int i=0; i<itemNodes.getLength(); i++) {
  org.w3c.dom.Node itemNode = itemNodes.item(i);
  String itemid   = ((Element)itemNode).getAttribute("partNum");
  String quantity = XPathUtil.getNodeText(itemNode, "quantity");
  String price    = XPathUtil.getNodeText(itemNode, "price");
  OrderItem oi    = new OrderItem(itemid, Long.parseLong(quantity),
                               Double.parseDouble(price));
  itemVect.add(i,oi);
}
co.setItems(itemVect);
// update the customer order into the local database
CustomerOrder ordData = (CustomerOrder)(oc.process(co,
                                        "createorder"));
//store the data portion as [orderid].xml into a local file
long oid = ordData.getOrderId();
String msg = custId+":"+oid+":"+poNbr;

//send an ack message with the order id
ManufacturerAsyncSend mas = ManufacturerAsyncSend.getInstance();
mas.sendMessage("ACK", msg);

. . . . . . . . . .

The ManufacturerAsyncSend, a Singleton on receipt of an 'Order Approval' signal from the administrator, prepares the Invoice document, embeds it within a SOAP message, and dispatches it to the respective customer via the JMS Topic using JAXM API. The JMS messages are converted to SOAP messages using the MessageTransformer class. You could have a return queue for each customer instead of a single Topic object. The sendMessage() function builds the SOAP response, either an Acknowledgement message or an XML Invoice document for the customer. The SOAP message is converted to a JMS message before sending it to the JMS destination.

This application uses the Jakarta Struts framework to implement the Model-View-Controller (MVC) architecture for its page navigation and operations by the administrator. It illustrates the powerful and flexible features offered by the framework. All action elements extend the abstract BusinessBaseAction class. Refer to the Resources section for more information on the Jakarta Struts framework. Figure 7 shows the screen snapshot of the manufacturer Web application where the administrator views customer orders for approval of pending orders.



Click here for a larger image.

Figure 7: Screen snapshot of manufacturer application showing the View/Approve Order page

The administrator, upon initiating an Approve action, causes the order status to be updated by respective business controllers and an invoice message is sent to the ManufacturerAsyncSend. Figure 8 shows the interaction diagram for the order processing function.



Click here for a larger image.

Figure 8: The interaction diagram for the Order Processing function





Page 4 of 6



Comment and Contribute

 


(Maximum characters: 1200). You have characters left.

 

 


Enterprise Development Update

Don't miss an article. Subscribe to our newsletter below.

Sitemap | Contact Us

Rocket Fuel