4

我在 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)
4

3 回答 3

2

尝试通过 RestEasy 访问服务时遇到相同的异常。因此,以防其他人偶然发现它:

正如 Andreas 已经提到的,它通常指的是错误的 URL。

就我而言,我可以通过 Postman 或 resteasy 目标调用我的服务

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

例如

        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";

例如

    ResteasyClient client = new ResteasyClientBuilder().build();
    ResteasyWebTarget target = client.target(UriBuilder.fromPath("http://localhost:8080/repository"));
    IUserTestRepository proxy = target.proxy(IUserTestRepository.class);
于 2018-05-24T16:22:33.630 回答
1

发生此错误通常是因为 rest/endpoint 地址不可用:

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

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

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

于 2018-10-16T17:48:50.073 回答
0

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

我打了电话:http://localhost:8080/my-app/my-service/param1

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

于 2017-05-02T06:07:35.910 回答