Skip to content

cannot register REST service in 2.7 due to the changes in RestProtoco#getContextPath #3445

Closed

Description

@hewguo

2.7.0版本getContextPath方法:

protected String getContextPath(URL url) {
        String contextPath = url.getPath();
        return contextPath.endsWith("/") ? contextPath.substring(0,contextPath.length()-1) : contextPath;
    }

无法将方法置入web容器中,退回2.6.5版本的方法:

protected String getContextPath(URL url) {
        int pos = url.getPath().lastIndexOf("/");
        return pos > 0 ? url.getPath().substring(0, pos) : "";
    }

使用正常,两个方法应该不等价的。

Activity

  1. kezhenxu94 commented on Feb 10, 2019

    @kezhenxu94
    Member

    Related issue #2088

    Verified. I can reproduce this issue using the sample in https://github.com/apache/incubator-dubbo-samples/tree/master/dubbo-samples-rest(changing the dubbo version to 2.7.1-SNAPSHOT), will take more investigation in it. So this may be a bug?

  2. hewguo commented on Feb 11, 2019

    @hewguo
    Author

    一个最简单的rest例子:

    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xmlns:dubbo="http://dubbo.apache.org/schema/dubbo"
           xsi:schemaLocation="http://www.springframework.org/schema/beans
                               http://www.springframework.org/schema/beans/spring-beans-4.3.xsd
                               http://dubbo.apache.org/schema/dubbo
                               http://dubbo.apache.org/schema/dubbo/dubbo.xsd">
    
        <dubbo:application name="demo-provider" logger="slf4j"/>
        <dubbo:registry address="zookeeper://127.0.0.1:2181"/>
    
        <!-- use dubbo protocol to export service on port 20880 -->
        <dubbo:protocol name="dubbo" port="20880"/>
        <dubbo:protocol name="rest" port="8080" server="tomcat" />
    
        <bean id="demoService" class="com.nbport.dubbo.rest.ServiceImpl"/>
        <!-- declare the service interface to be exported -->
        <dubbo:service interface="com.nbport.dubbo.rest.ServiceFacade" ref="demoService" protocol="rest"/>
    
    </beans>
    

    @Path("demo")
    public class ServiceImpl implements ServiceFacade {
    
        @Override
        @Path("hello")
        @GET
        public String hello() {
            return "Hello World! ";
        }
    
        @Override
        @GET
        @Path("/error")
        public String error() {
            throw new RuntimeException();
        }
    }
    

    使用2.7.0的代码,在浏览器上是访问不到http://localhost:8080/demo/hello页面的,而用2.6.5的代码是可以的。代码跟了一下,2.7的代码getContextPath会返回接口的类名,如:“com.nbport.dubbo.rest.ServiceFacade”,而本例中原来版本返回的是“”。

  3. chickenlj commented on Feb 12, 2019

    @chickenlj
    Contributor

    Thanks for the report, I will take a look at this issue.

  4. xfbxag commented on Feb 18, 2019

    @xfbxag

    遇到了同样的问题

  5. ZhaoLoON commented on Feb 21, 2019

    @ZhaoLoON

    遇到了同样的问题,希望可以尽快修复

  6. netsail commented on Feb 28, 2019

    @netsail

    dubbo2.7版本也遇到了同样的问题了。
    failed to execute
    javax.ws.rs.NotFoundException: Could not find resource for full path: http://xxxxx.com/rest/getxxx
    at org.jboss.resteasy.core.registry.ClassNode.match(ClassNode.java:73)
    at org.jboss.resteasy.core.registry.RootClassNode.match(RootClassNode.java:48)
    at org.jboss.resteasy.core.ResourceMethodRegistry.getResourceInvoker(ResourceMethodRegistry.java:444)
    at org.jboss.resteasy.core.SynchronousDispatcher.getInvoker(SynchronousDispatcher.java:234)
    at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:171)
    at org.jboss.resteasy.plugins.server.servlet.ServletContainerDispatcher.service(ServletContainerDispatcher.java:220)
    at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:56)
    at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:51)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
    at org.apache.dubbo.rpc.protocol.rest.DubboHttpServer$RestHandler.handle(DubboHttpServer.java:89)
    at org.apache.dubbo.remoting.http.servlet.DispatcherServlet.service(DispatcherServlet.java:61)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:292)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:212)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:141)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:528)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1099)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:670)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1520)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1476)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    at java.lang.Thread.run(Thread.java:745)

  7. javaql commented on Feb 28, 2019

    @javaql

    获取到的contextPath是错误的,自己改了下这个方法打了个包好用了:

    protected String getContextPath(URL url) {
            int pos = url.getPath().lastIndexOf("/");
            return pos > 0 ? url.getPath().substring(0, pos) : "";
    }
    
  8. added a commit that references this issue on Mar 14, 2019
  9. added this to the 2.7.1 milestone on Mar 14, 2019
  10. changed the title [-]dubbo2.7 中RestProtocol.java getContextPath实现方式更改后无法注册rest服务[/-] [+]cannot register REST service in 2.7 due to the changes in RestProtoco#getContextPath[/+] on Mar 14, 2019
  11. yuxiao97 commented on May 2, 2019

    @yuxiao97

    I meet the same problem, when change dubbo version to 2.7.1 then fix it !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions