IOException while calling createNewGSFile()

2019-07-04 23:53发布

I am getting an IOException while trying to write to the Google store

The stack trace is attached

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

The code ia as follows

    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
    }

I am using App Engine SDK 1.6.4

Thanks

2条回答
倾城 Initia
2楼-- · 2019-07-05 00:27

This is solved. It is the typical impatient newbie problem :)

What I had not done was give my app permission to the Google cloud storage project [which I missed].

See pre-requisite 5 at

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

查看更多
等我变得足够好
3楼-- · 2019-07-05 00:45

I solved this by using App Engine SDK 1.7 instead of 1.6.3.1( which cause the problem )

Nothing change in the my code. Just change App Engine SDK version to 1.7.

查看更多
登录 后发表回答