Skip to content

Commit 5e6cbbe

Browse files
chickenljbeiwei30
authored andcommitted
check null for path before call rest server (#3665)
1 parent 70898ef commit 5e6cbbe

File tree

1 file changed

+9
-5
lines changed
  • dubbo-rpc/dubbo-rpc-rest/src/main/java/org/apache/dubbo/rpc/protocol/rest

1 file changed

+9
-5
lines changed

dubbo-rpc/dubbo-rpc-rest/src/main/java/org/apache/dubbo/rpc/protocol/rest/RestProtocol.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -237,13 +237,17 @@ public void destroy() {
237237
*/
238238
protected String getContextPath(URL url) {
239239
String contextPath = url.getPath();
240-
if (contextPath.equalsIgnoreCase(url.getParameter(Constants.INTERFACE_KEY))) {
240+
if (contextPath != null) {
241+
if (contextPath.equalsIgnoreCase(url.getParameter(Constants.INTERFACE_KEY))) {
242+
return "";
243+
}
244+
if (contextPath.endsWith(url.getParameter(Constants.INTERFACE_KEY))) {
245+
contextPath = contextPath.substring(0, contextPath.lastIndexOf(url.getParameter(Constants.INTERFACE_KEY)));
246+
}
247+
return contextPath.endsWith("/") ? contextPath.substring(0, contextPath.length() - 1) : contextPath;
248+
} else {
241249
return "";
242250
}
243-
if (contextPath.endsWith(url.getParameter(Constants.INTERFACE_KEY))) {
244-
contextPath = contextPath.substring(0, contextPath.lastIndexOf(url.getParameter(Constants.INTERFACE_KEY)));
245-
}
246-
return contextPath.endsWith("/") ? contextPath.substring(0, contextPath.length() - 1) : contextPath;
247251
}
248252

249253
protected class ConnectionMonitor extends Thread {

0 commit comments

Comments
 (0)