遇到该问题时,是由于客户端非正常关闭引起的,此时需要在onError中调用onClose来关闭链接,在onError中只能使用onClose方法,其他方法并不可用
@OnError
public void onError(Session session, Throwable error,@PathParam("type") Integer type,@PathParam("id") Integer id, @PathParam("uid") Integer uid) {
System.out.println("发生错误");
error.printStackTrace();
onClose(session,type,id,uid);//发生异常时候调用关闭错误连接
}
因为ws中一旦会话关闭调用其任何方法(close()方法除外)将导致抛出{@link java.lang.IllegalStateException}