Skip to content
Snippets Groups Projects
Commit 62188cd9 authored by Adrian Nöthlich's avatar Adrian Nöthlich Committed by Marius Dumitru Florea
Browse files

XWIKI-22547: Make websocket work with Root servlet context (#3539)

(cherry picked from commit f696d5e2)
parent 13de9e9d
No related branches found
No related tags found
No related merge requests found
......@@ -84,9 +84,14 @@ public String url(String pathOrRoleHint)
XWikiContext xcontext = this.xcontextProvider.get();
StringBuilder path = new StringBuilder("/");
path.append(xcontext.getWiki().getWebAppPath(xcontext));
path.append("websocket").append(path(pathOrRoleHint));
// Test if installed with ROOT servlet context and avoid double slash.
String webAppPath = xcontext.getWiki().getWebAppPath(xcontext);
if (!"/".equals(webAppPath)) {
path.append(webAppPath);
}
path.append("websocket").append(path(pathOrRoleHint));
URL serverURL = xcontext.getURLFactory().getServerURL(xcontext);
String scheme = "https".equals(serverURL.getProtocol()) ? "wss" : "ws";
// We have to add the path afterwards because the URI constructor double encodes it.
......
......@@ -109,4 +109,11 @@ void urlWithException() throws Exception
"Failed to create WebSocket URL for [test]. Root cause is [MalformedURLException: Invalid server URL!].",
this.logCapture.getMessage(0));
}
@Test
void urlWithRootServletContext() {
when(this.xcontext.getWiki().getWebAppPath(xcontext)).thenReturn("/");
assertEquals("ws://www.xwiki.org:80/websocket/one/two", this.service.url("/one/two"));
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment