gpt4 book ai didi

java - 提供静态内容时出错 Dropwziard

转载 作者:行者123 更新时间:2023-11-30 02:10:52 24 4
gpt4 key购买 nike

我在 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 类的问题是什么导致了 jetty 中的错误。

最佳答案

在一个答案中总结评论主题,无耻地追求声誉:)

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

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

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

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

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

server:
gzip:
enabled: false

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

关于java - 提供静态内容时出错 Dropwziard,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50142094/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com