在servlet中调用createNewGSFile()时发生IOException

时间:2012-04-06 14:53:37

标签: google-app-engine

我在尝试写入Google商店时收到了IOException

附加堆栈跟踪

  

java.io.IOException的       在com.google.appengine.api.files.FileServiceImpl.translateException(FileServiceImpl.java:601)       在com.google.appengine.api.files.FileServiceImpl.makeSyncCall(FileServiceImpl.java:574)       在com.google.appengine.api.files.FileServiceImpl.create(FileServiceImpl.java:481)       在com.google.appengine.api.files.FileServiceImpl.createNewGSFile(FileServiceImpl.java:151)       at guestbook.StoreFileServlet.Insert(StoreFileServlet.java:106)       at guestbook.StoreFileServlet.doPost(StoreFileServlet.java:76)       在javax.servlet.http.HttpServlet.service(HttpServlet.java:637)       在javax.servlet.http.HttpServlet.service(HttpServlet.java:717)       在org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:511)       在org.mortbay.jetty.servlet.ServletHandler $ CachedChain.doFilter(ServletHandler.java:1166)       在com.google.apphosting.utils.servlet.ParseBlobUploadFilter.doFilter(ParseBlobUploadFilter.java:102)       在org.mortbay.jetty.servlet.ServletHandler $ CachedChain.doFilter(ServletHandler.java:1157)       在com.google.apphosting.runtime.jetty.SaveSessionFilter.doFilter(SaveSessionFilter.java:35)       在org.mortbay.jetty.servlet.ServletHandler $ CachedChain.doFilter(ServletHandler.java:1157)       在com.google.apphosting.utils.servlet.TransactionCleanupFilter.doFilter(TransactionCleanupFilter.java:43)       在org.mortbay.jetty.servlet.ServletHandler $ CachedChain.doFilter(ServletHandler.java:1157)       在org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:388)       在org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)       在org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182)       在org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:765)       在org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:418)       在com.google.apphosting.runtime.jetty.AppVersionHandlerMap.handle(AppVersionHandlerMap.java:249)       在org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)       在org.mortbay.jetty.Server.handle(Server.java:326)       在org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:542)       at org.mortbay.jetty.HttpConnection $ RequestHandler.headerComplete(HttpConnection.java:923)       在com.google.apphosting.runtime.jetty.RpcRequestParser.parseAvailable(RpcRequestParser.java:76)       在org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)       在com.google.apphosting.runtime.jetty.JettyServletEngineAdapter.serviceRequest(JettyServletEngineAdapter.java:135)       在com.google.apphosting.runtime.JavaRuntime $ RequestRunnable.run(JavaRuntime.java:446)       在com.google.tracing.TraceContext $ TraceContextRunnable.runInContext(TraceContext.java:449)       在com.google.tracing.TraceContext $ TraceContextRunnable $ 1.run(TraceContext.java:455)       在com.google.tracing.TraceContext.runInContext(TraceContext.java:695)       在com.google.tracing.TraceContext $ AbstractTraceContextCallback.runInInheritedContextNoUnref(TraceContext.java:333)       在com.google.tracing.TraceContext $ AbstractTraceContextCallback.runInInheritedContext(TraceContext.java:325)       在com.google.tracing.TraceContext $ TraceContextRunnable.run(TraceContext.java:453)       在com.google.apphosting.runtime.ThreadGroupPool $ PoolEntry.run(ThreadGroupPool.java:251)       在java.lang.Thread.run(Thread.java:679)   引起:com.google.apphosting.api.ApiProxy $ ApplicationException:ApplicationError:8:       在java.lang.Thread.getStackTrace(Thread.java:1495)       在com.google.apphosting.runtime.ApiProxyImpl.doSyncCall(ApiProxyImpl.java:237)       在com.google.apphosting.runtime.ApiProxyImpl.access $ 000(ApiProxyImpl.java:68)       在com.google.apphosting.runtime.ApiProxyImpl $ 1.run(ApiProxyImpl.java:182)       在com.google.apphosting.runtime.ApiProxyImpl $ 1.run(ApiProxyImpl.java:180)       at java.security.AccessController.doPrivileged(Native Method)       在com.google.apphosting.runtime.ApiProxyImpl.makeSyncCall(ApiProxyImpl.java:180)       在com.google.apphosting.runtime.ApiProxyImpl.makeSyncCall(ApiProxyImpl.java:68)       在com.google.apphosting.api.ApiProxy.makeSyncCall(ApiProxy.java:101)       在com.google.apphosting.api.ApiProxy.makeSyncCall(ApiProxy.java:50)       在com.google.appengine.api.files.FileServiceImpl.makeSyncCall(FileServiceImpl.java:570)       ......还有36个   引起:com.google.apphosting.api.ApiProxy $ ApplicationException:ApplicationError:8:       在com.google.apphosting.runtime.ApiProxyImpl $ AsyncApiFuture.failure(ApiProxyImpl.java:546)       在com.google.net.rpc3.client.RpcStub $ RpcCallbackDispatcher $ 1.runInContext(RpcStub.java:788)       在com.google.tracing.TraceContext $ TraceContextRunnable $ 1.run(TraceContext.java:455)       在com.google.tracing.TraceContext.runInContext(TraceContext.java:695)       在com.google.tracing.TraceContext $ AbstractTraceContextCallback.runInInheritedContextNoUnref(TraceContext.java:333)       在com.google.tracing.TraceContext $ AbstractTraceContextCallback.runInInheritedContext(TraceContext.java:325)       在com.google.tracing.TraceContext $ TraceContextRunnable.run(TraceContext.java:453)       在com.google.net.rpc3.client.RpcStub $ RpcCallbackDispatcher.rpcFinished(RpcStub.java:828)       在com.google.net.rpc3.client.RpcStub $ RpcCallbackDispatcher.failure(RpcStub.java:819)       在com.google.net.rpc3.impl.client.RpcClientInternalContext.runCallbacks(RpcClientInternalContext.java:906)       在com.google.net.rpc3.impl.client.RpcClientInternalContext.finishRpcAndNotifyApp(RpcClientInternalContext.java:809)       在com.google.net.rpc3.impl.client.RpcNetChannel.afterFinishingActiveRpc(RpcNetChannel.java:1062)       在com.google.net.rpc3.impl.client.RpcNetChannel.finishRpc(RpcNetChannel.java:908)       在com.google.net.rpc3.impl.client.RpcNetChannel.handleResponse(RpcNetChannel.java:2265)       在com.google.net.rpc3.impl.client.RpcNetChannel.messageReceived(RpcNetChannel.java:2077)       在com.google.net.rpc3.impl.client.RpcNetChannel.access $ 2000(RpcNetChannel.java:147)       在com.google.net.rpc3.impl.client.RpcNetChannel $ TransportCallback.receivedMessage(RpcNetChannel.java:3115)       在com.google.net.rpc3.impl.client.RpcChannelTransportData $ TransportCallback.receivedMessage(RpcChannelTransportData.java:602)       在com.google.net.rpc3.impl.wire.RpcBaseTransport.receivedMessage(RpcBaseTransport.java:420)       在com.google.net.rpc3.impl.wire.RpcClientTcpTransport.parseOneMessage(RpcClientTcpTransport.java:773)       在com.google.net.rpc3.impl.wire.RpcClientTcpTransport.parseMessages(RpcClientTcpTransport.java:651)       在com.google.net.rpc3.impl.wire.RpcClientTcpTransport.access $ 100(RpcClientTcpTransport.java:38)       在com.google.net.rpc3.impl.wire.RpcClientTcpTransport $ 1.dataReceived(RpcClientTcpTransport.java:293)       在com.google.net.async3.SocketConnection.handleNetworkReadEvent(SocketConnection.java:843)       在com.google.net.async3.SocketConnection.access $ 400(SocketConnection.java:40)       在com.google.net.async3.SocketConnection $ NetworkReadHandlerImpl.run(SocketConnection.java:872)       在com.google.net.eventmanager.AbstractFutureTask $ Sync.innerRun(AbstractFutureTask.java:260)       在com.google.net.eventmanager.AbstractFutureTask.run(AbstractFutureTask.java:121)       在com.google.net.eventmanager.EventManagerImpl.runTask(EventManagerImpl.java:576)       在com.google.net.eventmanager.EventManagerImpl.internalRunWorkerLoop(EventManagerImpl.java:997)       在com.google.net.eventmanager.EventManagerImpl.runWorkerLoop(EventManagerImpl.java:878)       在com.google.net.eventmanager.WorkerThreadInfo.runWorkerLoop(WorkerThreadInfo.java:134)       在com.google.net.eventmanager.EventManagerImpl $ WorkerThread.run(EventManagerImpl.java:1833)

代码如下

    FileService fileService = FileServiceFactory.getFileService();
    GSFileOptionsBuilder optionsBuilder = new GSFileOptionsBuilder()
      .setBucket("mybucket")
      .setKey(key)
      .setMimeType("text/html")
      .setAcl("public-read")
      .addUserMetadata("myfield1", "my field value");
    try {
        AppEngineFile writableFile = fileService.createNewGSFile(optionsBuilder.build());
        // Open a channel for writing
        boolean lockForWrite = false;
        FileWriteChannel writeChannel = fileService.openWriteChannel(writableFile, lockForWrite);
        PrintWriter out = new PrintWriter(Channels.newWriter(writeChannel, "UTF8"));
        out.println(value);
        out.close();
        writeChannel.closeFinally();
    } catch (IOException e) {
        // TODO Auto-generated catch block
    }

我正在使用App Engine SDK 1.6.4

由于

2 个答案:

答案 0 :(得分:2)

这已经解决了。这是典型的不耐烦的新手问题:)

我没有做的是将我的应用程序授权给Google云存储项目[我错过了]。

参见

的先决条件5

https://developers.google.com/appengine/docs/java/googlestorage/overview

答案 1 :(得分:2)

我通过使用App Engine SDK 1.7而不是1.6.3.1(导致问题)解决了这个问题

我的代码没有任何变化。只需将App Engine SDK版本更改为1.7。