3

I am Using GWT SDK 2.4.0 Google appengine 1.6.3

I am trying to create a application where a file is uploaded to external repository.

The max size of file is 5 MB.

With help of formPanel, formupload and servlet i send the file to server.

On server Side this file is send to external repository.

fileName = item.getName();
mimetype = item.getContentType();

int len;

        while ((len = stream.read(buffer, 0, buffer.length)) != -1) {
            output.write(buffer, 0, len);
        }
        ByteArrayInputStream input = new ByteArrayInputStream(output.toByteArray());
        Session session =getSession();
    ContentStream contentStream = session.getObjectFactory()
                .createContentStream(fileName, output.size(), mimetype, input);



        FilenetDocument document = new FilenetDocument(fileName);
        Folder folder =getFolderSession();
        folder.createDocument(document.addDocumentProperty(),
                contentStream, VersioningState.MAJOR);

with this procedure i create document in external repository. and on refresh i can see the file on my GWT client GUI.

Now i want to download the same file from external repository. So on server side i wrote this code (FileUtils.download method for downloading from external repositrry.)

System.out.println(" id " +docId);
FileUtils.download(docId,"C:/FilenetDownload",session);  <--line 55

but this gives me Error

PrintStack :

java.lang.NoClassDefFoundError: java.io.FileOutputStream is a restricted class. Please see the Google  App Engine developer's guide for more details.
    at com.google.appengine.tools.development.agent.runtime.Runtime.reject(Runtime.java:51)
    at org.apache.chemistry.opencmis.client.util.FileUtils.download(FileUtils.java:241)
    at org.apache.chemistry.opencmis.client.util.FileUtils.download(FileUtils.java:263)
    at com.filenet.server.CmisFileDownload.doPost(CmisFileDownload.java:55)
    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.appengine.tools.development.HeaderVerificationFilter.doFilter(HeaderVerificationFilter.java:35)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    at com.google.appengine.api.blobstore.dev.ServeBlobFilter.doFilter(ServeBlobFilter.java:60)
    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 com.google.appengine.tools.development.StaticFileFilter.doFilter(StaticFileFilter.java:122)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    at com.google.appengine.tools.development.BackendServersFilter.doFilter(BackendServersFilter.java:97)
    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.appengine.tools.development.DevAppEngineWebAppContext.handle(DevAppEngineWebAppContext.java:78)
    at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
    at com.google.appengine.tools.development.JettyContainerService$ApiProxyHandler.handle(JettyContainerService.java:363)
    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.content(HttpConnection.java:938)
    at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:755)
    at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:218)

Plz Can any one explain what is wrong .. or What should i Do..

ᄂ ᄀ
  • 5,669
  • 6
  • 43
  • 57
NewCodeLearner
  • 738
  • 3
  • 14
  • 38

2 Answers2

1

Google App Engine has some restrictions, you can read more about the problem you're experiencing here. Instead of using FileUtils.download you should use a lower level api and then store the content in some available storage location (normal file system is not an option in GAE). For instance, using the BlobStore API:

CmisObject object = session.getObject(session.createObjectId(docId));
Document document = (Document) object;
String filename = document.getName();
InputStream stream = document.getContentStream().getStream();
BlobStoreContext context = new BlobStoreContextFactory().createContext("aws-s3", identity, credential);
Map<String, InputStream> map = context.createInputStreamMap("my_content");
map.put(document.getId(), stream);
context.close();
Community
  • 1
  • 1
skuro
  • 13,414
  • 1
  • 48
  • 67
  • :I have to download the file from external repository to GWT server then GWT serverto client side. for dowloading the file to ext repository to GWT server `FileUtils.download(docId,"C:/FilenetDownload",session); `is used. [http://chemistry.apache.org/java/0.7.0/maven/apidocs/] – NewCodeLearner Jun 14 '12 at 11:03
  • `FileUtils` is just one option, which you can't use because you're on GAE. You need to directly handle the content stream as you simply can't save it on a file. – skuro Jun 14 '12 at 11:16
  • : I understood your point , but help me more please. What is `("aws-s3", identity, credential)` and How to transfer the file back to client. – NewCodeLearner Jun 14 '12 at 13:54
  • That's the Blobstore API from Google. I'd suggest you to open a different question, as there are a number of details related to how you expect to serve client calls that don't fit in here. E.g. why to store the file locally instead of streaming it back to the client? – skuro Jun 14 '12 at 15:28
1

on the app engine you can not access the file system directly, this is not permitted.

Here is an example on how to use the app engine blobstore to upload a file: Blobstore Java API Overview

UdayKiran Pulipati
  • 6,579
  • 7
  • 67
  • 92
Daniel Kurka
  • 7,973
  • 2
  • 24
  • 43
  • I have to download a file from exterior repository to server then server to client. Uploading is done (code is given above.) .. My problem is downloading it. For dowloading from ext repository `FileUtils.download(docId,"C:/FilenetDownload",session); ` .. this method is also in exterior JAR file. – NewCodeLearner Jun 14 '12 at 10:57