server push example with GWT?

421 views
Skip to first unread message

Edward Montgomery

unread,
Jun 1, 2015, 2:14:54 PM6/1/15
to google-we...@googlegroups.com
Can anyone point me to a tutorial or example of how to implement server push with a GWT application?

Is this typically done by somehow matching a JavaScript socket on one end to a Java socket on the other?

Thanks.

Greg

unread,
Jun 1, 2015, 2:22:00 PM6/1/15
to google-we...@googlegroups.com

Joseph Gardi

unread,
Jun 2, 2015, 2:10:28 PM6/2/15
to google-we...@googlegroups.com
Check out errai bus. it worked great for me.

Mat

unread,
Jun 4, 2015, 5:06:31 AM6/4/15
to google-we...@googlegroups.com

Thomas Lefort

unread,
May 9, 2017, 7:52:03 AM5/9/17
to GWT Users
Has anybody managed to run an example of websockets with the embedded jetty in gwt 2.8? ie only using the jsr API. I just can't get it to work, the ServerEndpoint annotation doesn't get picked up. I also tried with the "manual" registrarion, eg with serverContainer.addEndpoint, but I have other issues there too (class cast exception). On the other hand it seems to work fine on my standalone server, so it feels like it's a problem with the embedded version.

Thomas Broyer

unread,
May 9, 2017, 8:44:24 AM5/9/17
to GWT Users


On Tuesday, May 9, 2017 at 1:52:03 PM UTC+2, Thomas Lefort wrote:
Has anybody managed to run an example of websockets with the embedded jetty in gwt 2.8? ie only using the jsr API. I just can't get it to work, the ServerEndpoint annotation doesn't get picked up. I also tried with the "manual" registrarion, eg with serverContainer.addEndpoint, but I have other issues there too (class cast exception). On the other hand it seems to work fine on my standalone server, so it feels like it's a problem with the embedded version.

…and not something we're willing to "fix", fyi.

(in case it wasn't clear: we're really pushing towards using external servlet containers, and using the CodeServer endpoint rather than DevMode integration; DevMode is handy but people regularly try to do "too much" with it –just like you in this case–, spend an awful lot of time trying to make it work, then find that their hacks break with a new version of GWT and start complaining, etc. So, your time is much better spent setting up a developer experience where you run an external server; if it were only me, DevMode would only serve static files)

Thomas Lefort

unread,
May 9, 2017, 9:18:38 AM5/9/17
to GWT Users
Hi Thomas,

Thanks for the reply. Sure I don't expect anyone to fix it for me, just to know if it is a problem my end or if I am trying to do too much with the embedded server indeed.

I am happy with running an external server, however, it would be nice if I could get a similar level of debug functionality, ie breakpoint in server code, all the superdev mode feature, etc... Any good step by step manual? I tried the noserver flag (in Intellij) and running a server aside (as per GWT project page instructions) but it doesn't provide the goodies I mentioned previously, for instance, it doesn't update the client when I change it and reload it. To be honest, I can't really see how the magic would happen without some connection between the two. I am probably missing a key element/step :)

Thomas Broyer

unread,
May 9, 2017, 9:34:13 AM5/9/17
to GWT Users


On Tuesday, May 9, 2017 at 3:18:38 PM UTC+2, Thomas Lefort wrote:
Hi Thomas,

Thanks for the reply. Sure I don't expect anyone to fix it for me, just to know if it is a problem my end or if I am trying to do too much with the embedded server indeed.

I am happy with running an external server, however, it would be nice if I could get a similar level of debug functionality, ie breakpoint in server code, all the superdev mode feature, etc... Any good step by step manual? I tried the noserver flag (in Intellij) and running a server aside (as per GWT project page instructions) but it doesn't provide the goodies I mentioned previously, for instance, it doesn't update the client when I change it and reload it. To be honest, I can't really see how the magic would happen without some connection between the two. I am probably missing a key element/step :)

Assuming a server setup that correctly reloads (redeploys the webapp) whenever server-side code (and/or resources) changes (this is outside the scope of GWT; same for debugging).
You run CodeServer with launcherDir pointing to a folder served by the server (or DevMode with -noserver, and -war pointing to that same folder), it then generates a *.nocache.js file in the directory (and copies public resources there too).
When you load your page in the browser, the *.nocache.js is loaded and triggers a compilation in the CodeServer.
Whenever you change client-side code, refresh the page in the browser and it'll trigger a recompilation.
Whenever you change server-side code, redeploy the webapp (depending on the setup, this can be entirely automatic, or involve some manual action).
To debug client-side code, use the browser's devtools, or your usual SDM/IDE integration (I never used any, so can't really comment)

When using my gwt-maven-archetypes for example, "mvn tomcat7:run" will automatically redeploy the webapp whenever resources or classes change in target/classes. Most IDEs will happily compile your code (automatically on save, or triggered by a keyboard shortcut) into target/classes, which would trigger a redeploy. "mvnDebug tomcat7:run" (or running the Maven goal for debug in your IDE; for example, in Eclipse, Debug As… → Maven… → tomcat7:run) allows you to debug your server-side code. And "mvn gwt:codeserver" launches SDM for the client-side code.

AFAIK, the GWT Eclipse Plugin has some "one click" way of running both a server runtime (configured in Eclipse WTP) and SDM, and I'd assume that Eclipse is smart enough to make redeploying after changes either completely automatic or only a keyboard shortcut / click away.

The "connections" you're talking about are the standard JDWP protocol for connecting to a JVM to debug the server-side code in the server runtime, and SDM with SourceMaps (and possibly a "remote debugging" protocol of your browser if you want IDE integration rather than debugging right in your browser).

Thomas Lefort

unread,
May 9, 2017, 9:42:00 AM5/9/17
to GWT Users
Aw thanks Thomas, I feel guilty to take so much of your time.

I did just figure out the -war option but ran into another issue... I am running the jetty server from Intellij and the CodeServer with the no server and war options as suggested. However when it comes to updating the code (which it does ;-)) it gets stuck because the jetty server seems to be locking the directory. I am basically getting a [ERROR] Can't update launcher dir message. I guess this is something to do with Intellij and I need to look into it a bit more. I just mention it in case someone has had the issue before and is sympathizing with my problems ;-)

Thomas Lefort

unread,
May 9, 2017, 11:57:07 AM5/9/17
to GWT Users
OK, finally got it to work, but had to add the following to my web.xml (so it was jetty all along), the webdefault didn't work

    <servlet>
        <servlet-name>default</servlet-name>
        <servlet-class>org.eclipse.jetty.servlet.DefaultServlet</servlet-class>
        <init-param>
            <param-name>useFileMappedBuffer</param-name>
            <param-value>false</param-value>
        </init-param>
        <load-on-startup>0</load-on-startup>
    </servlet>
Reply all
Reply to author
Forward
0 new messages