在某些REST端点上出现404错误

时间:2020-06-10 07:57:34

标签: java spring-boot maven jersey

以下是项目的众多终点之一-

import javax.ws.rs.*;

@Path("/some/api")
@POST
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
@Produces(MediaType.APPLICATION_JSON)
public PanDetails savePan(@FormParam("pan_number") String pan_number,
                          @FormParam("dob") String dob,
                          @Context SecurityContext security)
            throws Exception {

    }

卷曲请求-

curl --location --request POST 'http://127.0.0.1:8084/service/v2/some/api' \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'pan_number=<pan>' \
--data-urlencode 'dob=08/09/<year>'

获得答复-

{
    "timestamp": 1591773545909,
    "status": 404,
    "error": "Not Found",
    "message": "Not Found",
    "path": "/service/v2/some/api"
}

应用程序日志-

2020-06-10 12:49:05,905 752003 [XNIO-3 task-16] WARN  [WebComponent.java:692] - A servlet request to the URI http://127.0.0.1:8084/service/v2/some/api 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.
2020-06-10 12:49:05,906 752004 [XNIO-3 task-16] INFO  [LoggingFilter.java:155] - 15 * Server has received a request on thread XNIO-3 task-16
15 > POST http://127.0.0.1:8084/service/v2/some/api
15 > Accept: */*
15 > Accept-Encoding: gzip, deflate, br
15 > Authorization: Bearer <token>
15 > Cache-Control: no-cache
15 > Connection: keep-alive
15 > Content-Length: 40
15 > Content-Type: application/x-www-form-urlencoded
15 > Host: 127.0.0.1:8084
15 > Postman-Token: c233cd0f-4689-4947-aa5e-ecea3b4a49d7
15 > User-Agent: PostmanRuntime/7.25.0

2020-06-10 12:49:05,907 752005 [XNIO-3 task-16] INFO  [LoggingFilter.java:155] - 15 * Server responded with a response on thread XNIO-3 task-16
15 < 404

2020-06-10 12:49:05,910 752008 [XNIO-3 task-16] INFO  [LoggerInterceptor.java:42] - Visitor [j7PvTZWa_O4XUrqXIvZ7xguZcD8D-DlGfORGuhPH] [POST] [/error] [pan_number=<pan>|dob=08/09/<year>|] [1ms] [OK]

并非所有端点都在失败。直到2天后,此终点也能正常工作。昨天我玩过jenv for Java版本。现在,我在命令行上通过jenv运行Maven-

jenv exec mvn install -Denv=live -Dmaven.test.skip=true

因此采用Java 1.8。

SandeepanNath:prepaid sandeepan.nath$ jenv exec mvn -version
Apache Maven 3.3.9 (bb52d8502b132ec0a5a3f4c09453c07478323dc5; 2015-11-10T22:11:47+05:30)
Maven home: /Users/sandeepan.nath/.sdkman/candidates/maven/current
Java version: 1.8.0_20, vendor: Oracle Corporation
Java home: /Library/Java/JavaVirtualMachines/jdk1.8.0_20.jdk/Contents/Home/jre
Default locale: en_GB, platform encoding: UTF-8
OS name: "mac os x", version: "10.14.3", arch: "x86_64", family: "mac"

正在使用Javax.ws.rs 2.0.1-

<dependency>
    <groupId>javax.ws.rs</groupId>
    <artifactId>javax.ws.rs-api</artifactId>
    <version>2.0.1</version>
</dependency>

是的,这是一个遗留应用程序,因此包含很多依赖项。

0 个答案:

没有答案