GWT Websockets with Elemental - gwt

I would like to use websockets technology in a GWT web application.
I know that there are some implementations using Commet and Atmospere, but i would like to avoid them as they are actually a long lived HTTP request to the server.
I have my own implementation of web sockets and i would like to know if someone knows a client side library or way that i can achieve to communicate between my client/server with websockets. More specifically, i heard that GWT Elemental package provides this kind of functionality. I researched (googled) about that but couldn't find anything specific.
Could someone point me to the right direction? Any suggestions except GWT Elemental are welcomed as well.
EDIT:
I found out the below link, which is GWT-Elemental interface. I can see that it is a ReleaseCandidate version, but i would be willing to try using the functionality. So if anyone has used that before i would like to know his/her comments/suggestions.
http://grepcode.com/file/repo1.maven.org/maven2/com.google.gwt/gwt-elemental/2.5.1-rc1/elemental/html/WebSocket.java?av=f

Well I haven't used Websockets from Elemental but the FileReader API and it worked fine.
However you have to take into account that Elemental is highly experimental.
Some of the specifications in the IDL of Webkit have changed since the Elemental library was auto-generated and thus won't work.
So you might need to find workarounds, etc.
Working with Elemental is quite straightforward.
You usually use Browser or Window from the package to get an instance of the class you want to work with.
Something like this:
Window window = Browser.getWindow();
WebSocket webSocket = window.newWebSocket(URL);
webSocket.setOnmessage(new EventListener() ....);
websocket.send();

Related

Is there a good, maintained solution for Server Push with Google Web Toolkit?

The GWT RPC mechanism is great for client initiated communication. We're looking for a solid, supported way to do Push notifications from the server to the clients. All the solutions we can find are several years old and don't seem to work with newer versions of Eclipse and GWT.
We're prepared to use the Google App Engine if that helps.
We can roll our own socket code if that helps, as well, but we are Java developers. Writing JavaScript to do socket work would be a last resort, although if that's what it takes and there are examples we could probably handle it.
Any pointers to sample code or suggestions as to packages to use are greatly appreciated.
You could use the Atmosphere Framework. They have a gwt20 module which works great with gwt.
As far as I know there are two possible solutions.
First you can use Errai. Errai has an event bus which also can be used on the server:
https://docs.jboss.org/author/display/ERRAI/Messaging+API+Basics?_sscc=t
I did not use it, but think it is possible to do server push.
The second framework I know is gwt-comet:
https://github.com/rzschech/gwt-comet
I did not use one of them. But if I would look for a server push solution, I would give gwt-comet a try.

HTTP messaging gateway with Scala

I'm developing a gateway that will be located between mobile web apps and web services on backend systems. The purpose of this gateway is to protect web apps against changes to backend web service api's, to introduce concurrency, transform messages, buffering, etc.
My proposed architecture is as follows:
Platform independent mobile web apps using PhoneGap (done)
Gateway is a web service using Scala for business logic and ZeroMQ for message passing (new)
Backends are existing web services (existing)
The gateway is purely responsible passing, translation, aggregation, etc. of messages and does not need to keep state or do user authentication at this point - it's simply responsible for being a single interface that knows how to talk to mobile apps on the one side and one or more services on the other side.
I'm strongly considering using Scala as the development language because it seems well suited for this type of application, but what would be the correct architecture for such a Scala service? I looked at frameworks such as Lift and Play and also considered doing a simple "java" based web service and just use Scala as to implement my business logic. I believe strongly in keeping things as simple as possible. I'm wary of complicated setups and thousands of lines of dead code in frameworks that may never be used. On the other side, limiting oneself to a 'role your own' solution and creating a lot of work and having to maintain code that may have been part of existing solutions is also not ideal.
Some things to consider: I'm the architect and developer, but my knowledge of Scala is limited to the first half of "Programming in Scala, Second Edition". Also, my time is very limited. Still, I want to get this right the first time.
I'm hoping that some clever gent or dame will provide me with insights to this type of solution and maybe a link or two to get started quick. I really need to get going FAST, but hope that the experience or insights of another professional could help me avoid pitfalls along the way. Any insights to development environments and tools will also be helpful. I have to develop on Mac (company rules) but will be deploying on Ubuntu server. I'm currently juggling between installs of Eclipse or Idea as IDE's and the scala compiler or sbt for building.
UPDATE
Thanks for all the potential answers below. I had a look at each and every suggestion and all of them have merit. The problem is now to bet on the right horse. Spray is possibly the simplest solution to the problem, but I also found Finagle. It seams like a stunning solution to my problem. I'm a bit concerned that it is built on top of Netty instead of Akka. Does anyone see any problem with that. I was hoping to keep my solution as purely Scala as possible, but Finagle appears to be the most mature of the lot. Any ideas?
It might be worth taking a look at Akka, which provides a lightweight framework for writing concurrent, fault-tolerant applications on the JVM, as well as useful built-in abstractions for writing web services. In addition, the Spray project looks like it could be useful for your purposes, providing HTTP server and client libraries on top of Akka (Although, unlike Akka itself, I haven't used this so myself so can't vouch for it).
If you're using a web service that is purely for other services, then an Akka based service like Spray or Blueeyes is probably your best bet. You can use Jerkson to do the JSON mapping to and from your case classes and use Akka-Camel to link to ZeroMQ.
As mistertim says, Akka is a good option. I'm biased, but I think Lift and its RestHelper is a fantastic way to go also (I've built several APIs for iPhone apps using Lift). Beyond those, I know several people who are very happy with Unfiltered.
Unfiltered is very interesting option if you want to keep it lightweight, as is not a full blown web framework.
To be honest, the documentation can use more detail, but to provide a web service you just write:
object MyService extends unfiltered.filter.Plan {
def intent = {
case req # GET(Path ("/myendpoint")& Params(params)) =>
for {
param1<-params("param1")
param2<-params("param2")
} yield ResponseString(yourMethod(param1,param2))
}
override def main(args:Array[String]) = unfiltered.jetty.Http.anylocal.filter(MyService).run();
}
Very useful if you don't want to use a framework and don't want to mix java/java annotations with Scala (otherwise, you have the usual java solutions)
Still, I would recommend to look into Akka if you think you think actors will fit your problem
If your system is middle-ware and get the things done quickly, then Spray will be a best. Spray was developed on top of Akka. Akka has ZeroMQ support.
in future if you are going to add some other web like module along with your middle-ware, then choosing Lift + Akka will be better because, Lift also provides Spray like web service stuff + it will be easy to start developing other modules.
You can choose SBT as your build, there are some project templates, template generation tools available, so you can get the project build very quickly.
In my experience , SBT + InteliJ Idea works well, have a look on sbt-idea plugin
Spray Project Template
Lift Project Template Generator

What do I need to learn before I can start using Lift?

I know Scala. I've used mongoDB, redis, sbt, ... backend stuff.
I know basic HTML, CSS and JavaScript but have never done real web development.
I don't know what AJAX is. I don't really know any frontend stuff.
What should I learn before I start trying to tackle Lift?
If you know Scala, you are pretty much set on the programming side.
On the other hand, Lift requires HTML/CSS templates. In fact, it is completely separate from programming, so that a professional web designer can work on them, while the programmer works on the code. If you can revise your HTML/CSS stuff, it will help.
You don't need to know AJAX -- that part Lift takes care of for you.
So, it seems you are mostly set. I strongly recommend Timothy Perret's Lift in Action, from Manning. Though the book hasn't been released yet, you can get the Manning Early Access Program (MEAP) for it and, as it happens, the whole book has been written already.
If you already know Scala, learn some basics of web development and how Java handles it:
HTTP protocol
Servlets (also know what JSP is)
AJAX

GWT, Sproutcore or Cappuccino

I am about to start a new webapp that will be running on P/GAE and reagarding the front end we would like to use one of the mentioned frameworks (GWT, SC, Cap).
Which one do you think is the most developer friendly? It seems that Cappuccino looks stunning but you have to learn Obj-J. Sproutcore seems nicer (since there is only JS) but I could not say I am impressed with the docs plus some of the demos are broken.
GWT on the other hand is very mature but I have the feeling that using Java may slow you down as you cannot use some of the JS quirks on the other hand there is vibrant ecosystem around it.
I think the answer depends on what type of developer are you?
For me, I'm comfortable with Javascript and like the ability to manipulate the browser DOM so that I can implement features that may not be in the framework. That's why I prefer Sproutcore.
Checkout http://www.infoq.com/news/2009/09/sproutcore-1-0.
I have to agree with you that documentation is limited. However, I've found wiki useful and the community really helpful.
GWT is a very nice choice if you're using GAE-Java because then you can develop server-side and client-side in the same language. If you're using Python on the server-side, you won't be able to use GWT's simple RPC calls to serialize objects to/from the browser. It's still a nice framework though.
GWT does allow you to write JS-native code if needed, so you can "use some of the JS quirks" if you need to.
One warning: GWT apps are totally AJAX, so they can't really be seen by search engines (a general problem with AJAX, not with GWT specifically)

Is there a scala version of Python's Mechanize?

I have used mechanize in Python with great success. However, I am trying to learn Scala. I have an IRC bot that I would like to add some features to, mostly having to do with screen scraping web pages from our corporate intranet. That requires being redirected to a corp-wide login page, then going to the destination, then having to possibly submit another login.
Does anyone know of something that I can use from Scala to get this sort of functionality?
I don't know any Scala effort of similar functionality. Pending answers to the contrary, I advise you to look for Java libraries of similar functionality.
The closest Java libraries I can think of are browser drivers. The most well-known are Selenium and WebDriver. The latter also offers an in-process mode.
Since Selenium's API isn't all that pleasent to use, a couple of projects sprung-up with DSLish façades: Selenium DSL and Selenium Inspector.
A caveat is that they are all oriented towards testing of web application, so they might be lacking in features that attend your case.