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



我有两个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()... )

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

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

是什么原因导致在amazon实例上出现此错误,但在我的本地机器上没有,因为地址是localhost?

我刚刚找到了答案:Startup PollerShutdown Poller(在"服务器状态检测器"下(被设置为Management Service而不是Web Port。我认为,当Behavior profile/Server Adapter配置文件设置为Controlled By: Managment Operations而不是Filesystem and shell operations时,就会发生这种情况。

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

最新更新