I'm developing a Java EE web application running on WildFly 18, and Angular on the front end. All the HTTP calls from Angular to Wildfly are POSTs. The application works fine, but once a month, when I start it, I cannot use it because Wildfly rejects the request saying that the HTTP method POST is not supported by this URL
(see error below on browser console). Just to make sure is not Angular, I made the POST call from a Java program, and got the same error.
The solution is to close everything and restart, sometimes more than once. Why does this happen and how to fix this? The big problem is that this may happen in production.
visualcode/rest/getbropr:1 Failed to load resource: the server responded with a status of 405 (Method Not Allowed) main.js:1127 HttpErrorResponse error: "Error HTTP method POST is not supported by this URL" headers: HttpHeaders {normalizedNames: Map(0), lazyUpdate: null, lazyInit: ƒ} message: "Http failure response for http://localhost:4400/visualcode/rest/getbropr: 405 Method Not Allowed" name: "HttpErrorResponse" ok: false status: 405 statusText: "Method Not Allowed" url: "http://localhost:4400/visualcode/rest/getbropr"
UPDATE
This happened to me in two different machines with identical Wildfly configuration, so it must be something on how JAX-RS or any other related component is set up.
UPDATE 2
I got the error and this is the server log:
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
==============================================================
And this is the code that (sometimes) fails:
@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
}