Search code examples
javagoogle-app-engineblobstore

java BlobStore and Google SPI AppEngine endpoint


I am using localhost:8080/_ah/api/explorer google explore: I keep getting

{
 "error": {
  "message": "com.google.appengine.repackaged.org.codehaus.jackson.map.JsonMappingException: Can not construct instance of javax.servlet.http.HttpServletResponse, problem: abstract types can only be instantiated with additional type information\n at [Source: N/A; line: -1, column: -1]",
  "code": 400,
  "errors": [
   {
    "domain": "global",
    "reason": "badRequest",
    "message": "com.google.appengine.repackaged.org.codehaus.jackson.map.JsonMappingException: Can not construct instance of javax.servlet.http.HttpServletResponse, problem: abstract types can only be instantiated with additional type information\n at [Source: N/A; line: -1, column: -1]"
   }
  ]
 }

my Google SPI Code is:

    @ApiMethod(name = "findBillImage", httpMethod = ApiMethod.HttpMethod.GET )
public void findImage(HttpServletResponse httpServletResponse ,  @Named("blobkey") String blobKeyValue)   throws IOException {
     BlobKey blobKey = new BlobKey( blobKeyValue );
     BlobstoreService blobstoreService = BlobstoreServiceFactory.getBlobstoreService();          
     blobstoreService.serve(blobKey, httpServletResponse);       
}

anytime I attempt to write anything to the HttpServletResponse I get this error.. im lost on why I cannot write to the httpServletResponse


Solution

  • Soooo.. the answer is really 'design' in my case.

    Since i am implement "REST" with google app engine...I should not modify the HttpResponse to return an "image".

    so "serving" an image back to the HttpResponse is not ideal. I should expose the image directly with the storage URL to clients.:

    https://storage.cloud.google.com/myapp.appspot.com/20160603_154924.jpg
    

    Can't say I '100%' like this answer, but from what I am reading i believe this is correct.