@Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain)
            throws IOException {
        HttpServletRequest request = (HttpServletRequest) servletRequest;
        String uri = request.getRequestURI();
        String method = request.getMethod();
        try {
            if (isRegisterInstanceUri(uri, method)) {
                //register
                ClientAttributes attributes = getClientAttributes();
                RequestContextHolder.getContext()
                        .addExtensionContext(ClientAttributes.class.getSimpleName(), attributes);
            } else if (isBeatUri(uri, method)) {
                //beat
                String ip = WebUtils.optional(request, IP, StringUtils.EMPTY);
                int port = Integer.parseInt(WebUtils.optional(request, PORT, ZERO));
                String clientId = IpPortBasedClient.getClientId(ip + InternetAddressUtil.IP_PORT_SPLITER + port, true);
                IpPortBasedClient client = (IpPortBasedClient) clientManager.getClient(clientId);
                if (client != null) {
                    ClientAttributes requestClientAttributes = getClientAttributes();
                    //update clientAttributes,when client version attributes is null,then update.
                    if (canUpdateClientAttributes(client, requestClientAttributes)) {
                        client.setAttributes(requestClientAttributes);
                    }
                }
            }
        } catch (Exception e) {
            Loggers.SRV_LOG.error("handler client attributes error", e);
        }
        try {
            filterChain.doFilter(request, servletResponse);
        } catch (ServletException e) {
            throw new RuntimeException(e);
        }
    }
@Test
    void testDoFilterForBeatUri() throws IOException {
        when(request.getParameter("ip")).thenReturn("127.0.0.1");
        when(request.getParameter("port")).thenReturn("8848");
        when(request.getParameter("encoding")).thenReturn("utf-8");
        when(clientManager.getClient("127.0.0.1:8848#true")).thenReturn(client);
        when(request.getRequestURI()).thenReturn(
                UtilsAndCommons.NACOS_SERVER_CONTEXT + UtilsAndCommons.NACOS_NAMING_CONTEXT
                        + UtilsAndCommons.NACOS_NAMING_INSTANCE_CONTEXT + "/beat");
        when(request.getMethod()).thenReturn("PUT");
        filter.doFilter(request, response, new MockFilterChain());
        verify(client).setAttributes(any(ClientAttributes.class));
    }