# GWT hosted mode (debug) and rails

**URL:** <https://www.ruby-forum.com/t/gwt-hosted-mode-debug-and-rails/122214>\
**Category:** Rails\
**Created:** [December 5, 2007, 5:00pm UTC](https://www.ruby-forum.com/t/gwt-hosted-mode-debug-and-rails/122214 "2007-12-05T17:00:05Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![David\_Stubbs](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/3ab097/32.png) [@David\_Stubbs](https://www.ruby-forum.com/u/David_Stubbs)\
**Post date:** [December 5, 2007, 5:00pm UTC](https://www.ruby-forum.com/t/gwt-hosted-mode-debug-and-rails/122214/1 "2007-12-05T17:00:05Z")

</div>

Hi all,

First of all sorry about the double posting I thought it might be  
useful for both lists.

We’ve have a project that’s moving on quite quickly now using GWT for  
display and Rails for the backend. Our application uses JSON for  
communication, it works very well. The only problem we’ve had is debug  
in hosted mode. Below is a solution that works for us, I hope that  
other people might find it useful.

WARNING: before you run your application in debug, ensure that you  
DON’T have the compile module in your public directory…  
we remove it with a rake task just before we start up the hosted mode.  
Forget and it will run, but debug ing will not work.

1. Add the following to your config/routes.rb

# repeat this for each GWT module

map.connect “my.gwt.test/\*path”, :controller =\> “gwt\_proxy”, :action  
=\> “proxy”

1. create a controller called gwt\_proxy and add the following code to it

# !!! BIG FAT WARNING !!!

# 

# The below code works but isn’t nice.

# 

require ‘net/http’  
class GwtProxyController \< ApplicationController

# turn off the proxy

session :off

# done authenticate the proxy requests

skip\_before\_filter :check\_authentication

# protect ourselfs from the loop that normal browswer get into

before\_filter :reject\_compile\_js\_requests

# URL of gwt’s in built tomcat server

GWT\_SERVER = “[http://localhost:8888](http://localhost:8888)”

# warning not a hosted mode broswer

NONE\_HOSTED\_MODE = “== WARNING PROXY REQUEST NOT HANDLED, YOU MUST  
NOT USE A NORMAL BROSWER==”

# GWT tomcat server not responding

PROXY\_NOT\_UP = “== GWT Server is not running at #{GWT\_SERVER} ==”

# this filter stops the recusive look that normal - no hosted mode

broswers get them selfs into.  
def reject\_compile\_js\_requests  
if request.query\_string.ends\_with?(“compiled”)  
puts NONE\_HOSTED\_MODE

```
   render :text => NONE_HOSTED_MODE,:status => 500
   return false
 end

```

end

# Proxy a request to gwt’s in built tomact server

# TODO: we should really proxy status codes and headers…

def proxy  
begin  
req =  
Net::HTTP.get\_response(URI.parse(“#{GWT\_SERVER}/”+request.path))  
text = req.body  
render :text =\> text  
rescue  
puts PROXY\_NOT\_UP  
render :text =\> PROXY\_NOT\_UP, :status =\> 500  
end  
end  
end

1. Start up your the gwt hosted mode browser with something like this,  
notice the url at the end and the debug information.

java -XstartOnFirstThread -Xmx512M -Xdebug -  
Xrunjdwp:transport=dt\_socket,server=y,suspend=n,address=1035   
-Dfile.encoding=MacRoman -classpath   
com.google.gwt.dev.GWTShell   
-style OBFUSCATED -logLevel DEBUG -whitelist ^http.\*   
[http://localhost:3000/my.gwt.test/test.html](http://localhost:3000/my.gwt.test/test.html)

1. Start up your IDE and tell it to debug on the port shown in the  
command above (1035)

2. Enjoy debugging

David
