Chris' Tech Blog

February 25, 2010

Eclipse hangs on startup – swiss knife solution

Filed under: Eclipse — Chris Ey @ 11:57 am

I just experienced what probably many devs experience with Eclipse occasionally: It hangs on startup.

Looks like there is a pretty easy solution to delete a .snap file which helped me too:

  1. cd to <workspace>/.metadata/.plugins/org.eclipse.core.resources
  2. remove the file .snap

Found here:
http://stackoverflow.com/questions/207843/how-do-i-prevent-eclipse-from-hanging-on-startup

I am reposting it so I can find it easier in future :)

February 21, 2010

Line numbers in exception don’t match GSP file

Filed under: Grails — Chris Ey @ 2:19 am

I would assume almost everyone who builds or maintains a larger web application project will want perfect tooling and debugging facilities for their project. With the good reputation Grails has, I was expecting tooling and debugging to be just that: perfect.

Yet, when taking a closer look, debugging a GSP template might be more difficult and inconvenient than it should be.

In my current case, I forgot a closing parenthesis in an expression. The GSP page which I just started had 12 lines, but the error message which occured at run time had no hint to where I had the error! Instead, it showed me the line number and column of a precompiled file I don’t even know how it was created! The Exception started like this:

2010-02-19 16:01:05,868 [http-8090-1] ERROR pages.GroovyPagesTemplateEngine  - Compilation error compiling GSP [home_cey_dev_p4_sandbox_..._content_createPopup_gsp]:startup failed, home_cey_dev_p4_sandbox_..._content_createPopup_gsp: 25: expecting ')', found '}' @ line 25, column 327.
1 error
[...]

Line 25… really? As I said, I was editing a 12 line file.

Error messages like this are not helpful at all. This is a huge “minus” for Grails in my opinion!

February 20, 2010

Grails’ REST Client violates HTTP 1.1?

Filed under: Grails — Chris Ey @ 8:50 pm

The goal of this is to build a Grails application that uses a REST servive as a backend.

The REST endpoint is implemented using RESTEasy from the JBoss guys.I have a “create” endpoint, which takes an object of type “Content”, stores it using its own backend and then returns the URI to the newly created object in the HTTP Location header.

The server looks something like this:

@Path("/")
@Produces("application/json")
@Consumes("application/json")
public class RESTEndpoint {

@POST
@Path("/create")
public Response create(Content content, UriInfo uriInfo) {
    Long contentId = contentService.create(content);
    URI newURI = uriInfo.getBaseUriBuilder().path("/content/{key}").build(contentId);
    return Response.created(newURI).build();
}

The point is that the HTTP response produced by this will set the Location header, but it will NOT contain any body. According to HTTP 1.1 this is perfectly legal:

10.2.2 201 Created

   The request has been fulfilled and resulted in a new resource being
   created. The newly created resource can be referenced by the URI(s)
   returned in the entity of the response, with the most specific URI
   for the resource given by a Location header field. The response
   SHOULD include an entity containing a list of resource
   characteristics and location(s) from which the user or user agent can
   choose the one most appropriate.
[...]

So the key phrase is “The response SHOULD include an entity…” but it doesn’t HAVE TO.

But, when we use Grails’ REST client, the following results in an exception from the client:

render withRest(uri: "http://cey-linux:8080/restservice/") {
    def resp = post(path : 'create',
    body: '{ "content":{"name":"My Content"}}"',
    requestContentType: "application/json")
    resp.getHeaders("Location")
}

I don’t have the exception handy but will reproduce and paste it here.

To fix this problem, I now send the URI of the new content object in the Location header and in the body of the response:

    return Response.created(newURI).type(MediaType.TEXT_PLAIN).entity(newURI).build();

This also makes us compatible with HTTP 1.0, which requires that a body is sent in case of response status 201-Created.

Getting started with Grails

Filed under: Grails — Chris Ey @ 1:43 am

I am just getting started with Groovy on Grails. I’ll post my experiences and challenges while I go.

Welcome!

Filed under: About this blog — Chris Ey @ 1:33 am

Welcome to my new Tech Blog. This will probably contain random thoughts and experiences with technology I encounter while playing with web related technologies.

« Newer Posts

Powered by WordPress