Errai JAX-RS - 找不到POST的资源方法,返回405 with Allow header

时间:2013-07-31 08:21:05

标签: java gwt errai

我在Errai Jax-rs上遇到问题,我不确定为什么这不起作用:

@Path("userservice")
public interface UserService {
    @POST
    @Consumes(MediaType.APPLICATION_JSON)
    @Produces(MediaType.APPLICATION_JSON)
    public void login(LoginForm login);
}

从UI调用时:

    service.call(new RemoteCallback<Void>() {
        @Override
        public void callback(Void response) {
                         // Do stuff        
        }
    }, new ErrorCallback() {
        @Override
        public boolean error(Message message, Throwable throwable) {
            return false;
        }
    }).login(new LoginForm(this.username.getText(),
            this.password.getText(),
            true)); 

引发此错误:

[INFO] DEBUG [SynchronousDispatcher] PathInfo: /userservice
[INFO] DEBUG [ExceptionHandler] Failed executing POST /userservice
[INFO] org.jboss.resteasy.spi.MethodNotAllowedException: No resource method found for POST, return 405 with Allow header
[INFO]  at org.jboss.resteasy.core.registry.Segment.match(Segment.java:112)
[INFO]  at org.jboss.resteasy.core.registry.PathParamSegment.matchPattern(PathParamSegment.java:200)
[INFO]  at org.jboss.resteasy.core.registry.RootSegment.matchChildren(RootSegment.java:339)
[INFO]  at org.jboss.resteasy.core.registry.RootSegment.matchRoot(RootSegment.java:374)
[INFO]  at org.jboss.resteasy.core.registry.RootSegment.matchRoot(RootSegment.java:367)
[INFO]  at org.jboss.resteasy.core.ResourceMethodRegistry.getResourceInvoker(ResourceMethodRegistry.java:354)
[INFO]  at org.jboss.resteasy.core.SynchronousDispatcher.getInvoker(SynchronousDispatcher.java:231)
[INFO]  at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:170)
[INFO]  at org.jboss.resteasy.plugins.server.servlet.ServletContainerDispatcher.service(ServletContainerDispatcher.java:208)
[INFO]  at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:56)
[INFO]  at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:51)
[INFO]  at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
[INFO]  at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:511)
[INFO]  at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1166)
[INFO]  at com.google.inject.servlet.FilterChainInvocation.doFilter(FilterChainInvocation.java:66)
[INFO]  at com.googlecode.objectify.cache.AsyncCacheFilter.doFilter(AsyncCacheFilter.java:39)
[INFO]  at com.google.inject.servlet.FilterDefinition.doFilter(FilterDefinition.java:163)
[INFO]  at com.google.inject.servlet.FilterChainInvocation.doFilter(FilterChainInvocation.java:58)
[INFO]  at org.apache.shiro.web.servlet.AbstractShiroFilter.executeChain(AbstractShiroFilter.java:449)
[INFO]  at org.apache.shiro.web.servlet.AbstractShiroFilter$1.call(AbstractShiroFilter.java:365)
[INFO]  at org.apache.shiro.subject.support.SubjectCallable.doCall(SubjectCallable.java:90)
[INFO]  at org.apache.shiro.subject.support.SubjectCallable.call(SubjectCallable.java:83)
[INFO]  at org.apache.shiro.subject.support.DelegatingSubject.execute(DelegatingSubject.java:383)
[INFO]  at org.apache.shiro.web.servlet.AbstractShiroFilter.doFilterInternal(AbstractShiroFilter.java:362)
[INFO]  at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:125)
[INFO]  at com.google.inject.servlet.FilterDefinition.doFilter(FilterDefinition.java:163)
[INFO]  at com.google.inject.servlet.FilterChainInvocation.doFilter(FilterChainInvocation.java:58)
[INFO]  at com.google.inject.servlet.ManagedFilterPipeline.dispatch(ManagedFilterPipeline.java:118)
[INFO]  at com.google.inject.servlet.GuiceFilter.doFilter(GuiceFilter.java:113)
[INFO]  at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
[INFO]  at com.google.appengine.api.socket.dev.DevSocketFilter.doFilter(DevSocketFilter.java:74)
[INFO]  at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
[INFO]  at com.google.appengine.tools.development.ResponseRewriterFilter.doFilter(ResponseRewriterFilter.java:123)
[INFO]  at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
[INFO]  at com.google.appengine.tools.development.HeaderVerificationFilter.doFilter(HeaderVerificationFilter.java:34)
[INFO]  at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
[INFO]  at com.google.appengine.api.blobstore.dev.ServeBlobFilter.doFilter(ServeBlobFilter.java:63)
[INFO]  at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
[INFO]  at com.google.apphosting.utils.servlet.TransactionCleanupFilter.doFilter(TransactionCleanupFilter.java:43)
[INFO]  at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
[INFO]  at com.google.appengine.tools.development.StaticFileFilter.doFilter(StaticFileFilter.java:125)
[INFO]  at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
[INFO]  at com.google.appengine.tools.development.DevAppServerServersFilter.doDirectRequest(DevAppServerServersFilter.java:369)
[INFO]  at com.google.appengine.tools.development.DevAppServerServersFilter.doDirectServerRequest(DevAppServerServersFilter.java:352)
[INFO]  at com.google.appengine.tools.development.DevAppServerServersFilter.doFilter(DevAppServerServersFilter.java:115)
[INFO]  at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
[INFO]  at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:388)
[INFO]  at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
[INFO]  at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182)
[INFO]  at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:765)
[INFO]  at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:418)
[INFO]  at com.google.appengine.tools.development.DevAppEngineWebAppContext.handle(DevAppEngineWebAppContext.java:97)
[INFO]  at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
[INFO]  at com.google.appengine.tools.development.JettyContainerService$ApiProxyHandler.handle(JettyContainerService.java:438)
[INFO]  at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
[INFO]  at org.mortbay.jetty.Server.handle(Server.java:326)
[INFO]  at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:542)
[INFO]  at org.mortbay.jetty.HttpConnection$RequestHandler.content(HttpConnection.java:938)
[INFO]  at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:755)
[INFO]  at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:218)
[INFO]  at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)
[INFO]  at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:409)
[INFO]  at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:582)

3 个答案:

答案 0 :(得分:2)

尝试通过RestEasy访问服务时遇到了相同的异常。所以万一其他人偶然发现它:

正如安德烈亚斯已经提到的那样,它经常指错误的网址。

在我的情况下,我可以通过Postman或resteasy目标来调用我的服务

final String path = "http://localhost:8080/repository/user";

e.g。

        Client client = ClientBuilder.newBuilder().build();
        WebTarget target = client.target("http://localhost:8080/repository/user");
        Response response = target.request().get();

使用Resteasy-Proxy时我必须使用

final String path = "http://localhost:8080/repository";

e.g。

    ResteasyClient client = new ResteasyClientBuilder().build();
    ResteasyWebTarget target = client.target(UriBuilder.fromPath("http://localhost:8080/repository"));
    IUserTestRepository proxy = target.proxy(IUserTestRepository.class);

答案 1 :(得分:1)

通常会发生此错误,因为剩余/端点地址不可用:

  1. 检查类名上方的 @Path 批注
  2. 检查方法名称上方的 @Path 批注
  3. 如果使用的是 @PathParam @QueryParam 批注,请确保两件事:

    • 该值对应于方法签名中声明的类型
    • 检查是否传递了正确数量的参数
    • 所有注释导入实际上都是从包 javax.ws.rs

如果错误仍然存​​在,请尝试检查您的CORS实现。

答案 2 :(得分:0)

尝试使用错误数量的参数访问我的方法时遇到此异常。

我致电:http://localhost:8080/my-app/my-service/param1

而服务期待:http://localhost:8080/my-app/my-service/param1/param2