Demo - Sales Dashboard using AppFabric SDK for Java

Introduction
The Sales Dashboard application demonstrates how a traveling sales person can create and update orders on a corporate Sales application running within the enterprise datacenter. The sales person is able to view and update the company's sales data despite the fact that (s)he is not able to otherwise access the corporate network. The sample demonstrates how the Access Control Service and Service Bus can be used to provide secure access to a service running inside the corporate network from an external network. The application is developed in Java and MySQL. Either apache or IIS Web Server can be used. Web server can be used Sun GlassFish or Apache Tomcat or JBoss.
 
Scenario Architecture
 

Architecture
The following diagram illustrates the technical design of the Sales Dashboard application. In this scenario, the Java client application is hosted on the Internet and RESTful web services are inside the enterprise network.
 
Low Level Diagram
Low Level Architecture of Sales Dashboard Scenario
 
Various components shown in architecture diagram are described below.
 
Sales Dashboard Web Service
 
Sales Dashboard web service provides RESTful web services for basic operations like Create, Read, Update, Delete (CRUD) over the Sales Database.
 
The application validates the ACS token received through request header in order to allow or deny further processing of request and response accordingly. For the validation ACS token validation functionality exposed by SDK is used.
 
The Sales Dashboard REST web services are exposed outside enterprise network using Service Bus endpoint. This is achieved by using an intermediate service, so no changes to the Sales Dashboard service are required.
 
Intermediate Polling Service
 
Intermediate Polling Service is a console application. It continuously polls on the specified Message Buffer for incoming messages. The first time, it internally creates a Message Buffer and then keeps on polling for incoming messages on it, using Service Bus section of the SDK. On receiving a new message, message contents are extracted and an HTTP REST request is formed and forwarded to the configured URL passed in the message (In Sales Dashboard application it is 'Sales Dashboard web service URL'). The response returned by web service is then written to another Message Buffer which is specified by the client, in its request message.
 
/*
 * Intermediate service that helps the client send messages to the service  
 * using Message buffers and sends the response back
 * @param credentials Required for authentication
 * @param serviceMessageBuffer Name of the message buffer at 
 * which the service is going to listen for requests
 * */
   public void startPolling(Credentials credentials, String serviceMessageBuffer )
        throws Exception{			
	MessageBuffer msgBuffer = new MessageBuffer(credentials, solutionName);
	MessageBufferPolicy msgBufferPolicyObj = new MessageBufferPolicy
         (authorization,transportProtection, expiresAfter, maxMessageCount);
	
       //Create message buffer
	msgBuffer.createMessageBuffer(serviceMessageBuffer, msgBufferPolicyObj);
	
       //Poll for requests
	while(true)
	{
	    //Retrieve message from message buffer
	    String str = msgBuffer.retrieveMessage(serviceMessageBuffer);
	    if(!StringUtil.IsNullOrEmpty(str)){
		//Parse the message
		ServiceMessage record = parseMessage(str);
		//Forward request to service
		response = fireHttpRequest(record);
		//Send response to client
		msgBuffer.sendMessage(messageBufferName, response);
        }	
     } 
  }
 
Client Application
 
Client application communicates with ACS, using SDK, in order to obtain token, that is used while requesting exposed Sales Dashboard RESTful web services. Similarly, client application uses the SDK to communicate with the Sales Dashboard web service using the intermediate service.
 
To make any request to the web service, the client application will call a function, sendRequest(), with the target URI. The sendRequest function creates the Message Buffer using the SessionId as Message Buffer name in case it is not already created. It writes a message to the Message Buffer "salesOp" and waits for response on the Message Buffer {clientSessionId}. The sendRequest method, returns the response to the client application.
 
public PollingServiceResponse sendRequest(String url,
    HttpVerbs httpVerb, String sessionId, HashMap<String, String> headers,
    String body) throws DotNetServicesException {
        MessageBuffer msgBuffer;
        PollingServiceResponse responseObj = null;
        MessageBuffer msgBuffer = new MessageBuffer(credentials, solutionName);
    
        // To send message to message buffer 
        String messageStr = xmlForPollingService(url, httpVerb,sessionId,
            headers, body, false);
        msgBuffer.sendMessage(messageBufferName, messageStr.toString());
    
       //reading the response. Message buffer with name sessionId was 
       //created while logging in
       String retrievedMessage = msgBuffer.retrieveMessage(sessionId);

       //Extract and return response code and response String 
       responseObj = parseResponse(retrievedMessage);
       return responseObj;

  }