diff --git a/dubbo-rpc/dubbo-rpc-rest/src/main/java/org/apache/dubbo/rpc/protocol/rest/RestProtocol.java b/dubbo-rpc/dubbo-rpc-rest/src/main/java/org/apache/dubbo/rpc/protocol/rest/RestProtocol.java index 5b8149518ad..6265254d4c6 100644 --- a/dubbo-rpc/dubbo-rpc-rest/src/main/java/org/apache/dubbo/rpc/protocol/rest/RestProtocol.java +++ b/dubbo-rpc/dubbo-rpc-rest/src/main/java/org/apache/dubbo/rpc/protocol/rest/RestProtocol.java @@ -237,13 +237,17 @@ public void destroy() { */ protected String getContextPath(URL url) { String contextPath = url.getPath(); - if (contextPath.equalsIgnoreCase(url.getParameter(Constants.INTERFACE_KEY))) { + if (contextPath != null) { + if (contextPath.equalsIgnoreCase(url.getParameter(Constants.INTERFACE_KEY))) { + return ""; + } + if (contextPath.endsWith(url.getParameter(Constants.INTERFACE_KEY))) { + contextPath = contextPath.substring(0, contextPath.lastIndexOf(url.getParameter(Constants.INTERFACE_KEY))); + } + return contextPath.endsWith("/") ? contextPath.substring(0, contextPath.length() - 1) : contextPath; + } else { return ""; } - if (contextPath.endsWith(url.getParameter(Constants.INTERFACE_KEY))) { - contextPath = contextPath.substring(0, contextPath.lastIndexOf(url.getParameter(Constants.INTERFACE_KEY))); - } - return contextPath.endsWith("/") ? contextPath.substring(0, contextPath.length() - 1) : contextPath; } protected class ConnectionMonitor extends Thread {