Wednesday, December 29, 2010

Avoiding recompile after every change in Google App Engine/GWT development environment

Google app engine development environment plugin in eclipse provides a great way of making changes to the code and viewing the changes just by refreshing the browser instead of recompiling the whole project. This saves a lot of time as recompilation takes time and when you multiply that with the number of changes you make on any given day, you can see that most of your productive days goes down the drain.

I noticed that this feature stropped working after some of the changes I've made. After some research I found out that this is because of google user authentication code I've added. After authenticating the user, I was forwarding the user to the URL that did not have gwt.codesvr URL parameter. Presence of this parameter is required to get the above behavior.

This post on Google Groups helped me identify the problem and fix it. I made the following code changes to make it work [slightly different from what's suggested on that post].


<%
    UserService userService = UserServiceFactory.getUserService();
    User user = userService.getCurrentUser();
    if (user != null) {
         

    String gwtCodeSvrParam = request.getParameter("gwt.codesvr");
    String forwardingUrl = myUrl;
    if (!"".equals(gwtCodeSvrParam)) {
     forwardingUrl = forwardingUrl + "?gwt.codesvr=" + gwtCodeSvrParam;
    
    } 
    %>
      
    <a href=<%=forwardingUrl %>> Access the system </a>
  
    The above code will ensure that myUrl will be used in production environment and myURL with gwt.codesvr will be used in development environment