0

我試圖升級我們用於Play的App Engine SDK的版本! web應用程序從1.6.0到1.7.6。未能在升級App Engine Java SDK後打開寫通道

升級之後,我們不再能夠將文件寫入本地開發服務器的blobstore。我們用下面的代碼寫入文件:

Image img = ImagesServiceFactory.makeImage(uploadedData); 

FileService fileService = FileServiceFactory.getFileService(); 
AppEngineFile file = fileService.createNewBlobFile("image/png", "__initial_data/" + vf.getName()); 

FileWriteChannel writeChannel = fileService.openWriteChannel(file, true); 
OutputStream output = Channels.newOutputStream(writeChannel); 

fileService.openWriteChannel調用失敗,出現以下堆棧跟蹤:

Caused by: java.lang.NullPointerException 
    at com.google.appengine.tools.development.RequestEndListenerHelper.register(RequestEndListenerHelper.java:39) 
    at com.google.appengine.api.files.dev.LocalFileService.open(LocalFileService.java:247) 
    at com.google.appengine.tools.development.ApiProxyLocalImpl$AsyncApiCall.callInternal(ApiProxyLocalImpl.java:527) 
    at com.google.appengine.tools.development.ApiProxyLocalImpl$AsyncApiCall.call(ApiProxyLocalImpl.java:481) 
    at com.google.appengine.tools.development.ApiProxyLocalImpl$AsyncApiCall.call(ApiProxyLocalImpl.java:458) 
    at java.util.concurrent.Executors$PrivilegedCallable$1.run(Executors.java:461) 
    at java.security.AccessController.doPrivileged(Native Method) 
    at java.util.concurrent.Executors$PrivilegedCallable.call(Executors.java:458) 
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303) 
    at java.util.concurrent.FutureTask.run(FutureTask.java:138) 
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895) 
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918) 
    at java.lang.Thread.run(Thread.java:680) 

雖然應用程序引擎的SDK是開源的,我無法找到源用於這些特定於開發的類的文件,以查明內部發生了什麼。

有誰知道從1.6.0版本開始,對象寫入blobstore的實現細節是否發生了變化?

回答

0

原來這是一個玩!具體問題。 play-gae模塊實現了它自己的App Engine的LocalServerEnvironment,名爲PlayDevEnvironment。這包含一個獲取屬性列表的方法。在App Engine的1.6.0和1.7.7版本之間進行了更改,需要返回其他屬性。我們通過如下改變該類來解決它:

public class PlayDevEnvironment implements Environment, LocalServerEnvironment { 

    ... 

    @Override 
    public Map<String, Object> getAttributes() { 
     HashMap<String, Object> hashMap = new HashMap<String, Object>(); 
     hashMap.put(LocalEnvironment.REQUEST_END_LISTENERS, new ArrayList<RequestEndListener>()); 
     return hashMap; 
    } 
} 
相關問題