Re: 500 Server Error

37 views
Skip to first unread message

Peter Ondruška

unread,
Nov 28, 2012, 11:27:47 AM11/28/12
to google-a...@googlegroups.com
Check your application log.

On Wednesday, November 28, 2012 4:21:54 PM UTC+1, bo wrote:

Hi,

I just tried my first java servlet with google app engine. It works fine at localhost (Eclipse: Run As > Web Application), but it dosen't work at the Google App Engine (500 Server Error).

The error message is not really meaningful.

Error: Server Error

The server encountered an error and could not complete your request.

If the problem persists, please report your problem and mention this error message and the query that caused it.

How can I proceed to find the problem?

package de.bvl.myhighscoreserver;

import java.io.IOException;

import java.util.List;

import javax.servlet.http.*;


import com.google.appengine.api.datastore.DatastoreService;
import com.google.appengine.api.datastore.DatastoreServiceFactory;
import com.google.appengine.api.datastore.Entity;
import com.google.appengine.api.datastore.FetchOptions;
import com.google.appengine.api.datastore.Key;
import com.google.appengine.api.datastore.KeyFactory;
import com.google.appengine.api.datastore.Query;


@SuppressWarnings("serial")
public class MyHighscoreServerServlet extends HttpServlet {
public void doGet(HttpServletRequest req, HttpServletResponse resp)
throws IOException {
String game = req.getParameter("game");
String name = req.getParameter("name");
String pointsStr = req.getParameter("points");
String maxStr = req.getParameter("max");
int max = 10;
if(maxStr!= null){
max = Integer.parseInt(maxStr);
}
int points = 0;
if(pointsStr != null){
points = Integer.parseInt(pointsStr);
}
if(points>0 && name!=null){
addHighscore(game,name,points);
}
returnHighscores(resp,game,max);
}
private void returnHighscores(HttpServletResponse resp, String game, int max) throws IOException {
// TODO Auto-generated method stub
DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
Key gameKey = KeyFactory.createKey("game", game);
Query query = new Query("highscore", gameKey);
query.addSort("points", Query.SortDirection.DESCENDING);
List<Entity> highscores = datastore.prepare(query).asList(FetchOptions.Builder.withLimit(max));
for(Entity e : highscores){
resp.getWriter().println(e.getProperty("name")+","+ e.getProperty("points"));
}
}
private void addHighscore(String game, String name, int points){
DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
Key gameKey = KeyFactory.createKey("game", game);
Entity highscore = new Entity("highscore",gameKey);
highscore.setProperty("name", name);
highscore.setProperty("points", points);
datastore.put(highscore);
}
}

THX in advance
Bo
Reply all
Reply to author
Forward
0 new messages