【问题标题】:Jersey response HTTP 400 Bad Requests, no clue way泽西岛响应 HTTP 400 错误请求,没有线索
【发布时间】:2018-04-02 17:45:11
【问题描述】:

我有一个 NGINX 服务器,然后是一个 Tomcat 作为 Servlet 容器。 我从球衣 2.25.1 升级到 2.26,我可以让它工作:

我将服务器中的 Java 版本从 jdk1.8.0_91 更新为 jdk1.8.0_161。 我更新了 REST 项目中的依赖项:

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.glassfish.jersey</groupId>
            <artifactId>jersey-bom</artifactId>
            <version>${jersey.version}</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>

    <!-- Jersey core Servlet 2.x implementation -->
    <dependency>
        <groupId>org.glassfish.jersey.containers</groupId>
        <artifactId>jersey-container-servlet-core</artifactId>
        <scope>${dependency.scopes}</scope>
    </dependency>

    <dependency>
        <groupId>org.glassfish.jersey.inject</groupId>
        <artifactId>jersey-hk2</artifactId>
        <scope>${dependency.scopes}</scope>
    </dependency>

    <dependency>
        <groupId>org.glassfish.jersey.media</groupId>
        <artifactId>jersey-media-json-binding</artifactId>
        <scope>${dependency.scopes}</scope>
    </dependency>

    <!-- Jersey Multipart entity providers support module -->
    <dependency>
        <groupId>org.glassfish.jersey.media</groupId>
        <artifactId>jersey-media-multipart</artifactId>
        <scope>${dependency.scopes}</scope>

        <exclusions>
            <exclusion>
                <groupId>com.fasterxml.jackson.jaxrs</groupId>
                <artifactId>jackson-jaxrs-base</artifactId>
            </exclusion>
            <exclusion>
                <groupId>com.fasterxml.jackson.jaxrs</groupId>
                <artifactId>jackson-jaxrs-json-provider</artifactId>
            </exclusion>
            <exclusion>
                <groupId>com.fasterxml.jackson.core</groupId>
                <artifactId>jackson-annotations</artifactId>
            </exclusion>
        </exclusions>
    </dependency>

    <!-- https://mvnrepository.com/artifact/org.glassfish.jersey.media/jersey-media-json-jackson -->
    <dependency>
        <groupId>org.glassfish.jersey.media</groupId>
        <artifactId>jersey-media-json-jackson</artifactId>
        <scope>${dependency.scopes}</scope>

        <exclusions>
            <exclusion>
                <groupId>com.fasterxml.jackson.jaxrs</groupId>
                <artifactId>jackson-jaxrs-base</artifactId>
            </exclusion>
            <exclusion>
                <groupId>com.fasterxml.jackson.jaxrs</groupId>
                <artifactId>jackson-jaxrs-json-provider</artifactId>
            </exclusion>
            <exclusion>
                <groupId>com.fasterxml.jackson.core</groupId>
                <artifactId>jackson-annotations</artifactId>
            </exclusion>
        </exclusions>
    </dependency>

提供dependency.scopes 的地方。所有依赖项都放在 Tomcat 的 lib 文件夹中。我在依赖项方面遇到了一些问题,但现在我看不到这方面的例外情况。

NGINX 将 HTTP 和 HTTPS 后端流量重定向到 Tomcat。当我使用 HTTP 请求时,我得到了正确的响应。当我不使用 HTTPS 请求时,我得到 HTTP 400。相同的 URL,相同的请求标头,只是更改了协议。

另外,如果我使用 WGET 命令从 NGINX 服务器请求相同的 URL,我会从 Tomcat(使用 HTTP 和 HTTPS)得到正确的答案。

所以,Tomcat 看起来在这两种协议中都能很好地回答,但有时。

tomcat中的任何日志都没有异常。当我通过 NGINX 请求 GET 时,我只是在访问日志中看到了 HTTP 400 代码。

  HTTPS Request
  - - - [02/Apr/2018:17:02:00 +0000] "GET /request HTTP/1.0" 400 1001 71 https-jsse-nio-8542-exec-4

  HTTP Request
  - - - [02/Apr/2018:17:29:35 +0000] "GET /request HTTP/1.0" 200 45 16 https-jsse-nio-8542-exec-9

看起来问题是在 HTTP 标头中产生的,但我无法从 tomcat 端看到它们。是否可以启用一些额外的日志记录以获得任何线索?

谢谢,

下图展示了在tomcat中添加的依赖:

【问题讨论】:

    标签: java tomcat nginx jersey http-status-code-400


    【解决方案1】:

    我可以解决 NGINX 配置中的问题,比较 HTTP 和 HTTPS 配置。 我有错误的 HOST 标头。

    【讨论】:

      猜你喜欢
      • 2023-03-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-11-05
      • 2011-02-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多