package com.manage.service.webSocket;

import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;


public class StartFilter implements Filter {

    @Override
    public void destroy() {

    }
    @Override
    public void doFilter(ServletRequest arg0, ServletResponse arg1,
                         FilterChain arg2) throws IOException, ServletException {
        HttpServletRequest arg3 = (HttpServletRequest)arg0;
        String ctx = arg3.getContextPath();
        if("/power".equals(ctx)|| "/".equals(ctx)){
            arg3.getRequestDispatcher("/login").forward(arg3, arg1);
        }
    }
    @Override
    public void init(FilterConfig arg0) throws ServletException {
        this.startWebsocketInstantMsg();
    }

    /**
     * 启动即时聊天服务
     */
    public void startWebsocketInstantMsg() {
        //WebSocketImpl.DEBUG = false;
        WebServer s = new WebServer(8088);
        s.start();
    }
}