【发布时间】:2018-05-03 04:34:08
【问题描述】:
我在 dropwizard 中提供静态资产,只是我的应用程序初始化方法中的一个基本 AssetBundle。 1.3 DW serving static assets.
bootstrap.addBundle(new AssetsBundle("/assets/", "/assets"));
我的静态资源位于src/main/resources/assets/
目前,我只想在localhost:port/assets/index.html 提供一个.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 类的问题是什么。
【问题讨论】:
-
我之前遇到过 dropwizard+gzip 的问题,浏览器可能会添加一些允许压缩内容的 Accept 标头。如果您
curl -v相同的 URL 会发生什么? -
在访问我的 api 端点时似乎不会引起问题,只是出于某种原因特别是这个静态文件。有没有办法在应用配置文件中禁止压缩内容?我相信我在文档的某个地方读到过。
-
这就是为什么我建议检查请求标头,也许浏览器正在添加导致此错误的内容。如果你使用
curl http://localhost:port/assets/index.html会发生什么,同样的错误? -
上下文:我有一个 TLS 连接,所以我的浏览器使用的是自签名证书。使用
curl -k -v https://localhost:port/assets/index.html似乎接受请求并显示index.html文件的html 视图。 -
如果它适用于 curl 但不适用于浏览器,我敢打赌您的浏览器会在您不知情的情况下将
Accept-Encoding: gzip标头添加到请求中。见this issue。这不太可能与 TLS 有关。
标签: java rest dropwizard