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

时间:2018-12-14 18:50:39

标签: java java-ee jax-rs wildfly

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

当我在本地计算机上运行它们时,它可以工作,因此我怀疑是配置问题,而不是代码问题,但我不知道。

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

是什么原因导致该错误在亚马逊实例上而不是在我的本地计算机上,因为地址是本地主机?

1 个答案:

答案 0 :(得分:0)

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

我不知道轮询程序如何工作或为什么会导致此错误,但这就是解决方案。