提供静态内容Dropwziard时出错

时间:2018-05-02 19:24:43

标签: java rest dropwizard

我在dropwizard中提供静态资源,只是我的应用程序初始化方法中的基本AssetBundle。 1.3 DW serving static assets

bootstrap.addBundle(new AssetsBundle("/assets/", "/assets"));

我的静态资源位于src/main/resources/assets/

目前,我只想在.html投放一个localhost:port/assets/index.html文件。

当我转到localhost:port/assets/index.html时,我似乎遇到了一个奇怪的jetty-server错误。

org.eclipse.jetty.util.SharedBlockingCallback: Blocker not complete Blocker@6aa2d91b{null}
WARN  [2018-05-02 19:10:32,492] org.eclipse.jetty.servlet.ServletHandler: Error for /assets/MultiFileUpload.html
! java.lang.ClassNotFoundException: org.eclipse.jetty.http.GzipHttpContent
! at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
! at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
! at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
! at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
! ... 43 common frames omitted
! Causing: java.lang.NoClassDefFoundError: org/eclipse/jetty/http/GzipHttpContent
! at org.eclipse.jetty.server.handler.gzip.GzipHttpOutputInterceptor.commit(GzipHttpOutputInterceptor.java:229)
! at org.eclipse.jetty.server.handler.gzip.GzipHttpOutputInterceptor.write(GzipHttpOutputInterceptor.java:104)
! at org.eclipse.jetty.server.HttpOutput.write(HttpOutput.java:235)
! at org.eclipse.jetty.server.HttpOutput.write(HttpOutput.java:219)
! at org.eclipse.jetty.server.HttpOutput.close(HttpOutput.java:269)
! at io.dropwizard.servlets.assets.AssetServlet.doGet(AssetServlet.java:197)
! at javax.servlet.http.HttpServlet.service(HttpServlet.java:687)
! at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
! at io.dropwizard.jetty.NonblockingServletHolder.handle(NonblockingServletHolder.java:49)
! at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1772)
! at io.dropwizard.servlets.ThreadNameFilter.doFilter(ThreadNameFilter.java:35)
! at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1759)
! at io.dropwizard.jersey.filter.AllowedMethodsFilter.handle(AllowedMethodsFilter.java:45)
! at io.dropwizard.jersey.filter.AllowedMethodsFilter.doFilter(AllowedMethodsFilter.java:39)
! at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1759)
! at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:582)
! at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1180)
! at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:512)
! at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1112)
! at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)
! at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:134)
! at com.codahale.metrics.jetty9.InstrumentedHandler.handle(InstrumentedHandler.java:239)
! at io.dropwizard.jetty.RoutingHandler.handle(RoutingHandler.java:52)
! at org.eclipse.jetty.server.handler.gzip.GzipHandler.handle(GzipHandler.java:493)
! at io.dropwizard.jetty.BiDiGzipHandler.handle(BiDiGzipHandler.java:69)
! at org.eclipse.jetty.server.handler.RequestLogHandler.handle(RequestLogHandler.java:56)
! at org.eclipse.jetty.server.handler.StatisticsHandler.handle(StatisticsHandler.java:169)
! at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:134)
! at org.eclipse.jetty.server.Server.handle(Server.java:534)
! at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:320)
! at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:251)
! at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:283)
! at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:108)
! at org.eclipse.jetty.io.ssl.SslConnection.onFillable(SslConnection.java:240)
! at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:283)
! at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:108)
! at org.eclipse.jetty.io.SelectChannelEndPoint$2.run(SelectChannelEndPoint.java:93)
! at org.eclipse.jetty.util.thread.strategy.ExecuteProduceConsume.executeProduceConsume(ExecuteProduceConsume.java:303)
! at org.eclipse.jetty.util.thread.strategy.ExecuteProduceConsume.produceConsume(ExecuteProduceConsume.java:148)
! at org.eclipse.jetty.util.thread.strategy.ExecuteProduceConsume.run(ExecuteProduceConsume.java:136)
! at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:671)
! at org.eclipse.jetty.util.thread.QueuedThreadPool$2.run(QueuedThreadPool.java:589)
! at java.lang.Thread.run(Thread.java:745)
0:0:0:0:0:0:0:1 - - [02/May/2018:19:10:32 +0000] "GET /assets/index.html HTTP/1.1" 500 265 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36" 27

我已阅读Here使用DropwizardViews更好的主意 虽然,我不确定gziphttpContent类在jetty中导致错误的问题是什么。

1 个答案:

答案 0 :(得分:2)

在无耻的声誉报价中总结答案中的评论主题:)

Gzip是HTTP请求中使用的编码策略。最有可能的是,您的浏览器正在为请求添加Accept-Encoding: gzip标头。无论出于何种原因,dropwizard无法gzip响应的内容,这是您发布的堆栈跟踪。

要检查浏览器是否可能添加此标头,您可以使用

curl -vk https://localhost:<port>/assets/index.html

发出相同的请求,看看你是否得到了相同的异常。如果没有,那么很可能是浏览器要求gzip压缩内容,dropwizard无法提供。要明确确定这一点,您可以使用Wireshark或Charles Proxy等嗅探工具来检查浏览器正在进行的完整HTTP请求。

作为解决方法,您可以在dropwizard服务器配置中禁用gzip:

server:
  gzip:
    enabled: false

这应该可以解决问题,尽管它不一定是最佳解决方案。我不知道根本原因是否是dropwizard中的错误或与gzip配置有关。