users@grizzly.java.net

Re: newbie help: read from console, send to browser

From: Jeanfrancois Arcand <Jeanfrancois.Arcand_at_Sun.COM>
Date: Wed, 02 Jul 2008 22:17:03 -0400

Salut,

good catch! This is fixed now and will be part of 1.8.1 :-)

A+

-- Jeanfrancois

falcon wrote:
> Thanks, this one worked. Now I need to look through the code and adapt it
> for myself.
>
> I open a browser to localhost:8080, the other to
> http://localhost:8080/BayeuxExternalServlet/?message=Salut,user=JFA
>
> I set my user name through the chat window then refresh the servlet window a
> couple of times. I get the following Exception (I don't think this is a big
> problem for me, I, hopefully, have enough to start doing my experiments):
>
> ...
> cometd-bayeux-1.8.1-20080702.224045-1
> Adapter : com.sun.grizzly.tcp.http11.GrizzlyAdapterChain
> Thread Pool (Pipeline): com.sun.grizzly.http.LinkedListPipeline
> Asynchronous Request Processing enabled: true
> Server started in 3297 milliseconds.
> No data is sent.
> No data is sent.
> Data is sent.
> Jul 2, 2008 10:05:53 PM com.sun.grizzly.tcp.http11.GrizzlyAdapter service
> SEVERE: service exception
> java.lang.ClassCastException: com.sun.grizzly.tcp.http11.GrizzlyRequest
> cannot b
> e cast to com.sun.grizzly.cometd.CometdRequest
> at
> com.sun.grizzly.cometd.standalone.CometdAdapter.service(CometdAdapter
> .java:126)
> at
> com.sun.grizzly.tcp.http11.GrizzlyAdapterChain.service(GrizzlyAdapter
> Chain.java:76)
> at
> com.sun.grizzly.tcp.http11.GrizzlyAdapter.service(GrizzlyAdapter.java
> :151)
> at
> com.sun.grizzly.http.DefaultProcessorTask.invokeAdapter(DefaultProces
> sorTask.java:620)
> at
> com.sun.grizzly.comet.CometEngine.executeServlet(CometEngine.java:559
> )
> at com.sun.grizzly.comet.CometEngine.handle(CometEngine.java:310)
> at
> com.sun.grizzly.comet.CometAsyncFilter.doFilter(CometAsyncFilter.java
> :84)
> at
> com.sun.grizzly.arp.DefaultAsyncExecutor.invokeFilters(DefaultAsyncEx
> ecutor.java:177)
> at
> com.sun.grizzly.arp.DefaultAsyncExecutor.interrupt(DefaultAsyncExecut
> or.java:155)
> at
> com.sun.grizzly.arp.AsyncProcessorTask.doTask(AsyncProcessorTask.java
> :94)
> at com.sun.grizzly.http.TaskBase.call(TaskBase.java:359)
> at
> com.sun.grizzly.util.WorkerThreadImpl.run(WorkerThreadImpl.java:169)
>
>
> Again, this should help me very much. Merci!
>
> Jeanfrancois Arcand-2 wrote:
>> Hum...works for me, but the maven repo is quite bogus today. I'm
>> attaching the bundle to this mail. Can you try it?
>>
>> Thanks
>>
>> -- Jeanfrancois
>>
>> Jeanfrancois Arcand wrote:
>>> Strange....let me try to upload it again.
>>>
>>> Stay tuned!
>>>
>>> -- Jeanfrancois
>>>
>>> falcon wrote:
>>>> Ah, looks like Cometd.class is missing from the jar.
>>>>
>>>>
>>>> falcon wrote:
>>>>> I think I found the right one:
>>>>>
>>>>> http://download.java.net/maven/2/com/sun/grizzly/grizzly-cometd/1.8.1-SNAPSHOT/grizzly-cometd-1.8.1-20080702.224622-3.jar
>>>>>
>>>>> and
>>>>> http://download.java.net/maven/2/com/sun/grizzly/samples/grizzly-cometd-bayeux/1.8.1-SNAPSHOT/grizzly-cometd-bayeux-1.8.1-20080702.224045-1.war
>>>>>
>>>>>
>>>>> I tried running the following:
>>>>> java -jar grizzly-cometd-1.8.1-20080702.224622-3.jar -p 8080 -a
>>>>> grizzly-cometd-bayeux-1.8.1-20080702.224045-1.war
>>>>> com.sun.grizzly.bayeux.BayeuxExternalServlet
>>>>>
>>>>> But received the following message:
>>>>>
>>>>> Failed to load Main-Class manifest attribute from
>>>>> grizzly-cometd-1.8.1-20080702.224622-3.jar
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> falcon wrote:
>>>>>> Impressive turn-around time!
>>>>>>
>>>>>> Now, is there somewhere I can download
>>>>>> grizzly-cometd-webserver-1.8.1-SNAPSHOT, grizzly-cometd-bayeux.war and
>>>>>> com.sun.grizzly.bayeux.BayeuxExternalServlet? Or am I in for a few
>>>>>> hours
>>>>>> wrestling with maven? ;)
>>>>>>
>>>>>>
>>>>>> Jeanfrancois Arcand-2 wrote:
>>>>>>>
>>>>>>> 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
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>> ---------------------------------------------------------------------
>>>>>>> To unsubscribe, e-mail: users-unsubscribe_at_grizzly.dev.java.net
>>>>>>> For additional commands, e-mail: users-help_at_grizzly.dev.java.net
>>>>>>>
>>>>>>>
>>>>>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe_at_grizzly.dev.java.net
>>> For additional commands, e-mail: users-help_at_grizzly.dev.java.net
>>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe_at_grizzly.dev.java.net
>> For additional commands, e-mail: users-help_at_grizzly.dev.java.net
>>
>