Excessive warning messages from Jersey 2.x

情到浓时终转凉″ 提交于 2019-12-30 10:59:08

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/23808594/excessive-warning-messages-from-jersey-2-x

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!