How to get the client IP? - scala

While this sounds silly, I haven't been able to find a way to get the IP of the client in Play 2.0. It was available in 1.2.x as Http.Request.remoteAddress, but 2.0 (I primarily checked the Scala API, but I did a quick check of the Java one too) only seems to provide information about the server side of the request in play(.api).mvc.Request. Is there something I'm missing? The closest hack I can think of right now is setting it up behind a reverse proxy and then checking X-Forwarded-For, but this doesn't work too well in dev.

EDIT:Coming back to this answer, this was added in playframework 2.0.2: see release announcement on https://groups.google.com/forum/#!msg/play-framework/Z97GQ2VnR5M/T-STGaeuN68J%5B1-25%5D and more importantly the API documentation at http://www.playframework.org/documentation/api/2.0.2/scala/index.html#play.api.mvc.Request
As you can see there is now support for Request.remoteAddress
Original:
There is currently a bug open for this in the tracker: https://play.lighthouseapp.com/projects/82401/tickets/256-add-back-requestheaderremoteaddress
I think that hacking the play2.0 libraries to include the linked patch is currently the best bet. It is probably still cleaner than to use a proxy with the sole purpose of adding XFF headers, and using those to determine the IP.

Please check this Github project at https://github.com/orefalo/play2-xforward
I took the code from Play1 and ported it to Play2, it should work the same.
Still a work in progress...

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.

CORS and GWT does it work now?

I have been trying to get cross domain RPC calls to work on my GWT app because I would like to deploy my java script directly onto a users mobile device and then have it make RPC calls to the Google App Engine.
App currently works fine but only if the JS is downloaded on the fly to the client. I see this issue on gwt from 2 yrs ago. Any know if it is still a problem or had any luck with cross Domain RPC calls?
Yes, you can do it, see here: http://css.dzone.com/articles/cross-site-requests-gwt
However this requires fairly modern browser so if you are after support also on older devices, than JSONP is safer bet (for that you can use JsonpRequestBuilder or RestyGWT).
EDIT: I just realised that you asked specifically about RPC. So this does not answers your question, but might help you.
I only bumped into a work around suggested around 2010 in a blog. It is seriously hacky though.
Maybe we can try using some ideas from http proxy on my GWT server-side code
GWT discussion on same topic - https://groups.google.com/forum/#!msg/google-web-toolkit/TFZsxQIeQXs/cQtKHVKCAr8J
Note - Based on Broyer's comment you might want to re-evaluate your requirements!!!

Using WebSockets in Objective-C

I have tried, unsuccessfully, to use websockets in objective-c with the following two libraries:
http://code.google.com/p/unitt/wiki/UnittWebSocketClient
https://github.com/zootreeves/iOS-WebSockets
In both cases I was unable to establish even a basic connection to a server (runnning on localhost). I was wondering if someone could please provide or point me in the direction of some code that will just simply connect to a server via a websocket and/or perform a handshake.
Ideally, it would be nice if the code could use one of the above libraries, but at this point I'm open to anything that'd work.
I've posted about some issues with UnitT beore but I haven't received any feedback so I'm not sure exactly what step I'm messing up on. Appreciate any help, thanks!
We just released SocketRocket. It supports the latest standard, RFC 6455, which neither ZTWebSocket, nor Unitt does. No CocoaAsyncSocket needed to boot.
Also, libPusher is experimenting with SocketRocket too.
The libPusher library uses the ZTWebSocket object. And we have a number of clients who've developed iOS applications against our service. So, the ZTWebSocket object works and should be a good starting point. The libPusher library would be a good reference for usage.
The key to making UnitT work is to find out what version of the specification is your server running. Then you use the correct version for the client. The latest (rev17) of the specification FINALLY allows for multiple versions and having the server send back an appropriate response, but none of the prior versions do. Therefore, you may not receive a meaningful error from the server, just a disconnection. Do you know what version your server is running?

Play not answering HTTP requests

I'm currently exploring similar alternatives to Ruby on Rails, and have been considering Playframework using Scala (cuz I'm not fond of Java).
Problem is, even if the default sample of application works very fine, everytime I try doing actual work with Playframework, it end up with it not answering HTTP requests.
It compiles after the first request, but doesn't answer it.
Then it ignores every other request (not even re-compiling when I changed stuff).
It does kick out an user typing an incorrect request, but it never times you out if the request is correct.
What is this ?
I'm using Playframework 1.2.3 with the Scala module. Is there any way to get a better insight at what's happening ?
So it never times out, isn't it? as if it was compiling forever?
If yes, maybe you have problems with the Scala compiler which is slower than Java compiler and requires more stack. Generally if you don't have enough stack, it should crash with a StackOverflow.
YOu can try to run play with "play run -Xss1024k" for example to increase the stack size.
If you get empty answer, it means the problem is somewhere else like routes or bad object returned from your controller.
Anyway, Play-Scala is still young and in evolution so it's not a reliable solution for an entreprise solution if you're not yet an expert in Scala and don't already know Play IMO. It's already robust and stable but not well documented and as complete as Java version.
Finally, you say you're not found of Java and it's something I can understand but you should really give a try to Play/Java since it's completely different from any other Java stuff. I can say that because I'm an old Java developer and find the language getting a bit outdated in its syntax and basic features. I don't really like Java EE web frameworks in general because they are not really productive and user-friendly. When I found Play more than one year ago, it was like a breath of air for me. You get the best of modern web frameworks and the best of the Java world which are all the robust and approved entreprise tools coming from opensource. I've never been deceived by it since this time.

How do I use mod_perl2 and Apache Bucket Brigades?

I'm writing an application to do proxying and rewriting of webpages on the fly and am pretty settled on using mod_perl2 - there is an existing implementation using mod_perl (v1) that I'm working from. In mod_perl2, there's this idea of APR::Brigades and APR::Buckets which, from my vague understanding, are an efficient way to do the sort of filtering & rewriting that I want. I can't, however, find anything but the Perldoc pages for these modules, so I'm really quite unsure how to utilize them.
Can anyone explain mod_perl2 Bucket Brigades to me, point me to a tutorial, or even show me some open-source app that uses mod_perl2 that I could learn from?
Buckets and Brigades are native concept to the Apache Portable Runtime. You'll find ample examples of the native API, with a HTTP-specific slant, in the source code for Apache HTTP Server modules like mod_proxy, mod_deflate, and mod_substitute.
See the filter info here:
http://www.apachetutor.org/dev/#filter
Then take a peek at the previously mentioned Apache HTTP Server modules.
There seems to be a simple perl-specific filter here:
http://perl.apache.org/docs/2.0/user/handlers/filters.html#Bucket_Brigade_based_Output_Filters