April 25, 2014
Hot Topics:
RSS RSS feed Download our iPhone app

A Dynamic e-Business Application Using Web Services , Page 3

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

A successful login process fetches the customer profiles, product details, and his previous order details using synchronous RPC to initialize the customer data models. TradingWebServicesMgr is the component that interacts with the manufacturer Web services on behalf of the customer client. The client makes use of a local proxy object and invokes a method on them. This proxy could be a stub in the case of static binding or a dynamic proxy, a class created by the client at runtime. In this application, the manufacturer Web service description document (TradingWebServices.wsdl) that is generated during deployment is available to the customer either directly or through a link in the public registry. Refer to the Resources section for more information on WSDL. The customer application uses this WSDL document to generate a dynamic proxy at run time and invokes calls on this object. The runtime makes use of serializers and de-serializers to transfer Java objects between the client and server. The code snippet from TradingWebServicesMgr.java below shows steps for creating serializers for the Product class and registering with the service.

// set up serializers and de-serializers
CombinedSerializer productSerializer =
  new Product_SOAPSerializer(productQname, ENCODE_TYPE, NULLABLE,
productSerializer = new ReferenceableSerializerImpl(
                    SERIALIZE_AS_REF, productSerializer);
SerializerFactory productSerializerFactory =
              new SingletonSerializerFactory(productSerializer);
DeserializerFactory productDeSerializerFactory =
              new SingletonDeserializerFactory(productSerializer);

. . . . . . . . . .

TypeMappingRegistry registry = service.getTypeMappingRegistry();
TypeMapping typeMapping = registry.getTypeMapping(
typeMapping.register(Product.class, productQname,

The Product_SOAPSerializer class above is created when the xrpc compiler generates Web services ties on the server using information in config.xml. The extract below shows the creation of a dynamic proxy handle with the help of the Web service class and the WSDL document.

ServiceFactory serviceFactory = ServiceFactory.newInstance();
Service service = serviceFactory.createService(etradeWsdlUrl,
                  new QName(wsdlNSUri, serviceName));

. . . . . . . . . .

//get the proxy handle
tradeIF = (TradingWebServicesIF) service.getPort(new
                                 QName(wsdlNSUri, servicePort),

The JAX-RPC runtime establishes a synchronous communication channel between the client proxy and the tie object on the server. Ties are components running at the server complementing the proxy stubs on the client. JAX-RPC uses XML-based remote procedure calls to invoke services on remote systems. The calls and responses are transmitted as SOAP messages over HTTP. The JAX-RPC API hides all the complexity from the developer while writing the client code. Figure 5 shows the communication between a client and server using a dynamic proxy with JAX-RPC.

Click here for a larger image.

Figure 5: A synchronous interaction using Java API for XML-RPC

The asynchronous delivery process is implemented using JMS Queue and Topic. The customer performs a lookup for the JMS connection factories and destinations on the LDAP server using the JNDI lookup mechanism. All customer orders in the form of a Purchase Order XML document embedded within a SOAP message is funneled through the JMS Queue and delivered to the manufacturer application. The client code for this is developed using the JAXM API. Shown below is the Purchase Order XML document sent within a SOAP message.

<?xml version="1.0" encoding="UTF-8"?>
 <soap-env:Envelope xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/">
  <PurchaseOrder custId="JOHNS" poRef="JOHNS1048316652804" poDate="20030322" poValue="25235">
   <billTo country="AE">
    <name>John Simon</name>
    <street>P.O Box 00001</street>
   <shipTo country="AE">
    <name>John Simon</name>
    <street>P.O Box 00001</street>
    <orderItem partNum="2512EA">
     <productName>Presario-2512EA Laptop PC</productName>
     <desc>Intel-P4, 2.5GHz, 256MB RAM, 40GB HDD, 15" XGA</desc>
    <orderItem partNum="2125EA">
     <productName>Presario-2125EA Laptop PC</productName>
     <desc>Intel-M Celeron, 2.0GHz, 256MB RAM, 30GB HDD, 15" XGA</desc>

The customer implements a MessageListener interface to receive asynchronous responses from the manufacturer via the JMS Topic destination. The JMS messages are converted to SOAP messages and the embedded data extracted from it. The code snippet from the onMessage() handler below shows how data is extracted from an incoming JMS message.

. . . . . . . . . .

TransformerFactory tf = TransformerFactory.newInstance();
Transformer transformer = tf.newTransformer();

// convert JMS to SOAP message.
SOAPMessage soapMessage =
     MessageTransformer.SOAPMessageFromJMSMessage( message,
                        MessageFactory.newInstance() );

// Get SOAP part.
SOAPPart soapPart = soapMessage.getSOAPPart();

// Get SOAP envelope.
SOAPEnvelope soapEnvelope = soapPart.getEnvelope();

// Get the empty SOAP Envelope as a generic Source and put it
// into a DOMResult
javax.xml.transform.Source spSrc = soapPart.getContent();
javax.xml.transform.dom.DOMResult domResultEnv =
          new javax.xml.transform.dom.DOMResult();
transformer.transform(spSrc, domResultEnv);

// Get the document
org.w3c.dom.Node envelopeRoot = domResultEnv.getNode();

. . . . . . . . . .

The internal customer data models are updated upon receipt of appropriate messages from the manufacturer that in turn update the onscreen data. Figure 6 is a screen snapshot of the customer application showing the Order Details tab page. This page is automatically updated when the Manufacturer receives a PO and sends an ACK back or approves the pending order.

Click here for a larger image.

Figure 6: Screen snapshot of customer application showing the Order Details tab page

The customer is assembled as a .jar standalone application.

Page 3 of 6

Comment and Contribute


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



Sitemap | Contact Us

Rocket Fuel