Sure. Yes, I do know the servlet is running. I was able to put a
breakpoint in the GAE servlet to verify the request was hitting the
container. Below is an example of my servlet which I was testing with.
This servlet just uses the user service to retrieve the user's information.
The variable 'user' is always null from the userService.getCurrentUser()
request, which will then send me back the response to redirect me to the
login page - which shouldn't occur from the Android application. When I use
my domain, I have no problems with my request as mentioned before. The auth
tocken I get from my google account on my device will allow me to retrieve
the cookie to automatically make requests on my api.
Unfortunately I am at work at the moment. I will reply here when i get a
change to inspect all the request headers coming into the servlet. Is my
assumption correct that I should just be able to change the base url to my
localhost and the same code should execute? Thanks for the help.
Example of my servlet.
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws
IOException
{
doPost(req, resp);
}
public void doPost(HttpServletRequest req, HttpServletResponse resp)
throws IOException
{
UserService userService = UserServiceFactory.getUserService();
User user = userService.getCurrentUser();
if (user != null)
{
PersistenceManager pm = PMF.get().getPersistenceManager();
Query query = pm.newQuery(Player.class);
query.setFilter("userId == userIdParam");
query.declareParameters("String userIdParam");
List<Player> users = (List<Player>)
query.execute(user.getUserId());
Player currentPlayer = null;
if (!users.isEmpty())
{
currentPlayer = users.get(0);
}
else
{
System.out.println("Players are empty");
currentPlayer = new Player(user);
try {
pm.makePersistent(currentPlayer);
System.out.println("addded new player: " +
currentPlayer.getUser().getEmail());
} finally {
pm.close();
}
}
Gson gson = new Gson();
String json = gson.toJson(currentPlayer);
resp.setContentType("application/json");
resp.getWriter().println(json );
}
// redirect user to sign-in
else
{
resp.sendRedirect(userService.createLoginURL(req.getRequestURI()));
}
}
--
You received this message because you are subscribed to the Google Groups
"Google App Engine for Java" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-appengine-java?hl=en.