Skip to content

Commit

Permalink
Force the container to use "/" instead of "" when looking up Endpoints
Browse files Browse the repository at this point in the history
This works around a bug in EAP where ServerEndpoints mounted at "/"
won't be activated if the Servlet has a mapping of "/*".
  • Loading branch information
tobias committed Aug 26, 2015
1 parent 82885d8 commit f8a633b
Showing 1 changed file with 15 additions and 8 deletions.
Expand Up @@ -33,8 +33,10 @@
* know all the pathInfos we need to register the endpoint under,
* because they are handled by frameworks in ruby/clojure at the app-level.
*
* So, this filter sends a request down the chain that doesn't have a pathInfo
* if the request is a websocket upgrade request.
* So, this filter sends a request down the chain (if the request is
* a websocket upgrade request) that doesn't have a pathInfo
* and returns "/" for servletPath when it is "" to workaround an EAP issue
* (https://bugzilla.redhat.com/show_bug.cgi?id=1256945).
*
* It also grabs the original ServletRequest in a ThreadLocal for the
* downstream handshake to use.
Expand All @@ -45,17 +47,16 @@ public class WebSocketHelpyHelpertonFilter implements Filter {

@Override
public void init(FilterConfig filterConfig) throws ServletException {

}

@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
if (request instanceof HttpServletRequest &&
!(request instanceof PathInfoRemovingRequestJacket) && // this filter has already been applied
!(request instanceof PathMungingRequestJacket) && // this filter has already been applied
"websocket".equalsIgnoreCase(((HttpServletRequest) request).getHeader("Upgrade"))) {
requestTL.set((HttpServletRequest)request);
try {
chain.doFilter(new PathInfoRemovingRequestJacket((HttpServletRequest) request), response);
chain.doFilter(new PathMungingRequestJacket((HttpServletRequest) request), response);
} finally {
requestTL.remove();
}
Expand All @@ -66,14 +67,20 @@ public void doFilter(ServletRequest request, ServletResponse response, FilterCha

@Override
public void destroy() {

}

class PathInfoRemovingRequestJacket extends HttpServletRequestWrapper {
public PathInfoRemovingRequestJacket(HttpServletRequest request) {
class PathMungingRequestJacket extends HttpServletRequestWrapper {
public PathMungingRequestJacket(HttpServletRequest request) {
super(request);
}

@Override
public String getServletPath() {
String superPath = super.getServletPath();

return "".equals(superPath) ? "/" : superPath;
}

@Override
public String getPathInfo() {
return null;
Expand Down

0 comments on commit f8a633b

Please sign in to comment.