@Override
    public void registerService(String serviceName, String groupName, Instance instance) throws NacosException {
        NAMING_LOGGER.info("[REGISTER-SERVICE] {} registering service {} with instance: {}", namespaceId, serviceName,
                instance);
        String groupedServiceName = NamingUtils.getGroupedName(serviceName, groupName);
        if (instance.isEphemeral()) {
            throw new UnsupportedOperationException(
                    "Do not support register ephemeral instances by HTTP, please use gRPC replaced.");
        }
        final Map<String, String> params = new HashMap<>(32);
        params.put(CommonParams.NAMESPACE_ID, namespaceId);
        params.put(CommonParams.SERVICE_NAME, groupedServiceName);
        params.put(CommonParams.GROUP_NAME, groupName);
        params.put(CommonParams.CLUSTER_NAME, instance.getClusterName());
        params.put(IP_PARAM, instance.getIp());
        params.put(PORT_PARAM, String.valueOf(instance.getPort()));
        params.put(WEIGHT_PARAM, String.valueOf(instance.getWeight()));
        params.put(REGISTER_ENABLE_PARAM, String.valueOf(instance.isEnabled()));
        params.put(HEALTHY_PARAM, String.valueOf(instance.isHealthy()));
        params.put(EPHEMERAL_PARAM, String.valueOf(instance.isEphemeral()));
        params.put(META_PARAM, JacksonUtils.toJson(instance.getMetadata()));
        reqApi(UtilAndComs.nacosUrlInstance, params, HttpMethod.POST);
    }
@Test
    void testRegisterServiceThrowsException() throws Exception {
        assertThrows(NacosException.class, () -> {
            
            NacosRestTemplate nacosRestTemplate = mock(NacosRestTemplate.class);
            HttpRestResult<Object> a = new HttpRestResult<Object>();
            a.setCode(503);
            // makes exchangeForm failed with a NullPointerException
            when(nacosRestTemplate.exchangeForm(any(), any(), any(), any(), any(), any())).thenReturn(null);
            
            final Field nacosRestTemplateField = NamingHttpClientProxy.class.getDeclaredField("nacosRestTemplate");
            nacosRestTemplateField.setAccessible(true);
            nacosRestTemplateField.set(clientProxy, nacosRestTemplate);
            String serviceName = "service1";
            String groupName = "group1";
            Instance instance = new Instance();
            instance.setEphemeral(false);
            
            try {
                clientProxy.registerService(serviceName, groupName, instance);
            } catch (NacosException ex) {
                // verify the `NacosException` is directly thrown
                assertTrue(ex.getErrMsg().contains("java.lang.NullPointerException"));
                assertEquals(NacosException.SERVER_ERROR, ex.getErrCode());
                
                throw ex;
            }
        });
    }