First Post.
I’m a mobile game developer looking into using the Java version of AppEngine for the backend of an Andriod game. Since the game is written in Java, I figured that I’d use the Java version of AppEngine. I’ve some experience with the Python version of AppEngine, and am finding some difficulty in my migration to the Java version of AppEngine, specifically in relation to URL mapping.
In Python, this is what I was used to:
def main():
application = webapp.WSGIApplication(
[('/', Main),
('/admin', Admin),
('/setScore', SetScore),
('/getScores', SetScores),
('/getUser', GetUser),
('/getCatelog', GetCatelog)
])
webapp.util.run_wsgi_app(application)
The WSGI application would map different URLs to the different request handlers. My question is whether there is equivalent functionality in Java or if a similar approach is even considered best practices in the Java incarnation of AppEngine.
Does Java have an alternate way to achieve this functionality, or is there some alternate paradigm for how Java Servlets handle this sort of thing?
I am aware that the web.xml file gives you the opportunity to map urls to servelets, but I’m not sure if that’s the proper way.
What’s the standard way that one might map URLs in the Java version of AppEngine to have different functionality triggered by different URLs?
Thanks.
Mapping URLs to servlets in web.xml is pretty basic, but might get the job done for you. However, depending on your actual intention, it might be quite cumbersome.
Are you writing a “traditional” web application or a REST service? Then, there are a myriad of frameworks you could choose from. For appengine I learned to use lightweight frameworks, such as Stripes, which I have made some good experience with.
For REST, I recommend Jersey, but there are other options out there, too.
So, in Stripes, for example, you use
ActionBeanswhich are then mapped to URLs. Here is a simple example:Edit: since you are writing a game backend, you might be more interested in a REST service? There are some good tutorials out there, but to give you an impression, it’s quite similar to the example above: