Search code examples
javagwt

How to mask browser URL with GWT


I'm currently looking for masking GWT browser URL.

Currently, when I access to an application page, my browser URL looks like this:

http://localhost:8080/app/#!config/users

or:

http://localhost:8080/app/#!b/reports?7900

I'd like to mask URLs with some kind of encoding like this:

http://localhost:8080/app/#!config/sdsuwksp

For example Vaadin Framework do exactly the same (Vaadin Demo), but I don't know how to obtain this in my application.


Solution

  • I solved it with a com.mvp4g.client.history.PlaceService override. By overriding convertToken and tokenize methods I'm able to mask the GWT browser URL.

    public class MyPlaceService extends PlaceService {
    
    @Override
    protected void convertToken(String token) {
        super.convertToken(UrlTokenizer.decode(token));
    }
    
    @Override
    public String tokenize(String eventName, String param) {
        
        return UrlTokenizer.encode(eventName, param);
    }}
    

    Finally, in my gwt.xml file I've added this lines to "replace" PlaceService class with my own class:

    <replace-with class="com.comp.app.gwt.mvp4.myPlaceService">
        <when-type-is class="com.mvp4g.client.history.PlaceService" />
    </replace-with>