问题描述
我正在尝试在Payara 162上调试我的jersey 2应用程序,但是在每次请求时,在打印跟踪信息后,我都会收到此异常,并且客户端没有任何响应:
I am trying to debug my jersey 2 app on Payara 162, but on every request, after the trace information is printed I get this exception and the client gets no response:
org.glassfish.grizzly.http.util.MimeHeaders$MaxHeaderCountExceededException: Illegal attempt to exceed the configured maximum number of headers: 100
at org.glassfish.grizzly.http.util.MimeHeaders.createHeader(MimeHeaders.java:396)
at org.glassfish.grizzly.http.util.MimeHeaders.addValue(MimeHeaders.java:422)
at org.glassfish.grizzly.http.HttpHeader.addHeader(HttpHeader.java:707)
at org.glassfish.grizzly.http.server.Response.addHeader(Response.java:1177)
at org.apache.catalina.connector.Response.addHeader(Response.java:1221)
at org.apache.catalina.connector.ResponseFacade.addHeader(ResponseFacade.java:579)
at org.glassfish.jersey.servlet.internal.ResponseWriter.writeResponseStatusAndHeaders(ResponseWriter.java:165)
at org.glassfish.jersey.server.ServerRuntime$Responder$1.getOutputStream(ServerRuntime.java:701)
at org.glassfish.jersey.message.internal.CommittingOutputStream.commitStream(CommittingOutputStream.java:200)
at org.glassfish.jersey.message.internal.CommittingOutputStream.flushBuffer(CommittingOutputStream.java:305)
at org.glassfish.jersey.message.internal.CommittingOutputStream.commit(CommittingOutputStream.java:261)
at org.glassfish.jersey.message.internal.CommittingOutputStream.close(CommittingOutputStream.java:276)
at org.glassfish.jersey.message.internal.OutboundMessageContext.close(OutboundMessageContext.java:839)
at org.glassfish.jersey.server.ContainerResponse.close(ContainerResponse.java:412)
at org.glassfish.jersey.server.ServerRuntime$Responder.writeResponse(ServerRuntime.java:784)
at org.glassfish.jersey.server.ServerRuntime$Responder.processResponse(ServerRuntime.java:444)
at org.glassfish.jersey.server.ServerRuntime$Responder.process(ServerRuntime.java:434)
at org.glassfish.jersey.server.ServerRuntime$2.run(ServerRuntime.java:329)
在球衣中,我的应用程序将跟踪配置为:
In my jersey I app I configured trace as so:
public class RestApplication extends ResourceConfig {
public RestApplication() {
super();
packages(true, "com.example");
register(JacksonFeature.class);
register(JsonProvider.class);
register(RolesAllowedDynamicFeature.class);
property("jersey.config.server.tracing.type", "ON_DEMAND");
property("jersey.config.server.tracing.threshold", "VERBOSE");
}
}
我在logback.xml中启用了记录器(我已将Payara配置为使用logback),并且通过在请求中添加X-Jersey-Tracing-Accept
标头来按需启用该记录器,因此我会在服务器日志中看到完整的跟踪信息,但后来我得到了例外.当我不将标头添加到请求中时,一切正常,但是我当然没有得到跟踪.
I enabled the logger in my logback.xml (I have configured Payara to use logback), and I see the full trace info in my server log when I enable it on demand by adding the X-Jersey-Tracing-Accept
header to my request, but then I get the exception. When I don't add the header to the request everything works but of course I don't get the trace.
我想知道是否可以更改以解决此问题,或者它是一个错误?
I'm wondering if there is anything I can change to fix this or is it a bug?
推荐答案
问题是跟踪添加了针对每个事件进入REST响应的标题.
Grizzly对响应中的标头数量施加了限制.默认情况下,Payara Server在响应中将100定义为maximum number of headers
.您需要增加此数字,以允许响应中的所有跟踪信息.
Grizzly imposes a limit on number of headers in the response.Payara Server by default defines 100 as maximum number of headers
in the response. You need to increase this number to allow all tracing info in the response.
要为最大标题数设置一个更大的数字,您需要使用asadmin.在GUI管理控制台中没有设置此选项的选项,在配置HTTP协议的屏幕中缺少该选项.
To set a higher number for maximum number of headers, you need to use asadmin. There is no option to set this in the GUI admin console, it is missing in the screen to configure the HTTP protocol.
如果您的配置名为server-config
,并且网络侦听器为http-listener-1
,则执行以下asadmin命令将其设置为1000:
If your configuration is named server-config
and the network listener is http-listener-1
, then execute the following asadmin command to set it to 1000:
您可以使用类似的命令来设置所有 Grizzly网络侦听器属性选项,只需替换设置为您要设置的选项的名称,使用-
作为单词分隔符,而不是驼峰式大小写.
You can use a similar command to set all Grizzly network listener propertiesoptions, just replace max-response-headers
to the name of the option you want to set, using -
as a word separator instead of camel case.
这篇关于启用Jersey跟踪日志记录会导致MaxHeaderCountExceededException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!