Results 1 to 5 of 5

Hybrid View

  1. #1
    Power Member
    Join Date
    Jul 2006
    Location
    Cesano Maderno, Italy
    Posts
    784

    Post Request-Response "hack" #1

    ...continue

    Now we need a client to test it, we implement a simple client with the web SDK.
    In this page we put a <div> that is filled with the "response" and a "response is complete" message. There is also a form, fill the input field and press submit to make a request to the server. NOTE that since LiteralBasedProvider is used as MetaDataProvider, and since the demo uses the string inside the inputField as a group string, if you try to send a reuqest like "something somethingElse" you subscribe 2 items (in this case 2 "requests").
    The page is made to be deployed under Lightstreamer internal web server so domain host and port are set to null.
    To gather the desired data we use a NonVisualTable. Refer to the comments inside the code for further explanations

    Code html:
    1. <html>
    2. <head>
    3.     <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">    
    4.     <!-- inclusion of Lightstreamer web client library-->
    5.     <script src="/LS/lscommons.js"></script>
    6.     <script src="/LS/lspushpage.js"></script>
    7. </head>
    8.  
    9. <body>
    10.     <!--this div will show the response-->
    11.     <div id="response"></div>        
    12.  
    13.     <!--this form is used to call a method that makes the requests-->
    14.     <form onsubmit="makeRequest();return false;">
    15.         <input id="requestQuery" type="text" />
    16.         <input type="submit" value="send request" />
    17.     </form>
    18. <script>
    19.  
    20.    
    21. /////////////////PushPage Configuration
    22.     lsPage = new PushPage();
    23.    
    24.     lsPage.context.setDomain(null);
    25.    
    26.     lsPage.onEngineReady = function(lsEngine) {
    27.                 lsEngine.connection.setLSHost(null);
    28.                 lsEngine.connection.setLSPort(null);
    29.                 lsEngine.connection.setAdapterName("FAKESUB");
    30.                 lsEngine.changeStatus("STREAMING");
    31.             }
    32.    
    33.     lsPage.bind();
    34.     lsPage.loadEngineMinimal("/LS/lsengine.html");
    35.    
    36. /////////////////////////////////Request/Response handler    
    37.     var responseDiv = document.getElementById("response");
    38.     var requestQuery = document.getElementById("requestQuery");
    39.  
    40.     function makeRequest() {
    41.         //this is the string of the input field
    42.         var request = requestQuery.value;
    43.         //create a NonVisualTable, the item is the string of the input field, as fields
    44.         //"key" and "value" and subscribe in DISTINCT mode
    45.         var table = new NonVisualTable(request, new Array("key","value"), "DISTINCT");
    46.         //we need just the snapshot
    47.         table.setSnapshotRequired(true);
    48.         //this callback is called after subscription notification. We clear the responseDiv
    49.         //so our response will be the only one inside it
    50.         table.onStart = function() {
    51.             responseDiv.innerHTML = "";
    52.         }
    53.         //this callback is called per each received update. We compose a string with
    54.         //the "key" and "value" fields and append this string to the responseDiv
    55.         table.onItemUpdate = function(itemPos, itemObj, itemName) {
    56.             var k = itemObj.getNewValue("key");
    57.             var v = itemObj.getNewValue("value");
    58.             responseDiv.innerHTML += k + ": " + v +"<br/>";
    59.         }
    60.         //this callback is called when all snapshot events have been received. Put
    61.         //this info in the responseDiv and remove the subscription
    62.         table.onEndOfSnapshot = function(itemPos,itemName) {
    63.             responseDiv.innerHTML += "Response COMPLETE " +itemPos+"<br/>";
    64.             //until we keep the table subscribed the data adapter will not be
    65.             //called for others clients making the same request (ie Lightstreamer
    66.             //kernel will handle directly responses for those clients). In this case
    67.             //we don't remove the subscription.
    68.             //lsPage.removeTable("req");
    69.         }
    70.         //this callback is called in case some updates were lost. Put the info inside
    71.         //the responseDiv
    72.         table.onLostUpdates = function(itemPos,lostUpdates,itemName) {
    73.             responseDiv.innerHTML += "We've lost updates!<br/>";
    74.         }
    75.        
    76.         //subscribe the table. In this demo we always use the same id ("req") to avoid
    77.         //multiple concurrent requests.
    78.         lsPage.addTable(table, "req");
    79.     }
    80. </script>
    81. </body>
    82.  
    83. </html>

    The sources of the demo are also available as a downloadable zip attacched to this post.
    Attached Files Attached Files

 

 

Similar Threads

  1. Replies: 3
    Last Post: January 27th, 2012, 09:26 AM
  2. Getting time out on initial subscription request
    By PeterHiross in forum Adapter SDKs
    Replies: 4
    Last Post: December 20th, 2010, 08:36 AM
  3. Bad request: LS_Session parameter missing
    By lstest in forum Adapter SDKs
    Replies: 5
    Last Post: February 26th, 2010, 02:47 PM
  4. User Specific Response
    By vishnugs in forum General
    Replies: 4
    Last Post: April 6th, 2007, 11:06 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT +1. The time now is 08:57 PM.