上传一个小的 .txt 文件并在 Java Google App Engine 中读取它的行

Uploading a small .txt file and reading its line in Java Google App Engine

我正在尝试上传一个只有几行的小 txt 文件并在我的休息应用程序中阅读它。我能够在 Jetty 服务器上使用 GAE (1.9.25) 运行 时间在我的本地机器上运行它。但是,当我将它部署到云端并尝试上传文件时,它会抛出一个 运行time 异常,如下所示。

请注意我没有启用计费或 blob 存储。并且异常不会在这些行上说明任何内容。所以我猜这与它无关。 因为我没有保存文件,只用于读取它,没有写入操作.. App Engine 支持此功能吗?

    Uncaught exception from servlet
javax.servlet.UnavailableException: java.lang.NoSuchMethodException: com.sun.jersey.multipart.impl.MultiPartReaderClientSide.<init>()
    at org.mortbay.jetty.servlet.ServletHolder.makeUnavailable(ServletHolder.java:415)
    at org.mortbay.jetty.servlet.ServletHolder.initServlet(ServletHolder.java:458)
    at org.mortbay.jetty.servlet.ServletHolder.doStart(ServletHolder.java:263)
    at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
    at org.mortbay.jetty.servlet.ServletHandler.initialize(ServletHandler.java:685)
    at org.mortbay.jetty.servlet.Context.startContext(Context.java:140)
    at org.mortbay.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1250)
    at org.mortbay.jetty.handler.ContextHandler.doStart(ContextHandler.java:517)
    at org.mortbay.jetty.webapp.WebAppContext.doStart(WebAppContext.java:467)
    at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
    at com.google.apphosting.runtime.jetty.AppVersionHandlerMap.createHandler(AppVersionHandlerMap.java:206)
    at com.google.apphosting.runtime.jetty.AppVersionHandlerMap.getHandler(AppVersionHandlerMap.java:179)
    at com.google.apphosting.runtime.jetty.JettyServletEngineAdapter.serviceRequest(JettyServletEngineAdapter.java:135)
    at com.google.apphosting.runtime.JavaRuntime$RequestRunnable.run(JavaRuntime.java:457)
    at com.google.tracing.TraceContext$TraceContextRunnable.runInContext(TraceContext.java:437)
    at com.google.tracing.TraceContext$TraceContextRunnable.run(TraceContext.java:444)
    at com.google.tracing.CurrentContext.runInContext(CurrentContext.java:230)
    at com.google.tracing.TraceContext$AbstractTraceContextCallback.runInInheritedContextNoUnref(TraceContext.java:308)
    at com.google.tracing.TraceContext$AbstractTraceContextCallback.runInInheritedContext(TraceContext.java:300)
    at com.google.tracing.TraceContext$TraceContextRunnable.run(TraceContext.java:441)
    at com.google.apphosting.runtime.ThreadGroupPool$PoolEntry.run(ThreadGroupPool.java:235)
    at java.lang.Thread.run(Thread.java:745)

下面是我的 HTML、Rest Controller 和 Web.xml

HTML

<form action="rest/locality/upload" method="post"
    enctype="multipart/form-data;charset=UTF-8">
    <p>
        Select a new file : <input type="file" name="file" />
    </p>
    <input type="submit" value="Upload File" />
</form>

休息控制器

@POST
@Path("/upload")
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Produces(MediaType.TEXT_PLAIN)
public String uploadFile(@FormDataParam("file") InputStream fis) {

    try (BufferedReader br = new BufferedReader(new InputStreamReader(fis))) {
        String strLine = null;

和Web.xml

<servlet-name>MyApplication</servlet-name>
    <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
    <init-param>
        <param-name>jersey.config.server.provider.packages</param-name>
        <param-value>com.smart.win.controller</param-value>
    </init-param>
    <init-param>
        <param-name>jersey.config.server.provider.classnames</param-name>
        <param-value>org.glassfish.jersey.filter.LoggingFilter;org.glassfish.jersey.media.multipart.MultiPartFeature
        </param-value>
    </init-param>

希望我提供了足够的信息

回答了我的问题。

使用 apache 公共库解决了它。

http://www.webring.org/l/rd?ring=theshogiwebring;id=13;url=http%3A%2F%2Fshogi-software%2Eblogspot%2Ein%2F2009%2F04%2Fgoogle-app-engine-and-file-upload%2Ehtml