2015-03-23 3 views
1

У меня проблемы с обновлением моего устаревшего кода до нового. После этого кода Google образец работает в устаревшем режиме, но не в новом; ссылку ниже ->Миграция из Google Cloud Storage API java

google sample

package com.google.appengine.demos; 

import com.google.appengine.tools.cloudstorage.GcsFileOptions; 
import com.google.appengine.tools.cloudstorage.GcsFilename; 
import com.google.appengine.tools.cloudstorage.GcsInputChannel; 
import com.google.appengine.tools.cloudstorage.GcsOutputChannel; 
import com.google.appengine.tools.cloudstorage.GcsService; 
import com.google.appengine.tools.cloudstorage.GcsServiceFactory; 

import java.io.BufferedReader; 
import java.io.IOException; 
import java.io.PrintWriter; 
import java.nio.ByteBuffer; 
import java.nio.channels.Channels; 

import javax.servlet.http.HttpServlet; 
import javax.servlet.http.HttpServletRequest; 
import javax.servlet.http.HttpServletResponse; 

/** 
* Create, Write, Read, and Finalize Cloud Storage objects. 
* Access your app at: http://myapp.appspot.com/ 
*/ 
@SuppressWarnings("serial") 
public class PortOfFilesAPIGuestbookServlet extends HttpServlet { 
    public static final String BUCKETNAME = "ExampleBucketName"; 
    public static final String FILENAME = "ExampleFileName"; 

    @Override 
    public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException { 
    resp.setContentType("text/plain"); 
    resp.getWriter().println("Hello, world from java"); 
    GcsService gcsService = GcsServiceFactory.createGcsService(); 
    GcsFilename filename = new GcsFilename(BUCKETNAME, FILENAME); 
    GcsFileOptions options = new GcsFileOptions.Builder() 
     .mimeType("text/html") 
     .acl("public-read") 
     .addUserMetadata("myfield1", "my field value") 
     .build(); 

    GcsOutputChannel writeChannel = gcsService.createOrReplace(filename, options); 
    // You can write to the channel using the standard Java methods. 
    // Here we use a PrintWriter: 
    PrintWriter writer = new PrintWriter(Channels.newWriter(writeChannel, "UTF8")); 
    writer.println("The woods are lovely dark and deep."); 
    writer.println("But I have promises to keep."); 
    writer.flush(); 

    // Note that the writeChannel is Serializable, so it is possible to store it somewhere and write 
    // more to the file in a separate request. To make the object as small as possible call: 
    writeChannel.waitForOutstandingWrites(); 

    // This time we write to the channel directly 
    writeChannel.write(ByteBuffer.wrap("And miles to go before I sleep.".getBytes("UTF8"))); 

    // If you want partial content saved in case of an exception, close the 
    // GcsOutputChannel in a finally block. See the GcsOutputChannel interface 
    // javadoc for more information. 
    writeChannel.close(); 
    resp.getWriter().println("Done writing..."); 

    // At this point, the file is visible to anybody on the Internet through Cloud Storage as: 
    // (http://storage.googleapis.com/BUCKETNAME/FILENAME) 

    GcsInputChannel readChannel = null; 
    BufferedReader reader = null; 
    try { 
     // We can now read the file through the API: 
     readChannel = gcsService.openReadChannel(filename, 0); 
     // Again, different standard Java ways of reading from the channel. 
     reader = new BufferedReader(Channels.newReader(readChannel, "UTF8")); 
     String line; 
     // Prints "The woods are lovely, dark, and deep." 
     // "But I have promises to keep." 
     // "And miles to go before I sleep." 
     while ((line = reader.readLine()) != null) { 
     resp.getWriter().println("READ:" + line); 
     } 
    } finally { 
     if (reader != null) { reader.close(); } 
    } 
    } 
} 

добавить разрешения, добавьте библиотеки ... но всегда я вижу эту ошибку

java.lang.NoClassDefFoundError: com/google/api/client/googleapis/services/json/AbstractGoogleJsonClient$Builder 

мне нужно добавить что-то еще? некоторый ключ Oauth? У кого-нибудь есть полный пример с библиотеками, которые мне нужно добавить?

Ваша помощь будет оценена

Благодаря

Christian

ответ

0

Вы, кажется, не хватает клиентских API LIBS Google, вы можете скачать их here

Использование этих услуг с OAuth для GAE должны быть довольно простыми here - вот некоторые примеры.

+0

У меня уже есть клиентские клики Google Api, как и вы, (включая все эти). С appengine-gcs-client-0.3.jar работает, но с версии 0.3.8 нет. Это имеет смысл? Я бы хотел иметь последнюю версию или одну из них, потому что это лучшая, я так думаю. О OAuth необходимо добавить дополнительный код, как вы приложили? Я говорю, потому что я добавляю разрешения на ведро, и в теории должно быть достаточно, а не? Потому что с версией 0.3.0 работает. Спасибо за ваше время :) – user2195683

+0

Все ли в папке WEB-INF/lib? – jirungaray

+0

Ну, я думаю, у меня есть на моем lib -> appengine-api-1.0-sdk-1.9.18.jar, appengine-api-labs.jar, appengine-api-stubs-1.7.7.jar, appengine-endpoints .jar, appengine-endpoints-deps.jar, appengine-gcs-client-0.3.jar, appengine-jsr107cache-1.9.18.jar, appengine-local-runtime-shared.jar, appengine-testing-1.8.8.jar , asm-4.0.jar, commons-lang3-3.2.1.jar, commons-logging-1.1.1.jar, datanucleus-api-jdo-3.1.3.jar, datanucleus-api-jpa-3.1.3.jar , datanucleus-appengine-2.1.2.jar, datanucleus-core-3.1.3.jar, el-api-2.2.jar, geronimo-jpa_2.0_spec-1.0.jar, geronimo-jpa_3.0_spec-1.1.1.jar ... – user2195683

Смежные вопросы