我在GAE中的Java App无法从blobstore提供mp4

时间:2013-09-20 22:01:29

标签: java google-app-engine html5-video mp4 blobstore

这是我第一次觉得我需要问一个问题,因为我似乎无法在任何地方找到答案。

所以,在这个应用程序中,我创建了一个简单的网站页面,使用html5视频作为我的朋友的背景,这是一个摄影师。为了让我的朋友能够进行未来的更改,我想使用appengine blobstore来提供为后台上传的视频。一切似乎都很好,除了在Safari中,视频从未收到或收到错误。

这是我服务的servlet类:

public class Serve extends HttpServlet {
private static final long serialVersionUID = 1L;

private BlobstoreService blobstore = BlobstoreServiceFactory.getBlobstoreService();
private DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();

public void doGet(HttpServletRequest req, HttpServletResponse resp)
    throws ServletException, IOException {
      String format = req.getParameter("video");
      Key key = KeyFactory.createKey("Video", "None");
      if(format.equals("mp4")){
          key = KeyFactory.createKey("Video", "MP4");
          resp.setHeader("Content-type", "video/mp4");
      }
      if(format.equals("webm")){
          key = KeyFactory.createKey("Video", "WebM");
          resp.setHeader("Content-type", "video/webm");
      }
      try{
          Entity e = datastore.get(key);
          String blobKey = (String)e.getProperty("Blob-Key");
          BlobKey bKey = new BlobKey(blobKey);
          resp.setHeader("Cache-Control", "max-age=31557600, must-revalidate");
          //resp.setHeader("Transfer-Encoding", "chunked");
          blobstore.serve(bKey, resp);
      }
      catch (EntityNotFoundException error){
          resp.getWriter().print("No video found");
      }
}
}

编辑:删除了Transfer-Encoding标头。

现在在开发服务器上,当我尝试访问/服务时,我得到这个例外吗?仅在Safari中使用video = mp4:

[java] WARNING: IOException thrown while closing Closeable.
 [java] org.mortbay.jetty.EofException
 [java]     at org.mortbay.jetty.HttpGenerator.flush(HttpGenerator.java:787)
 [java]     at org.mortbay.jetty.HttpConnection.flushResponse(HttpConnection.java:693)
 [java]     at org.mortbay.jetty.HttpConnection$Output.close(HttpConnection.java:992)
 [java]     at com.google.appengine.repackaged.com.google.common.io.Closeables.close(Closeables.java:77)
 [java]     at com.google.appengine.api.blobstore.dev.ServeBlobFilter.serveBlob(ServeBlobFilter.java:195)
 [java]     at com.google.appengine.api.blobstore.dev.ServeBlobFilter.doFilter(ServeBlobFilter.java:67)
 [java]     at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
 [java]     at com.google.apphosting.utils.servlet.TransactionCleanupFilter.doFilter(TransactionCleanupFilter.java:43)
 [java]     at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
 [java]     at com.google.appengine.tools.development.StaticFileFilter.doFilter(StaticFileFilter.java:125)
 [java]     at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
 [java]     at com.google.appengine.tools.development.DevAppServerModulesFilter.doDirectRequest(DevAppServerModulesFilter.java:368)
 [java]     at com.google.appengine.tools.development.DevAppServerModulesFilter.doDirectModuleRequest(DevAppServerModulesFilter.java:351)
 [java]     at com.google.appengine.tools.development.DevAppServerModulesFilter.doFilter(DevAppServerModulesFilter.java:116)
 [java]     at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
 [java]     at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:388)
 [java]     at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
 [java]     at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182)
 [java]     at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:765)
 [java]     at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:418)
 [java]     at com.google.appengine.tools.development.DevAppEngineWebAppContext.handle(DevAppEngineWebAppContext.java:97)
 [java]     at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
 [java]     at com.google.appengine.tools.development.JettyContainerService$ApiProxyHandler.handle(JettyContainerService.java:485)
 [java]     at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
 [java]     at org.mortbay.jetty.Server.handle(Server.java:326)
 [java]     at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:542)
 [java]     at org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:923)
 [java]     at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:547)
 [java]     at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:212)
 [java]     at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)
 [java]     at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:409)
 [java]     at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:582)
 [java] Caused by: java.io.IOException: Broken pipe
 [java]     at sun.nio.ch.FileDispatcherImpl.write0(Native Method)
 [java]     at sun.nio.ch.SocketDispatcher.write(SocketDispatcher.java:47)
 [java]     at sun.nio.ch.IOUtil.writeFromNativeBuffer(IOUtil.java:89)
 [java]     at sun.nio.ch.IOUtil.write(IOUtil.java:46)
 [java]     at sun.nio.ch.SocketChannelImpl.write(SocketChannelImpl.java:450)
 [java]     at org.mortbay.io.nio.ChannelEndPoint.flush(ChannelEndPoint.java:169)
 [java]     at org.mortbay.io.nio.SelectChannelEndPoint.flush(SelectChannelEndPoint.java:221)
 [java]     at org.mortbay.jetty.HttpGenerator.flush(HttpGenerator.java:721)
 [java]     ... 31 more
 [java] 
 [java] Sep 20, 2013 2:48:25 PM com.google.appengine.repackaged.com.google.common.io.Closeables close
 [java] WARNING: IOException thrown while closing Closeable.
 [java] org.mortbay.jetty.EofException
 [java]     at org.mortbay.jetty.HttpGenerator.flush(HttpGenerator.java:787)
 [java]     at org.mortbay.jetty.HttpConnection.flushResponse(HttpConnection.java:693)
 [java]     at org.mortbay.jetty.HttpConnection$Output.close(HttpConnection.java:992)
 [java]     at com.google.appengine.repackaged.com.google.common.io.Closeables.close(Closeables.java:77)
 [java]     at com.google.appengine.api.blobstore.dev.ServeBlobFilter.serveBlob(ServeBlobFilter.java:195)
 [java]     at com.google.appengine.api.blobstore.dev.ServeBlobFilter.doFilter(ServeBlobFilter.java:67)
 [java]     at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
 [java]     at com.google.apphosting.utils.servlet.TransactionCleanupFilter.doFilter(TransactionCleanupFilter.java:43)
 [java]     at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
 [java]     at com.google.appengine.tools.development.StaticFileFilter.doFilter(StaticFileFilter.java:125)
 [java]     at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
 [java]     at com.google.appengine.tools.development.DevAppServerModulesFilter.doDirectRequest(DevAppServerModulesFilter.java:368)
 [java]     at com.google.appengine.tools.development.DevAppServerModulesFilter.doDirectModuleRequest(DevAppServerModulesFilter.java:351)
 [java]     at com.google.appengine.tools.development.DevAppServerModulesFilter.doFilter(DevAppServerModulesFilter.java:116)
 [java]     at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
 [java]     at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:388)
 [java]     at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
 [java]     at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182)
 [java]     at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:765)
 [java]     at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:418)
 [java]     at com.google.appengine.tools.development.DevAppEngineWebAppContext.handle(DevAppEngineWebAppContext.java:97)
 [java]     at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
 [java]     at com.google.appengine.tools.development.JettyContainerService$ApiProxyHandler.handle(JettyContainerService.java:485)
 [java]     at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
 [java]     at org.mortbay.jetty.Server.handle(Server.java:326)
 [java]     at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:542)
 [java]     at org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:923)
 [java]     at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:547)
 [java]     at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:212)
 [java]     at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)
 [java]     at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:409)
 [java]     at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:582)
 [java] Caused by: java.io.IOException: Broken pipe
 [java]     at sun.nio.ch.FileDispatcherImpl.write0(Native Method)
 [java]     at sun.nio.ch.SocketDispatcher.write(SocketDispatcher.java:47)
 [java]     at sun.nio.ch.IOUtil.writeFromNativeBuffer(IOUtil.java:89)
 [java]     at sun.nio.ch.IOUtil.write(IOUtil.java:46)
 [java]     at sun.nio.ch.SocketChannelImpl.write(SocketChannelImpl.java:450)
 [java]     at org.mortbay.io.nio.ChannelEndPoint.flush(ChannelEndPoint.java:169)
 [java]     at org.mortbay.io.nio.SelectChannelEndPoint.flush(SelectChannelEndPoint.java:221)
 [java]     at org.mortbay.jetty.HttpGenerator.flush(HttpGenerator.java:721)
 [java]     ... 31 more

视频仍将显示在此页面上,但是,在生产中没有任何事情发生。此外,我没有在appengine控制台中获取任何日志,所以如果有其他错误,我不会。我知道该视频已正确上传,因为它适用于谷歌浏览器。谷歌浏览器将发回响应标头并播放视频。我也尝试过使用curl,它也会发回一切。是否有我缺少的东西或我需要采取的东西才能在Safari中正常工作。

编辑:我也想知道Safari中是否收到响应标题,就像在Firefox,Chrome和Opera中收到blobstore请求一样?

感谢您给出的任何建议。

0 个答案:

没有答案