GameFile should not deal with File objects

Bug #728148 reported by Matt Giuca
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
MUGLE
Fix Released
Medium
Prageeth Silva

Bug Description

I don't think the current GameFile class is appropriate. Note that it deals with java.io.File a lot -- not as a field (which would be very wrong since we can't store a "File" in the database), but nonetheless, I don't know if GAE will even let us use the java.io.File class, let alone give us one. GAE does not have a file system (which is why we are using blobs in the first place).

Think about the use cases for GameFile. They will basically be entirely HTTP-based. MUGLE isn't going to use the files at all -- it is just implementing a file-system-like interface on the blobstore, via HTTP. The HTTP interface will basically be you can PUT files and you can GET files, and that's it.

From within the program, the PUT operation will basically come to us as a javax.servlet.http.HttpServletRequest object (http://download.oracle.com/javaee/6/api/javax/servlet/http/HttpServletRequest.html). You get the body via the HttpServletRequest.getInputStream() method, which returns a java.io.InputStream object (http://download.oracle.com/javase/1.4.2/docs/api/java/io/InputStream.html) -- the same type as System.in. So the GameFile constructor should not take a File, it should take an InputStream, and read the contents from there, storing it into the blobstore. This will allow some higher-level HTTP code to receive a PUT request, get the InputStream, and pass it to GameFile.

From within the program, the GET operation will basically require that we fill in a javax.servlet.http.HttpServletResponse (http://download.oracle.com/javaee/6/api/javax/servlet/http/HttpServletResponse.html). You can write to the body via the HttpServletResponse.getWriter() method, which returns a java.io.PrintWriter object (http://download.oracle.com/javase/1.4.2/docs/api/java/io/PrintWriter.html) -- similar to the type of System.out, but not the same. So the GameFile.getActualFile() method should not return a File, it should take a PrintWriter as an argument, and write the contents to it. This will allow some higher-level HTTP code to receive a GET request, get the PrintWriter from the response, and pass it to GameFile.getActualFile() to populate the response.

Related branches

Revision history for this message
Matt Giuca (mgiuca) wrote :

Fixed in trunk r65.

Changed in mugle:
assignee: nobody → Matt Giuca (mgiuca)
status: Triaged → Fix Committed
Revision history for this message
Prageeth Silva (prageethsilva) wrote :

Gwtc still complains about java.io includes in the shared packages.

gwtc:
     [java] Compiling module au.edu.unimelb.csse.mugle.Mugle
     [java] Validating newly compiled units
     [java] [ERROR] Errors in 'file:/home/prageeth/Desktop/Mugle/data-wrapper/src/au/edu/unimelb/csse/mugle/shared/model/GameFile.java'
     [java] [ERROR] Line 60: No source code is available for type java.io.InputStream; did you forget to inherit a required module?
     [java] [ERROR] Line 107: No source code is available for type java.io.PrintWriter; did you forget to inherit a required module?

Changed in mugle:
status: Fix Committed → Incomplete
assignee: Matt Giuca (mgiuca) → Prageeth Silva (prageethsilva)
Revision history for this message
Prageeth Silva (prageethsilva) wrote :

I'll look into this soon.

Revision history for this message
Prageeth Silva (prageethsilva) wrote :

I think this new bug should be addressed in https://bugs.launchpad.net/mugle/+bug/734769
Hence, this will be changed to Fixed.

Changed in mugle:
status: Incomplete → Fix Committed
Matt Giuca (mgiuca)
Changed in mugle:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.