2013-02-04 2 views
2

저는 Google 클라우드 저장소 api를 처음 사용하고 서버를 사용하는 방법에 익숙하지 않습니다. Eclipse의 IDE를 사용하여 Java에서 웹 응용 프로그램을 작성하여 Google의 클라우드 저장소에 저장된 파일을 읽으려고합니다. 서버 측에서 파일을 읽는 코드가 있고 클라이언트 측에서 샘플 코드를 수정하는 방법을 모르므로 RemoteServiceServlet 대신 httpServlet을 지원합니다. 어떤 도움이나 제안이라도 대단히 감사하겠습니다!자바를 사용하여 Google 클라우드 저장소에서 파일 읽기

아래 코드는 서버 측 코드입니다.

package com.google.gwt.sample.interfacecloud.server; 

import java.io.BufferedReader; 
import java.io.BufferedWriter; 
import java.io.FileNotFoundException; 
import java.io.FileReader; 
import java.io.FileWriter; 
import java.io.IOException; 
import java.io.PrintWriter; 
import java.nio.channels.Channels; 
import java.util.ArrayList; 

import javax.servlet.http.*; 
import com.google.gwt.sample.interfacecloud.client.GreetingService; 

import com.google.appengine.api.files.AppEngineFile; 
import com.google.appengine.api.files.FileReadChannel; 
import com.google.appengine.api.files.FileService; 
import com.google.appengine.api.files.FileServiceFactory; 
import com.google.appengine.api.files.FileWriteChannel; 
import com.google.appengine.api.files.GSFileOptions.GSFileOptionsBuilder; 

@SuppressWarnings("serial") 
public class CloudInteraction extends HttpServlet implements GreetingService{ 
public static final String BUCKETNAME = "obd_data"; 
public static final String FILENAME = "data.txt"; 

@Override 
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException 
{ 
    resp.setContentType("text/plain"); 

    String filename = "/gs/" + BUCKETNAME + "/" + FILENAME; 
    FileService fileService = FileServiceFactory.getFileService(); 
    AppEngineFile readableFile = new AppEngineFile(filename); 
    FileReadChannel readChannel = 
      fileService.openReadChannel(readableFile, false); 
    BufferedReader reader = 
      new BufferedReader(Channels.newReader(readChannel, "UTF8")); 
    String line = reader.readLine(); 
    resp.getWriter().println("READ:"+line); 
    System.out.println(line); 
    readChannel.close(); 
} 

@Override 
public String greetServer(String name) throws IllegalArgumentException { 
    // TODO Auto-generated method stub 
    return null; 
} 

} 

답변

1

RPC를 일반 서블릿과 혼합하여 사용하고 있습니다. 당신은 그렇게해서는 안됩니다. 일반 서블릿을 사용하려는 경우 이러한 상호 작용을 위해 RPC 인터페이스를 사용하지 마십시오. 이 시나리오에서는 RequestBuilder를 사용하는 것이 좋습니다. 참고 - 귀하의 요구 사항이 무엇인지는 명확하지 않습니다.

+0

답장을 보내 주셔서 감사합니다. 앱 엔진 플러그인을 사용하여 GWT를 사용하려고 시도 했었습니다. 앱 엔진을 사용하기 만하면 Google의 클라우드 저장소에 저장된 파일을 읽을 수있었습니다. – alperkin