javax.ws.rs.NotAllowedException: 不允许使用 HTTP 405 方法

javax.ws.rs.NotAllowedException: HTTP 405 Method Not Allowed

我有 2 个 Wildfly 14 实例 运行 在同一个 Windows 服务器 EC2 实例上。一个正在向另一个请求:

List<Long> ids = ...
WebTarget target = client.target("http://localhost:8080/test");
boolean put = target.request().put(Entity.entity(ids, MediaType.APPLICATION_JSON), boolean.class);

另一台服务器上的端点是:

@PUT
@Path("/test")
@Produces(MediaType.APPLICATION_JSON)
public boolean prepareGame(List<Long> ids) {
    return true;
}

我得到

17:30:05,640 ERROR [stderr] (EE-ManagedExecutorService-default-Thread-2) javax.ws.rs.NotAllowedException: HTTP 405 Method Not Allowed

17:30:05,641 ERROR [stderr] (EE-ManagedExecutorService-default-Thread-2)    at org.jboss.resteasy.resteasy-jaxrs@3.6.1.Final//org.jboss.resteasy.client.jaxrs.internal.ClientInvocation.handleErrorStatus(ClientInvocation.java:223)

17:30:05,641 ERROR [stderr] (EE-ManagedExecutorService-default-Thread-2)    at org.jboss.resteasy.resteasy-jaxrs@3.6.1.Final//org.jboss.resteasy.client.jaxrs.internal.ClientInvocation.extractResult(ClientInvocation.java:191)

17:30:05,641 ERROR [stderr] (EE-ManagedExecutorService-default-Thread-2)    at org.jboss.resteasy.resteasy-jaxrs@3.6.1.Final//org.jboss.resteasy.client.jaxrs.internal.ClientInvocation.invoke(ClientInvocation.java:463)

17:30:05,641 ERROR [stderr] (EE-ManagedExecutorService-default-Thread-2)    at org.jboss.resteasy.resteasy-jaxrs@3.6.1.Final//org.jboss.resteasy.client.jaxrs.internal.ClientInvocationBuilder.put(ClientInvocationBuilder.java:207)

(at the line: boolean put = target.request()... )

当我 运行 这些在我的本地机器上时它工作,所以我怀疑是配置问题而不是代码问题,但我不知道。

亚马逊实例允许服务器侦听的 8080 上的所有传出流量和所有传入 TCP 流量 (jboss.http.port:8080)。机器上的防火墙也允许这种流量。我已经通过使用 client.target("http://x.x.x.x:8080/..."); 从我的本地机器向远程服务器发送请求来测试在那里接受流量,其中 x.x.x.x 是实例的 public ip。没有问题。

什么会导致亚马逊实例出现此错误,但由于地址是 localhost 而不会在我的本地计算机上导致此错误?

我刚找到答案:Startup PollerShutdown Poller(在 "Server State Detectors" 下)被设置为 Management Service 而不是 Web Port。我认为,当 Behavior profile/服务器适配器配置文件设置为 Controlled By: Managment Operations 而不是 Filesystem and shell operations.

时,就会发生这种情况

我不知道轮询器是如何工作的,也不知道它为什么会导致这个错误,但这就是解决方案。