perwendel / spark

A simple expressive web framework for java. Spark has a kotlin DSL https://github.com/perwendel/spark-kotlin
Apache License 2.0
9.64k stars 1.56k forks source link

Using JSR356 with Spark and Tomcat #1111

Closed andersou closed 5 years ago

andersou commented 5 years ago

Hi! I'm trying to use Websockets in Spark by running Tomcat. But the Spark filter is blocking the route to the Websocket. One suggestion is to implement a parameter in the filter to add URL's that are excluded from the Spark filter.

andersou commented 5 years ago

My solution:


public class SparkWebSocketFilter extends SparkFilter {

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
        if(((HttpServletRequest)request).getServletPath().equals("/websocket")){
            chain.doFilter(request,response);
        }else
        super.doFilter(request, response, chain);
    }
}