Jetty MultipartFormDataInput 未被调度

Jetty MultipartFormDataInput not being dispatched

我正在开发一个Jetty Servlet,应该用于上传文件和一些参数,但是MultipartFormDataInput 抛出异常。但是码头网络服务器到目前为止按预期启动。

代码如下所示:

@POST
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Produces(MediaType.APPLICATION_JSON)
public void createApp(MultipartFormDataInput ressources, @Suspended AsyncResponse response);

当请求调用此 servlet 时,抛出以下异常:

java.lang.NoClassDefFoundError: Could not initialize class org.apache.james.mime4j.storage.DefaultStorageProvider
at java.lang.Class.forName0(Native Method) ~[?:1.8.0_60]
at java.lang.Class.forName(Class.java:348) ~[?:1.8.0_60]
at org.apache.logging.log4j.core.util.Loader.initializeClass(Loader.java:285) ~[log4j-core-2.0.2.jar:2.0.2]
at org.apache.logging.log4j.core.impl.ThrowableProxy.loadClass(ThrowableProxy.java:500) ~[log4j-core-2.0.2.jar:2.0.2]
at org.apache.logging.log4j.core.impl.ThrowableProxy.toExtendedStackTrace(ThrowableProxy.java:621) [log4j-core-2.0.2.jar:2.0.2]
at org.apache.logging.log4j.core.impl.ThrowableProxy.<init>(ThrowableProxy.java:146) [log4j-core-2.0.2.jar:2.0.2]
at org.apache.logging.log4j.core.impl.Log4jLogEvent.getThrownProxy(Log4jLogEvent.java:323) [log4j-core-2.0.2.jar:2.0.2]
at org.apache.logging.log4j.core.impl.Log4jLogEvent.serialize(Log4jLogEvent.java:429) [log4j-core-2.0.2.jar:2.0.2]
at org.apache.logging.log4j.core.appender.AsyncAppender.append(AsyncAppender.java:153) [log4j-core-2.0.2.jar:2.0.2]
at org.apache.logging.log4j.core.config.AppenderControl.callAppender(AppenderControl.java:97) [log4j-core-2.0.2.jar:2.0.2]
at org.apache.logging.log4j.core.config.LoggerConfig.callAppenders(LoggerConfig.java:428) [log4j-core-2.0.2.jar:2.0.2]
at org.apache.logging.log4j.core.config.LoggerConfig.log(LoggerConfig.java:407) [log4j-core-2.0.2.jar:2.0.2]
at org.apache.logging.log4j.core.config.LoggerConfig.log(LoggerConfig.java:365) [log4j-core-2.0.2.jar:2.0.2]
at org.apache.logging.log4j.core.Logger.logMessage(Logger.java:112) [log4j-core-2.0.2.jar:2.0.2]
at org.apache.logging.slf4j.Log4jLogger.log(Log4jLogger.java:374) [log4j-slf4j-impl-2.0.2.jar:2.0.2]
at org.eclipse.jetty.util.log.JettyAwareLogger.log(JettyAwareLogger.java:607) [jetty-util-9.2.10.v20150310.jar:9.2.10.v20150310]
at org.eclipse.jetty.util.log.JettyAwareLogger.warn(JettyAwareLogger.java:431) [jetty-util-9.2.10.v20150310.jar:9.2.10.v20150310]
at org.eclipse.jetty.util.log.Slf4jLog.warn(Slf4jLog.java:69) [jetty-util-9.2.10.v20150310.jar:9.2.10.v20150310]
at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:667) ~[jetty-servlet-9.2.10.v20150310.jar:9.2.10.v20150310]
at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1127) ~[jetty-server-9.2.10.v20150310.jar:9.2.10.v20150310]
at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:515) ~[jetty-servlet-9.2.10.v20150310.jar:9.2.10.v20150310]
at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1061) ~[jetty-server-9.2.10.v20150310.jar:9.2.10.v20150310]
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141) ~[jetty-server-9.2.10.v20150310.jar:9.2.10.v20150310]
at org.eclipse.jetty.server.handler.HandlerList.handle(HandlerList.java:52) ~[jetty-server-9.2.10.v20150310.jar:9.2.10.v20150310]
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:97) ~[jetty-server-9.2.10.v20150310.jar:9.2.10.v20150310]
at org.eclipse.jetty.server.Server.handle(Server.java:497) ~[jetty-server-9.2.10.v20150310.jar:9.2.10.v20150310]
at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:310) [jetty-server-9.2.10.v20150310.jar:9.2.10.v20150310]
at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:257) [jetty-server-9.2.10.v20150310.jar:9.2.10.v20150310]
at org.eclipse.jetty.io.AbstractConnection.run(AbstractConnection.java:540) [jetty-io-9.2.10.v20150310.jar:9.2.10.v20150310]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [?:1.8.0_60]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [?:1.8.0_60]
at java.lang.Thread.run(Thread.java:745) [?:1.8.0_60]

如果我删除 MultipartFormDataInput 参数,一切都会按预期进行。我的代码有什么问题?

更新

此后还有一条输出信息:

2016-01-26 13:20:00,152 WARN  [pool-2-thread-15] ? (:) - badMessage: java.lang.IllegalStateException: too much data after closed for HttpChannelOverHttp@46c1358f{r=1,c=false,a=IDLE,uri=-}

更新 2

这是我的 maven 依赖。

<dependency>
        <groupId>org.jboss.resteasy</groupId>
        <artifactId>resteasy-multipart-provider</artifactId>
        <version>3.0.9.Final</version>
        <exclusions>
            <exclusion>
                <groupId>commons-logging</groupId>
                <artifactId>commons-logging</artifactId>
            </exclusion>
        </exclusions>
    </dependency>

堆栈跟踪告诉您您的 slf4j + log4j 设置配置不正确。

您的设置中的某些东西正在尝试将日志发送到需要正常运行的附加程序 org.apache.james.mime4j.storage.DefaultStorageProvider class。

这个 class 由于某种原因无法初始化。应该有更多的日志记录事件(可能更早)来说明原因。

来自 Apache James Mime4j 网站 ...

Apache James Mime4J provides a parser, MimeStreamParser, for e-mail message streams in plain rfc822 and MIME format.

也许您的 log4j 设置试图在某些事件上发送电子邮件?

有关 "too much data after closed for HttpChannelOverHttp" 的警告消息是 servlet 出错且未处理请求正文内容的结果。忽略该警告,首先解决根本问题。