views:

688

answers:

5

I want to pass a parameter 'A1B2C3' to a GWT application based on Google App Engine. I do it like www.example.com/index.html?key=A1B2C3. Although it's working, I'd like to use pretty URLs. Is it possible to do URL rewriting on Google App Engine? I couldn't find out how.

www.example.com/A1B2C3

instead of

www.example.com/index.html?key=A1B2C3

I'm using Google App Engine and GWT. All in Java.

+2  A: 

You need to configure the application (see here). In other words, you need to "wire" the patterns you want.

From the manual, an example:

<servlet-mapping>
    <servlet-name>redteam</servlet-name>
    <url-pattern>/red/*</url-pattern>
</servlet-mapping>

<servlet-mapping>
    <servlet-name>blueteam</servlet-name>
    <url-pattern>/blue/*</url-pattern>
</servlet-mapping>
jldupont
Thanks for your answer. I've tried this before, but I only see how this works with Java servlets. However, I programmed the application in GWT and there I don't have the abstraction of servlets. Any idea how this can work with GWT?
Mike Brecht
Look at URL rewriting in your HTTP server - like in Apache (http://httpd.apache.org/docs/2.0/misc/rewriteguide.html) or nginx (http://wiki.nginx.org/NginxConfiguration#Rewrite_examples).
Igor Klimer
Thanks. But seems like this doesn't work on Google App Engine.
Mike Brecht
with GWT, you go from "page to page" usually through an "#page" URL pattern - that's how the GWT application doesn't get reloaded on each page change. If you really want to navigate away from a page, then you'll end up having to reload the GWT application on each new page... that's not a very efficient way of using GWT.
jldupont
Hm not this is not how I navigate within the application. However, users need to be able to get links to the forms they've created, and they need to be able to distribute these URLs (e.g. www.questionform.com/form.html?key=123 - however, I'd like to make this nicer by giving them URLs like www.questionform.com/123
Mike Brecht
Then distribute the URL to the form using the pattern "/#/formKey". The usual practice with GWT is to perform AJAX calls to the server.
jldupont
Cool, thanks! That sounds like a cool hack.
Mike Brecht
@Mike Brecht: I see you are new around here. Have Fun! (BTW, have you read the FAQ? For the questions you ask, it is customary to "accept" the answer that is "best" to your liking. Cheers.
jldupont
+2  A: 

This is a cool question. I figured out how to do it for python as well.

app.yaml:

- url: /test/(.*)
  script: test.py \1

test.py:

#!/usr/bin/env python

import sys

def main():           
  for arg in sys.argv:
     print arg

if __name__ == '__main__':                               
  main()
Kousha
He's asking about java. Maybe this answer would be better on a python based question?However I do agree this would work in python.
Josh Patton
Yes. I do realize this was a java related question, but I was looking for this similar thing when searching on the internet. I found this article, but I wanted to know how to do it with python. When I figured it out, I thought I should put it up here so other people wouldn't have to search as far as I did.
Kousha
+1  A: 

Try UrlRewriteFilter: http://tuckey.org/urlrewrite/ it is a plain ol' JEE filter, so it should work.

Jeroen
+1  A: 

Save yourself some time and use Restlet. You can do exactly this and I've done this in two different projects. It's quite straight forward. If you need some help, let me know.

JP
A: 

Here is another project that I think may really help you:

It's called restful-gwt... it's pretty slick too: http://code.google.com/p/restful-gwt/

Good luck!

JP