我正在开发一个运行在 WildFly 18 和前端 Angular 上的 Java EE Web 应用程序。从 Angular 到 Wildfly 的所有 HTTP 调用都是 POST。该应用程序工作正常,但每月一次,当我启动它时,我无法使用它,因为 Wildfly 拒绝了请求,说HTTP method POST is not supported by this URL
(请参阅下面的浏览器控制台上的错误)。只是为了确保不是 Angular,我从 Java 程序进行了 POST 调用,并得到了同样的错误。
解决方案是关闭所有内容并重新启动,有时不止一次。为什么会发生这种情况以及如何解决这个问题?最大的问题是这可能在生产中发生。
visualcode/rest/getbropr:1 加载资源失败:服务器响应状态为 405(不允许使用方法) main.js:1127 HttpErrorResponse 错误:“此 URL 不支持错误 HTTP 方法 POST”标头:HttpHeaders {normalizedNames :Map(0),lazyUpdate:null,lazyInit:ƒ} 消息:“http://localhost:4400/visualcode/rest/getbropr 的 Http 失败响应:405 Method Not Allowed” 名称:“HttpErrorResponse” ok:false 状态: 405 statusText:“方法不允许”网址:“http://localhost:4400/visualcode/rest/getbropr”
更新
这发生在两台具有相同 Wildfly 配置的不同机器上,因此它必须与 JAX-RS 或任何其他相关组件的设置方式有关。
更新 2
我收到了错误,这是服务器日志:
11:46:17,306 DEBUG [io.undertow.request] (default I/O-12) Matched prefix path /visualcode for path /visualcode/rest/getbropr
11:46:17,306 DEBUG [io.undertow.request.security] (default task-1) Attempting to authenticate /visualcode/rest/getbropr, authentication required: false
11:46:17,306 DEBUG [io.undertow.request.security] (default task-1) Authentication outcome was NOT_ATTEMPTED with method io.undertow.security.impl.CachedAuthenticatedSessionMechanism@2d8f2c0a for /visualcode/rest/getbropr
11:46:17,306 DEBUG [io.undertow.request.security] (default task-1) Authentication result was ATTEMPTED for /visualcode/rest/getbropr
11:46:17,307 INFO [io.undertow.request.dump] (default task-1)
----------------------------REQUEST---------------------------
URI=/visualcode/rest/getbropr
characterEncoding=null
contentLength=2
contentType=[application/json]
cookie=_ga=GA1.1.1378850711.1587329434
header=accept=application/json, text/plain, */*
header=accept-language=en-US,en;q=0.9,es;q=0.8
header=accept-encoding=gzip, deflate, br
header=sec-fetch-mode=cors
header=origin=http://localhost:4400
header=user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36
header=sec-fetch-dest=empty
header=connection=close
header=sec-fetch-site=same-origin
header=cookie=_ga=GA1.1.1378850711.1587329434
header=content-type=application/json
header=content-length=2
header=referer=http://localhost:4400/login
header=host=localhost:8080
locale=[en_US, en, es]
method=POST
protocol=HTTP/1.1
queryString=
remoteAddr=/127.0.0.1:51323
remoteHost=kubernetes.docker.internal
scheme=http
host=localhost:8080
serverPort=8080
isSecure=false
--------------------------RESPONSE--------------------------
contentLength=104
contentType=text/html;charset=UTF-8
header=Connection=close
header=Content-Type=text/html;charset=UTF-8
header=Content-Length=104
header=Date=Thu, 09 Jul 2020 15:46:17 GMT
status=405
==============================================================
这是(有时)失败的代码:
@Path("/")
@Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON })
public class LoginService {
@Inject
private SomeBean bean;
@Context
private HttpServletRequest httpRequest;
@POST
@Path("/getbropr")
public Response getBrowserProperties() {
// process response
}