I just re-watched the video from Google IO.  /_ah/channel/jsapi
defaults to polling on the development server but should use comet on
the live server by default.

James

On Nov 29, 8:31 pm, James M <jmort...@gmail.com> wrote:
> Thanks for the tip.  I added the call to the controller to create the
> ChannelService.  However, what's odd is that my implementation is like
> your first attempt.  I had to use the channelId returned from
> ChannelService in the JavaScript when opening the socket.
>
> The other odd thing I'm seeing is that this is polling.  Do you happen
> to have the javadocs for the ChannelAPI?  So far I haven't turned up
> anything specific to Java.
>
> Thanks again,
> James
>
> On Nov 29, 12:01 pm, Scott <shathaw...@gmail.com> wrote:
>
>
>
>
>
>
>
> > Is the HTML snippet the full client code? If so you need to call the
> > createChannel service from the client prior to opening the socket.
> > Also what does the "?key=dev" do for you in your script import?
>
> > Good luck!
>
> > Scott
>
> > On Nov 29, 7:20 am, James M <jmort...@gmail.com> wrote:
>
> > > Hi Scott,
>
> > > I'm trying to follow your example but am getting stuck.  I've created
> > > the following controllers:
>
> > > /** create the channel **/
> > >  public ModelAndView createChannel(HttpServletRequest request,
> > > HttpServletResponse response) {
> > >           ChannelService channelService =
> > > ChannelServiceFactory.getChannelService();
> > >       channelService.createChannel("coupoz");
>
> > >       return constructModelAndView("example");
>
> > >   }
>
> > > /** send a message **/
> > >   public ModelAndView sendMessage(HttpServletRequest request,
> > > HttpServletResponse response) {
> > >       ChannelService channelService =
> > >           ChannelServiceFactory.getChannelService();
> > >                       channelService.sendMessage(new
> > >           ChannelMessage("coupoz","test"));
>
> > >           return constructModelAndView("example");
> > >   }
>
> > > // NOTE:  both controllers return a JSON string.
>
> > > I also have an HTML file:
>
> > > <html>
> > > <head>
> > > <script src="_ah/channel/jsapi?key=dev"></script>
> > > <script>
> > >          var channel = new goog.appengine.Channel("coupoz");
> > >          var   socket = channel.open();
> > >             socket.onopen = function() {
> > >                 console.info("socket opened...");
> > >             }
> > >             socket.onmessage = function(evt) {
> > >                  var o = JSON.parse(evt.data);
> > >                  alert(o);
> > >             }
> > > </script>
>
> > > </head>
>
> > > <body>
> > > </body>
> > > </html>
>
> > > My steps to test are as follows:
>
> > > * Loadhttp://localhost:8888/business/createChannel.do
> > > * Loadhttp://localhost:8888/channel.html
> > > * Loadhttp://localhost:8888/business/sendMessage.do
>
> > > Here is the stack trace that I get when loading the channel.html file:
>
> > > WARNING: /_ah/channel/dev
> > > com.google.appengine.api.channel.dev.LocalChannelFailureException:
> > > Channel for application key null not found.
> > >         at
> > > com.google.appengine.api.channel.dev.ChannelManager.getChannel(ChannelManag
> > >  er.java:
> > > 58)
> > >         at
> > > com.google.appengine.api.channel.dev.ChannelManager.getClientChannel(Channe
> > >  lManager.java:
> > > 73)
> > >         at
> > > com.google.appengine.api.channel.dev.ChannelManager.connectClient(ChannelMa
> > >  nager.java:
> > > 122)
> > >         at
> > > com.google.appengine.api.channel.dev.LocalChannelServlet.doGet(LocalChannel
> > >  Servlet.java:
> > > 64)
> > >         at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
> > >         at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
> > >         at 
> > > org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:
> > > 511)
> > >         at org.mortbay.jetty.servlet.ServletHandler
> > > $CachedChain.doFilter(ServletHandler.java:1166)
> > >         at
> > > com.google.appengine.api.blobstore.dev.ServeBlobFilter.doFilter(ServeBlobFi
> > >  lter.java:
> > > 58)
> > >         at org.mortbay.jetty.servlet.ServletHandler
> > > $CachedChain.doFilter(ServletHandler.java:1157)
> > >         at
> > > com.google.apphosting.utils.servlet.TransactionCleanupFilter.doFilter(Trans
> > >  actionCleanupFilter.java:
> > > 43)
> > >         at org.mortbay.jetty.servlet.ServletHandler
> > > $CachedChain.doFilter(ServletHandler.java:1157)
> > >         at
> > > com.google.appengine.tools.development.StaticFileFilter.doFilter(StaticFile
> > >  Filter.java:
> > > 122)
> > >         at org.mortbay.jetty.servlet.ServletHandler
> > > $CachedChain.doFilter(ServletHandler.java:1157)
> > >         at
> > > org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:
> > > 388)
> > >         at
> > > org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:
> > > 216)
> > >         at
> > > org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:
> > > 182)
> > >         at
> > > org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:
> > > 765)
> > >         at 
> > > org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:
> > > 418)
> > >         at
> > > com.google.apphosting.utils.jetty.DevAppEngineWebAppContext.handle(DevAppEn
> > >  gineWebAppContext.java:
> > > 70)
> > >         at
> > > org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:
> > > 152)
> > >         at com.google.appengine.tools.development.JettyContainerService
> > > $ApiProxyHandler.handle(JettyContainerService.java:349)
> > >         at
> > > org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:
> > > 152)
> > >         at org.mortbay.jetty.Server.handle(Server.java:326)
> > >         at 
> > > org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:
> > > 542)
> > >         at org.mortbay.jetty.HttpConnection
> > > $RequestHandler.headerComplete(HttpConnection.java:923)
> > >         at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:547)
> > >         at 
> > > org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:212)
> > >         at 
> > > org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)
> > >         at
> > > org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:
> > > 409)
> > >         at org.mortbay.thread.QueuedThreadPool
> > > $PoolThread.run(QueuedThreadPool.java:582)
> > > Nov 29, 2010 12:12:17 PM
> > > com.google.apphosting.utils.jetty.AppEngineAuthentication
> > > $AppEngineAuthenticator authenticate
> > > FINE: Got /_ah/channel/dev, returning NOBODY to imply authentication
> > > is in progress.
> > > Nov 29, 2010 12:12:21 PM
> > > com.google.appengine.api.datastore.dev.LocalDatastoreService
> > > $PersistDatastore persist
> > > INFO: Time to persist datastore: 21 ms
> > > Nov 29, 2010 12:12:25 PM
> > > com.google.appengine.tools.development.LocalResourceFileServlet doGet
> > > WARNING: No file found for: /favicon.ico
> > > Nov 29, 2010 12:12:25 PM
> > > com.google.apphosting.utils.jetty.AppEngineAuthentication
> > > $AppEngineAuthenticator authenticate
> > > FINE: Got /favicon.ico with null response, returning null.
>
> > > Any ideas?  Thanks!
>
> > > James
>
> > > On Nov 24, 7:28 pm, Scott <shathaw...@gmail.com> wrote:
>
> > > > I found the problem and now pushing to the client works!!
>
> > > > In the controller that creates the channel, I just need create the
> > > > service and use the same id on the client. Whatever is returned by the
> > > > create channel method is not the id that I need to use to send the
> > > > message.
>
> > > > So this:
>
> > > > >                 ChannelService channelService =
> > > > > ChannelServiceFactory.getChannelService();
>
> > > > >                 String channelId = 
> > > > > channelService.createChannel("coupoz");
>
> > > > >                 return new ChannelModel(channelId);
>
> > > > becomes:
> > > >                 ChannelService channelService =
> > > > ChannelServiceFactory.getChannelService();
>
> > > >                 channelService.createChannel("coupoz");
>
> > > >                 return OK_RESPONSE;
>
> > > > On the client, I just change:
>
> > > > >          var channel = new goog.appengine.Channel(channelId);
>
> > > > to be:
> > > >            var channel = new goog.appengine.Channel("coupoz");
>
> > > > The push then works great, which is really all I needed, but I am
> > > > interested in how to receive though.
>
> > > > On Nov 24, 8:52 pm, Scott <shathaw...@gmail.com> wrote:
>
> > > > > I am trying to use the Channel API in the 1.4.0 preview, but I am not
> > > > > using GWT. Here is what I have done so far:
>
> > > > > 1. Using the Spring framework I have a controller that listens for a
> > > > > channel create request form a client to create a new channel. The
> > > > > controller creates the channel using the following code:
>
> > > > >                 ChannelService channelService =
> > > > > ChannelServiceFactory.getChannelService();
>
> > > > >                 String channelId = 
> > > > > channelService.createChannel("coupoz");
>
> > > > >                 return new ChannelModel(channelId);
>
> > > > > 2. The client, which imports the "_ah/channel/jsapi" script, then
> > > > > creates a channel and opens a socket using the channel id returned by
> > > > > the controller. Here is the client code:
>
> > > > >          var channel = new goog.appengine.Channel(channelId);
> > > > >          var   socket = channel.open();
> > > > >             socket.onopen = function() {}
> > > > >             socket.onmessage = function(evt) {
> > > > >                  var o = JSON.parse(evt.data);
> > > > >                  alert(o);
> > > > >             }
>
> > > > > 3. I then have a button that I can push from the client that calls
> > > > > another controller that sends a message to the client via the channel.
> > > > > I am sending back the channel id in the call from the client. Here is
> > > > > the code:
>
> > > > >             ChannelService channelService =
>
> ...
>
> read more »

-- 
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 google-appengine-j...@googlegroups.com.
To unsubscribe from this group, send email to 
google-appengine-java+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=en.

Reply via email to