将servlet模式转换为应用引擎端点模式 [英] convert servlet schema to app-engine endpoint schema

查看:102
本文介绍了将servlet模式转换为应用引擎端点模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



$ p




















$ b pre> public void doPost(HttpServletRequest req,HttpServletResponse res)
throws ServletException,IOException {...}


$ b TO

  @ApiMethod(name =save_blob_key,path =save_blob_key httpMethod = HttpMethod.POST)
public void saveBlobKey(HttpServletRequest req)throws IOException {...}

CONTEXT:

我正在尝试使用端点来处理blobstore回调。



Ref: https://developers.google.com/appengine/docs/java/blobstore/overview# Complete_Sample_App



问题:

这里的大问题是,以下两行似乎需要类 H ttpServletRequest ,我不知道是否可以将它传递给端点。

  BlobstoreService blobstoreService = BlobstoreServiceFactory .getBlobstoreService(); 
Map< String,List< BlobKey>> blobs = blobstoreService.getUploads(req);

编辑:



我一直在尝试解决这个问题的路线相当多。我的最新是将blob servlet与endpoint api结合。尽管如此,我仍然无法让代码工作。所以,赏金可以提供给任何提供解决方案或实际导致解决方案的信息的人。

解决方案

目前不能使用端点作为对Blobstore blobstoreService.createUploadUrl 的回调。请参阅此相关答案。有支持 mediaUpload 的开放功能请求,可能会提供类似于您想要的功能。您可以自由地为它显示支持并获得自动更新。



根据您尝试的数据量,我推荐的是两种可能的备选方案之一如果您正在上传少量的blob数据,那将适合数据存储,请使用 ShortBlob (最多500字节)或 Blob (最多1 MB)类型。端点将处理后端的序列化,并且会通过客户端库期待(并发回)base64编码的字符串。这是一个非常简单直接的方法。



如果您想要提供大于1 MB的Blob,现在请使用 Google Cloud Storage JSON API 。此API使用与Endpoints相同的客户端库,因此您不必担心将另一个库与应用程序捆绑在一起。 此页面提供了一个将blob插入Google Cloud的示例使用Java客户端库进行存储。


Would the following conversion hold for converting from Java servlet to google app-engine cloud endpoint?

FROM

public void doPost(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException { … }

TO

@ApiMethod(name = "save_blob_key", path = "save_blob_key" httpMethod = HttpMethod.POST)
public void saveBlobKey(HttpServletRequest req) throws IOException { … }

CONTEXT:

I am trying to use endpoint to process blobstore callback.

Ref: https://developers.google.com/appengine/docs/java/blobstore/overview#Complete_Sample_App

PROBLEM:

The big hickup here is that the following two lines seem to require the class HttpServletRequest and I don't know if I may pass it to endpoint.

BlobstoreService blobstoreService = BlobstoreServiceFactory.getBlobstoreService();
Map<String, List<BlobKey>> blobs = blobstoreService.getUploads(req);

EDIT:

I have been trying quite a lot of routes to solve this problem. My latest is combining blob servlet with endpoint api. Still I am not able to get the code to work. So the bounty goes to anyone who provides a solution or information that actually leads to a solution.

解决方案

You can't currently use Endpoints as a callback to the blobstore blobstoreService.createUploadUrl. See this related answer. There is an open feature request for supporting mediaUpload, which would likely provide similar functionality to what you want. Feel free to star it to show support and get automatic updates.

What I'd recommend would be one of two possible alternatives, depending on the amount of data you are trying to upload.

If you're uploading small amounts of blob data, that would fit in the datastore, use the ShortBlob (up to 500 bytes) or Blob (up to 1 MB) type in your Endpoints entity class. Endpoints will handle serialization on the backend and will expect (and send back) base64-encoded strings via the client libraries. This is a very simple, straightforward approach.

If you want to provide blobs larger than 1 MB, for now, use the Google Cloud Storage JSON API. This API uses the same client library as Endpoints, so you don't have to worry about bundling another library with your application. This page has an example of inserting a blob into Google Cloud Storage with the Java client library.

这篇关于将servlet模式转换为应用引擎端点模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆