You're trying to connect with the userId in your script.  You need to
connect with the token.  I made the same mistake the first time :)

BTW,  here's a collaborative whiteboard demo with the channel API :

http://goo.gl/F5rb2


Luis


On Thu, Dec 16, 2010 at 3:26 AM, Tarun <[email protected]> wrote:

> I have been trying to use the newly launched Channel API on SDK 1.4 in
> my project. I try to push a message to client which actually pops up a
> notification but I am getting the ChannelFailureException.
> Here is the code:
> TestServlet Where the token is created:
> public void doGet(HttpServletRequest req, HttpServletResponse resp)
>                        throws ServletException, IOException {
>                PrintWriter out = resp.getWriter();
>                resp.setContentType("text/html");
>                // Creating the userID on the basis of the session id
>                String userId = req.getSession().getId();
>                // Starting the ChannelService of the channel API
>                ChannelService channelService = ChannelServiceFactory
>                                .getChannelService();
>                // Creating the client token
>                String token = channelService.createChannel(userId);
>                req.getSession().setAttribute("token", token);
>
>                out.println("<html>");
>                out.println("<head>");
>                out.println("<title>This is a servlet which will be used to
> try the
> new Channel API</title>");
>                out.println("</head>");
>                out.println("<body>");
>                out.println("<a href=\"/ChannelAPI.jsp\">Click Here</a> to
> recieve a
> notification on the next page using channel API");
>                out.println("</body>");
>        }
> }
>
> Channel API.jsp
> <script>
>    channel = new goog.appengine.Channel('<%= userId%>');
>    socket = channel.open();
>    //socket.onopen = onOpened;
>    socket.onmessage = onMessage;
>    socket.onerror = onError;
>    socket.onclose = onClose;
>    onMessage = function (message){
>        $.pnotify({
>                        pnotify_title: 'Regular Notice',
>                        pnotify_text: message.data
>                });
>    };
>
>    onError = function (description,code){
>        $.pnotify({
>                        pnotify_title: 'Uh Oh!',
>                        pnotify_text: 'something went wrong',
>                        pnotify_type: 'error',
>                        pnotify_hide: false
>                });
>    };
>  </script>
>
> Send Message servlet:
> public void doGet(HttpServletRequest req, HttpServletResponse resp)
>                        throws ServletException, IOException {
>
>                String userId = (String)
> req.getSession().getAttribute("token");
>                ChannelService channelService =
> ChannelServiceFactory.getChannelService();
>                channelService.sendMessage(new ChannelMessage(userId,
>                                "This is the message that has been sent"));
>
>        }
>
> }
>
> The stack trace I got
> Uncaught exception from servlet
> com.google.appengine.api.channel.ChannelFailureException: An
> unexpected error occurred.
>        at
>
> com.google.appengine.api.channel.ChannelServiceImpl.sendMessage(ChannelServiceImpl.java:
> 59)
>
> Can you tell me if there is something wrong with the code or with the
> Channel API?
>
> Thanks in advance,
> Tarun
>
> --
> You received this message because you are subscribed to the Google Groups
> "Google App Engine for Java" group.
> To post to this group, send email to
> [email protected].
> To unsubscribe from this group, send email to
> [email protected]<google-appengine-java%[email protected]>
> .
> For more options, visit this group at
> http://groups.google.com/group/google-appengine-java?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine for Java" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=en.

Reply via email to