问题描述
对URI的本地servlet请求(local请求URI)在请求正文中包含表单参数,但请求正文已被servlet或访问请求参数的servlet过滤器使用。只有使用@FormParam的资源方法才能按预期工作。通过其他方式使用请求主体的资源方法将无法按预期工作。
我将其追溯到org.glassfish.jersey.servlet.WebComponent:
if(!form.asMap()。isEmpty()){
containerRequest.setProperty(InternalServerProperties.FORM_DECODED_PROPERTY,form); (LOGGER.isLoggable(Level.WARNING)){
LOGGER.log(Level.WARNING,LocalizationMessages.FORM_PARAM_CONSUMED(containerRequest.getRequestUri()));
if
$ b因此,如果有任何表单数据,打印此警告。我是否做了错误的事情,因为填写日志和正常操作的警告似乎不是一个好主意。 解决方案我在Slf4j中使用Logback,您只需添加 jul-to-slf4j 作为依赖关系,并将其配置在logback.xml中。
在 pom.xml中:
:
<依赖性>
< groupId> ch.qos.logback< / groupId>
< artifactId> logback-classic< / artifactId>
< version> $ {logback.version}< / version>
< /依赖关系>
< dependency>
< groupId> org.slf4j< / groupId>
< artifactId> slf4j-api< / artifactId>
< version> $ {slf4j.version}< / version>
< /依赖关系>
< dependency>
< groupId> org.slf4j< / groupId>
< artifactId> jul-to-slf4j< / artifactId>
< version> $ {slf4j.version}< / version>
< /依赖关系>
要将jul消息重定向到logback,请将其添加到 logback.xml :
<?xml version =1.0encoding =UTF-8?>
<配置>
< contextListener class =ch.qos.logback.classic.jul.LevelChangePropagator>
< resetJUL> true< / resetJUL>
< / contextListener>
< appender name =OUTclass =ch.qos.logback.core.ConsoleAppender>
...
< logger name =org.glassfish.jersey.servletlevel =ERROR/>
< / configuration>
将 org.glassfish.jersey.servlet 设置为ERROR的级别可让您避免在日志文件中发出警告消息。
I keep getting these warning messages from any POST operation with APPLICATION_FORM_URLENCODED form data:
A servlet request to the URI (local request URI) contains form parameters in the request body but the request body has been consumed by the servlet or a servlet filter accessing the request parameters. Only resource methods using @FormParam will work as expected. Resource methods consuming the request body by other means will not work as expected.
I've traced this down to org.glassfish.jersey.servlet.WebComponent:
if (!form.asMap().isEmpty()) {
containerRequest.setProperty(InternalServerProperties.FORM_DECODED_PROPERTY, form);
if (LOGGER.isLoggable(Level.WARNING)) {
LOGGER.log(Level.WARNING, LocalizationMessages.FORM_PARAM_CONSUMED(containerRequest.getRequestUri()));
}
}
So, if there's any form data, it will always print this warning. Am I doing something wrong as filling up the log with warnings for normal operations doesn't seem like a good idea.
解决方案 I'm using Logback with Slf4j, and you only should add "jul-to-slf4j" as dependency and configure it in logback.xml.
In pom.xml:
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>${logback.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${slf4j.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jul-to-slf4j</artifactId>
<version>${slf4j.version}</version>
</dependency>
To redirect jul messages to logback, add this inside in logback.xml:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<contextListener class="ch.qos.logback.classic.jul.LevelChangePropagator">
<resetJUL>true</resetJUL>
</contextListener>
<appender name="OUT" class="ch.qos.logback.core.ConsoleAppender">
...
<logger name="org.glassfish.jersey.servlet" level="ERROR" />
</configuration>
Setting level for org.glassfish.jersey.servlet to ERROR lets you avoid warning messages in log files.
这篇关于来自Jersey 2.x的过多警告消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!