Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the GWT base URL or Module Name from the GWT server scope?

Tags:

gwt

I know you can get the GWT module name client side using GWT.getModuleName() or getHostPageBaseURL(), but is it possible to access it from the server?

What I'm after is the base URL of the deployed application. For example, if the GWT app is deployed as http://foo.com/deploy1/MyModule/ what I want to know is that the request came from the base URL of http://foo.com/deploy1/

Simply getting the URI from the HTTP request will give me the full module path, when I really want the base (it will be deployed under different sub-paths at the same domain)

like image 727
dpdearing Avatar asked Jun 27 '11 20:06

dpdearing


3 Answers

getContextPath() will give you the /deploy1 path.

If you need the full URL, you can easily reconstruct it from the other HttpServletRequest properties, or you can start with getRequestURL and tweak the result to replace the path part.

like image 95
Thomas Broyer Avatar answered Nov 18 '22 18:11

Thomas Broyer


You need to understand the relationship between server and client in GWT.

So, you are looking at the usual Greetings GWT RPC stub and you see the client, server, shared folders (and you could add the public folder to place html, jsp or other files directly accessible thro the module's path).

What you probably do not realise is that the server-side responder to a client's RPC request need not be satisfied by a class within the module. Within the module you would have the RPC request definition interface where you define the server-side responder's path @RemoteServiceRelativePath("/hello").

To satisfy the RPC request thro the path "/hello", you do not need to code your servlet inside any module's "server" folder. You could even have

@RemoteServiceRelativePath("/hello.jsp")

or

@RemoteServiceRelativePath("/hello.php")

In fact, I have a login JSP which accepts RPC request from a few modules and it has to find out which module is emitting the request.

Or you could be using RequestBuilder or placing a JSON javascript-include request.

With that in mind, how would a RPC server-side responder be constrained to be defined by any module, regardless that it is placed inside the folder of a particular module? You simply have to have the client inform the server-side responder what module the client belongs to. Using a Map or HashMap as the datatype for RpC transmission would be very helpful. In case you are using REquestFactory, the identification of an entity would be able to tell your server what the module is through the entity object namespace.

http://h2g2java.blessedgeek.com/2009/08/gwt-rpc.html

like image 3
Blessed Geek Avatar answered Nov 18 '22 18:11

Blessed Geek


You can inspect the Referer http header: http://en.wikipedia.org/wiki/HTTP_referrer

like image 1
Peter Knego Avatar answered Nov 18 '22 17:11

Peter Knego