提供静态内容时出错 Dropwziard
Error serving static content Dropwziard
我在 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.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.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
我读过 that it may be a better idea to use DropwizardViews
虽然,我不确定导致码头错误的 gziphttpContent class 是什么问题。
无耻地在一个答案中总结评论线程:)
Gzip 是一种用于 HTTP 请求的编码策略。很可能,您的浏览器正在将 Accept-Encoding: gzip
header 添加到请求中。无论出于何种原因,dropwizard 无法 gzip 响应的内容,这就是您发布的堆栈跟踪。
要检查浏览器是否可能添加此 header,您可以使用
curl -vk https://localhost:<port>/assets/index.html
发出相同的请求,看看是否得到相同的异常。如果不是,则浏览器可能要求压缩内容,而 dropwizard 无法提供。要明确确定这一点,您可以使用 Wireshark 或 Charles Proxy 等嗅探工具来检查您的浏览器发出的完整 HTTP 请求。
作为解决方法,您可以在 dropwizard 服务器配置中禁用 gzip:
server:
gzip:
enabled: false
这应该可以解决问题,尽管它不一定是最佳解决方案。我不知道根本原因是dropwizard中的错误还是与gzip配置有关。
我在 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.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.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
我读过
无耻地在一个答案中总结评论线程:)
Gzip 是一种用于 HTTP 请求的编码策略。很可能,您的浏览器正在将 Accept-Encoding: gzip
header 添加到请求中。无论出于何种原因,dropwizard 无法 gzip 响应的内容,这就是您发布的堆栈跟踪。
要检查浏览器是否可能添加此 header,您可以使用
curl -vk https://localhost:<port>/assets/index.html
发出相同的请求,看看是否得到相同的异常。如果不是,则浏览器可能要求压缩内容,而 dropwizard 无法提供。要明确确定这一点,您可以使用 Wireshark 或 Charles Proxy 等嗅探工具来检查您的浏览器发出的完整 HTTP 请求。
作为解决方法,您可以在 dropwizard 服务器配置中禁用 gzip:
server:
gzip:
enabled: false
这应该可以解决问题,尽管它不一定是最佳解决方案。我不知道根本原因是dropwizard中的错误还是与gzip配置有关。