PDA

View Full Version : Persistent Connection and "Agents"


epopov
07-06-2004, 02:51 AM
Hello!
I have some problems with laszlo persistent connection engine. I want to sent notification to laszlo app. from Java back-end at any time I need (not the response on the laszlo app. request).

Here is the lzx code:
<canvas debug="true" height="200">
<connection authenticator="anonymous" authparam="usr=frontend" group="backend">
<agent url="http://localhost:8080/app/pers" />
<method event="onconnect">
Debug.write("persistent connection established");
</method>
<method event="ondisconnect">
Debug.write("persistent connection closed");
</method>
</connection>

<script>
connection.connect();
</script>

<connectiondatasource name="myconnection">
<dataset name="msg_msg" />
</connectiondatasource>

<datapointer xpath="myconnection:msg_msg:/*">
<method event="ondata">
Debug.write('Hello');
</method>
</datapointer>

<button>Button
<method event="onclick">
myconnection.sendMessage('*', 'a message', 'msg_msg');
</method>
</button>
</canvas>

So, if I'll send notification to dataset msg_msg, I should see "Hello" in debug console. In Java Servlet I generate query string to my laszlo app. with lzt=agentmessage. Full query string: http://localhost:8080/app/conn_test.lzx?lzt=agentmessage&ccache=false&cache=false&url=http://localhost:8080/app/pers&group=backend&to=frontend&dset=msg_msg&msg=&range=user.

When my servlet executes and send redirect with generated query string to the laszlo app. I don't see 'Hello' in the debug window.

But, when I click on button in laszlo app (code above) sendMessage method executes -> 'Hello' in the debug console. Then I clear up my debug window and excute my Servlet again and the 'Hello' string appears in the debug console!!

Does anybody known what is my problem ?

TripleToe
07-06-2004, 12:32 PM
Can you post the servlet code? I'm not sure if it will help, but I'd be interested to see it.

epopov
07-07-2004, 01:27 AM
Servlet Code:

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;

public class PersistentConnectionTest extends HttpServlet {

public void doPost(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException {

String dset = request.getParameter("dest_dset");

String url = "http://localhost:8080/app/pers";
String group = "backend";
String to = "frontend";
String msg = "";
String range = "user";

if (dset !=null && dset.length() > 0) {
System.out.println("Received dest_dset: " + dset);

String qStr = "http://localhost:8080/app/conn_test.lzx?lzt=agentmessage";
qStr += "&ccache=" + "false";
qStr += "&cache=" + "false";
qStr += "&url=" + url;
qStr += "&group=" + group;
qStr += "&to=" + to;
qStr += "&dset=" + dset;
qStr += "&msg=" + msg;
qStr += "&range=" + range;

response.sendRedirect(qStr);
} else {
response.sendError(HttpServletResponse.SC_BAD_REQU EST);
}
}

public void doGet(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException {
doPost(request, response);
}
}

TripleToe
07-09-2004, 07:24 AM
I tried the servlet code and I'm getting the same issue. Also, after the servlet-invoked agent calls the LZX client, it will not make any further calls. It only works once, and (as you stated already) only after the LZX client makes an initial call. Not sure what is wrong with it. :(

epopov
07-09-2004, 11:04 AM
Hello!
I have done a workaround in laszlo source, just to make it working...But it's askew...

P.S. Still waiting for reply from Antun...

TripleToe
07-09-2004, 11:27 AM
Very cool. Go ahead and post the workaround if you can.

:)

epopov
07-20-2004, 12:34 AM
Sorry for delay...Here is the lzx code with a workaround:
<canvas debug="true" height="200">
<attribute name="usr" value="'ui'" />
<method event="oninit">
canvas.connection.setAttribute('authparam', 'usr=' + canvas.usr);
connection.connect();
</method>
<connection authenticator="anonymous" group="backend">
<agent url="http://localhost:8080/app/pers" />

<method event="onconnect">
Debug.write("persistent connection established");
myconnection.sendMessage(canvas.usr, 'connect', 'msg1');
</method>
<method event="ondisconnect">
Debug.write("persistent connection closed");
</method>
</connection>

<connectiondatasource name="myconnection">
<dataset name="msg1" />
</connectiondatasource>

<datapointer xpath="myconnection:msg1:/*">
<method event="ondata">
var mesg = this.xpathQuery('/text()');

if (mesg != 'connect') {
Debug.write('Notification for msg1 dataset');
myconnection.sendMessage(canvas.usr, 'connect', 'msg1');
}
</method>
</datapointer>
</canvas>