Google Cloud Endpoints:从@ApiMethod启动servlet

时间:2014-09-30 10:46:54

标签: java google-app-engine servlets google-cloud-endpoints blobstore

我目前处理图像上传到blobstore的方式是使用像@ApiMethod这样的

@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" ) );
}

客户端向此方法发送第一个请求,该请求为他提供了一个URL,他可以在该URL上发送他的图像以及他应该用于上传的名称。

客户端发送第二个请求,其中包含编码为表单数据的实际图像到此URL,并在成功上传到blobstore后,我在servlet中进行后期处理,映射到" / image"路径

现在,我希望从客户角度来看,上传操作是一个单一的请求。我知道这将涉及从@ApiMethod以编程方式调用UploadBlobServlet。所以请参考文档here并将我的@ApiMethod改为

@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, ??? );
}

问题是,我的方法可以inject the ServletContext and the HttpServletRequest,但HttpServletResponse dispatcher.forward()需要(显然)。

那么,从端点@ApiMethod启动servlet的正确方法是什么?

0 个答案:

没有答案