Results 1 to 5 of 5
  1. #1
    Member
    Join Date
    Apr 2008
    Location
    Muang
    Posts
    5

    Cool DataAdapter using XML

    hi
    I have modified your HelloWorld DataAdapter class to test if it can read from an xml file. So I have written ReadXMLData class which uses
    Code:
    import java.io.File;
    import org.w3c.dom.Document;
    import org.w3c.dom.*;
    
    import javax.xml.parsers.DocumentBuilderFactory;
    import javax.xml.parsers.DocumentBuilder;
    import org.xml.sax.SAXException;
    import org.xml.sax.SAXParseException;
    This is the class I use in my app, so it works ok.
    When I run it on LS the LS seems to work but there is no data on screen.
    When I remove the ReadXMLData part and just put in some numbers. They appear.

    I have included all the packages in my class folder except java.io and javax.xml Do I need to include them as well?

  2. #2
    Administrator
    Join Date
    Jul 2006
    Location
    Milan
    Posts
    1,089
    XML related libraries are already included in the latest JDKs.
    Anyway, problems from missing libraries should manifest themselves
    in a clear way.

    There may be a mismatch in the item or field names used.
    Note that both item and field names have to be asked for by client code.
    A problem of this kind could be put into evidence through the Server log,
    by setting the priority of the "LightstreamerLogger.subscriptions" and "LightstreamerLogger.pump" categories to DEBUG in "lightstreamer_log_conf.xml".

  3. #3
    Member
    Join Date
    Apr 2008
    Location
    Muang
    Posts
    5
    Thanks DarioCrivelli

    I'll look for it.

  4. #4
    Member
    Join Date
    Apr 2008
    Location
    Muang
    Posts
    5
    Code:
    20-ส.ค.-51 08:48:20,171 |INFO |LightstreamerLogger.requests     |SERVER POOLED THREAD 3     |Serving request: /lightstreamer/STREAMING_IN_PROGRESS?LS_phase=5302&LS_client_version=4.2&LS_adapter=KASETDATA& from 127.0.0.1:1615
    20-ส.ค.-51 08:48:20,171 |TRACE|LightstreamerLogger.pump         |SERVER POOLED THREAD 3     |Pump for session Sc4be158a9426b82eT4820171 added
    20-ส.ค.-51 08:48:20,171 |INFO |LightstreamerLogger.requests     |SERVER POOLED THREAD 3     |Starting new session: Sc4be158a9426b82eT4820171 from 127.0.0.1:1615
    20-ส.ค.-51 08:48:20,234 |INFO |LightstreamerLogger.connections  |SERVER POOLED THREAD 2     |Accepted HTTP connection on Lightstreamer HTTP Server from 127.0.0.1:1616
    20-ส.ค.-51 08:48:20,250 |INFO |LightstreamerLogger.connections  |SERVER POOLED THREAD 4     |Reused HTTP connection on Lightstreamer HTTP Server from 127.0.0.1:1616
    20-ส.ค.-51 08:48:20,250 |INFO |LightstreamerLogger.webServer    |SERVER POOLED THREAD 7     |Serving request: /KasetData/LS/lsblank.html from 127.0.0.1:1616
    20-ส.ค.-51 08:48:20,250 |INFO |LightstreamerLogger.connections  |SERVER POOLED THREAD 5     |Reused HTTP connection on Lightstreamer HTTP Server from 127.0.0.1:1616
    20-ส.ค.-51 08:48:20,406 |INFO |LightstreamerLogger.requests     |SERVER POOLED THREAD 6     |Serving request: /lightstreamer/control.html?LS_session=Sc4be158a9426b82eT4820171&LS_window=0&LS_win_phase=5&LS_op=add&LS_req_phase=46&LS_mode1=MERGE&LS_id1=kasetData&LS_schema1=last%20vol%20change%20percent&LS_unique=1 from 127.0.0.1:1616
    20-ส.ค.-51 08:48:20,406 |INFO |LightstreamerLogger.requests     |SERVER POOLED THREAD 6     |Controlling session: Sc4be158a9426b82eT4820171 from 127.0.0.1:1616
    20-ส.ค.-51 08:48:20,406 |INFO |LightstreamerLogger.connections  |SERVER POOLED THREAD 6     |Reused HTTP connection on Lightstreamer HTTP Server from 127.0.0.1:1616
    20-ส.ค.-51 08:48:20,421 |TRACE|LightstreamerLogger.pump         |PUMP POOLED THREAD 1       |Pumping event in session Sc4be158a9426b82eT4820171: c(6,5,0);setWin(0,5);
    20-ส.ค.-51 08:48:22,421 |TRACE|LightstreamerLogger.pump         |PUMP POOLED THREAD 2       |Sending probe in session Sc4be158a9426b82eT4820171
    20-ส.ค.-51 08:48:22,531 |TRACE|LightstreamerLogger.subscriptions|Thread-15                  |INCOMING DATA for kasetData --> {last=null, percent=null, vol=null, change=null}
    20-ส.ค.-51 08:48:22,531 |DEBUG|LightstreamerLogger.subscriptions|Thread-15                  |Manager: com.lightstreamer.e.s@140984b
    20-ส.ค.-51 08:48:22,531 |TRACE|LightstreamerLogger.pump         |PUMP POOLED THREAD 2       |Pumping event in session Sc4be158a9426b82eT4820171: d(0,1,1,"#","#","#","#");
    20-ส.ค.-51 08:48:24,546 |TRACE|LightstreamerLogger.pump         |PUMP POOLED THREAD 1       |Sending probe in session Sc4be158a9426b82eT4820171
    20-ส.ค.-51 08:48:24,890 |TRACE|LightstreamerLogger.subscriptions|Thread-15                  |INCOMING DATA for kasetData --> {last=null, percent=null, vol=null, change=null}
    20-ส.ค.-51 08:48:24,890 |DEBUG|LightstreamerLogger.subscriptions|Thread-15                  |Manager: com.lightstreamer.e.s@140984b
    This is part of the log
    Code:
      public void subscribe(String itemName, Object itemHandle, boolean needsIterator)
                throws SubscriptionException, FailureException {
            if (itemName.equals("kasetData")) {
                gt = new GreetingsThread(itemHandle);
                gt.start();
            }
        }
    .
    .
    .
      public void unsubscribe(String itemName) throws SubscriptionException,
                FailureException {
            if (itemName.equals("kasetData") && gt != null) {
                gt.go = false;
            }
        }
    .
    .
    .
       public void run() {
               
                Random rand = new Random();
                ReadXMLData xd = new ReadXMLData() ;
                dataSet = xd.ReadData("RSS3.xml") ;
                while (go) {
                    Map<String, String> data = new HashMap<String, String>();
                    data.put("last", dataSet[0]);
                    data.put("vol", dataSet[1]);
                    data.put("change", dataSet[2]);
                    data.put("percent", dataSet[3]);
                    listener.smartUpdate(itemHandle, data, false);
                    
                    try {
                        Thread.sleep(1000 + rand.nextInt(2000));
                    } catch (InterruptedException e) {
                    }
                }
    Code:
    <head>
    	<title>Lightstreamer</title>
    	<script language="JavaScript" src="LS/lscommons.js"></script>
    	<script language="JavaScript" src="LS/lspushpage.js"></script>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head>
    
    <body>
    <div source="lightstreamer" table="datatable" item="kasetData" field="last">loading...</div>
    <div source="lightstreamer" table="datatable" item="kasetData" field="vol">loading...</div>
    <div source="lightstreamer" table="datatable" item="kasetData" field="change">loading...</div>
    <div source="lightstreamer" table="datatable" item="kasetData" field="percent">loading...</div>
    
    <script>
    	var page = new PushPage();
    	page.onEngineCreation = function(engine) {
    		engine.connection.setAdapterName("KASETDATA");
    		engine.changeStatus("STREAMING");
    	}
    	page.bind();
    	page.createEngine("KasetDataApp", "LS", "SHARE_SESSION");
    
    	var pushtable = new OverwriteTable(null, null, "MERGE");
    	page.addTable(pushtable, "datatable");
    </script>
    I notice the data order in the log is not the same as in the class or the DIV tags other than that I can't find anything else , perhaps you can tell.

    Where do I put the RSS3.xml file , in which folder?

    Many Thanks in advance

  5. #5
    Administrator
    Join Date
    Jul 2006
    Location
    Milan
    Posts
    1,089
    The Server log snippet shows that the Data Adapter fills the maps with nulls, despite it reads data from an external file.
    As you suggest, maybe the RSS3.xml is in the wrong place and maybe "ReadData" does not throw an exception for this.
    Can you confirm this by debugging your "run" method?

    In fact, in order to access external files, your Data Adapter should refer to the "configDir" File argument it receives in the "init" method, which contains the absolute path to the directory where the related "adapters.xml" file resides
    You should never use relative pathnames, but rather absolute pathnames that you can build based on "configDir".
    Hence, you should put RSS3.xml beside "adapters.xml" or in a subfolder and build an absolute pathname for it.

 

 

Similar Threads

  1. Replies: 4
    Last Post: February 3rd, 2011, 11:33 AM
  2. How to debug .NET DataAdapter
    By msgiribabu in forum Adapter SDKs
    Replies: 1
    Last Post: January 21st, 2011, 02:38 PM
  3. DataAdapter Service
    By brucehoch in forum Adapter SDKs
    Replies: 3
    Last Post: October 15th, 2010, 12:22 AM
  4. DataAdapter with XML
    By Irwin in forum Adapter SDKs
    Replies: 11
    Last Post: April 30th, 2010, 09:42 AM
  5. Pre-Processor Snapshot vs DataAdapter Snapshot
    By sukhdev in forum Adapter SDKs
    Replies: 3
    Last Post: August 1st, 2007, 09:44 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 10:29 AM.