Google Cloud endpoints: running servlet from @ApiMethod

The way I currently handle uploading images to blobstore is to have @ApiMethod like

@ApiMethod( name = "getUploadUrl",
            path = "/images/uploadurl",
            httpMethod = ApiMethod.HttpMethod.GET )

public UploadUrl getUploadUrl( HttpServletRequest request ) throws UnauthorizedException
{
    authenticateRequest( request );
    return new UploadUrl( blobstoreService.createUploadUrl( "/image" ) );
}

      

The client sends the first request to this method, which gives him a URL where he can submit his image along with the name he should use to download.

The client sends a second request containing the actual image, encoded as form data, to this url and after successfully uploading to blobstore, I do my post processing in a servlet mapped to path "/ image"

Now I want the upload operation to be a separate request from the client's point of view. I understand this will involve a programmatic call UploadBlobServlet

from my @ApiMethod. So link to the docs here and change my @ApiMethod as

@ApiMethod( name = "uploadImage",
            path = "/images/upload",
            httpMethod = ApiMethod.HttpMethod.POST )

public void uploadImage( ServletContext context, HttpServletRequest request ) throws UnauthorizedException
{
    authenticateRequest( request );
    RequestDispatcher dispatcher = context.getRequestDispatcher( blobstoreService.createUploadUrl( "/image" ) );
    dispatcher.forward( request, ??? );
}

      

The problem is that I can inject ServletContext and HttpServletRequest into my method, but not HttpServletResponse

which one requires dispatcher.forward()

(obviously).

So what is the correct way to start a servlet from @ApiMethod endpoints?

+3


source to share





All Articles