Laszlo is an open source platform for the development and delivery of rich Internet applications on the World Wide Web.
Note: the binary distribution LPS-2.2 has a bug with the Agent code. I've submitted a patch to the forum ( see link). You need to apply the patch or grab my patched jar here.
You can find the application's source here.
You are suppose to extract the files in the directory ${LPS_HOME}/Server/lps-2.2/examples
.
That will create two directories: quoteAgent
and quoteServer
.
Once you have the files in place, point your browser to your local version of this page by pointing your browser to "http://localhost:8080/lps/examples/quoteAgent/main.html". Then follow the steps below.
Step:
First here is the simple client application. Here, I just use a local dataset
sampledataset.lzx to try out the UI.
What I've done here is to wrap the dataset
within a connectiondatasource
and
create a connection
specifying an agent
. Note that the actuall url
of the agent is not important at this point. What we are doing here is to make sure we can connect to
the LPS with a persistant connection.
<connection authenticator="anonymous" group="client">
<agent url="http://localhost:8080/lps/examples/quoteServer/somepath"/>
<method event="onconnect">
Debug.write("Connected with auth param: " + this.getAuthParam());
</method>
<method event="onerror" args="error">
Debug.write("Connection Error" + error);
</method>
</connection>
<script>
canvas.connection.setAuthParam('usr=guest');
canvas.connection.connect();
</script>
<connectiondatasource name="agentDatasource">
<dataset name="sampleQuote"/>
</connectiondatasource>
You should see the connection message as displayed here:
Next we need to send our quote request to the server,
note the request is in XML (eg. <getquote user="guest" symbol="IBM"/>
):
<button x="10" y="140" >Send XML to Server
<method event="onclick">
<![CDATA[
var to = "http://localhost:8080/lps/examples/quoteServer/getquote.jsp";
var xml = '<getquote user="guest" symbol="IBM"/>';
agentDatasource.sendAgentXML(to, xml);
]]>
Debug.write("Sent: " + xml);
</method>
</button>
I also set up a datapointer
to display the response dset
of sendAgentXML
:
<datapointer xpath="agentDatasource:sendXMLDset:/*[1]">
<method event="ondata" args="response">
Debug.write("Response: " + response);
</method>
<method event="onerror" args="err">
Debug.write("Error sending XML: " + err.errorstring);
</method>
</datapointer>
Now I need some way to answer to the quote request. Note above that I have changed the
agent path to point to quoteServer/getquote.jsp
.
The actual response by the server does not seem to matter.
For now, I just use a simple JSP (returning an XML message with the XML reqest received)
to keep LPS happy.
<%
String xml = request.getParameter("xml");
if (xml == null || xml.length() == 0) {
xml = "<nothing/>";
}
%>
<getrequest_response time="<%=new Date()%>">
<xml-msg>
<%=xml%>
</xml-msg>
</getrequest_response>
.../quoteServer/getquote.jsp?xml=<getquote user="guest" symbol="IBM"/>
).
Now we have a persistant connection
to LPS which acts as an agent between our client application
and the back-end server, and we have faked an request to the faked back-end server.
Next we'll emulate the QuoteServer pushing data to the application using the form below:
Also note the response from LPS to the back-end server when you submit the form, this is helpful when you are actually implementing your server in a servlet.
When you are implementing your server, you might need to detect the client disconnecting without
informing the server. You can use the agentlist
to determine if a client is still connected.
The following simulate the communication format for the agentlist
protocol:
<lps>
<status>200</status>
<message>ok</message>
<body>
<list>
<user name="guest"/>
</list>
</body>
</lps>
You might want to try changing the user and submit again to see the response for a non-exsistent user.
Send your comment/suggestion to: Jack Hung
Just thinking out loud:
|