falcon wrote:
> That sounds perfect! I'll download glassfish in the meantime and try to get
> it running myself!
OK fixed. I've described how to use it here:
https://grizzly.dev.java.net/issues/show_bug.cgi?id=180
I've also added an example + code that combine bayeux and a Servlet that
updates Bayeux channels.
A+
-- Jeanfrancois
>
> Thanks!
>
> Jeanfrancois Arcand-2 wrote:
>> Salut,
>>
>> falcon wrote:
>>> The most recent code I've tested with is almost exactly the same as Shing
>>> Wai
>>> Chan's code listed at the end of this message. Frankly, I'm not sure
>>> exactly where that servlet fits in.
>>>
>>> I start the server in the following manner:
>>>
>>> java -jar grizzly-cometd-webserver-1.8.0.jar -p 8080 -a
>>> grizzly-cometd-echo-1.8.0.war TestServlet
>>> (by the way, including or excluding TestServlet doesn't seem to make any
>>> difference at all)
>>>
>>> I open http://localhost:8080 in a couple of browsers. I type in
>>> something
>>> in the html form, press enter and it shows up in both web pages (which is
>>> exactly how it is supposed to work).
>>>
>>> I don't see any exception, any of my log messages, only the startup up
>>> message of cometd-webserver.
>> I see :-) You are using the cometd package, not the http-servlet package
>> :-) I've missed that case...Then specifying the Servlet doesn't make any
>> difference, I agree.
>>
>> The cometd-webserver cannot be used in conjunction with a Servlet....so
>> far. The cometd-webserver can only be used as a reflector, meaning your
>> application logic must be implemented on the client side, not on the
>> server side (using a Servlet). If you want to implement what Shing Wai
>> blogged about, you need to use a full Servlet Container like GlassFish
>> v2 or v3. As an example, take a look at this blog:
>>
>> http://weblogs.java.net/blog/caroljmcdonald/archive/2008/07/comet_slideshow.html
>>
>> I recommend you download GlassFish v2, enable Comet:
>>
>> http://weblogs.java.net/blog/jfarcand/archive/2008/02/comet_support_i.html
>>
>> and then deploy your war file. I suspect it will works.
>>
>> Now back to your example, I do think we should support your use case, so
>> I've filled:
>>
>> https://grizzly.dev.java.net/issues/show_bug.cgi?id=180
>>
>> I will work on it today and will update you as soon as I've it working.
>> If you can't wait, then just download v2 :-)
>>
>> How does that sound?
>>
>> Thanks!
>>
>> -- Jeanfrancois
>>
>>
>>
>>> For example, I type in "test" in the html form, and the following gets
>>> printed below the input field in _both_ browsers:
>>>
>>> /service/echo: test
>>>
>>> No other messages in the browsers or the console windows.
>>>
>>> As I mentioned before, I'd love to figure out how to publish my own
>>> messages
>>> to the browser.
>>>
>>> Following is the servlet code:
>>> -----------------
>>> import java.io.IOException;
>>> import java.util.*;
>>> import javax.servlet.*;
>>> import javax.servlet.http.*;
>>>
>>> import com.sun.grizzly.comet.*;
>>> import com.sun.grizzly.cometd.*;
>>> import com.sun.grizzly.cometd.bayeux.*;
>>>
>>> public class TestServlet extends HttpServlet {
>>> protected void doPost(HttpServletRequest request,
>>> HttpServletResponse response) throws ServletException,
>>> IOException {
>>> doProcess(request, response);
>>> }
>>>
>>> protected void doGet(HttpServletRequest request,
>>> HttpServletResponse response) throws ServletException,
>>> IOException {
>>> doProcess(request, response);
>>> }
>>>
>>> protected void doProcess(HttpServletRequest request,
>>> HttpServletResponse response) throws ServletException,
>>> IOException {
>>> String contextPath = "/cometd/cometd";
>>> String channel = "/service/echo";
>>> String messageDataName = "msg";
>>> String messageDataValue =
>>> request.getParameter("messageDataValue");
>>> ServletOutputStream out = response.getOutputStream();
>>> printForm(out);
>>>
>>> CometEngine engine = CometEngine.getEngine();
>>> CometContext context = engine.getCometContext(contextPath);
>>>
>>> if (context != null && messageDataValue != null) {
>>> Map<String, Object> map = new HashMap<String, Object>();
>>> map.put(messageDataName, messageDataValue);
>>> Data data = new Data();
>>> data.setMapData(map);
>>>
>>> DeliverResponse deliverResponse = new DeliverResponse();
>>> deliverResponse.setChannel("/service/echo");
>>> deliverResponse.setClientId("");
>>> deliverResponse.setData(data);
>>> deliverResponse.setLast(true);
>>> deliverResponse.setFollow(true);
>>>
>>> context.notify(deliverResponse);
>>> out.println("Data is sent.");
>>> System.out.println("Data is sent.");
>>> } else {
>>> out.println("No data is sent.");
>>> System.out.println("No data is sent.");
>>> }
>>> }
>>>
>>> private void printForm(ServletOutputStream out) throws IOException {
>>> out.println(
>>> "<h1>Send a cometd Message</h1> <form method=\"POST\" action=\"test\">
>>> <table> <tr><td>Message Data Value: <td><input type=\"text\"
>>> name=\"messageDataValue\" value=\"\"> <tr><td colspan=\"2\"><input
>>> type=\"submit\"> </table> </form> <hr>"
>>> );
>>> }
>>> }
>>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe_at_grizzly.dev.java.net
>> For additional commands, e-mail: users-help_at_grizzly.dev.java.net
>>
>>
>>
>