Hello,
I'm trying to develop simple app that:
1. Allows clients to subscribe to a channel. The index.html page is
a client's page where new data should be published.
Client logic is implemented using Dojo Toolkit v 1.1.1 (standard
subscribe method)
2. Publish new data using the servlet. The post.html is a admin page
from witch I send data to the servlet.
Servlet's logic is implemented with Grizzly Comet/Bayeux
(default GlassFish V3 components ...)
Here is what i do:
1. Open client page in browser A
2. Open client page in browser B (tab 1)
3. Open admin page in browser B (tab 2)
4. Send data from admin page to servlet ...
.. and nothing happens .. clients aren't notified until i open new
client page in browser B in tab 3 (or browser A in tab 2 - no matter)!
It looks like server is holding the data and i really don't know
why. Its really strange and i hope maybe some would be able to help me?
Servlet code :
public class DataServlet extends HttpServlet {
CometContext context;
@Override
public void init(ServletConfig config) throws ServletException {
super.init(config);
String contextPath = "/CometApp/cometd";
CometEngine cometEngine = CometEngine.getEngine();
context = cometEngine.register(contextPath);
context.setExpirationDelay(60 * 1000);
}
protected void processRequest(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
String channel = "/my/demo";
String messageDataName = "text";
String messageDataValue = request.getParameter("newinfo");
if (messageDataValue != null) {
Map<String, Object> map = new HashMap<String, Object>();
map.put(messageDataName, dummyBussinesLogic(messageDataValue));
Data data = new Data();
data.setMapData(map);
DeliverResponse deliverResponse = new DeliverResponse();
deliverResponse.setChannel(channel);
deliverResponse.setData(data);
deliverResponse.setLast(true);
deliverResponse.setFollow(true);
context.notify(deliverResponse);
out.println("Data is sent.");
} else {
out.println("No data is sent.");
}
response.sendRedirect("post.html");
}
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse
response)
throws ServletException, IOException {
processRequest(request, response);
}
@Override
protected void doPost(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}
private String dummyBussinesLogic(String s) {
return s.toUpperCase();
}
}
Thanks
Michal Orzechowski