【问题标题】:Excessive warning messages from Jersey 2.x来自 Jersey 2.x 的过多警告消息
【发布时间】:2014-05-22 13:39:57
【问题描述】:

我不断从任何带有 APPLICATION_FORM_URLENCODED 表单数据的 POST 操作中收到这些警告消息:

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.

我已将其追溯到 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()));
            }
        }

所以,如果有任何表单数据,它总是会打印这个警告。我是否做错了什么,因为用正常操作的警告填充日志似乎不是一个好主意。

【问题讨论】:

    标签: java glassfish jersey jersey-2.0


    【解决方案1】:

    我正在使用带有 Slf4j 的 Logback,您只需添加“jul-to-slf4j”作为依赖项并在 logback.xml 中配置它。

    在 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>
    

    要将 jul 消息重定向到 logback,请在 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>
    

    将 org.glassfish.jersey.servlet 的级别设置为 ERROR 可以避免日志文件中出现警告消息。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-08-23
      • 1970-01-01
      • 2012-06-20
      • 2014-05-31
      • 1970-01-01
      • 2016-08-21
      • 2019-07-03
      • 2016-03-09
      相关资源
      最近更新 更多